akhauriyash/Code-Regression huggingface dataset:
N , K = list(map(int,input().split()))

X = list(map(int,input().split()))

left = []
right = []

for x in X:
    if x<0:
        left.append(-x)
    if x==0:
        K-=1
    if x>0:
        right.append(x)
left = list(reversed(left))
left.insert(0,0)
right.insert(0,0)

def solve(left,right):
    result = float('inf')
    for i in range(min(len(left),K)):
        #print(i,left,right)
        tmp_time =  2*left[i]
        tmp_count = i
        if i + len(right)-1 < K:
            continue
        tmp_result = tmp_time+ right[K-i]
        result  = min(result,tmp_result)

    return result


if K==0 :
    print(0)
    exit()
print(min(solve(left,right),solve(right,left)))


Measured memory_bytes: 14660
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
//----------------------------------//

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

//-------------------------------------------------------//
#define rep(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::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...);
}
#else
#define debug(...)
#endif
#define _ist_ cout << "\nSTART OF INPUT DISPLAYING CHECK\n";
#define _iend_ cout << "\nEND OF INPUT DISPLAYING CHECK\n";
//------------------------------------------------------------//
#define mod (ll)(1e9 + 7)
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1LL;
    a%=mod;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a);
        a%=mod;
        b >>= 1;
    }
    return (res);
}
#define N (int)3e3+5
int n;
double dp[N];
int main()
{
    Ios;
    //inn;//outt;
    //auto tt = clock();
    cin >> n;
    dp[0] = 1.0;
    for(int coin = 1; coin <= n; coin++)
    {
        double p;
        cin >> p;
        repr(i, n, 0)
        {
            dp[i] = dp[i - 1]*p + dp[i]*(1.0 - p);
        }
    }
    double ans = 0;
    rep(i, 1, n)
    {
        int j = n - i;
        if(i > j)
            ans+=dp[i];
    }
    cout <<fixed<<setprecision(9)<< ans << endl;
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> >
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int mul(int a, int b) {
  a += mod; b += mod;
  a %= mod; b %= mod; return ((a * b) % mod);
}

void solve() {
  int n, k, ans = 1, K; cin >> n >> k;
  K = k;
  vector <int> p, neg, z;
  vector <pii> v;
  for(int i = 0; i < n; i++) {
    int x, s; cin >> x;
    if(x > 0) {
      p.pb(x);
      s = 1;
    }
    if(x < 0) {
      neg.pb(abs(x));
      s = -1;
    }
    if(x == 0) {
      z.pb(x);
      s = 1;
    }
    v.pb({abs(x), s});
  }
  sort(all(p)); sort(all(neg)); sort(all(z)); sort(all(v));
  int i = sz(p)-1, j = sz(neg)-1;

  if(k%2) {
    if(!p.empty()) {
      k--; ans = mul(ans, p[i]);
      i--;
    }
  }

  while(k && (i > 0 || j > 0)) {
     int a = -INF, b = -INF;
     if(i >= 1) {
       a = p[i] * p[i-1];
     }
     if(j >= 1) {
       b = neg[j] * neg[j-1];
     }
     if(a > b) {
       ans = mul(ans, a);
       k-=2; i-=2;
     }
     else {
       ans = mul(ans, b);
       k-=2; j-=2;
     }
  }
  if(k) {
    if(!z.empty()) {
      ans = 0;
    } else {
      ans = 1;
      for(int l = 0; l < K; l++) {
         ans = mul(ans, v[l].ss * v[l].ff);
      }
    }
  }
  cout << ans << '\n';
}

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

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
     solve();
  }
}



Measured memory_bytes: 9468
#include<stdio.h>
#include <string.h>
#include<math.h>

int main(){
	long a,b,m,n;
	
	while(scanf("%ld %ld",&a,&b)!=EOF){
		if(a>b){
			m=a;
			n=b;
		}else{
			m=b;
			n=a;
		}
		while(m!=n){
			if(m>n){
				m=m-n;
			}else{
				n=n-m;
			}
		}
		printf("%ld %ld\n",m,(a/m)*b);
	}
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, l;
    cin >> n >> l;
    string s[n];
    for(int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s, s + n);
    string ans = "";
    for(int i = 0; i < n; i++) {
        ans += s[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;


long long n,k,pre,ans,preD[100005],preS[100005],a,b;
vector<long long> dis, single;
pair<long long,long long> arr[100005];

bool cmp (long long a, long long b){
	return a>b;
}

int main(){
	scanf("%lld%lld",&n,&k);
	for(int i =0;i<n;i++){
		scanf("%lld%lld",&a,&b);
		arr[i] = {a,-b};
	}
	sort(arr,arr+n);
	
	dis.push_back(0);
	single.push_back(0);

	pre = -1;
	for(int i =0;i<n;i++){
		if(arr[i].FI!=pre){
			// printf("push to dis %lld\n",-arr[i].SE);
			dis.push_back(-arr[i].SE);
		} else {
			single.push_back(-arr[i].SE);
			// printf("push to single %lld\n",-arr[i].SE);
		}
		pre = arr[i].FI;
	}

	sort(dis.begin()+1,dis.end(),cmp);
	sort(single.begin()+1,single.end(),cmp);

	for(int i= 1;i<dis.size();i++){
		preD[i] = preD[i-1]+dis[i];
	}
	for(int i= 1;i<single.size();i++){
		preS[i] = preS[i-1]+single[i];
	}
	for(long long i =0;i<=k;i++){
		if(i>=dis.size()||k-i>=single.size())continue;
		ans = max(ans, preD[i]+preS[k-i]+i*i);
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  char c; cin >> c; c++;
  cout << c;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int h1, m1, s1, h2, m2, s2, i;

  for(i=0; i<3; i++){
    scanf(" %d %d %d %d %d %d", &h1, &m1, &s1, &h2, &m2, &s2);

    s2-=s1;
    if(s2<0){
      s2 += 60;
      m2--;
    }

    m2-=m1;
    if(m2<0){
      m2 += 60;
      h2--;
    }

    h2-=h1;

    printf("%d %d %d\n", h2, m2, s2);
  }

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
#include<limits.h>

#include<iomanip>
#include<cmath>
using namespace std;



int main() {
	int n, k, q,x;
	int v[100001] = {};
	cin >> n >> k >> q;

	for (int i = 1;i <= q;i++) {
		cin >> x;
		v[x]++;
	}

	for (int i = 1;i <= n;i++) {
		if (k - q + v[i] > 0)
			cout << "Yes"<<endl;
		else
			cout << "No"<<endl;
}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL
    char ch;
    cin>>ch;
    if(ch>=65 && ch<=90)
    {
        cout<<'A'<<endl;
    }
    else cout<<'a'<<endl;
    return 0;
}



Measured memory_bytes: 3596
package main

import (
	"fmt"
)

func pow(x, n, mod int64) int64 {
	if n == 0 {
		return 1
	}
	xx := x * x % mod
	r := pow(xx, n/2, mod)
	if n%2 == 1 {
		r = x * r % mod
	}
	return r
}

const mod = 1e9 + 7

func main() {
	var n int
	fmt.Scan(&n)

	fmt.Println(3 * n * n)

}


Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

ll dp[4][3005][3005];

void solve() {
    int R, C, K;
    cin >> R >> C >> K;
    map<ll, ll> d;
    V<ll> s;
    rep(i, K) {
        ll r, c;
        ll v;
        cin >> r >> c >> v;
        r--;
        c--;
        d[r * (ll)C + c] = v;
        s.push_back(r * (ll)C + c);
    }
    sort(s.begin(), s.end());
    rep(k, 4) rep(i, R) rep(j, C) dp[k][i][j] = 0;

    rep(i, R) rep(j, C) {
        rep(k, 4) {
            if (i > 0) {
                dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]);
            }
        }
        rep(k, 4) {
            if (j > 0) {
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1]);
            }
        }
        auto idx = lower_bound(s.begin(), s.end(), i * C + j);
        if (*idx == i * C + j) {
            for (int k = 2; k >= 0; k--) {
                //
                ll v = d[i * C + j];
                dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + v);
            }
        }
    }

    ll ans = 0;
    rep(i, 4) ans = max(ans, dp[i][R - 1][C - 1]);
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 298836
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] S = new String[H+2];
		int[][] wlen = new int[H+2][W+2];
		int[][] hlen = new int[H+2][W+2];
		for(int i = 1; i <= H; i++) {
			S[i] = sc.next();
			S[i] = '#' + S[i] + '#';
		}
		for(int i = 0; i < W+2; i++) {
			S[0] += '#';
			S[H+1] += '#';
		}
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++) {
				wlen[i][j] = wlen[i][j-1];
				if(S[i].charAt(j) == '.')
					wlen[i][j]++;
				else
					wlen[i][j] = 0;
			}
		}
		for(int i = 1; i <= H; i++) {
			for(int j = W; j >= 1; j--)
				if(S[i].charAt(j-1) == '.' && S[i].charAt(j) == '.')
					wlen[i][j-1] = wlen[i][j];
		}
		for(int j = 1; j <= W; j++) {
			for(int i = 1; i <= H; i++) {
				hlen[i][j] = hlen[i-1][j];
				if(S[i].charAt(j) == '.')
					hlen[i][j] ++;
				else
					hlen[i][j] = 0;
			}
		}
		for(int j = 1; j <= W; j++) {
			for(int i = H; i >= 1; i--)
				if(S[i-1].charAt(j) == '.' && S[i].charAt(j) == '.')
				hlen[i-1][j] = hlen[i][j];
		}
		int ans = 1;
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++)
				ans = Math.max(ans,hlen[i][j]+wlen[i][j]-1);
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 108628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define SIZE 1000001
ll parent[1000001];
ll Rank[1000001];
map<int, list<int>> g;
int findParent(int a)
{
    if (parent[a] == a)
    {
        return a;
    }
    else
    {
        parent[a] = findParent(parent[a]);
    }
    return parent[a];
}
void Union(int a, int b)
{
    int parentA = findParent(a);
    int parentB = findParent(b);
    if (parentA == parentB)
    {
        if (Rank[parentA] < Rank[parentB])
        {
            parent[parentA] = parentB;
        }
        else if (Rank[parentB] < Rank[parentA])
        {
            parent[parentB] = parentA;
        }
        else
        {
            parent[parentB] = parentA;
            Rank[parentA]++;
        }
    }
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
// gcd of a and b
void count(int curIndex, int originalIndex, int &day, vector<int> &days, vector<int> &a)
{
    if (curIndex == originalIndex)
    {
        days[originalIndex - 1] = day;
        return;
    }
    day++;
    count(a[curIndex - 1], originalIndex, day, days, a);
    days[curIndex - 1] = days[originalIndex - 1];
}
void rever(string &str, int index)
{
    index++;
    if (index - 1 < 0)
    {
        return;
    }
    for (int i = 0; i < index; i++)
    {
        if (str[i] == '0')
        {
            str[i] = '1';
        }
        else
        {
            str[i] = '0';
        }
    }
    for (int i = 0; i < index / 2; i++)
    {
        swap(str[i], str[index - i - 1]);
    }
}
ll powe(ll x, ll y)
{
    ll res = 1;
    x = x % mod;

    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;

        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
int sign(int a)
{
    if (a > 0)
    {
        return 1;
    }
    if (a < 0)
    {
        return -1;
    }
    return 0;
}
int dp[100005];
bool visited[100005];
int dfs(int src)
{
    if (g[src].size() == 0)
    {
        return 0;
    }
    if (dp[src] != -1)
    {
        return dp[src];     
    }
    for (auto to : g[src])
    {
        if (visited[to] == false)
        {
            visited[to] = true;
            int len = dfs(to);
            visited[to] = false;
            dp[src] = max(dp[src], len + 1);
        }
    }
    return dp[src];
}
void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }
    memset(visited, false, sizeof visited);
    memset(dp, -1, sizeof dp);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int number = dfs(i);
        ans = max(ans, number);
    }
    cout << ans << endl;
}
//STL based comparing
int main()
{
    int t = 1;
    // cin >> t;
    //t = 1;
    for (int i = 1; i <= t; i++)
    {
        //cout << "Case #" << i << ":" << endl;
        solve();
    }
    return 0;
}

Measured memory_bytes: 18948
n,m = map(int, input().split())

ac_count = 0
wa_count = 0
p_dict = {str(i):[0,0] for i in range(1, n+1)}

for m_i in range(m):
  p,s = input().split()
  if p_dict[p][1] == 0:
    if s=='WA':
      p_dict[p][0] += 1
    elif s=='AC':
      p_dict[p][1] += 1
  
for val in p_dict.values():
  if val[1] == 1:
    ac_count += 1
    wa_count += val[0]
    
print(ac_count, wa_count)

Measured memory_bytes: 25252
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int c,n,ans=0,cnt=0;
  scanf("%d %d",&c,&n);
  char b[n+1];
  int a[n][n],ch[n/2][n/2];
  FOR(n){
    scanf("%s",b);
    FORJ(n)a[i][j]=b[j]-'0';
  }
  FOR(n/2)FORJ(n/2)cnt+=ch[i][j]=1-(a[i][j]==a[n-1-i][j]&&a[n-1-i][j]==a[i][n-1-j]&&a[i][n-1-j]==a[n-1-i][n-1-j]);
  FOR(c){
    if(i){
      int f,h,w;
      scanf("%d",&f);
      FORJ(f){
        scanf("%d %d",&h,&w);
        h--,w--;
        a[h][w]=(a[h][w]+1)%2;
        h=min(h,n-1-h);
        w=min(w,n-1-w);
        if(!ch[h][w]){
          cnt++;
          ch[h][w]++;
        }else{
          ch[h][w]=1-(a[h][w]==a[n-1-h][w]&&a[n-1-h][w]==a[h][n-1-w]&&a[h][n-1-w]==a[n-1-h][n-1-w]);
          if(!ch[h][w])cnt--;
        }
      }
    }
    if(cnt<1)ans++;
  }
  PRN(ans);
  return 0;
}


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

using namespace std;

int main() {
    float cir[101];
    float pi=3.1415;
    for(int i=1;i<101;i++)
    {
     cir[i]=2*(pi)*i; 
    }
    int r;
    cin>>r;
    cout<<cir[r]<<endl;
}

Measured memory_bytes: 3780
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

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

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    string s,s1;
    cin>>s>>s1;
    ll n=(ll)s.length();
    if((ll)s1.length()!=n+1)
        cout<<"No\n";
    else
    {
        rep(a,0,n)
        {
            if(s[a]!=s1[a])
            {
                cout<<"No\n";
                exit(0);
            }
        }
        cout<<"Yes\n";
    }
    
	printclock;
	return 0;
}

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = INF + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e1 + 5;

int main() {
 
	sync;
	
	int n; cin >> n;
	if (n % 2 == 0) cout << n / 2 - 1 << endl;
	else cout << n / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001

stack<pair<int, int> > st;	 //index, num
int N;
int main() {
	cin >> N;
	st.push(make_pair(-1, 0));
	long long sum = 0;
	REP(i, 0, N + 1) {
		int buf;
		if (i == N) {
			buf = 0;
		} else {
			cin >> buf;
		}
		while (st.top().second > buf) {
			int num = st.top().second;
			int idx = st.top().first;
			int left, right;
			right = i - idx;
			st.pop();
			left = idx - st.top().first;
			sum += (long long)num * left * right;
		}
		st.push(make_pair(i, buf));
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

int main(){
	std::string s;
	std::vector<bool> isfound(26, false);
	std::vector<char> cList= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int pos=-1;
	std::cin>>s;

	for(int i=0; i<s.size(); i++)
		isfound[s[i]-'a']=true;

	for(int i=0; i<26; i++)
		if(!isfound[25-i])
			pos=25-i;

	if(pos==-1)
		std::cout<<"None"<<std::endl;
	else
		std::cout<<cList[pos]<<std::endl;

	return 0;

}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
  int A,B,K,ans;
  cin >> A >> B >> K;
  
  for(int i = min(A,B);i > 0 ; --i){
    if(A % i == 0 && B % i == 0)
      K--;
    if(K == 0){
      ans = i;
      break;
    }  
  }

  cout << ans << endl;    
}

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

int main(){
    int N;
    cin >> N;
    vector<char> ans;
    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    while(N){
        int now=N%(-2);
        if(now!=0){
            ans.push_back('1');
            N-=1;
        }else{
            ans.push_back('0');
        }
        N/=-2;
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

ll dp[512][512];

void solve(ll N, ll M_a, ll M_b, vector<ll> a, vector<ll> b, vector<ll> c) {
  REP(i,512) REP(j,512) dp[i][j] = 1e9;
  dp[0][0] = 0;
  REP(p,N) {
    for (int i = 400; i >= 0; --i) {
      REP(j,400) {
        chmin(dp[i + a[p]][j + b[p]], dp[i][j] + c[p]);
      }
    }
  }
  ll res = 1e9;
  REP(i,401) REP(j,401) {
    if (i > 0 && i * M_b == j * M_a) chmin(res, dp[i][j]);
  }
  if (res == ll(1e9)) res = -1;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll M_b;
	ll M_a;
	scanf("%lld", &N);
	vector<ll> c(N-1+1);
	vector<ll> a(N-1+1);
	vector<ll> b(N-1+1);
	scanf("%lld", &M_a);
	scanf("%lld", &M_b);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	  scanf("%lld", &c[i]);
	}
	solve(N, M_a, M_b, a, b, c);
	return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b){
    cout << c << endl;
  }else if(b==c){
    cout << a << endl;
  }else{
    cout << b << endl;
  }
}


Measured memory_bytes: 256
let [| n; m; c; |] = stdin.ReadLine().Split(" ") |> Array.map int
let B = stdin.ReadLine().Split(" ") |> Array.map int |> Array.toList
[1 .. n]
|> List.map (
  fun _ -> 
    stdin.ReadLine().Split(" ") 
    |> Array.map int 
    |> Array.toList 
    |> List.zip B
    |> List.map (fun (a,b) -> a*b)
    |> List.reduce (+)
  )
|> List.filter (fun x -> x + c > 0)
|> List.length
|> printfn "%d"

Measured memory_bytes: 30120
import math
n, d = map(int, input().split())
x = list(input().split() for i in range(n))
x = [[int(i) for i in x[j]] for j in range(len(x))]
a = 0
for i in range(n-1):
    for j in range(i+1,n):
        di = 0
        for b in range(d):
            di += (x[i][b] - x[j][b]) ** 2
        di = math.sqrt(di)
        if di == int(di):
            a += 1
        else:
            pass
print(a)


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  priority_queue<ll> A;
  REP(i, N) {
    ll a = 0;
    cin >> a;
    A.push(a);
  }
  ll all = 0;
  while (true) {
    ll a = A.top();
    A.pop();
    if (a + all < N)
      break;
    ll po = ceil((long double)(all + a - (N - 1)) / N);
    all += po;
    A.push(a - (po * N) - po);
  }

  cout << all << endl;
  return 0;
}


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


char change(char s){
    if(s == 'A'){
        return 'a';
    }else if(s == 'B'){
        return 'b';
    }else if(s == 'C'){
        return 'c';
    }
}

int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    S.at(K-1) = change(S.at(K-1));
    cout << S;
}

Measured memory_bytes: 256
def s(n):
    ret=0    
    for i in range(15):
        ret+=(n%10**(i+1))//10**i
    return ret

k=int(input())
ans=set()
for i in reversed(range(14)):
    m=float('inf')
    for j in reversed(range(1,1000)):
        n=int(str(j)+'9'*i)
        if n/s(n)<=m :
            ans.add(n)
            m=n/s(n)
ans=sorted(list(ans))
for a in ans[:k]:
    print(a)


Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, A, B;
int C[300000];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> A >> B;
  if (A+B > N+1) {
    cout << -1 << "\n";
    return 0;
  }
  rep(i, B) C[i]++;
  int rest = N-B;
  rep(i, B) {
    rep(_, A-1) {
      if (rest <= 0) break;
      C[i]++;
      rest--;
    }
  }
  vector<int> ret;
  int h = N;
  rep(i, B) {
    h -= C[i];
    rep(j, C[i]) ret.pb(h+1+j);
  }
  if (rest != 0 || h != 0 || C[0] < A) {
    cout << -1 << "\n";
    return 0;
  }
  assert(ret.size() == N);
  for (int x : ret) cout << x << " "; cout << "\n";
  return 0;
}


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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for(ll bit = 0; bit <= 60; bit++){
        ll o = 0, z = 0;
        ll t = (1LL << bit);
        rep(i,n){
            if(a[i] & t) o++;
            else z++;
        }
        ll cnt = o * z;
        ans += ((o * z) % mod) * ((1LL << bit) % mod);
        ans %= mod;
    }
        
    cout << ans % mod << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2)//split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 16)
	{
		solve(0, h-1, j, min(j+15, w-1), query(0, w-1, j, min(j+15, w-1)), 1);
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

ll F(ll x) {
	return x * (x + 1) / 2;
}

ll rangu(ll le, ll ri) {
	return (F(ri) - F(le - 1)) % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	n++;
	for(int i = k - 1; i < n; i++) {
		ll cr = rangu(n - i, n) - rangu(1, i + 1) + 1;
		//LOG << cr << '\n';
		ans = (ans + MOD + cr) % MOD;
	}
	cout << ans << '\n';
}



Measured memory_bytes: 3656
import java.util.ArrayList;
import java.util.List;
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 X = Integer.parseInt(sc.next());
		int m_sum = 0;
		int m_min = Integer.MAX_VALUE;

		List<Integer> M = new ArrayList<Integer>();
		for(int i=0; i<N; i++){
			int m = Integer.parseInt(sc.next());
			m_sum += m;
			M.add(m);
			m_min = m_min > m ? m:m_min;
		}
		System.out.println(N + (X - m_sum)/m_min);
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;
const double pi = acos(-1.0);

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    reg double a, b, x;
    cin >> a >> b >> x;
    double V = a * a * b;
    if (x * 2 <= V) {
        reg double area = x / a;
        reg double A = b, B = area * 2.0 / A;
        reg double angle = atan(A / B);
        angle = angle * 180.0 / pi;
        printf("%.9f\n", angle);
    }
    else {
        reg double area = (V - x) / a;
        reg double A = a, B = area * 2.0 / A;
        reg double angle = atan(B / A);
        angle = angle * 180.0 / pi;
        printf("%.9f\n", angle);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {

  string inp;
  int n;
  cin >> n >> inp;
  for(int i = 0;i < inp.size();i++){
    cout << char('A' + (inp[i] - 'A' + n) % ('Z' - 'A' + 1));
  }
  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int valu[100005];
struct node{
    int x;
    int y;
    int next;
}no[100005];
int head[100005];
int cnt;
void add(int x,int y)
{
    no[cnt].x=x;
    no[cnt].y=y;
    no[cnt].next=head[x];
    head[x]=cnt++;
}

void dfs(int x)
{
    for(int i=head[x];i!=-1;i=no[i].next)
    {
        dfs(no[i].y);
    }
	vector<int>ve; 
    for(int i=head[x];i!=-1;i=no[i].next)
    {
        ve.push_back(valu[no[i].y]);
    }
    sort(ve.begin(),ve.end());
    for(int i=0;i<ve.size();i++)
        valu[x]=max(valu[x],ve[i])+1;
}
int main() {
    int n;
    scanf("%d",&n); 
    memset(head,-1,sizeof(head));
    cnt=0;
    for(int i=2;i<=n;i++)
    {
        int temp;
        scanf("%d",&temp);
        add(temp,i);//temp 将 i打败了 
    }  
    dfs(1);
    printf("%d\n",valu[1]); 
    return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin>>N;
   int64_t sum=0;
  for (int64_t i=0; i<=N; i++){
    if (i%3!=0 && i%5!=0){
      sum+=i;}}
  cout<<sum<<endl;
}
    


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define gcd __gcd
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vec(cr)vector<cr>
#define fr(j, n)for(int i=j; i<n; i++)
#define scan(cr)for(auto &it:cr)cin >> it
#define all(cr)cr.begin(), cr.end()
#define sz(cr)cr.size()
#define Test() int t; for(cin >> t; t>0; t--)
#define deb(x)cout << #x << ":" << x << '\n'
int lcm(int a, int b){ return a/gcd(a, b) * b; }

int main(){
	ll n, k, d;
	cin >> n >> k >> d;
	n = abs(n);
	ll moves = min(n/d, k);
	n -= (moves*d);
	k -= moves;
	if(k%2==0)cout << abs(n);
	else cout << abs(n-d);
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, r;
  cin>>n>>r;
  if(n < 10){
    int d = 100 * (10 - n);
    cout<<r + d<<endl;
  }
  else{
    cout<<r<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

struct point
{
  int x;
  int y;

  point
  rotate90
  () const
  {
    const point p{ -y, x };
    return p;
  }
};

point
operator+
(
  const point p1,
  const point p2
)
{
  const point p12
  {
    p1.x + p2.x,
    p1.y + p2.y
  };
  return p12;
}

point
operator-
(
  const point p1,
  const point p2
)
{
  const point p12
  {
    p1.x - p2.x,
    p1.y - p2.y
  };
  return p12;
}

std::ostream &
operator<<
(
  std::ostream & os,
  const point p
)
{
  os << p.x << ' ' << p.y;
  return os;
}

int
main
()
{
  point p1;
  point p2;

  std::cin >> p1.x >> p1.y >> p2.x >> p2.y;

  const point p12{ p2 - p1 };

  const point p23{ p12.rotate90() };
  const point p3{ p2 + p23 };

  const point p34{ p23.rotate90() };
  const point p4{ p3 + p34 };

  std::cout << p3 << ' ' << p4 << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int k, q;
  cin >> k >> q;
  vector<ll> d(k), e(k);
  for (int i = 0; i < (int)(k); ++i) cin >> d[i];

  for (int i = 0; i < (int)(q); ++i) {
    ll n, x, m;
    cin >> n >> x >> m;

    x %= m;
    for (int i = 0; i < (int)(k); ++i) e[i] = d[i] % m;
    ll ans = n - 1, s = accumulate((e).begin(), (e).end(), 0LL);
    ll l = (n - 1) / k;

    ans -= l * count((e).begin(), (e).end(), 0LL);
    for (int i = 0; i < (int)((n - 1) % k); ++i) ans -= (e[i] == 0);

    ll y = x + l * s;
    for (int i = 0; i < (int)((n - 1) % k); ++i) y += e[i];
    ans -= y / m - x / m;

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math

A, B = map(int, input().split())

# R = 1
# while ((A - 1) * (R - 1)) + A < B:
#     R += 1

print(math.ceil((B - 1.0) / (A - 1.0)))


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main(void){
  long long int n,k,q,i;
  scanf("%lld%lld%lld",&n,&k,&q);
  long long int a[n],t;
  for(i=0;i<n;i++){
    a[i]=k-q;
  }
  for(i=0;i<q;i++){
    scanf("%lld",&t);
    a[t-1]++;
  }
  for(i=0;i<n;i++){
    if(a[i]<=0) printf("No\n");
    else printf("Yes\n");
  }
  return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= 9; i++) {
    if (n <= 100 * i + 10 * i + i) {
      cout << 100 * i + 10 * i + i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#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(){
    int x,n;
    cin >> x >> n;
    vector <int> p(101,0);
    int pp;
    rep(i,n){
        cin >> pp;
        p[pp]=-1;
    }

    int k=0,kk=0,ans=0;

    
    while(k==0){
        if(x+kk>100){
            ans=x+kk;
            k=2;
        }
        
        if((x+kk)<=100){
            if(p[x+kk]==0){
                ans=x+kk;
                k=1;
            }
        }
        if(x-kk>0){
        if((p[x-kk])==0){
            ans=x-kk;
            k=2;
    }

        }
        if(x-kk<=0){
            ans=x-kk;
            k=4;
        }
        
        ++kk;
    }
    


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	while (scan.hasNext()) {
	    int m = scan.nextInt();
	    int f = scan.nextInt();
	    int r = scan.nextInt();
	    if (m == -1 && f == -1 && r == -1) {
		break;
	    }
	    if (m == -1 || f == -1) {
		System.out.println("F");
	    } else if (m + f >= 80) {
		System.out.println("A");
	    } else if (65 <= m + f && m + f < 80) {
		System.out.println("B");
	    } else if (50 <= m + f && m + f < 65) {
		System.out.println("C");
	    } else if (30 <= m + f && m + f < 50) {
		if (r >= 50) {
		    System.out.println("C");
		} else {
		    System.out.println("D");
		}
	    } else if (m + f < 30) {
		System.out.println("F");
	    }
	}
    }
}

Measured memory_bytes: 26268
var
  p1,p2,i:longint;
  s:string;
begin
  readln(s);
  p1:=pos('C',s);
  for i:=length(s) downto 1 do
    if (s[i]='F') and (p1<i) and (p1<>0) then
    begin
      writeln('Yes');
      halt;
    end;
  writeln('No');
end.

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	string a, b, c;

	cin >> a >> b;

	c = a + b;
	
	int tmp = stoi(c);

	bool check = false;
	for (int i = 0; i <= 320; i++) {

		if (i*i == tmp) {

			check = true;
			break;

		}

	}

	if (check)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long int ll;

int main(){

	int a, b, c;
	cin >> a >> b >> c;
	if(a+b>=c){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
  
  return 0;
}


Measured memory_bytes: 764