akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    int len,k;
    cin>>len>>k;
    cin>>s;
    int cnt=1,f=s[0]-'0';
    vector<int>v;
    int x=0,y=0,ans=0;
    for(int i=1; i<len; i++)
    {
        if(s[i]-'0'!=f)
        {
            if(f)
            {
                x=max(x,cnt);
                v.push_back(cnt);
            }
            else
            {
                y=max(y,cnt);
                v.push_back(cnt*-1);
            }
            cnt=0;
            f^=1;
        }
        cnt++;

    }
    if(f)
    {
        x=max(x,cnt);
        v.push_back(cnt);
    }
    else
    {
        y=max(y,cnt);
        v.push_back(cnt*-1);
    }
    int l=0,r=0;
    ans=x;
    if(k)
        ans=max(ans,y);
    int sz=v.size(),tk=0,cur=0;
    while(l<sz)
    {
        while(v[l]<0 && tk==k)
        {
            cur-=abs(v[r]);
            if(v[r]<0)
                tk--;
            r++;
        }
        cur+=abs(v[l]);
        if(v[l]<0)
            tk++;
        ans=max(ans,cur);
        l++;

    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N;
string X;
ll pop[200010];
ll bin[200010][3];
vector<ll> v;

ll popcount(ll n){
    if(n == 0) return 0;
    else if(pop[n] > 0) return pop[n];
    ll d = __builtin_popcount(n);
    pop[n] = 1 + popcount(n % d);
    return pop[n];
}

signed main(){
    cin >> N >> X;
    reverse(ALL(X));
    ll B = 0;
    REP(i, N) if(X[i] == '1') B++;
    bin[0][0] = bin[0][1] = bin[0][2] = 1;
    REP(i, N){
        if(B > 1) bin[i + 1][0] = (bin[i][0] * 2) % (B - 1);
        if(B > 0) bin[i + 1][1] = (bin[i][1] * 2) % B;
        bin[i + 1][2] = (bin[i][2] * 2) % (B + 1);
    }
    ll Y = 0, Z = 0;
    REP(i, N){
        if(B > 1) Y = (Y + (X[i] - '0') * bin[i][0]) % (B - 1);
        Z = (Z + (X[i] - '0') * bin[i][2]) % (B + 1);
    }
    REP(i, N){
        if(X[i] == '0'){
            v.push_back(popcount((Z + bin[i][2]) % (B + 1)));
        }else{
            if(B > 1) v.push_back(popcount((Y - bin[i][0] + B - 1) % (B - 1)));
            else v.push_back(-1);
        }
    }
    REP(i, N){
        PRINT(v[N - i - 1] + 1);
    }
    return 0;
}

Measured memory_bytes: 10952
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
    NodePointer cur = nil->next;
    while (cur != nil){
        if (key == cur->key){ return cur; }
        cur = cur->next;
    }
    return NULL;
}
 
void init(){
    nil = (NodePointer)malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}
 
void printList(){
    NodePointer cur = nil->next;
    int isf = 1;
    while (1){
        if (cur == nil) break;
        if (isf == 0)  printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}
 
void deleteNode(NodePointer t){
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
 
void deleteFirst(){
    NodePointer t = nil->next;
    if (t == nil) return;
    deleteNode(t);
}
 
void deleteLast(){
    NodePointer t = nil->prev;
    if (t == nil) return;
    deleteNode(t);
}
 
void delete(int key){
    NodePointer t = listSearch(key);
    if (t != NULL){
        deleteNode(t);
    }
}
 
 
void insert(int key){
    NodePointer x;
    x = (NodePointer)malloc(sizeof(struct node));
    x->key = key;
 
    x->next=nil->next;
    nil->next->prev = x;
    x->prev = nil;
    nil->next = x;
}
 
int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if (com[0] == 'i') { insert(key); np++; size++; }
        else if (com[0] == 'd') {
            if (strlen(com) > 6){
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            }
            else {
                delete(key); nd++;
            }
            size--;
        }
    }
 
    printList();
    return 0;
}

Measured memory_bytes: 31788
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = b = 0
l = []

for i in range(1, n+1):
  l.append(i)

all_list = list(itertools.permutations(l))
a = all_list.index(p) + 1
b = all_list.index(q) + 1
print(abs(a - b))

Measured memory_bytes: 44912
n,k=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0

L=[1]*(n+1)
Linv=[1]*(n+1)
inv=[0]+[1]*n

for i in range(2,n+1):
    L[i]=(L[i-1]*i)%MOD
    inv[i]=(MOD-inv[MOD%i]*(MOD//i))%MOD
    Linv[i]=(Linv[i-1]*inv[i])%MOD

def cmb(n,k):
    return (((L[n]*Linv[k])%MOD)*Linv[n-k])%MOD

A.sort()

for j in range(n-k+1):
    ans+=((A[-1-j]-A[j])*cmb(n-1-j,k-1))%MOD

if ans>=0:
    print(ans%MOD)
else:
    print(MOD+ans)


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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

long long solve(long long n) {
    long long m = sqrt(n);
    long long ans = 1e18;
    for (long long i=1; i <= m; i++) {
        if (n % i == 0) {
            long long j = n / i;
            long long val = (i - 1) + (j - 1);
            ans = min(ans, val);
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    long long ans = solve(n);
    cout << ans << endl;
    return 0;
}


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

int main(){
    ll N,K; cin >> N >> K;
    vector <ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    
    ll ans=1e9;
    for(ll i=0; i<=N-K; i++){
        ans=min(ans,A[i+K-1]-A[i]);
    }
    cout << ans;
}


Measured memory_bytes: 1024
s=input()
if s!=s[::-1]:
  print("No")
elif s[0:int((len(s)-1)/2)]!=s[0:int((len(s)-1)/2)][::-1]:
  print("No")
elif s[int((len(s)+3)/2)-1:]!=s[int((len(s)+3)/2)-1:][::-1]:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

bool get_input(std::vector<int>& cards_a, std::vector<int>& cards_b)
{
	int n;
	std::cin >> n;

	if (n == 0) return false;

	cards_a.clear(), cards_b.clear();
	int card_a, card_b;
	for (int i = 0; i < n; i++) {
		std::cin >> card_a >> card_b;
		cards_a.push_back(card_a);
		cards_b.push_back(card_b);
	}
	return true;
}

void calc_and_output(std::vector<int>& cards_a, std::vector<int>& cards_b)
{
	int point_a = 0, point_b = 0;
	std::vector<int>::iterator a_itr = cards_a.begin();
	std::vector<int>::iterator b_itr = cards_b.begin();
	for (; a_itr != cards_a.end() && b_itr != cards_b.end(); a_itr++, b_itr++) {
		if (*a_itr > *b_itr) {
			point_a += (*a_itr + *b_itr);
		} else if (*a_itr < *b_itr) {
			point_b += (*a_itr + *b_itr);
		} else {
			point_a += *a_itr;
			point_b += *b_itr;
		}
	}
	std::cout << point_a << " " << point_b << std::endl;
}

int main()
{
	std::vector<int> cards_a, cards_b;
	while (get_input(cards_a, cards_b)) {
		calc_and_output(cards_a, cards_b);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

lli solve(string const &str) {
  auto const n = str.size();
  if (n < 2) { return 1; }
  vector<lli> dp1(n, 0), dp2(n, 1);
  dp1[0] = 1, dp1[1] = (str[0] != str[1] ? 2: 0);
  dp2[0] = 0, dp2[1] = 1;
  for (int i = 2; i < n; ++i) {
    dp1[i] = max(
        dp2[i-1] + 1,
        str[i-1] != str[i] ? dp1[i-1] + 1 : 0);
    dp2[i] = max(
        dp1[i-2] + 1,
        (i > 2 && str.substr(i-3,2) != str.substr(i-1,2)) ? dp2[i-2] + 1 : 0);
  }
  return max(dp1[n-1], dp2[n-1]);
}

int main() {
  // cout << fixed << setprecision(10);

  string S;
  cin >> S;
  cout << solve(S) << endl;
  return 0;
}


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

using namespace std;

int main(void) {
  string s;
  int n;
  cin >> s >> n;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    string w;
    cin >> w;
    w += w;
    ans += w.find(s) != string::npos;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>
#include<math.h>

int main(void){
int n,i,j;
double s[1005],S,m,sgm;
while(1){
   scanf("%d",&n);
   if(n==0){break;}
   S=0;
   for(i=0;i<n-1;i++){
      scanf("%lf ",&s[i]);
      S=S+s[i];
   }
   scanf("%lf",&s[n-1]);
   S=S+s[n-1];
   m=S/(double) n;
   sgm=0;
   for(i=0;i<n;i++){
   sgm=sgm+(s[i]-m)*(s[i]-m);
   }
   printf("%.6lf\n",sqrt(sgm/(double)n));
}

return(0);
}

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

int main() {
  long h,w,d,q;
  cin >> h >> w >> d;
  vector<long> x(h*w);
  vector<long> y(h*w);
  vector<long> aaa(h*w);
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      long num;
      cin >> num;
      x[num-1]=j;
      y[num-1]=i;
    }
  }
  for(int i=d;i<h*w;i++) {
    aaa[i]=aaa[i-d];
    aaa[i]+=max(x[i]-x[i-d],x[i-d]-x[i]);
    aaa[i]+=max(y[i]-y[i-d],y[i-d]-y[i]);
  }
  cin >> q;
  vector<long> ans(q);
  for(int i=0;i<q;i++) {
    long l,r;
    cin >> l >> r;
    ans[i]=aaa[r-1]-aaa[l-1];
  }
  for(int i=0;i<q;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3968
// AOJ Volume 0 Problem 0030

#include <stdio.h>
#include <string.h>

int cnt;

void comb(int useflag[], int n, int s)
{
	int i;
	
	if (s < 0){
		return;
	}
	
	if (n == 1){
		if (s > 9){
			return;
		}
		if (useflag[s] == 0){
#if 0
			printf("<");
			for (i = 0; i <= 9; i++){
				if (useflag[i] == 1){
					printf("%d ", i);
				}
			}
			printf("%d>\n", s);
#endif
			cnt++;
		}
		return;
	}
	
	for (i = 0; i <= 9; i++){
		if (useflag[i] == 0){
			useflag[i] = 1;
			comb(useflag, n - 1, s - i);
			useflag[i] = 0;
		}
	}
}


int main(void)
{
	int n, s;
	int useflag[10];
	
    while (1){
		scanf("%d%d", &n, &s);
		if (n == 0 && s == 0){
			break;
		}
		
		memset(useflag, 0, sizeof(useflag));
		cnt = 0;
		comb(useflag, n, s);
		
		for (; n > 1; n--){
			cnt /= n;
		}		
		
		printf("%d\n", cnt);
	}
	
    return (0);
}

Measured memory_bytes: 408
#include <stdio.h>
#define S 1000000000

int N[500000], L[250001], R[250001], count=0;
  
int main(){
  int i, n;
  scanf("%d",&n);
  for(i = 0;i < n;i++)
    scanf("%d",&N[i]);
  
  MergeSort(0, n);
  
  for(i = 0;i < n;i++){
    if(i > 0) printf(" ");
    printf("%d",N[i]);
  }
  printf("\n%d\n",count);
  return 0;
}
 
void merge(left, mid, right){
  int n1, n2, i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0;i < n1;i++)
    L[i] = N[left + i];
  for(i = 0;i < n2;i++)
    R[i] = N[mid + i];
  L[n1] = S;
  R[n2] = S;
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    if(L[i] <= R[j]){
      N[k] = L[i];
      i = i + 1;
      count++;
    }
    else{
      N[k] = R[j];
      j = j + 1;
      count++;
    }  
  }
}
  
void MergeSort(left, right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    MergeSort(left, mid);
    MergeSort(mid, right);
    merge(left, mid, right);
  }
}

Measured memory_bytes: 4508
#include<iostream>
using namespace std;
int main() {
	int a[8], b[10];
	for (int i = 1; i <= 7; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= 7; i++) {
		cout << a[i] - b[i] << endl;
	}
}


Measured memory_bytes: 3064
import itertools
def main():
    N = int(input())
    initial = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}

    for i in range(N):
        S = input()
        if S[0] == "M" or S[0] == "A" or S[0] == "R" or S[0] == "C" or S[0] == "H":
            initial[S[0]] += 1
    pat = 0

    for c in itertools.combinations("MARCH", 3):
        pat += initial[c[0]]*initial[c[1]]*initial[c[2]]
        
    print(pat)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
int a,b,c;
bool j=false;
cin>>a>>b>>c;
for (int  i = 1; i <= b; i++)
{
    if ((a*i)%b==c)
    {
j=true;
    }
    
}
if (j==1)
{
    cout<<"YES"<<endl;
}
else
{
    cout<<"NO"<<endl;
}

    return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    long double m;
    int n;cin >> n >> m;
    long double a[n];
    long double sum=0;
    rep(i,0,n){ cin >> a[i]; sum += a[i]; }
    int cnt=0;
    rep(i,0,n){
        if(a[i] >= (sum)/((long double)4.0*m)) cnt++;
    }
    if(cnt>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------------------------head--------------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n;
vi g[N];

int dfs(int x){
	int mx=0;
	vi a(0);
	for(int y:g[x])
		a.pb(dfs(y));
	sort(a.begin(),a.end());
	for(int i=0;i<SZ(a);i++)
		gmax(mx,a[i]+SZ(a)-i);
	return mx;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(n);
	for(int i=2;i<=n;i++){
		int x;read(x);
		g[x].pb(i);
	}
	print(dfs(1));
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ll cnt=0;
	ll a[n];rep(i,0,n){cin>>a[i];if(a[i]>=k)cnt++;}
	cout<<cnt;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll modPow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}


int main(void) {
    string s;
    cin >> s;
    ll i;
    ll ans=0;
    ll la=0, lq=0, rc=0, rq=0;
    
    for(i=0; i<(ll)s.size(); i++) {
        if(s[i]=='C') rc++;
        else if(s[i]=='?') rq++;
    }
    
    for(i=0; i<(ll)s.size(); i++) {
        if(s[i]=='C') rc--;
        else if(s[i]=='?') rq--;
        
        if(s[i]=='B' || s[i]=='?') {
            ll left=la*modPow(3, lq)%MOD+lq*modPow(3, lq-1)%MOD;
            ll right=rc*modPow(3, rq)%MOD+rq*modPow(3, rq-1)%MOD;
            ans+=left*right%MOD;
        }
        
        if(s[i]=='A') la++;
        else if(s[i]=='?') lq++;
    }
    
    prin(ans%MOD)
}


Measured memory_bytes: 512
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    *P,=map(int, input().split())
    P=[0]+P
    uf=UnionFindTree(N+1)
    for _ in range(M):
        x,y=map(int, input().split())
        uf.union(x,y)
    ans=0
    for i in range(1,N+1):
        if uf.same(i,P[i]): ans+=1
    print(ans)

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return False
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x
        return True

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]

if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int K, N;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> K >> N;
    vl a(N); 
    F0R(i, N) {
        cin >> a[i];
    }
    sort(all(a));
    
    ll total = a[N - 1] - a[0];
    ll ans = total;
    ll extra = a[0] + (K - a[N - 1]);
    FOR(i, 1, N) {
        ans = min(ans, total + extra - (a[i] - a[i - 1]));
    }

    cout << ans;
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 1792
N=int(input())
s=input()

dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1

if s[0] in dicY: ans=1
else: ans=0

for i in range(1,N-1):
    if not s[i] in dicX: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll k, a, b;

    cin >> k >> a >> b;
    bool flag = (a / k < b / k) || a % k == 0 || b % k == 0;

    cout << (flag ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3624
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    string s, t;
    cin >> s >> t;

    bool ok = false;
    int v;
    rep(i, s.size()-t.size()+1) {
        rep(j, t.size()) {
            if(s[j+i] != '?' && s[j+i] != t[j]) {
                break;
            }
            if(j == t.size()-1) {
                v = i;
                ok = true;
            }
        }
    }


    if(ok) {
        rep(i, s.size()) {
            if(v<=i && i < t.size()+v) {
                cout << t[i-v];
            } else {
                if(s[i] == '?') {
                    cout << 'a';
                } else {
                    cout << s[i];
                }
            }
        }
        cout << endl;
    }
    else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
  
int main(){
  string s;
  cin >> s;
  int min_ans = 1000;
  bool judge;
  
  // setを使って判定してみる。
  set<char> chars;
  rep(i, s.size() - 1){
    chars.insert(s[i]);
  }
  
  if (chars.size() == 1 || s.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (auto key = chars.begin() ; key != chars.end(); ++key){
    bool flag = true;
    string str = s;
    int times = 1;
      while (flag) {
      	string vacant;
        flag = false;
        rep(i, str.size() - 1){
          if (str[i] == *key || str[i+1] == *key) vacant += *key;
          else vacant += str[i], flag = true;
        }
      
        if (flag){
          str = vacant;
          times++;
        }
      }
      min_ans = min(min_ans, times);
    }
  cout << min_ans << endl;
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

struct UF {
    vector<int> p;  // parent
    LL fuben;
    map<int, LL> mp;

    UF(int n) {
        p.resize(n);
        for(int i=0;i<n;i++){
            p[i] = i;
            mp[i]++;
        }
        fuben = LL(n)*(n-1)/2;
    }

    int find(int x) {
        if(x == p[x]){
            return x;
        }else{
            return p[x] = find(p[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        fuben -= mp[x]*mp[y];
        mp[x] += mp[y];
        p[y] = p[x];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    dec(i, 0, m){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }

    UF uf(n);

    vector<LL> ans;
    inc(i, 0, m){
        ans.pb(uf.fuben);
        uf.unite(a[i], b[i]);
    }
    dec(i, 0, m){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9720
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

set<int>a[200],b[200];

int main(void){
    int ans=10000;
    string s;
    cin>>s;
    for(char x='a';x<='z';x++){
        a[(x-'0')].insert(s.length()+1);
    }
    for(int i=0;i<s.length();i++){
        a[(s[i]-'0')].insert(i+1);
    }
    for(char x='a';x<='z';x++){
        int y=x-'0';
        int num1=0;
        int num2=0;
        for(auto itr=a[y].begin();itr!=a[y].end();++itr){
            int l=(*itr)-num1-1;
            num2=max(num2,l);
            num1=(*itr);
        }
        ans=min(ans,num2);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
public:
    UnionFind(int n):par(n),rank(n),sz(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]<rank[ry]){
            par[rx] = par[ry];
            sz[ry] += sz[rx];
        }else{
            par[ry] = par[rx];
            sz[rx] += sz[ry];
            if (rank[rx]==rank[ry]) rank[rx]++;
        }
    }
    int size(int x){
        return sz[root(x)];
    }
};

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin>>N>>Q;
    UnionFind uf(N);
    while(Q--){
        int t,u,v; cin>>t>>u>>v;
        if (t==1){
            cout<<uf.same(u,v)<<"\n";
        }else{
            uf.unite(u,v);
        }
    }
    return 0;
}


Measured memory_bytes: 5380
package main

/*
#include <stdio.h>
#include <stdlib.h>
void print(const char *str){
	printf("%s", str);
}
int nextInt(){
	int n;
	int _ = scanf("%d",&n);
	return n;
}

void scanint(int* n){
	int _ = scanf("%d", n);
}

*/
import "C"

import (
	"bytes"
	"fmt"
	"log"
	"strconv"
	"unsafe"
)

func nextInt() int {
	n := new(int)
	C.scanint((*C.int)(unsafe.Pointer(n)))
	return *n
}

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	M := nextInt()
	Q := nextInt()
	var data [510][510]int
	var l, r int
	for i := 0; i < M; i++ {
		l = nextInt()
		r = int(C.nextInt())
		data[l][r]++
	}

	for i := N; i >= 1; i-- {
		for j := 1; j <= N; j++ {
			data[i][j] += data[i+1][j]
			data[i][j] += data[i][j-1]
			data[i][j] -= data[i+1][j-1]
		}
	}
	var buf bytes.Buffer
	for i := 0; i < Q; i++ {
		p := nextInt()
		q := nextInt()
		buf.WriteString(strconv.Itoa(data[p][q]))
		buf.WriteString("\n")
	}
	fmt.Println(buf.String())
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int maxcount=0;
    for(int i=0; i<10; i++){
        int count=0;
        for(int j=i; j<10; j++){
            if(s[j]=='A' || s[j]=='T' || s[j]=='C' || s[j]=='G'){
                count++;
            }else{
                break;
            }
        }
        maxcount = max(maxcount, count);
    }
    cout << maxcount << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n, m;
	cin>>n>>m;
	vector<vll> S(n+1, vll(m+1));
	loop(i, 1, n+1){
		loop(j, 1, m+1){
			char ch;
			cin>>ch;
			if(ch == '#')
				S[i][j] = -1;
			else
				S[i][j] = 1;
		}
	}
	lli M = 1e9 + 7;
	vector<vll> dp(n+1, vll(m+1, 0));
	loop(i, 1, n+1){
		loop(j, 1, m+1){
			if(i == 1 && j == 1)
				dp[i][j] = 1;
			else if(S[i][j] == -1)
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
		}
	}
	cout<<dp[n][m]<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


int main(){
  int N;
  while(cin >> N){
    vector<LLI> A(N), B(N); cin >> A >> B;

    priority_queue<pair<LLI, LLI>> pq;

    REP(i,N) pq.emplace(B[i], i);

    LLI ans = 0;
    
    
    while(pq.size()){
      LLI x, i;
      tie(x, i) = pq.top(); pq.pop();

      if(B[i] != x) continue;
      if(B[i] == A[i]) continue;
      
      const LLI a = B[(i-1+N)%N];
      const LLI c = B[(i+1)%N];
      const LLI m = a + c;

      const LLI t = B[i] % m;
      LLI k = B[i] / m;

      if(k == 0) continue;
      
      if(t >= A[i]){
        B[i] = t;
        ans += k;

        pq.emplace(B[i], i);
      }else{
        if((A[i] - t) % m == 0){
          B[i] = A[i];
          k -= (A[i] - t) / m;
          ans += k;

          pq.emplace(B[i], i);
        }else{
          break;
        }
      }
      
      dump(B);
    }

    if(A != B){
      cout << -1 << endl;
    }else{
      cout << ans << endl;
    }
  }

  return 0;
}


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

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int mxN = 100*1000+5;

int a[mxN], b[mxN], n;
ll tree[2*mxN];

void upd(int i, int v) {
    for(; i < 2*mxN; i += i & -i) {
        tree[i] += v;
    }
}

ll get(int i) {
    ll ans = 0;
    for(; i > 0; i -= i & -i) {
        ans += tree[i];
    }
    return ans;
}

ll calc(int x) {
    forn(i, n) {
        b[i] = a[i] >= x ? 1 : -1;
    }
    memset(tree, 0, sizeof tree);
    ll ans = 0;
    upd(mxN, 1);
    int cur = 0;
    forn(i, n) {
        cur += b[i];
        ans += get(mxN+cur);
        upd(mxN+cur, 1);
    }
    
    return ans;
}

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

    cin >> n;
    forn(i, n) {
        cin >> a[i];
    }
    ll need = 1LL * n * (n+1)/2;
    need = 1LL * n * (n+1) / 2 - need/2;
    debug() nav(n) nav(need);
    int lo = 1, hi = 1e9;
    while(lo < hi) {
        int mid = lo + (hi - lo + 1)/2;
        debug() nav(mid) nav(calc(mid));
        if(calc(mid) >= need) {
            lo = mid;
        }
        else {
            hi = mid-1;
        }
    }
    cout << lo << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

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

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

constexpr int MAX_N_SQRT = 2000000;

int not_prime[MAX_N_SQRT+1];

map<ll, ll> factorize(ll n){
    map<ll, ll> ret;
    ll i = 2;
    not_prime[2] = 0;
    fill(not_prime, not_prime+MAX_N_SQRT+1, 0);
    while(n != 1 && i <= MAX_N_SQRT){
        if(not_prime[i]){
            ++i;
            continue;
        }
        ll j = i;
        while(j <= MAX_N_SQRT){
            not_prime[j] = 1;
            j += i;
        }

        while(n % i == 0){
            n /= i;
            ++ret[i];
        }

        ++i;
    }
    if(n != 1LL){
        ++ret[n];
    }
    return ret;
}


int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);

    map<ll, ll> fg = factorize(g);
    ll ans = 1;
    for(auto p: fg) {
        ++ans;
    }

    cout << ans << endl;

}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    long N=gl();
	    long K=gl();


	    long ans=0;
	    if (K%2==0) {
	    	long a= Math.floorDiv(N, K/2);
	    	if (a%2==0) {
	    		ans+=(Math.pow(a/2, 3))*2;
	    	} else {
	    		ans+=(Math.pow((a-1)/2, 3) + Math.pow((a+1)/2, 3));
	    	}
	    } else {
	    	ans+=Math.pow(Math.floorDiv(N, K),3);
	    }
	    System.out.print(ans);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35744
from math import sqrt
n = int(input())
m = int(sqrt(n))
li = list(range(m + 1))
#0と1は考えない
for i in range(2, m + 1):
    while li[i] <= n:
        li[i] *= i
    li[i] = int(li[i] / i)
print(max(li))

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

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

  if(N == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }

  int sum = 0;
  vector<int> ret;
  int pos = 2;
  REP(i, N - 2) {
    while((pos % 2) && (pos % 3)) ++pos;
    sum += pos;
    ret.push_back(pos);
    ++pos;
  }

  vector<int> cnd(6);
  REP(i, 6) cnd[i] = pos + i;

  REP(i,6){
    if((cnd[i] % 2) && (cnd[i] % 3)) continue;
    for(int j = i + 1; j < 6; ++j) {
      if((cnd[j] % 2) && (cnd[j] % 3)) continue;
      if((sum + cnd[i] + cnd[j]) % 6 == 0) {
        ret.push_back(cnd[i]);
        ret.push_back(cnd[j]);
        break;
      }
    }
    if(ret.size() == N) break;
  }

  REP(i,N) {
    if(i) cout << " ";
    cout << ret[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 512
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  map<int, int> cnt;
  int sum = 0, p10 = 1;
  cnt[0] = 1;
  int64 ret = 0;
  for (int i = n - 1; i >= 0; --i) {
    int x = s[i] - '0';
    sum = (sum + x * p10) % 2019;
    ret += cnt[sum];
    cnt[sum]++;
    p10 = p10 * 10 % 2019;
  }
  printf("%lld\n", ret);
  return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int M,m;
  M=max(A,B);
  m=min(A,B);
  for(int i=0;i<M;i++){
    cout << m;
  }
  cout << endl;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n;cin>>n;
    vl b(n);
    rep(i,n)cin>>b[i];
    vl res;

    rep(i,n){
        ll ans = 0;
        for(int j=(int)b.size()-1;j>=0;j--){
            if(b[j] == j+1){
                ans = j+1;
                break;
            }
        }
        if(ans == 0){
            out(-1);
            return 0;
        }
        res.push_back(ans);
        b.erase(b.begin()+ans-1);
    }
    reverse(all(res));
    rep(i,n)out(res[i]);
}


Measured memory_bytes: 256