akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    ll n, k; cin >> n >> k;
    ll ans = 0;

    repr(b, k+1, n+1){
        ll p = n/b;
        ans += (b-k) * p;
        if(k == 0) --ans;
        if(p*b+k <= n) ans += (n - (p*b+k) + 1);
    }
    cout << ans << endl;

    
    return 0;
}

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

int main(){
    int n,b=0,c=0,a[100000];
    long long ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){b=1;}
        if(a[i]<0){c++;}
        a[i]=abs(a[i]);
        }
    sort(a,a+n);
    if(b==0 && c%2==1){
        for(int i=1;i<n;i++){ans+=a[i];}
        ans-=a[0];
    }
    else{
        for(int i=0;i<n;i++){ans+=a[i];}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
n=int(input())
A=[[0 for i in range(9)] for j in range(9)]
for i in range(1,n+1):
  if i%10!=0:
    num=str(i)
    A[int(num[0])-1][int(num[-1])-1] +=1

cnt=0
for i in range(9):
  for j in range(9):
    cnt +=A[i][j]*A[j][i]
print(cnt)

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

int main() {
    int n;
    cin >> n ;
    vector <int> A(n);
    int ans;
    ans = 0;
    for( int i = 0; i < n; ++i){
      cin >> A.at(i);
    }
    for( int i = 0; i <= n - 3 ; ++i){
        if( max( A.at(i),A.at(i+1)) == A.at(i+1) && max( A.at(i+1),A.at(i+2)) == A.at(i+2)){
            ans += 1;
        }
        else if( max( A.at(i),A.at(i+1))== A.at(i) && max( A.at(i+1),A.at(i+2))==A.at(i+1)){
            ans +=1;
        }
        else{
            ans +=0;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll bit_count(ll a){
  ll ret=0;
  while(a>0){
    ret+=a%2;
    a/=2;
  }
  return ret;
}
ll norikae(ll a,ll b){
  ll keta=0;
  ll b1=b;
  while(b1>1){
    b1/=2;
    keta++;
  }
  //cout<<"KT:"<<keta<<endl;
  ll sum=0;
  for(int i=keta;i>=0;i--){
    ll bt=(b>>i)&1;
    sum+=(bt<<i);
    //cout<<"S:"<<sum<<" "<<i<<" "<<bt<<endl;
    if(sum>=a) return sum;
  }
  return -1;
}
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    if(a*b<=0) {
      if(a<0) a*=-1;
      if(b<0) b*=-1;
      cout<<bit_count(a)+bit_count(b)<<endl;
      continue;
    }
    a=max(a,-a);
    b=max(b,-b);
    if(a>b) swap(a,b);
    ll change=norikae(a,b);
    cout<<bit_count(change-a)+bit_count(b-change)<<endl;
  }
}



Measured memory_bytes: 3096
#include <stdio.h>

int main(){
	int n, i;
	double a[3], b[3], d;
	
	scanf("%d", &n);
	
	while(n--){
		for(i = 0; i < 3; i++) scanf("%lf", &a[i]);
		for(i = 0; i < 3; i++) scanf("%lf", &b[i]);
		
		d = (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]);
		
		if(d > (a[2] + b[2]) * (a[2] + b[2]))
			printf("0\n");
		else if(a[2] > b[2] && (a[2] - b[2]) * (a[2] - b[2]) > d)
			printf("2\n");
		else if(b[2] > a[2] && (b[2] - a[2]) * (b[2] - a[2]) > d)
			printf("-2\n");
		else
			printf("1\n");
	}
}

Measured memory_bytes: 620
N = int(input())
A = list(map(int,input().split()))

xorsum = A[0]
right = 0
ans = 0
for left in range(N):
    if right < N-1:
        while xorsum+A[right+1]==xorsum^A[right+1]:
            right += 1
            xorsum += A[right]
            if right == N-1:
                break
        xorsum -= A[left]
    ans += right-left+1
    
print(ans)

Measured memory_bytes: 24424
N,M = map(int, input().strip().split(' '))
graph_dict = {}
for _ in range(M):
  a,b = map(int, input().strip().split(' '))
  if a in graph_dict:
    graph_dict[a].add(b)
  else:
    graph_dict[a] = {b}
  if b in graph_dict:
    graph_dict[b].add(a)
  else:
    graph_dict[b] = {a}

def search(now, visited):
  #print(now, visited)
  if len(visited)+1 == N:
    return 1
  if len(graph_dict[now]-visited) == 0:
    return 0
  return sum(search(n, visited|{now}) for n in graph_dict[now]-visited)
  

print(search(1, set()))

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

const int N = 60;

int n, m; //頂点数,辺数

int adj[N][N]; //隣接行列
int v[N]; //訪問フラグ

void dfs(int i, int n){
  v[i] = 1;

  for(int j=0; j<n; j++){
    if(adj[i][j] == 1 && v[j] == 0) dfs(j, n);
  }
}

void reset(int n){
  for(int i=0; i<n; i++) v[i] = 0;
}

int main(){
  int i, j;
  int ans = 0;
  cin >> n >> m;


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

  int a[m],b[m];

  for (i=0; i<m; i++){
    cin >> a[i] >> b[i];
    adj[a[i]-1][b[i]-1] = 1;
    adj[b[i]-1][a[i]-1] = 1;
  }

/*
  cout << "adj" << endl;
  for (i=0; i<n; i++){
    for (j=0; j<n; j++){
      cout << adj[i][j] << " ";
    }
    cout << endl;
  }
*/

  for(i=0; i<m; i++){
    reset(n);
    adj[a[i]-1][b[i]-1] = 0;
    adj[b[i]-1][a[i]-1] = 0;
    dfs(a[i]-1, n);
//    cout << "i: " << i << endl;
    for (j=0; j<n; j++){
      if(v[j] == 0){ ans++; break; }
//      cout << "j: " << j << ", v[j]: " << v[j] << "\t";
    }
//    cout << endl;
    adj[a[i]-1][b[i]-1] = 1;
    adj[b[i]-1][a[i]-1] = 1;
  }

  cout << ans << endl;

  return 0;
}


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

int ds[] = {5, 9, 13};
int dx[] = {0, 0, -1, 0, 1, -1, -1, 1, 1, 0, -2, 0, 2};
int dy[] = {0, -1, 0, 1, 0, -1, 1, 1, -1, -2, 0, 2, 0};

int main()
{
  int x, y, s;
  vector<vector<int> > paper(10, vector<int>(10, 0));
  while (scanf("%d,%d,%d", &x, &y, &s) != EOF) {
    for (int i = 0; i < ds[s-1]; ++i) {
      int xx = x + dx[i];
      int yy = y + dy[i];

      if (xx >= 0 && xx < 10 && yy >= 0 && yy < 10)
	++paper[yy][xx];
    }
  }

  int plain = 0, con = 0;
  for (int i = 0; i < paper.size(); ++i) {
    for (int j = 0; j < paper[0].size(); ++j) {
      if (paper[i][j] == 0)
	++plain;
      con = max(con, paper[i][j]);
    }
  }
  
  cout << plain << endl << con << endl;

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final char[] string = scanner.nextLine().toCharArray();

        final StringBuilder stringA = new StringBuilder();
        boolean flag = true;
        for (int i = 0; i < string.length; i++) {
            if (flag) {
                stringA.append("0");
            } else {
                stringA.append("1");
            }
            flag = !flag;
        }
        final char[] a = stringA.toString().toCharArray();

        final StringBuilder stringB = new StringBuilder();
        flag = false;
        for (int i = 0; i < string.length; i++) {
            if (flag) {
                stringB.append("0");
            } else {
                stringB.append("1");
            }
            flag = !flag;
        }
        final char[] b = stringB.toString().toCharArray();

        int resultA = 0;
        int resultB = 0;

        for (int i = 0; i < string.length; i++) {
            if (string[i] != a[i]) {
                resultA++;
            }

            if (string[i] != b[i]) {
                resultB++;
            }
        }

        System.out.println(Math.min(resultA, resultB));
    }
}


Measured memory_bytes: 30028
x,y,m = map(int,input().split())
row = {}
ch = set()
column = {}
for i in range(m):
	h,k = map(int,input().split())
	ch.add((h,k))
	if h in row:
		row[h] += 1
	else:
		row[h] = 1

	if k in column:
		column[k] += 1
	else:
		column[k] = 1


r_max = 0
c_max = 0

for i in row:
	r_max = max(r_max,row[i])
for j in column:
	c_max = max(c_max,column[j])

r_inx = []
w_inx = []

for i in row:
	if row[i] == r_max:
		r_inx.append(i)
for j in column:
	if column[j] == c_max:
		w_inx.append(j)

flag = 0
for i in r_inx:
	for j in w_inx:
		if (i,j) not in ch:
			flag = 1
			break
if flag == 0:
	print(r_max+c_max-1)
else:
	print(r_max+c_max)

Measured memory_bytes: 80428
#include <bits/stdc++.h>
#define LL long long
#define db double

using namespace std;


typedef pair<int, int> pii;
#define X first
#define Y second
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool fg = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            fg = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (fg) {
        x = -x;
    }
}

const int MAXN = 100100;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;

int n, m;

signed main() {
	read(n), read(m);
	printf("%d\n", n + m / 2);
	return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,T;
  cin >> n >> T;
  int c[n],t[n];
  int min = 10000;
  REP(i,n){
    cin >> c[i] >> t[i];
    if(t[i] <= T){
      chmin(min,c[i]);
    }
  }
  if(min==10000){
    cout << "TLE" << endl;
  }else{
    cout << min << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a=0, b = 0,c,d, n, k;
string s, t;


int main()
{

	cin >> a >> b >> c;
	if ((a == b && a != c) || (b == c && a != b || a == c && b != a))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;

int main(void){
    int n;cin>>n;
    if(n==1)cout<<"Hello World\n";
    else{
        int a,b;cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)

//string s = to_string(i);

//char→小文字のほうが大きい数値　　&&　その差は32

//大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, n = 0, sum = 0, i = 0;
string s = ""; asas; cncn;

int main(void){
	int k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; i++) {
		if (i <= a + k - 1 || i >= b - k + 1)cout << i << rt;
	}
	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans = "";
    rep(i, n) ans += s[i], ans += t[i];
    cout << ans << endl;
}

Measured memory_bytes: 3652
S = input()
N = len(S)

arr = [0] * N

R = 0
for i in range(N - 1):
    if S[i] == "R":
        R += 1
    if S[i + 1] == "L":
        arr[i + 1] += R // 2
        arr[i] += (R + 1) // 2
        R = 0

L = 0

for i in range(N - 1, 0, -1):
    if S[i] == "L":
        L += 1
    if S[i - 1] == "R":
        arr[i - 1] += L // 2
        arr[i] += (L + 1) // 2
        L = 0

print(*arr)

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

using   namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define  all(v)       (v).begin(),(v).end()
#define  rall(v)      (v).rbegin(),(v).rend()
#define  pb           push_back  
#define  eb           emplace_back
#define  mp           make_pair
#define  ff           first
#define  ss           second
#define  pf           push_front
#define  bs           binary_search
#define  lb           lower_bound
#define  ub           upper_bound
#define  umap         unordered_map
#define  uset         unordered_set
#define  dec(x)       fixed<<setprecision(x)
#define  lcm(a,b)    (a*b/__gcd(a,b))

typedef  priority_queue<ll>  pq;
typedef  priority_queue<ll,vector<ll>,greater<ll>> pqmn;
typedef  pair<ll,ll> pll;

const    ll inf=LLONG_MAX;
const    ll mod=1e9+7;
const    ld pi=acos(-1);
                    
void solution(){
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=0;
    ll stool=a[0];
    for(int i=1;i<n;i++){
        if(a[i]<stool){
            ans+=(stool-a[i]);
        }
        else{
            stool=a[i];
        }
    }
cout<<ans;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    t=1;
 //   cin>>t;
    while(t--){
        solution();
        cout<<"\n";
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int count=0;
    vector<int> vec(n);
    rep(i,n){
        char c;
        cin >> c;
        if(c=='1'){
            count++;
            vec[i]=1;
        }
        else vec[i]=0;
    }
    vector<int> plus(n+1);
    vector<int> minus(n+1);
    vector<int> beki(n+1),beki2(n+1);
    plus[0]=0;minus[0]=0;
    rep(i,n){
        int x=vec[i];
        plus[i+1]=(plus[i]*2+x)%(count+1);
    }
    if(count!=1)rep(i,n){
        int x=vec[i];
        minus[i+1]=(minus[i]*2+x)%(count-1);
        
    }
    beki[0]=1;beki2[0]=1;
    rep(i,n){
        beki[i+1]=(beki[i]*2)%(count+1);
    }
    if(count!=1)rep(i,n){
        beki2[i+1]=(beki2[i]*2)%(count-1);
    }
    rep(i,n){
        int x=vec[i];
        
        if(x==0){
            int y=plus[n];
            y+=beki[n-i-1];
            y=y%(count+1);
            int ans=1;
            while(y!=0){
                bitset<30> bit(y);
                y=y%(bit.count());
                ans++;
            }
            cout << ans << endl;
        }
        else if(count!=1){
            int y= minus[n];
 
            y=y-beki2[n-i-1];

            y=(y+count-1)%(count-1);

            int ans=1;
            while(y!=0){
                bitset<30> bit(y);
                y=y%(bit.count());
                ans++;
            }
            cout << ans << endl;

        }
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 7216
using namespace std;
    #include<iostream>
    #include <math.h>
    #include<iomanip>
    #define diff(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))
    int fact(int k) {
      int sum = 1;
      for (int i = 1; i <= k; ++i) {
        sum *= i;
      }
      return sum;
    }
    int main() {
      pair<int, int> N[8];
      int x = 0;
      cin >> x;
      for (int j = 0; j < x; j++) {
        int a, b;
        cin >> a >> b;
        N[j] = make_pair(a, b);
      }
      int n = fact(x);
      double ans = 0.0, mul = n / x * 2;
      for (int i = 0; i < x; i++) {
        for (int j = i + 1; j < x; j++) {
          int l = diff(N[i].first, N[j].first);
          int m = diff(N[i].second, N[j].second);
          ans += sqrt(((double) (l * l + m * m)));
        }
      }
      ans = ans/x*2;
      cout << setprecision(20) << ans;
      return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    ll n;
    cin >> n;
    ll ans;
    for(int i=1;i<=n+1;i++){
        if(i*i>n) {
            ans=i-1;
            break;
        }
    }
    cout << ans*ans<<endl;
    return 0;
}

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

int main() {
  string S , T , U;
  int A , B;
 cin >> S >> T >> A >> B >> U;
  
  if (S == U)  A--;
   
  else  B--;
  
  cout << A << " " << B << endl;
  
  }
   


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N;
    vector<ll> A(N);
    REP(i,N){
        cin>>A.at(i);
    }

    if(N==1){
        cout << 0 <<endl;
    }
    else{
            ll takasa=A.at(0);
            ll ans=0;
        REPS(i,N-1){
            if(takasa<=A.at(i)){
                takasa=A.at(i);
            }
            else{
                ans+=(takasa-A.at(i));
            }
        }
        cout << ans <<endl;
    }


}


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


int main (){
  int N,M,C;
  cin>>N>>M>>C;
  vector<int>B(M);
  int count;
  int f;
  
  for(int i=0;i<M;i++){
    cin>>B.at(i);
  }
  for(int j=1;j<N+1;j++){
    vector<int>A(M);
    int sum=0;
    for(int k=0;k<M;k++){
      cin>>A.at(k);
      f=A.at(k)*B.at(k);
      sum+=f;
    }
    
    if(sum+C>0){
     count++;
    }
  }
 cout<<count<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
	int n, i, x;
	scanf("%d", &n);

	for (i = 1;i <= n;i++) {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				x /= 10;
			} while (x);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2100
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(h: i64, n: i64, mut a: [i64; n]);

    let ans = if a.iter().sum::<i64>() >= h {
        "Yes"
    } else {
        "No"
    };

    println!("{}", ans);
}


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

int main() {
  int a;
  string s1;
  cin >> a;
  cin >> s1;

    
  if ( 2*int(a/2)==a ){
    if ( s1.substr(0,a/2)==s1.substr(a/2) ) {
        cout << "Yes";
        return 0;
    }
  }
  cout << "No";
}

Measured memory_bytes: 256
A,B,C = [int(_n) for _n in input().split()]
K = int(input())

for i in range(8):
    for j in range(8):
        for k in range(8):
            if i + j + k> K:
                continue
            a = A * 2**i
            b = B * 2**j
            c = C * 2**k
            if a < b < c:
                print("Yes")
                exit(0)
print("No")

Measured memory_bytes: 61744
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] tri = new int[3];
		int[] c = new int[3];
		int flag = 1;
		while(true) {
			tri[0] = sc.nextInt();
			tri[1] = sc.nextInt();
			tri[2] = sc.nextInt();
			Arrays.sort(tri);
			if(tri[0]+tri[1] <= tri[2]) {
				System.out.println((c[0]+c[1]+c[2])+" "+c[0]+" "+c[1]+" "+c[2]);
				break;
			}
			int cheak = tri[0]*tri[0] + tri[1]*tri[1] - tri[2]*tri[2];
			if(cheak < 0) c[2]++;
			else if(cheak > 0)c[1]++;
			else c[0]++;
		}
	}
}



Measured memory_bytes: 26476
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n,d;
	cin>>n>>d;
	d=d*d;
	int cnt=0;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		x=abs(x);
		y=abs(y);
		ll dist=(x*x)+(y*y);
		
		if(dist<=d)
		cnt++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[1000];
    cin>>n;
    for (int i = 0; i < n; i++) cin>>a[i];
    sort(a,a+n);
    long long int sum = 0;
    for (int i=0;i<n;i++ )sum+=a[i];
   int     p=0;
    while(sum%10==0&&sum>0&&p<n){
            if (a[p]%10!=0)
        sum=sum-a[p];
        p++;
    }
    if (sum%10!=0)cout<<sum;
    else cout<<"0";
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

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

        ind = bisect_right(D, D[i] + D[j] - 1)
        count += max(ind - j - 1, 0)

print(count)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll h, w;
    cin >> h >> w;
    string s;
    vvll a(h, vll(w));
    REP(i, h){
        cin >> s;
        REP(j, w){
            if(s[j] == '.') a[i][j] = 1;
        }
    }
    ll cnt;
    vector<queue<ll>> qx(h), qy(w);
    vvll px(h, vll(w)), py(h, vll(w));
    REP(i, h){
        cnt = 0;
        REP(j, w){
            if(a[i][j]){
                cnt++;
                if(j == w - 1) qx[i].push(cnt);
            }
            if(!a[i][j]){
                qx[i].push(cnt);
                cnt = 0;
            }
        }
        REP(j, w){
            if(a[i][j]) px[i][j] = qx[i].front();
            else qx[i].pop();
        }
    }
    REP(j, w){
        cnt = 0;
        REP(i, h){
            if(a[i][j]){
                cnt++;
                if(i == h - 1) qy[j].push(cnt);
            }
            if(!a[i][j]){
                qy[j].push(cnt);
                cnt = 0;
            }
        }
        REP(i, h){
            if(a[i][j]) py[i][j] = qy[j].front();
            else qy[j].pop();
        }
    }
    
    ll res = 0;
    REP(i, h){
        REP(j, w){
            res = max(res, px[i][j] + py[i][j] - 1);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 99456
while True:
    a = list(map(int, input().split()));
    if (a[0] == -1) and (a[1] == -1) and (a[2] == -1):
        break;
    if a[0] == -1 or a[1] == -1:
        print('F');
    elif a[0] + a[1] >= 80:
        print('A');
    elif a[0] + a[1] < 80 and a[0] + a[1] >= 65:
        print('B');
    elif a[0] + a[1] < 65 and a[0] + a[1] >= 50:
        print('C');
    elif a[0] + a[1] < 50 and a[0] + a[1] >= 30 and a[2] >= 50:
        print('C');
    elif a[0] + a[1] < 50 and a[0] + a[1] >= 30:
        print('D');
    elif a[0] + a[1] < 30:
        print('F');


Measured memory_bytes: 5604
import java.util.Arrays;
import java.util.Scanner;

//ICPC: Intelligent Congruent Partition of Chocolate
public class Main{

	int w, h, si, sj, ti, tj, N, c;
	int[][] a;
	int[] sum;
	boolean[][] u;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};

	boolean cancel(int t){
		if(t<0)return false;
		int i = t/w, j = t%w;
		if(a[i][j]!=-1)return false;
		int cnt = 0;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w&&a[ni][nj]==-1)cnt++;
		}
		return cnt==0;
	}
	
	boolean dfs(int i, int j, int rot, int rev, int num){
		if(num==(N>>1)){
			for(boolean[]v:u)Arrays.fill(v, false);
			c = 0;
			check(si, sj, -1);
			if(c!=(N>>1))return false;
			c = 0;
			check(ti, tj, -2);
			return c==(N>>1);
		}
		if(i==h || (N>>1)-num > sum[i*w+j] || cancel(i*w+j-w-1))return false;
		if(j==w)return dfs(i+1, 0, rot, rev, num);
		if(a[i][j]==1){
			a[i][j] = -1;
			int di = i-si, dj = j-sj;
			int ni, nj;
			if(rot==0){
				ni = di; nj = dj;
			}
			else if(rot==1){
				ni = dj; nj = -di;
			}
			else if(rot==2){
				ni = -di; nj = -dj;
			}
			else{
				ni = -dj; nj = di;
			}
			if(rev==1)nj*=-1;
			int ki = ti+ni, kj = tj+nj;
			if(0<=ki&&ki<h&&0<=kj&&kj<w&&a[ki][kj]==1){
				a[ki][kj] = -2;
				if(dfs(i, j+1, rot, rev, num+1))return true;
				a[ki][kj] = 1;
			}
			a[i][j] = 1;
		}
		return dfs(i, j+1, rot, rev, num);
	}
	
	void check(int i, int j, int x){
		if(u[i][j])return;
		u[i][j] = true;
		c++;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(ni < 0 || h <= ni || nj < 0 || w <= nj || a[ni][nj]!=x)continue;
			check(ni, nj, x);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			N = 0;
			a = new int[h][w];
			u = new boolean[h][w];
			sum = new int[h*w+1];
			si = sj = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				a[i][j] = sc.nextInt();
				if(a[i][j]==1){
					N++;
					if(si==-1){
						si = i; sj = j;
					}
				}
			}
			if((N&1)==1){
				System.out.println("NO"); continue;
			}
			for(int i=h-1;i>=0;i--)for(int j=w-1;j>=0;j--)sum[i*w+j] = sum[i*w+j+1]+a[i][j];
			boolean res = false;
			a[si][sj] = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(a[i][j]==1){
				ti = i; tj = j;
				a[i][j] = -2;
				for(int rot=0;rot<4;rot++)for(int rev=0;rev<2;rev++){
					if(dfs(0, 0, rot, rev, 1)){
						res = true;
					}
					if(res)break;
				}
				a[i][j] = 1;
			}
			System.out.println(res?"YES":"NO");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> vec(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> vec[i][j];
    }
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (vec[y][x] == '#') {
        bool ok = false;
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k];
          int nx = x + dx[k];
          if (ny >= 0 && ny < h && nx >= 0 && nx < w && vec[ny][nx] == '#') {
            ok = true;
          }
        }
        if (!ok) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

#define ll long long int
#define pi pair<int,int>
#define M 998244353

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ll dp[c+7][d+7]={};
    dp[a][b]=1;
    for(int i=b+1;i<=d;i++)
        dp[a][i]=(dp[a][i-1]*a)%M;
    for(int i=a+1;i<=c;i++)
        dp[i][b]=(dp[i-1][b]*b)%M;
    for(int i=a+1;i<=c;i++)
    {
        for(int j=b+1;j<=d;j++)
        {
            dp[i][j]=(dp[i-1][j]*j)%M+(dp[i][j-1]*i)%M-((i-1)*(j-1)*dp[i-1][j-1]+M)%M;
            dp[i][j]+=M;
            dp[i][j]%=M;
        }
    }
    cout<<dp[c][d]<<endl;
    return 0;
}



Measured memory_bytes: 74104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            int k = Integer.parseInt(str[0]);
            int s = Integer.parseInt(str[1]);
            int count = 0;
            for (int x = 0; x <= k; x++) {
                for (int y = 0; y <= k; y++) {
                    if (x + y > s) {
                        break;
                    }
                    int z = s - (x + y);
                    if (z <= k) {
                        count++;
                    }
                }
            }
            System.out.println(count);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 9044
#include <cassert>
#include <cmath>
#include <cstdio>

int main() {
  int n = 0;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    float x1, y1, x2, y2, x3, y3;
    scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);

    // x^2 + y^2 + lx + my + n = 0

    float A[3][3] = { {x1, y1, 1}, {x2, y2, 1}, {x3, y3, 1} };
    // detA = a00a11a22 + a10a21a02 + a20a01a12 - a00a21a12 - a20a11a02 - a10a01a22
    float detA =
        A[0][0] * A[1][1] * A[2][2]
      + A[1][0] * A[2][1] * A[0][2]
      + A[2][0] * A[0][1] * A[1][2]
      - A[0][0] * A[2][1] * A[1][2]
      - A[2][0] * A[1][1] * A[0][2]
      - A[1][0] * A[0][1] * A[2][2];

    assert(detA != 0);
    float invA[3][3] = {
        { (A[1][1] * A[2][2] - A[1][2] * A[2][1]) / detA,
          (A[0][2] * A[2][1] - A[0][1] * A[2][2]) / detA,
          (A[0][1] * A[1][2] - A[0][2] * A[1][1]) / detA },
        { (A[1][2] * A[2][0] - A[1][0] * A[2][2]) / detA,
          (A[0][0] * A[2][2] - A[0][2] * A[2][0]) / detA,
          (A[0][2] * A[1][0] - A[0][0] * A[1][2]) / detA },
        { (A[1][0] * A[2][1] - A[1][1] * A[2][0]) / detA,
          (A[0][1] * A[2][0] - A[0][0] * A[2][1]) / detA,
          (A[0][0] * A[1][1] - A[0][1] * A[1][0]) / detA }
    }; 

    float b[3] = {-(x1 * x1 + y1 * y1), -(x2 * x2 + y2 * y2), -(x3 * x3 + y3 * y3)};
    
    float l = invA[0][0] * b[0] + invA[0][1] * b[1] + invA[0][2] * b[2];
    float m = invA[1][0] * b[0] + invA[1][1] * b[1] + invA[1][2] * b[2];
    float n = invA[2][0] * b[0] + invA[2][1] * b[1] + invA[2][2] * b[2];
      
    // (x + l/2)^2 - l^2/4 + (y + m/2)^2 - m^2/4 + n = 0;
    // (x, y) = (-l/2, -m/2)
    // r = l^2/4 + m^2/4 - n
    float px = -l / 2;
    float py = -m / 2;
    float r = std::sqrt(l * l / 4.0 + m * m / 4.0 - n);
    
    printf("%.3f %.3f %.3f\n", px, py, r);
  }
}

Measured memory_bytes: 1072
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
a =0
while a < x:
    a+=111
print(a)

Measured memory_bytes: 5276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

const int N=2e6+100;

struct p{
    int a,b;
    int id;
    int type;
}v[N];

bool comp(const p& A,const p& B){
    if(A.type!=B.type) return A.type<B.type;
    if(A.type==2){
        if(A.b!=B.b){
            return A.b<B.b;
        }else{
            return A.a>B.a;
        }
    }
    if(A.type==3){
        return A.a>B.a;
    }
    return A.type<B.type;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
        int a=0,b=0;
        for(char c:s[i]){
            if(c=='('){
                a++;
            }else{
                if(a>0)a--;
                else b++;
            }
        }
        v[i].id=i+1;
        v[i].a=a; v[i].b=b;
        if(a+b==0){
            v[i].type=0;
        }
        else if(a>0&&b==0){
            v[i].type=1;
        }
        else if(a>0&&b>0&&a-b>=0){
            v[i].type=2;
        }
        else if(a>0&&b>0){
            v[i].type=3;
        }
        else{
            v[i].type=4;
        }
    }
    sort(v,v+n,comp);
    int now=0;
    bool ok=1;
    for(int i=0;i<n;i++){
        if(now-v[i].b<0)ok=0;
        now-=v[i].b;
        now+=v[i].a;
    }
    if(now!=0)ok=0;
    if(!ok){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 50032
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int par[MAXN];
int chead[MAXN],cnxt[MAXN];
int mem[MAXN];
int cur[MAXN],ncur;

int dfs(int at) {
	for(int to=chead[at];to!=-1;to=cnxt[to]) dfs(to);
	ncur=0; for(int to=chead[at];to!=-1;to=cnxt[to]) cur[ncur++]=mem[to];
	sort(cur,cur+ncur); reverse(cur,cur+ncur); REP(i,ncur) cur[i]+=i+1;
	int ret=ncur; REP(i,ncur) if(cur[i]>ret) ret=cur[i]; return mem[at]=ret;
}

void run() {
	scanf("%d",&n);
	par[0]=-1; FOR(i,1,n) scanf("%d",&par[i]),--par[i];
	REP(i,n) chead[i]=-1;
	FOR(i,1,n) cnxt[i]=chead[par[i]],chead[par[i]]=i;
	int ret=dfs(0);
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 4864
/*
* @author:  codancer
* @createTime:  2020-04-04, 20:14:09
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
set<ll> all;
void dfs(ll now){
	if(now>3234566667) return ;
	// cout<<now<<endl;
	if(all.size()>300000){
		return ;
	}
	all.insert(now);
	ll x=now%10;
	if(x>=1){
		dfs(now*10+(x-1));
	}
	if(x+1<=9){
		dfs(now*10+x+1);
	}
	dfs(now*10+x);
}
int main(){
	int k;
	cin>>k;
	rep(i,1,9){
		dfs(i);
	}
	VII a;
	for(ll v:all){
		a.pb(v);
	}
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 6136
#include<string.h>
#include<stdio.h>
int main()
{
	int h,b,i,j;
	char r[5],a[5];
	while(1){
		scanf("%s %s",r,a);
		if(strcmp(r,"0")==0&&strcmp(a,"0")==0){
			break;
		}
		h=0;
		b=0;
		for(i=0;i<4;i++){
			if(r[i]==a[i]){
				h++;
				r[i]='r';
				a[i]='a';
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(r[i]==a[j]){
					b++;
					r[i]='r';
					a[j]='a';
				}
			}
		}
		printf("%d %d\n",h,b);
	}
	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[200005];
bool x[1000005],y[1000005];
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=1000000;i++){
        x[i]=true;
        y[i]=false;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(x[a[i]]==true&&y[a[i]]==false){
            y[a[i]]=true;
            for(int j=a[i]*2;j<=1000000;j=j+a[i]){
                x[j]=false;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(x[a[i]]==true){
            if(i!=0){
                if(a[i]!=a[i-1]&&a[i]!=a[i+1]){
                    ans++;
                }
            }else {
                if(a[i]!=a[i+1]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;


}



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

int main() {
    int n;
    cin >> n;
    vector<int>v (n + 1, 0);

    for(int x = 1; x*x <= n; x++) {
        for(int y = x; y*y <= n; y++) {
            for(int z = y; z*z <= n; z++) {
                ll ans = x*x + y*y + z*z + (x*y + y*z + x*z);
                if(ans > n)
                    break;
                if(x != y && y != z)
                    v[ans] += 6;
                else if(x == y && y == z) {
                    v[ans] += 1;
                } else
                    v[ans] += 3;
            }
        }
    }

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

}


Measured memory_bytes: 3548
class Q1051
  def citation n,ary
    p = ary[0]
    start = ary[0]
    for i in 1..n-1
      if ary[i] == p+1 
        p += 1
      else 
        if start == p
          print(p.to_s + " ")
        else
          print(start.to_s + "-" + p.to_s + " ")
        end
        p = ary[i]
        start = ary[i]
      end
    end
    if start == p
       puts p
    else
       puts(start.to_s + "-" + p.to_s)
    end
  end
  def doIt
    n = gets.to_i
    while n > 0
      ary = gets.split(" ").map {|x| x.to_i}
      citation n,ary
      n = gets.to_i
    end
  end
end

Q1051.new.doIt

Measured memory_bytes: 5140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int N = Integer.parseInt(strs[0]);
    int K = Integer.parseInt(strs[1]);
    
    System.out.println(N % K == 0 ? 0 : 1);
  }
}

Measured memory_bytes: 21588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC043A
{
	class Program
	{
		static void Main(string[] args)
		{
			int n;//人数
			int s;//必要な個数
	//人数nを入力
			n = int.Parse(Console.ReadLine());
			s = 0;//合計を０に初期化
			for (int i = 1; i <= n; i++)//１からnのくりかえし
			{
				s = s + i;//ｓをふやすs +=i
			}
			Console.WriteLine(s);
			
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


int main(){
    Int N; cin >> N;
    vector<Int> A(200010);
    map<Int,Int> cnt;
    rep(i, N){
        cin >> A[i];
        cnt[A[i]]++;
    }

    Int total = 0;
    for(pair<Int,Int> p : cnt){
        total += p.second*(p.second-1)/2;
    }

    rep(i, N){
        Int ans = total;
        ans -= cnt[A[i]] * (cnt[A[i]]-1)/2;
        ans += (cnt[A[i]]-1) * (cnt[A[i]]-2)/2;
        cout << ans << endl;
    }


}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int num[3];
int main() {
	int a, n;
	cin>>n;
	a = n / 1000;
	n %= 1000;
	num[0] = n / 100;
	n %= 100;
	num[1] = n / 10;
	n %= 10;
	num[2] = n;
	
	rep(s,1<<3) {
		int now = a;
		rep(i,3) {
			if ((s>>i) & 1) {
				now += num[i];
			} else now -= num[i];
		} 
		if (now == 7) {
			cout << a;
			rep(i,3) {
				if ((s>>i) & 1) cout << '+';
				else cout << '-';
				cout << num[i];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >>n;
    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(n-1);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> B[i];
    rep(i, n-1) cin >> C[i];

    int ans=0;
    rep(i, n){
        if (A[i-1]+1 == A[i] && i>=1) ans += C[A[i-1]-1];
        ans += B[A[i]-1];
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long MOD = (long)Math.pow(10, 9) + 7;
    int n = sc.nextInt();
    int[] c = new int[n];
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      c[a]++;
    }
    int p = 0;
    for(int i = 0; i < n; i++) {
      if(((n - 1) - i) % 2 == 0) {
        if(n % 2 == 0) {
          if(c[i] != 2) p++;
        } else {
          if((i == 0) && (c[i] != 1)) p++;
          if((i != 0) && (c[i] != 2)) p++; 
        }
      } else {
        if(c[i] > 0) p++;
      }
    }
    long ans = 0;
    if(p == 0) {
      ans = 1;
      for(int i = 0; i < n / 2; i++) {
        ans = (ans * 2) % MOD;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50868
import math

a, b, h, m = map(int, input().split())
ang1 = (h*60 + m)/2
x = (h*60 + m) % 60
ang2 = (6 * x)
# print(ang1 , ang2)
ang = abs( ang1 - ang2 )
ang = min(ang, 360 - ang) * math.pi / 180

ans = a*a + b*b - 2*a*b*math.cos(ang)
print(math.sqrt(ans) )





Measured memory_bytes: 62476
#include <bits/stdc++.h>
using namespace std;
# define f(a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define ll long long
#define INF 1000000000
#define MAX 1e9
#define MIN -1e9
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define mxn 1000041
ll mp[mxn];
bool find(ll n)
{
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(mp[i]>=1 || mp[n/i]>=1) return false;
		}
	}
	return true;
}
void solveD()
{
	ll n;
	cin>>n;
	ll a[n],c=0;
	for(int i=0;i<n;i++) cin>>a[i],mp[a[i]]++;
	if(mp[1]==1){
		cout<<1<<endl;
		return;
	}
	else if(mp[1]>=2){
		cout<<0<<endl;
		return;
	}
	else{
		for(ll i=0;i<n;i++)
		{
			ll no=a[i];
			if(mp[no]>=2) 
			continue;
			else if(find(no)) c++;
		}
	cout<<c<<endl;
	}
}
int main()
{
	fast;
//	int t;
//	cin>>t;
//	while(t--)
	solveD();
}

Measured memory_bytes: 12908
def main():
    n = int(input())
    v = list(map(int,input().split()))

    from collections import Counter
    a = Counter(v[::2]).most_common()
    b = Counter(v[1::2]).most_common()
    a.append((0,0))
    b.append((0,0))

    if a[0][0] != b[0][0]:
        print(n-(a[0][1]+b[0][1]))
    else:
        print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 65004