akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define ld          long double
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = int(2e5) + 7;
typedef pair<int, int> pii;

int a[N], n, Max;
ll res, sum;
set<int> s;
vector<int> v;

struct BIT {
   ll t[N];
   void Update(int x, int val) {for(; x > 0; x -= (x & -x)) t[x] += val;}
   ll Get(int x) {ll res = 0; for(x = max(x, 1); x < N; x += (x & -x)) res += t[x]; return res;}
} bit1, bit2;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i], v.pb(a[i]);
    sort(v.begin(), v.end());
    for(int i = n; i >= 1; --i) {
        sum += a[i];
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
        bit1.Update(a[i], 1); bit2.Update(a[i], v[a[i] - 1]);
    }
    for(int i = 1; i <= n; ++i) {
        if(Max >= a[i]) cout << "0\n";
        else {
            s.insert(a[i]); res = 0;
            auto p = s.lower_bound(a[i]);
            int x;
            if(p == s.begin()) x = 0;
            else p = prev(p), x = (*p);
            int upper = bit1.Get(a[i]);
            res += 1ll * v[a[i] - 1] * upper;
            //cout << res << ' ';
            res += bit2.Get(x + 1) - bit2.Get(a[i]);
            //cout << res << ' ';
            if(x) {
                res -= 1ll * (bit1.Get(x + 1) - bit1.Get(a[i])) * v[x - 1];
                res -= 1ll * v[x - 1] * upper;
            }
            cout << res << '\n';
            Max = a[i];
        }
        sum -= a[i]; bit1.Update(a[i], -1); bit2.Update(a[i], -v[a[i] - 1]);
    }
}


Measured memory_bytes: 8056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,i,c=1;
    cin>>n;
    int s[n];
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }

    for(i=0;i<n-1;i++)
    {

        if(s[i]>s[i+1])
        {
           // cout<<s[i]<<endl;
            c++;
        }
        else
        {
            s[i+1]=s[i];
        }
    }
    cout<<c<<endl;


    return 0;
}

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

signed main(void)
{
	long long x, n, cnt;
	cin >> x;
	n = 100;
	cnt = 0;
	while (x > n)
	{
		n *= 1.01;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  set<string> gacha;
  for(int i=0;i<N;i++){
    string tmp;
    cin >> tmp;
    gacha.insert(tmp);
  }
  cout << gacha.size() << endl;
  
  return 0;
}


Measured memory_bytes: 15728
cardArray = list(map(int,input().split()))

if cardArray[0]== cardArray[1]:
  print("Draw")
elif cardArray[0] < cardArray[1]:
  if cardArray[0] == 1:
    print("Alice")
  else:
    print("Bob")
else:
  if cardArray[1] == 1:
    print("Bob")
  else:
    print("Alice")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if ((d > 0) && ((4 * a * b) < (d * d))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

int A[100005];

int main(){
    int N, fare=0;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> A[i];
        if (i != 0){
            fare += abs(A[i-1] - A[i]);
        }
        else{
            fare += abs(A[0]);
        }
    }
    fare += abs(A[N-1]);
    for (int i=0; i<N; i++){
        int vfare = fare;
        if (i == 0){
            vfare -= abs(A[0]) + abs(A[0] - A[1]) - abs(A[1]);
        }
        else if (i == N-1){
            vfare -= abs(A[N-1]) + abs(A[N-2] - A[N-1]) - abs(A[N-2]);
        }
        else{
            vfare -= abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]) - abs(A[i-1] - A[i+1]);
        }
        cout << vfare << endl;
    }
}

Measured memory_bytes: 1664
// ABC159D
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

ll choose2(ll n) {
    return n*(n-1)/2;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<ll> cnt(n, 0);
    rep(i, n) cnt[a[i]]++;
    ll tot = 0;
    rep(i, n) tot += choose2(cnt[i]);
    rep(i, n) {
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define il inline
#define gc getchar()
#define mp make_pair
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)

const int N=1e6+10;
int n,m,d;
string str;

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}

int main()
{
	n=read();m=read();d=read();str=" RGBY";
	rp(i,0,n-1){rp(j,0,m-1){ri x=(m+i+j)/d%2,y=(m+i-j)/d%2;printf("%c",str[2*x+y+1]);}printf("\n");}
	return 0; 
}
//yjszd!

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int n, m, a;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> a;
        n -= a;
    }
    if(n<0){
        cout << -1;
    }else{
        cout << n;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x,k,d;
  cin>>x>>k>>d;
  int p=abs(x);
  if(k<=(p/d)){
    cout<<p-(k*d)<<endl;
  }else{
    k-=(p/d);
    int p1=p%d,p2=min(p1+d,abs(p1-d));
    k%=2;
    if(k==1) cout<<p2<<endl;
    else cout<<p1<<endl;
  }
    
  return 0;
}


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

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

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const ll M = 998244353;
const string END = "\n";

ll dp[301][90001];
ll dp2[301][90001];

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

	int n; cin >> n;
	ll a[301] = {};
	int sum = 0;
	ll ans = 1;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		ans = (ans * 3) % M;
	}
	int s = (sum+1) / 2;
	dp[0][0] = 1;
	dp2[0][0] = 1;
	rep(i, n){
		rep(j, 90001){
			(dp[i+1][j] += 2 * dp[i][j]) %= M;
			(dp2[i+1][j] += dp2[i][j]) %= M;
			if(j >= a[i]) {
				(dp[i+1][j] += dp[i][j-a[i]]) %= M;
				(dp2[i+1][j] += dp2[i][j-a[i]]) %= M;
			}
		}
	}
	if(sum % 2 == 0){
		(ans += 3 * dp2[n][sum/2]) %= M;
	}
	frep(i, s, sum+1){
		(ans -= 3 * dp[n][i] - M) %= M;
	}
	cout << (ans + M) % M << END;

	return 0;
}


Measured memory_bytes: 422912
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[111][101010];

int main(){
    int n,k;
    cin>>n>>k;
    if(k==0){
        cout<<1<<endl;
        return 0;
    }
    int a[n];
    rep(i,n)cin>>a[i];
    rep(j,k+1)dp[0][j]=1;
    rep(i,n){
        rep(j,k+1){
            dp[i+1][j]+=dp[i][j];
            if(j>a[i])dp[i+1][j]+=mod-dp[i][j-a[i]-1];
            dp[i+1][j]%=mod;
        }
        rep(j,k)(dp[i+1][j+1]+=dp[i+1][j])%=mod;
    }
    cout<<(dp[n][k]-dp[n][k-1]+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <algorithm>

using namespace std;

int N, M;
struct cake {
    long long x, y, z;
};
cake cakes[1000];
cake cakes_cp[1000];
bool xisp, yisp, zisp;
long long max_value = 0;

bool asc(const cake& left, const cake& right) {
    return (left.x + left.y + left.z) > (right.x + right.y + right.z);
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> cakes[i].x >> cakes[i].y >> cakes[i].z;
    }
    for (int i = 0; i < 8; i++) {
        xisp = !xisp;
        if (i % 2 == 0) {
            yisp = !yisp;
        }
        if (i % 4 == 0) {
            zisp = !zisp;
        }
        copy(cakes, cakes+N, cakes_cp);
        for (int j = 0; j < N; j++) {
            cakes_cp[j].x = xisp ? cakes_cp[j].x : -cakes_cp[j].x;
            cakes_cp[j].y = yisp ? cakes_cp[j].y : -cakes_cp[j].y;
            cakes_cp[j].z = zisp ? cakes_cp[j].z : -cakes_cp[j].z;
        }
        sort(cakes_cp, cakes_cp+N, asc);
        long long value = 0;
        for (int j = 0; j < M; j++) {
            long long sum_v = cakes_cp[j].x + cakes_cp[j].y + cakes_cp[j].z;
            value += sum_v;
        }
        if (value > max_value) {
            max_value = value;
        }
    }
    cout << max_value << endl;
}

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

int main(){
	int n;
	cin>>n;
	int arr[n];
	for (int i = 0; i<n; i++){
		cin>>arr[i];
	}
	int dp[n+1];
	dp[1] = 0;
	dp[2] = abs(arr[1] - arr[0]);
	for (int i = 3; i<=n; i++){
		dp[i] = min(abs(arr[i-1] - arr[i-2]) + dp[i-1], abs(arr[i-1] - arr[i-3]) + dp[i-2]);
	}
	cout<<dp[n];
}


Measured memory_bytes: 4376
//atcoder
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dfs(vector<vector<ll> > &adj,ll root,ll &count,vector<bool> &vis){
	vis[root]=true;
	count++;
	for(int i=0; i<adj[root].size(); i++){
		if(vis[adj[root][i]]==false) dfs(adj,adj[root][i],count,vis);
	}
   return count;	
}
int main(){
	ll n,m,u,v,ans=INT_MIN,count;
	cin>>n>>m;
	vector<vector<ll> > adj(n+1);
	vector<bool>vis(n+1,false);
	while(m>0){
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		m--;
	}
	for(ll i=1; i<n+1; i++){
		count=0;
		if(vis[i]==false) {
			ans=max(ans,dfs(adj,i,count,vis));
		}
	}
	cout<<ans;
	return 0;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
  int n; read(n);
  int l = 0, r = n - 1;
  string pl, pr;
  cout << l << endl; read(pl); if (pl[0] == 'V') return 0;
  cout << r << endl; read(pr); if (pr[0] == 'V') return 0;
  while (true) {
    int m = l + r >> 1;
    if (m == l || m == r) break;
    string res;
    cout << m << endl; read(res); if (res[0] == 'V') return 0;
    if ((m - l) % 2 == 1 && res[0] == pl[0]) r = m, pr = res;
    else if ((m - l) % 2 == 0 && res[0] != pl[0]) r = m, pr = res;
    else if ((r - m) % 2 == 1 && res[0] == pr[0]) l = m, pl = res;
    else if ((r - m) % 2 == 0 && res[0] != pr[0]) l = m, pl = res;
  }
  rep(i, l + 1, r) {
    cout << i << endl; string s;
    read(s); if (s[0] == 'V') return 0;
  }
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    int a,b;
    cin>>a>>b;
    int ans = max((int)0,a-2*b);
    cout<<ans;
}   

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

int main(){
	int n;
	while(cin >> n and n!=0){
		vector<string> s(n);
		for(int i=0;i<n;i++)
			cin >> s[i];

		vector<string> outp(n);
		int mxout=0;
		for(int i=0;i<n;i++){
			outp[i] = "";
			outp[i] += s[i][0];
			for(int j=0;j<s[i].size()-1;j++){
				if(s[i][j]=='a' || s[i][j]=='i' || s[i][j]=='u' || s[i][j]=='e' || s[i][j]=='o' ){
					outp[i] += s[i][j+1];
				}
			}
			if(outp[i].size()>mxout)
				mxout=outp[i].size();
		}

		int ans=-1;
		for(int i=0;i<mxout;i++)
		{
			set<string> st;
			for(int j=0;j<outp.size();j++)
				st.insert(outp[j].substr(0,i+1));
			if(st.size()<outp.size())
				continue;
			else
			{
				ans=i+1;
				break;
			}

		}
		cout << ans << endl;


	}
}



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

using namespace std;

const int max_n = 55, inf = 1000111222;

int n, t[max_n], sum;
string s[max_n], x;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> t[i];
        sum += t[i];
    }
    cin >> x;
    for (int i = 0; i < n; ++i) {
        sum -= t[i];
        if (s[i] == x) {
            break;
        }
    }
    cout << sum << "\n";
    return 0;
}


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

int main(void)
{
  int i, n;
  int a[128];
  cin >> n;
  for(i = 0; i < n; i++) cin >> a[i];
  for(i = n - 1; i > 0; i--) {
    cout << a[i] << " ";
  }
  cout << a[0] << endl;
}

Measured memory_bytes: 1160
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
X = iil()
r = sorted(X)
smed = r[n//2-1]
lmed = r[n//2]

for i in X:
    if i <= smed:
        print(lmed)
    else:
        print(smed)

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int zw=0;
    for(int i=0; i<n; ++i) if(s[i]=='W') zw++;
    int ans=zw;
    for(int i=n-zw; i<n; ++i) if(s[i]=='W') ans--;

    cout<<ans;
    return 0;
}


Measured memory_bytes: 3764
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define INF 1000000000
#define pb push_back
struct bipartite_matching{
	const static int MAX_V=2100;
	int V;
	vector<int> G[MAX_V];
	int match[MAX_V];
	bool used[MAX_V];
	void add_edge(int u,int v)
	{
		G[u].pb(v);
		G[v].pb(u);
	}
	bool dfs(int v)
	{
		used[v]=true;
		for(int i=0;i<G[v].size();i++)
		{
			int u=G[v][i],w=match[u];
			if(w<0||!used[w]&&dfs(w))
			{
				match[v]=u;
				match[u]=v;
				return true;
			}
		}
		return false;
	}
	int matching()
	{
		int res=0;
		memset(match,-1,sizeof(match));
		for(int v=0;v<V;v++)
		{
			if(match[v]<0)
			{
				memset(used,0,sizeof(used));
				if(dfs(v))res++;
			}
		}
		return res;
	}
};
int d[105][105];
int p[1050],t[1050];
int N,M,L;
int main()
{
	while(1)
	{
		scanf("%d %d %d",&N,&M,&L);
		if(N==0&&M==0&&L==0)break;
		bipartite_matching bm;
		bm.V = 2*L;
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<N;j++)
			{
				d[i][j]=INF;
				if(i==j)d[i][j]=0;
			}
		}
		for(int i=0;i<M;i++)
		{
			int u,v,dist;
			scanf("%d %d %d",&u,&v,&dist);
			d[u][v]=dist;
			d[v][u]=dist;
		}
		for(int k=0;k<N;k++)
		{
			for(int i=0;i<N;i++)
			{
				for(int j=0;j<N;j++)
				{
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}	
		for(int i=0;i<L;i++)scanf("%d %d",&p[i],&t[i]);
		for(int i=0;i<L;i++)
		{
			for(int j=0;j<L;j++)
			{
				if(t[i]<t[j]&&d[p[i]][p[j]]<=t[j]-t[i])bm.add_edge(i,j+L);
			}
		}
		printf("%d\n",L - bm.matching());
	}
	return 0;
}

Measured memory_bytes: 6504
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
#define mod 1000000007
ll mypower(ll a, ll b, ll N)
{
    ll ans = 1;
    while(b)
    {
        if(b%2)
            ans = ans*a%N;
        b=b/2;
        a=a*a%N;
    }
    return ans;
}
void bfs(vector<int> graph[], int v, int par[], int vis[])
{
    queue<int> q;
    q.push(v);
    vis[v] = 1;
    while(q.empty() == false)
    {
        int tp = q.front();
        q.pop();
        for(auto j : graph[tp])
        {
            if(!vis[j])
            {
                vis[j] = 1;
                par[j] = tp;
                q.push(j);
            }
        }
    }
}
#define PI acos(-1)
int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k)
        cout << s << '\n';
    else
    {
        string str = "";
        int i;
        for(i=0;i<k;i++)
            str+=s[i];
        str+="...";
        cout << str;    
    }
    
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int sum = 0;
        for(int i=0;i<n;i++){
            sum += Integer.parseInt(sc.next());
        }
        System.out.println(sum - n);

    }

    private static char[] rotateArray(char[] c, int d){
        char[] newc = new char[c.length];
        for(int i=0;i<c.length;i++){
            newc[(i+d)%c.length] = c[i];
        }
        return newc;
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]<p){l++;}
            while(d[r]>p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

Measured memory_bytes: 25940
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  la = list(map(int, input().split(' ')))
  counts = [0] * (n+1)
  
  def f(n):
    return int((n * (n-1)) / (2))
  
  for a in la:
    counts[a] += 1
    
  ans = 0
  for count in counts:
    if count >= 2:
      ans += f(count)
      
  for a in la:
    if counts[a] >= 2:
      fc = f(counts[a])
      count = counts[a]
      print(ans - fc + int(fc * ((count-2) / count)))
    else:
      print(ans)    

if __name__=='__main__':
  main()



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

#define SZ(a) (int)(a).size()
using ll = long long;

bool solve() {
    int n;
    cin >> n;
    bool ret = false;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ret |= x & 1;
    }
    return ret;
}

int main() {
    cin.sync_with_stdio(false);
    puts(solve() ? "first" : "second");
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll X;
  cin >> X;
  if (X == 7 || X == 5 || X == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n;
  cin >> n;
  int divCnt = 0;
  REP(i, n) {
    int tmp = read();
    if (~tmp & 1) {
      while (~tmp & 1) {
        tmp /= 2;
        divCnt++;
      }
    }
  }
  print(divCnt);
  // print(min(mulCnt, divCnt));
  // int divCnt = 0, mulCnt = 1e18;
  // REP(i, n) {
  // int tmp = read();
  // if (tmp & 1) {
  // int cnt = 0;
  // while (tmp <= 1e9) {
  // tmp *= 3;
  // cnt++;
  // }
  // chmin(mulCnt, cnt);
  // } else {
  // while (~tmp & 1) {
  // tmp /= 2;
  // divCnt++;
  // }
  // }
  // }
  // print(min(mulCnt, divCnt));
}


Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.rbegin(), A.rend());
  cout << A[0] - A[1] + (A[1] - A[2]) << endl;
}


Measured memory_bytes: 256
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map {String($0)}
}

func readStringToStrings() -> [String] {
    return readLine()!.map{String($0)}
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map {Int($0)!}
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map {Double($0)!}
}

// 二進数に変換
func convertIntToRadix2(n: Int, radix: Int = 2) -> String {
    return String(n, radix: radix)
}

//配列を逆順にする reverced ソートする　sorted
//最初数文字取得 prefix


let N = readInt()
let students = readSeparatedInts()

var top = 0
var result = 0


for i in 0..<N {
    let h = students[i]
    
    if i == 0 {
        top = h
    } else {
        if top > h {
            result += top - h
        } else if top == h {
            
        } else {
            top = h
        }
    }
}
print(result)


Measured memory_bytes: 26216
void solve(){
}
void main(){
	int a, b;
	readf("%d %d\n", &a, &b);
	if(a<=8 && b<=8)writeln("Yay!");
	else writeln(":(");
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }



Measured memory_bytes: 2788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 1e9;
int n, a;
vector<pair<int, int> > vec;;
struct sorter{
  bool operator()(const pair<int,int> & a, const pair<int,int> & b){
    return a.second > b.second;
  }
};
const int maxn = 2e3+5;
long long dp[maxn][maxn];

int main(){
  cin>>n;
  vec.push_back({0, 0});
  for(int i = 1; i <= n; ++i){cin>>a; vec.push_back({i, a});}
  sort(vec.begin()+1, vec.end(), sorter());
  for(long long i = 1; i <= n; ++i){
    dp[i][0] = dp[i-1][0]+vec[i].second * abs(vec[i].first - (n-i+1));
    for(long long j = 1; j < i; ++j){
      dp[i][j] = max(dp[i-1][j-1] + vec[i].second * abs(vec[i].first - j), dp[i-1][j] + vec[i].second * abs(vec[i].first-(n-i+j+1)));
    }
    dp[i][i] = dp[i-1][i-1] + vec[i].second * abs(vec[i].first - i);
  }
  long long ans = 0;
  for(int i = 0; i <= n; ++i)ans = max(ans, dp[n][i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 26260
N = int(input())

if N < 10:
    print(N)
else:
    count = 9
    import numpy as np
    counter = np.zeros((9,9), dtype = int)
    for i in range(11, N+1):
        if i % 10 == 0:
            pass
        else:
            s = list(str(i))
            i1 = int(s[0]) - 1
            i2 = int(s[-1]) - 1
            counter[i1][i2] += 1
    #print(counter)
    for i in range(9):
        count += counter[i][i] ** 2 + counter[i][i] * 2
    #print(count)
    for i in range(8):
        for j in range(i+1, 9):
            #print(i,j,min(counter[i][j], counter[j][i]))
            count += counter[i][j] * counter[j][i] * 2
    print(count)

Measured memory_bytes: 14420
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    BigInteger MOD = BigInteger.TEN.pow(9);
    for (int i = 0; i < 7; i++) {
      MOD = MOD.add(BigInteger.ONE);
    }

    BigInteger ten = BigInteger.TEN;
    BigInteger nine = ten.add(BigInteger.ONE.negate());
    BigInteger eight = nine.add(BigInteger.ONE.negate());

    ten = ten.pow(n);
    nine = nine.pow(n);
    eight = eight.pow(n);

    System.out.println(ten.add(eight).add(nine.multiply(BigInteger.TWO).negate()).mod(MOD));

  }
}

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

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        StringBuilder sb = new StringBuilder();
        int N = sc.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        boolean isEven = true;
        for(int i=0; i<N; i++) {
           A[i] = sc.nextLong();
            if (isEven) {
                B[0] += A[i];
                isEven = false;
            } else {
                B[0] -= A[i];
                isEven = true;
            }
        }
        sb.append(B[0]);
        sb.append(" ");
        for(int i=1; i<N; i++) {
            B[i] = 2*A[i-1]-B[i-1];
            sb.append(B[i]);
            sb.append(" ");
        }
        out.println(sb.toString());
        out.flush();
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 33700
import sys
def input(): return sys.stdin.readline().strip()

class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        tree.union(a - 1, b - 1)
    ans = 0
    for root in tree.roots():
        ans = max(ans, tree.size(root))
    print(ans)



if __name__ == "__main__":
    main()


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

int main() {
  int x;
  
  for(int i = 1; i <= 10000; i++){
    cin >> x;
     if(x == 0){
       break;
     } 
    cout << "Case " << i << ": " <<  x << endl;
    
    
  }
  
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define cwk freopen("D:\\c++\\in.txt","r",stdin),freopen("D:\\c++\\out.txt","w",stdout)
using namespace std;
const int N=1e6+10;
int n,k,dp[N],a[N];
int main()
{
	//cwk;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(dp,inf,sizeof(dp));
	dp[1]=0;
	for(int i=2;i<=n;i++) {
		for(int j=1;j<=k;j++) {
			if(i-j>=1) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 6400
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> que;
    rep(i, s.size()) { que.push_back(s[i]); }
    bool rev = 0;
    rep(i, q) {
        int a;
        cin >> a;
        if (a == 1) {
            rev = 1 - rev;
        } else if (a == 2) {
            int b;
            char c;
            cin >> b >> c;
            if (b == 1 && !rev)
                que.push_front(c);
            if (b == 1 && rev)
                que.push_back(c);
            if (b == 2 && !rev)
                que.push_back(c);
            if (b == 2 && rev)
                que.push_front(c);
        }
    }

    if (rev)
        reverse(all(que));

    for (auto q : que) {
        cout << q;
    }
    cout << endl;
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
class Program{
	static List<int[]> he=new List<int[]>();
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[][] a=new int[n][];
		int[][] b=new int[n][];
		long ans=0,ih=1;
		for(int i=0;i<n;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			a[i]=new int[]{q[0],i};
			b[i]=new int[]{q[1],i};
		}
		Array.Sort(a,(u,v)=>u[0]-v[0]);
		Array.Sort(b,(u,v)=>u[0]-v[0]);
		for(int i=0;i<n-1;i++){
			heapa(a[i+1][0]-a[i][0],a[i][1],a[i+1][1]);
			heapa(b[i+1][0]-b[i][0],b[i][1],b[i+1][1]);
		}
		uf t=new uf(n);
		while(ih!=n){
			if(!t.same(he[0][1],he[0][2])){
				t.union(he[0][1],he[0][2]);
				ans+=he[0][0];
				ih++;
			}
			heapr();
		}
		Console.WriteLine("{0}",ans);
	}
	static void heapa(int a,int b,int c){
		he.Add(new int[]{a,b,c});
		int j=he.Count-1;
		while(he[j][0]<he[(j-1)/2][0]){
			int v=he[j][0];
			he[j][0]=he[(j-1)/2][0];
			he[(j-1)/2][0]=v;
			v=he[j][1];
			he[j][1]=he[(j-1)/2][1];
			he[(j-1)/2][1]=v;
			v=he[j][2];
			he[j][2]=he[(j-1)/2][2];
			he[(j-1)/2][2]=v;
			j=(j-1)/2;
		}
	}
	static void heapr(){
		he[0]=he[he.Count-1];
		he.RemoveAt(he.Count-1);
		int j=0;
		while(true){
			if(j*2+2<he.Count){
				if(he[j*2+1][0]<he[j*2+2][0]){j=j*2+1;}
				else{j=j*2+2;}
			}
			else if(j*2+1<he.Count){j=j*2+1;}
			else{break;}
			if(he[j][0]>=he[(j-1)/2][0]){break;}
			int v=he[j][0];
			he[j][0]=he[(j-1)/2][0];
			he[(j-1)/2][0]=v;
			v=he[j][1];
			he[j][1]=he[(j-1)/2][1];
			he[(j-1)/2][1]=v;
			v=he[j][2];
			he[j][2]=he[(j-1)/2][2];
			he[(j-1)/2][2]=v;
		}
	}
}
public class uf{//union find
	private int[] arr;
	private int[] hi;
	public uf(int n){
		arr=new int[n];
		hi=new int[n];
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void union(int a,int b){
		a=root(a);
		b=root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
		}
	}
	public bool same(int a,int b){return root(a)==root(b);}
	public int total(int a){return -arr[root(a)];}
	private int root(int a){return arr[a]<0?a:arr[a]=root(arr[a]);}
}

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

int main(){
ios::sync_with_stdio(0); 
cin.tie(0);
map<int,int> m;

string s;
cin>>s;

int n = s.length();
int count = 1;
int ans = 0,x = 0;
m[0] = 1;
for(int i=n-1;i>=0;i--){
  
  	x = ((s[i] -'0') * count + x) % 2019;
  	ans+=m[x];
  	m[x]++;
  	count = count *10 %2019;

}

cout<<ans;


}


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

int main()
{
    int f, n, t;
    while (true) {
        bool schedule[50][31] = {};
        long long maps[50];
        cin >> n;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            cin >> f;
            for (int j = 0; j < f; j++) {
                cin >> t;
                schedule[i][t] = true;
            }
        }
        
        for (int i = 0; i <n; i++) {
            maps[i] = 1LL << i;
        }
        
        int ans = -1;
        long long gather;
        for (int t = 1; t <= 30; t++) {
            gather = 0;
            for (int i=0; i < n; i++) {
                if (schedule[i][t]) {
                    gather |= maps[i];
                }
            }
            for (int i=0; i < n; i++) {
                if (schedule[i][t]) {
                    maps[i] = gather;
                }
            }
            if (gather == (1LL << n) - 1){
                ans = t;
                break;
            }
        }
        cout << ans << endl;
        
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int32_t main() 
{
    fast;
	int A;
    double B;
	cin >> A >> B;
    double res = A*B;
    B=round(B*100);
    cout << (int) (A* (int)B/100);
    
}




Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int s[10];
    fill(s,s+10,0);
    s[a]++;
    s[b]++;
    s[c]++;
    if(s[5]==2&&s[7]==1) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
from itertools import accumulate 
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  a2 = [0] + list(accumulate(a))

  for i in range(n+1):
    a2[i] %= m
  c = Counter(a2)
  ans = 0
  for i in c.values():
    ans += i*(i-1)//2
  print(ans)
if __name__ == "__main__":
  solve()

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

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

    ll mod = n % k;

    cout << min(mod, k-mod) << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
N = 100005
G = [[] for _ in range(N)]
def dfs(v):
    child = []
    for e in G[v]:
        child.append(dfs(e))
    child.sort()
    depth = 0
    for i,c in enumerate(child):
        depth = max(depth,c + len(child) - i)
    return depth

def main():
    N = int(input())
    for i in range(1,N):
        a = int(input()) - 1
        G[a].append(i)
    print(dfs(0))
if __name__ == '__main__':
    main()


Measured memory_bytes: 117684
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    s = list(input())
    
    s.pop()

    l = s[0:len(s)//2]
    r = s[len(s)//2:]

    while l != r:
        s.pop()
        l = s[0:len(s)//2]
        r = s[len(s)//2:]
        # print(s)
    print(len(s))
if __name__ == "__main__":
    main()




Measured memory_bytes: 5200
#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;
    string s;cin>>s;
    string s1 = to_string(s.size()-2);
    out(s[0]+s1+s[s.size()-1]);
}


Measured memory_bytes: 256
def answer(N:int,K:int) -> int:
    l = [i for i in range(N+1)]
    counter = 0
    for i in range(K,N+2):
        counter += i*(N - i + 1) + 1

    return counter % (10**9 + 7)



def main():
    N,K = map(int,input().split())
    # answer()
    print(answer(N,K))

if __name__ == '__main__':
   main()


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

using namespace std;
vector<int> prime;
bool isPrime[51000];

void PrimeCalc()
{
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 51000; ++i)
	{
		isPrime[i] = true;
	}
	for(int i = 2; i < 51000; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < 51000; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		for(int i = 0; i < prime.size(); ++i)
		{
			if(prime[i] > n / 2)
			{
				break;
			}
			if(isPrime[n - prime[i]])
			{
				++count;
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 1320
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; string s; cin >> n >> s;
  int ans = 0;
  REP(i, n - 2) ans += s.substr(i, 3) == "ABC";
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
// ※※※ 解答不能パターン. ※※※
// -> 以下のソースコードを復習する.
// rickytheta氏.
// https://atcoder.jp/contests/abc139/submissions/7268938
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
pair<long double, long double> es[125];

int main(){
    scanf("%d",&n);
    REP(i,n){
        long double x,y;
        scanf("%Lf%Lf",&x,&y);
        es[i] = make_pair(x,y);
    }
    sort(es,es+n,[&](pii a, pii b){
        return atan2(a.second, a.first) < atan2(b.second, b.first);
    });
    long double ans = 0;
    REP(i,n){
        long double dx=0, dy=0;
        REP(j,n){
            dx += es[(i+j)%n].first;
            dy += es[(i+j)%n].second;
            CHMAX(ans, dx*dx + dy*dy);
        }
    }
    printf("%.20Lf\n",sqrtl(ans));
    return 0;
}

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

typedef long long ll;

bool checker( string s , string a)
{
    if( s.substr(0,7) == a)
        return true;
    if( s.substr(0+s.length()-7,7)==a )
        return true;
    for( int i=1;i<=7;i++)
    {
        if( s.substr(0,i) == a.substr(0,i) )
        {
            string temp = a.substr(i,a.length()-i);
            int len = temp.length();
            if( s.substr(s.length()-len,len) == temp)
                return true;
        }
    }
    return false;
}
int main()
{
    string s;
    cin>>s;
    string a = "keyence";
    if( checker(s,a))
        cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 3616