akhauriyash/Code-Regression huggingface dataset:
# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47540
#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 next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}


int main(){
    int n;
    cin >> n;
    int k = 1;
    while(k*(k-1)<2*n){
        k++;
    }
    if(k*(k-1)!=2*n){
        cout << "No" << endl;
        return 0;
    }
    vector<vector<int>> S(k);

    int youso=1;

    rep(i,k){
        for(int j=i+1;j<k;++j){
            S[i].push_back(youso);
            S[j].push_back(youso);
            //cout << "add" << i << youso<<endl;
            //cout << "add" << j << youso << endl;
            youso++;
        }
    }

    cout << "Yes" << endl;
    cout << S.size() << endl;
    rep(i,S.size()){
        cout << S[i].size();
        rep(j,S[i].size()){
            cout << " " << S[i][j];
        }
        cout << endl;
    }


}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,dif=0;
	cin>>n;
	vl v(n),u(n);
	rep(i,n)cin>>v[i],u[i]=v[i];
	map<ll,ll> mp;
	sort(all(u));
	rep(i,n)mp[u[i]]=i;
	rep(i,n){
		if(mp[v[i]]%2!=i%2)dif++;
	}
	cout<<dif/2<<endl;;



}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,n,i;
	scanf("%d %d",&a,&b);
	for(i=0;i<b;i++)
	{
		scanf("%d",&c);
		a=a-c;
	}
	if(a<=0)
	printf("Yes");
	else
	printf("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <deque>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    ll a,b,c;
    cin >> a >> b >> c;

    if(c - a - b > 0 && (c - a - b) * (c - a - b) > 4 * a * b)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;
//cpp_int 多倍長

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

int A[100001];
cpp_int mxa[100001];
int N;

int sol(){

    //test();
    cin>>N;
    int mn=1;
    cpp_int mx=1;
    for(int i=0;i<N+1;i++){
        cin>>A[i];
        //cout<<",,,,"<<mx<<endl;
        mx-=A[i];
        mxa[i]=mx;
        if(mx<=0&&i!=N||mx<0&&i==N){
            //cout<<"-1"<<endl;
            return -1;
        }
        mx*=2;
    }


    int bef=A[N];
    int ans=A[N];
    for(int i=N-1;i>=0;i--){
        //cout<<ans<<","<<bef<<","<<mxa[i]<<endl;
        if(mxa[i]>bef) mxa[i]=bef;
        ans+=min(bef,(long long)mxa[i])+A[i];
        bef=min(bef,(long long)mxa[i])+A[i];
    }
    return ans;
}

signed main(){
  cout<<sol()<<endl;
}

Measured memory_bytes: 618816
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N,T;

    cin >> N >> T;

    int cm = 1000;
    int num = 0;
    bool TLE = true;

    for(int i = 0; i < N; i++){
        int c,t;

        cin >> c >> t;

        if(t <= T){
            cm = min(cm,c);
            TLE = false;
        }
    }

    if(TLE){
        cout << "TLE" << endl;
    }else{
        cout << cm << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    ll minus = 0;
    rep(i, n){
        cin >> a[i];
        b[i] = abs(a[i]);
        if(a[i] < 0) minus++;
        if(a[i] == 0) minus = 0;
    }
    sort(b.begin(), b.end());
    ll sum = 0;
    rep(i, n) sum += abs(a[i]);
    if(minus%2) sum -= 2 * b[0];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4852
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    rep(i,n/2) if(s[i] != s[n-1-i]) ok = false;
    int m = (n-1)/2;
    rep(i,m/2) if(s[i] != s[m-1-i]) ok = false;
    int k = (n+3)/2 - 1;
    rep(i,m/2) if(s[i+k] != s[n-1-i]) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define a first
#define b second
using namespace std;
const int N = 1e6 + 5;
ll n, c, h[N], dp[N];

//Li chao tree: cay IT dong de quan ly duoc pham vi lon
typedef pair<ll, ll> line;
ll get(line u, ll x) { return u.a * x + u.b; }
struct nut
{
    int l, r; //child
    ll s, e;  //range
    line u;
};
struct LiChaoTree
{
    vector<nut> it;
    void init(ll Lmin, ll Rmax)
    {
        it.push_back({-1, -1, Lmin, Rmax, {0, INT64_MAX}});
    }
    void insert(int k, line u)
    {
        ll s = it[k].s, e = it[k].e, m = (s + e) >> 1;
        line low = u, high = it[k].u;
        //low la duong can them, high la duong hien tai trong cay IT
        if (get(low, s) > get(high, s)) //Dam bao low la duong nam duoi o ben trai
            swap(low, high);
        if (get(low, e) < get(high, e)) //Neu low van la duong nam duoi ben phai
        {
            it[k].u = low;
            return;
        }
        //Cai nay dung desmos: ve hinh ra de thay duoc hai truong hop nay
        if (get(low, m) < get(high, m))
        {
            it[k].u = low;
            if (it[k].r == -1)
                it[k].r = it.size(), it.push_back({-1, -1, m + 1, e, {0, INT64_MAX}});
            insert(it[k].r, high);
        }
        else
        {
            it[k].u = high;
            if (it[k].l == -1)
                it[k].l = it.size(), it.push_back({-1, -1, s, m, {0, INT64_MAX}});
            insert(it[k].l, low);
        }
    }
    ll query(int k, ll x)
    {
        if (k == -1)
            return INT64_MAX;
        ll ans = get(it[k].u, x), mid = (it[k].s + it[k].e) / 2;
        if (x <= mid)
            return min(ans, query(it[k].l, x));
        else
            return min(ans, query(it[k].r, x));
    }
} T;

int main()
{
    //freopen("z.inp", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    //dp[i] = min(dpj + (hj - hi)^2 + c) = dpj + hj^2 - 2hjhi + hi^2 + c
    //dp[i] = min(-2hj*hi + dpj + hj^2) + hi^2 + c
    T.init(1, 1e6);
    dp[1] = 0;
    T.insert(0, {-2 * h[1], h[1] * h[1]});
    for (int i = 2; i <= n; i++)
    {
        dp[i] = T.query(0, h[i]) + h[i] * h[i] + c;
        T.insert(0, {-2 * h[i], dp[i] + h[i] * h[i]});
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 16536
#include"bits/stdc++.h"
#define pb push_back

using namespace std;

const int N=100005;

int n,sg[N];
vector<int>e[N];

void dfs(int x,int fa){
	for(auto v:e[x])if(v!=fa)dfs(v,x),sg[x]^=sg[v]+1;
}

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		e[u].pb(v),e[v].pb(u);
	}
	dfs(1,0);
	if(sg[1])puts("Alice");else puts("Bob");
	return 0;
}

Measured memory_bytes: 12416
N,A,B,Q,D = map(int,input().split())
S = input()
C = []
for i in range(len(S)):
    C.append(S[i])

if Q<D:
    error = 0
    for i in range(A,D-1):
        if C[i]=="#" and C[i+1]=="#":
            error = 1
            break
else:
    error = 0
    for i in range(B,D-1):
        if C[i]=="#" and C[i+1]=="#":
            error = 1
            break
    flag = 0
    for i in range(B-1,D):
        if C[i-1]=="." and C[i+1]=="." and C[i]==".":
            flag = 1
    if flag==0:
        error = 1

if error==0:
    print("Yes")
else:
    print("No")



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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
static int const max_size = 100;

int main()
{
	int  A, B, C, X; cin >> A >> B >> C >> X;

	int count = 0;
	rep(i, 0, A + 1) {
		rep(j, 0, B + 1) {
			rep(k, 0, C + 1) {
				if (X == i * 500 + j * 100 + k * 50) {
					count++;
				}
			}
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main{

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int e = sc.nextInt();
			if(e==0) break;
			int c = (int)cbrt(e), min = e;
			
			for(int z=0;z<=c;z++) {
				int s = (int)sqrt(e-z*z*z);
				for(int y=0;y<=s;y++) {
					int x = e - y*y - z*z*z;
					min = min(min, x+y+z);
				}
			}
			System.out.println(min);
			
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 26388
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int d, n, m, in;
vector<int> data;

main(){
  while(cin >> d && d){
    data.clear();
    cin >> n >> m;
    data.push_back(0);
    data.push_back(d);
    for(int i=0;i<n-1;i++){
      cin >> in;
      data.push_back(in);
    }
    sort(data.begin(), data.end());
    int ans = 0;
    for(int i=0;i<m;i++){
      cin >> in;
      vector<int>::iterator tmp, ite = lower_bound(data.begin(), data.end(), in);
      if(*ite != in){
        tmp = ite--;
        ans += min(in-(*ite), (*tmp)-in);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1428
#include<stdio.h>
int main(void)
{
	int a,b,W,B,R,i,j,k,o,X=100000;
	char s[101][101];
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%s",s[i]);
	}
	W=0;
	for(i=0;i<a-2;i++){
		for(o=0;o<b;o++){
			if(s[i][o]!='W'){
				W++;
			}
		}
		B=0;
		for(j=i+1;j<a-1;j++){
			for(o=0;o<b;o++){
				if(s[j][o]!='B'){
					B++;
				}
			}
			R=0;
			for(k=j+1;k<a;k++){
				for(o=0;o<b;o++){
					if(s[k][o]!='R'){
						R++;
					}
				}
			}
			if(X>W+B+R){
				X=W+B+R;
			}
		}
	}
	printf("%d\n",X);
	return 0;
}

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

using namespace std;

typedef long long LL;

#define fin "\n"


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

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

#define BITTYPE int
#define BITCNT  1
#define BITSIZE 512345
namespace BIT_{
    int i=0;
    BITTYPE t[BITCNT][BITSIZE];
    inline BITTYPE* get(){
        BITTYPE* res=t[i++];
        i%=BITCNT;
        return res;
    }
}
//[1,n],0?????±?????????!
struct BIT{
    using T=BITTYPE;
    T* bit;
    int n;
    BIT(T* _table,int n):bit(_table),n(n){
        std::fill(bit,bit+n+1,0);
    }
    BIT(int n):BIT(BIT_::get(),n){}
    T sum(int i){
        T s=0;
        while(i>0){
            chmax(s,bit[i]);
            i-=i&-i;
        }
        return s;
    }
    void add(int i,T x){
        while(i<=n){
            chmax(bit[i],x);i+=i&-i;
        }
    }
    void clear(int sz){
        std::fill(bit,bit+n+1,0);
    }

}; 
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(2*n,-1);
    REP(i,n){
        int p=i,q;
        cin>>q;q--;
        if(p<q)v[p+n]=q+n;
        else q+=n;
        v[p]=q;
    }
    int res=1+k;
    REP(i,n)if(v[i]!=-1){
        int p=i;
        int q=v[i];
        BIT bit(p+n-v[i]);

        FOR(j,p+1,q)if(v[i]<v[j]&&v[j]<p+n){
            int latte=bit.sum(v[j]-v[i]-1)+1;
            bit.add(v[j]-v[i],latte);
            chmax(res,latte+1+k);
        }
    }
    cout<<min(res,n/2)<<endl;
    return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>

int main()
{
	int i, N;
	scanf("%d", &N);
	if (N % 10 == 7 || N / 10 % 10 == 7 || N / 100 % 10 == 7) printf("Yes\n");
	else printf("No\n");
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1660
//IN THE NAME OF GOD

#include <iostream>
using namespace std;
typedef long long int ll;
int a,n,ans,d;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        for(int j=2;j*j<=a;j++){
            if(!(a%j)){
                a=-1;
                break;
            }
        }
        if(a!=-1)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1196
data = input().split()

legs = int(data[1])
animals = int(data[0])
flag = 0

if int(data[1]) % 2 == 1:
  flag = 0
elif int(data[0]) * 4 < legs:
  flag = 0
else:
  ans = animals * 2
  if ans == legs:
      flag = 1
  else:
    for i in range(animals):
      ans += 2
      if ans == legs:
        flag = 1
        break

if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9208
#include <iostream>
using namespace std;
int main()
{
    int n,k,m,b,l,u;
    cin>>n>>k;
    m=n+k;
    b=n-k;
    l=n*k;
    u=m;
    if (u<b) u=b;
    if (u<l) u=l;
    cout<<u;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define rep(i,n) for(int i=0;i<(n);i++)   

using namespace std;  

int main(void){
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i,N)cin >> a[i];
	deque<int> d;
	rep(i,N){
		int p = lower_bound(ALL(d),a[i]) - d.begin();
		if(p==0)d.push_front(a[i]);
		else d[p-1] = a[i];
	}
	cout << d.size() << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int a,b;
    cin >> a >> b;
    if(a==1&&b==1)
    {
        cout << "Draw" << endl;
    }
    else if(a==1)
    {
        cout << "Alice" << endl;
    }
    else if(b==1)
    {
        cout << "Bob" << endl;
    }
    else if(a>b)
    {
        cout << "Alice" << endl;
    }
    else if(a==b)
    {
        cout << "Draw" << endl;
    }
    else
    {
        cout << "Bob" << endl;
    }
}


Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

# Wrong Answer
# WA


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# 階乗、Combinationコンビネーション(numpyを使う)


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**6
fact, fact_inv = make_fact(N*2+10, MOD)


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


ans = 0
for i in range(N):
    if K < i:
        continue

    if N - 1 <= K:
        ans = mod_comb_k(N + N - 1, N - 1, MOD)
        break

    if i == 0:
        ans += 1
        continue

    a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD))
    a %= MOD
    ans += a
    ans %= MOD

    '''
    a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1])
    a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \
        int(fact_inv[N-i-1]) % MOD
    ans = (a + ans) % MOD
    '''

print(ans)


Measured memory_bytes: 28044
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll N;
ll M;
string s;
vector<ll > input1;  
vector<vector <ll > > input2;

int main(){
    
    //cin >> N;
    vector<pair<ll, ll> > aa;
    ll t = 0;
    for(int i = 0; i < 5; i++){
        cin >> t;
        if(t % 10 >= 0){
            if(t % 10 == 0){
                aa.push_back(make_pair((t % 10), t));
            }else{
                aa.push_back(make_pair(10 - (t % 10), t));
            }
        }
        
    } 
    
    sort(aa.begin(),aa.end());

    int ans = 0;
    for(ll i = 0; i < 5; i++){
        //cout << aa[i] << endl;
        ans += aa[i].second;
        if(aa[i].first > 0 && i < 4){
            ans += aa[i].first;
        }

    }
     cout << ans << endl;


} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




ll twodivides(ll n){
    ll cnt=0;
    while (n!=0 and n%2==0){
        cnt++;
        n/=2;
    }

    return cnt;
}


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

}

    






int main(){


    ll n,m;

    cin >> n >> m;


    vector<ll> data(n);
    rep(i,n){
        ll tmp;
        cin >> tmp;
        data.at(i)=tmp;
    }



    vector<ll> newdata(n,0);

    bool flag=true;
    rep(i,n){
        if (data.at(i)%2!=0){
            flag=false;
            break;
        }
        newdata.at(i)=data.at(i)/2;

    }

    ll tmp=twodivides(newdata.at(0));

    for (int i=1;i<n;i++){
        if (twodivides(newdata.at(i))!=tmp){
            flag=false;
            break;
        }
    }


    ll answer;

    if (flag==false){
        answer=0;

    }

    else {
        ll tmplcm=newdata.at(0);

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

            if (tmplcm>m){
                answer=0;
                break;
            }

            else {
                tmplcm=(newdata.at(i)*tmplcm)/gcd(newdata.at(i),tmplcm);
            }


        }

  
        if (tmplcm>m){
            answer=0;
        }

        else {
            answer=((m/tmplcm)+1)/2;
        }


    }


    cout<<answer<<endl;



}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)


int mat[3001][3001];
int dp[3001][3001][3];

signed main()
{
    fast

    #ifndef ONLINE_JUDGE
        freopen("inputf.in","r",stdin);
        freopen("outputf.in","w",stdout);
    #endif

    int r,c,k;
    cin>>r>>c>>k;

    f1(i,0,r) f1(j,0,c) mat[i][j] = 0;
    int x,y,v;
    f0(z,0,k)
    {
    	cin>>x>>y>>v;
    	mat[x][y] = v;
    }


    f1(i,0,r) dp[i][0][0] = dp[i][0][1] = dp[i][0][2] = 0;
    f1(j,0,c) dp[0][j][0] = dp[0][j][1] = dp[0][j][2] = 0;
    f1(j,1,c) dp[1][j][0] = max(dp[1][j-1][0], mat[1][j]);
    f1(j,1,c)
    {
    	dp[1][j][1] = max(dp[1][j-1][1], dp[1][j-1][0] + mat[1][j]);
    	dp[1][j][2] = max(dp[1][j-1][2], dp[1][j-1][1] + mat[1][j]);
    }

    f1(i,2,r)
    {
    	f1(j,1,c)
    	{
    		dp[i][j][0] = max(dp[i][j-1][0], dp[i-1][j][2]+mat[i][j]);

    		dp[i][j][1] = max(dp[i][j-1][1], dp[i-1][j][2]+mat[i][j]);
    		dp[i][j][1] = max(dp[i][j][1], dp[i][j-1][0]+mat[i][j]);

    		dp[i][j][2] = max(dp[i][j-1][2], dp[i-1][j][2]+mat[i][j]);
    		dp[i][j][2] = max(dp[i][j][2], dp[i][j-1][1]+mat[i][j]);
    	}
    }

    // f1(i,1,r)
    // {
    // 	f1(j,1,c)
    // 	{
    // 		cout<<dp[i][j][2]<<' ';
    // 	}
    // 	cout<<"\n";
    // }

    cout<<dp[r][c][2];
}

Measured memory_bytes: 284996
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout <<  lcs; 
} 
  
/* Driver program to test above function */
int main() 
{ 
	string X,Y;
  cin >> X >> Y;
  int m = X.size(); 
  int n = Y.size(); 
  lcs(X, Y, m, n); 
  return 0; 
} 


Measured memory_bytes: 35456
n = int(input())
rlst = []
blst = []

for _ in range(n):
    w, h = map(int, input().split())
    rlst.append([w, h, 0])
for _ in range(n):
    w, h = map(int, input().split())
    blst.append([w, h, 0])
    
rlst = sorted(rlst, key=lambda x:(x[1],x[0]))
blst = sorted(blst, key=lambda x:(x[0],x[1]))

ans = 0
for b in blst:
    i = 0
    for r in rlst:
        if r[0] < b[0] and r[1] < b[1] and r[2] == 0:
            ridx = i
            b[2] = 1
        i += 1
    if b[2] == 1:
        ans += 1
        rlst[ridx][2] = 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int FuncCmpInt(const int big, const int small);

int main(void)
{
	int val[100] = { 0 };
	int max = 0;
	int buf;
	int i;

	while (scanf("%d", &buf) != EOF) {
		val[buf - 1]++;
	}
		
	for (i = 0; i < 100; i++) {
		if (max < val[i]) {
			max = val[i];
		}
	}

	for (i = 0; i < 100; i++) {
		if (max == val[i]){
			printf("%d\n", i+1);
		}
	}

	return 0;
}

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

bool isAllocatable(int P, int k, const vector<int>& w) {
  int storage, n = w.size() - 1;
  for (size_t i = 0, j = 0; j < k; j++) {
    storage = 0;
    while (storage + w.at(i) <= P) {
      storage += w.at(i);
      if (i == n) return true;
      i++;
    }
  }

  return false;
}
int main() {
  int n, k, P = 0, sum = 0;
  cin >> n >> k;
  vector<int> w(n);
  for (size_t i = 0; i < n; i++) {
    cin >> w.at(i);
    sum += w.at(i);
  }

  int left = 0, right = sum, mid;

  while (right - left > 1) {
    mid = (left + right) / 2;
    if (isAllocatable(mid, k, w)) {
      right = mid;
    } else {
      left = mid;
    }
  }

  cout << right << endl;
}


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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    ll ans = 0;
    ll q = x / d, r = x % d;
    if (k <= q)
        ans = x - k * d;
    else
        ans = (k - q) & 1 ? d - r : r;
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3628
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
$cnt = count($a);
$total = array_sum($a);
// echo "total: " . $total . PHP_EOL;
$sum = 0;
$ans = PHP_INT_MAX;

for ($i = 0; $i < $cnt - 1; $i++) {
    
    $sum += $a[$i];
    $rest = $total - $sum;
    // echo $sum . " " . $rest . "\n";
    $ans = min($ans, abs($sum - $rest));
}
echo $ans . PHP_EOL;


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int a, b; cin >> a >> b;
  cout<<(a*b%2==0 ? "Even":"Odd")<<endl;

    return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, A int
	element_diffelent := true
	fmt.Scan(&N)
	int_arr := make([]int, N)

	for i := range int_arr {
		fmt.Scan(&A)
		int_arr[i] = A
	}

	sort.Ints(int_arr)

	for search_i, search_v := range int_arr {
		result := sort.SearchInts(int_arr, search_v)
		if result != search_i {
			if result == len(int_arr) {
				element_diffelent = true
			} else {
				element_diffelent = false
				break
			}
		}
	}

	if element_diffelent == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


Measured memory_bytes: 5632
const readline = require('readline');

const verdictCounter = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0};

async function processLineByLine() {
  const rl = readline.createInterface({
    input: process.stdin,
    crlfDelay: Infinity
  });
  for await (const line of rl) {
    if ( Object.keys(verdictCounter).includes(line) ) {
      verdictCounter[line]++
    }
  }
  for (let key in verdictCounter) {
    console.log(`${key} x ${verdictCounter[key]}`)
  }
}

processLineByLine();

Measured memory_bytes: 52996
#include <iostream>

using namespace std;
typedef long long ll;

ll memo[40];

ll calc(int n){
    if(memo[n] != -1) return memo[n];
    ll retval = 0;
    for(int i=1;i<=3;i++){
        retval += calc(n-i);
    }
    return memo[n] = retval;
}

int main(){
    for(int i=0;i<40;i++){
        memo[i] = -1;
    }
    memo[1] = 1;
    memo[2] = 2;
    memo[3] = 4;
    calc(30);

    int n;
    while(cin>>n && n != 0){
        cout << calc(n) / 3650 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>

void swap(int *a,int *b);

int main(void) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if( a > b)
		swap(&a, &b);
	if( b > c)
		swap(&b, &c);
	if( a > b)
		swap(&a, &b);
	printf("%d %d %d\n", a, b, c);
	return 0;
}

void swap(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}

Measured memory_bytes: 596
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        n: usize,
        pn: [isize; n]
    );
    // println!("{:?}", pn);
    let mut count = 0;
    for i in 0..(n-2) {
        if (pn[i+1] - pn[i]) * (pn[i+1] - pn[i+2]) < 0 {
            count += 1;
        }
    }
    println!("{}", count);
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    string s;
    cin >> s;

    int ans = 0;
    int tmp = 0;

    rep(i, 3){
        if(s[i] == 'S'){
            tmp = 0;
        }else{
            tmp++;
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 3e5 + 7;

ll a, b, c, T, d, e, l, r, x, y, z, mid, cnt, flag, mod = 1e9+7, p[MAX1], num[MAX1], now[MAX1], first[MAX1];
string s, t;
vector <ll> vec;

int main(){
	fast_io;
	cin >> a;
	for (int i = 0; i < a; ++i)	cin >> num[i];
	for (int i = 0; i < a-1; ++i){
		for (int j = i+1; j < a; ++j)	cnt += num[i]*num[j];
	}
	cout << cnt;
    return 0;
}
/*                          now or never                         */


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

/**
 * 0026：Dropping Ink
 * 
 * @author MS14A
 * @version 2015/04/13
 */
public class Main {

    private static int cells[][] = {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    };

    private static int count = 0;

    private static int maxValue = 0;

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // 入力読取り
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);

        String line = null;

        while ((line = bufferedReader.readLine()) != null) {
            String[] nums = line.split(",");

            int x = Integer.parseInt(nums[0]) + 2;
            int y = Integer.parseInt(nums[1]) + 2;
            int size = Integer.parseInt(nums[2]);

            // インクのサイズで分類してマス目の値を増加
            if (size == 1) {
                sinkSmall(x, y);

            } else if (size == 2) {
                sinkMiddle(x, y);

            } else if (size == 3) {
                sinkLarge(x, y);

            }
        }

        // 色のついていないマス目の個数と一番色の濃いマス目の値を求める
        for (int i = 2; i < 12; ++i) {
            for (int j = 2; j < 12; ++j) {
                if (cells[i][j] == 0) {
                    ++count;
                }
                if (maxValue <= cells[i][j]) {
                    maxValue = cells[i][j];
                }
            }
        }
        
        System.out.println(count);
        System.out.println(maxValue);

    }

    /**
     * @param x
     * @param y
     */
    private static void sinkLarge(int x, int y) {
        sinkMiddle(x, y);
        ++cells[y][x - 2];
        ++cells[y][x + 2];
        ++cells[y - 2][x];
        ++cells[y + 2][x];
    }

    /**
     * @param x
     * @param y
     */
    private static void sinkMiddle(int x, int y) {
        sinkSmall(x, y);
        ++cells[y - 1][x - 1];
        ++cells[y - 1][x + 1];
        ++cells[y + 1][x - 1];
        ++cells[y + 1][x + 1];
    }

    /**
     * @param x
     * @param y
     */
    private static void sinkSmall(int x, int y) {
        ++cells[y][x];
        ++cells[y - 1][x];
        ++cells[y + 1][x];
        ++cells[y][x - 1];
        ++cells[y][x + 1];
    }

}

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

const int SIZE = 100001;
priority_queue<pair<int, int> > D;//pair(depth, id)j
int P[SIZE];//parent, depth
vector<int> C[SIZE];//children
set<int> S;
void make_D(int id = 1, int depth = 0){
    D.push(make_pair(depth, id));
    for (int i = 0; i < C[id].size(); i++){
        make_D(C[id][i], depth + 1);
    }
}
void add_S(int x){
    if (S.find(x) != S.end())return;
    S.insert(x);
    for (int i = 0; i < C[x].size(); i++){
        add_S(C[x][i]);
    }
}
int main(){
    int N, K; cin >> N >> K;
    int ans = 0;
    for (int i = 1; i <= N; i++){
        int ai; cin >> ai;
        C[ai].push_back(i);
        P[i] = ai;
    }
    if (P[1] != 1){
        C[P[1]].erase(C[P[1]].begin());
        P[1] = 1;
        ans++;
    }
    else
        C[1].erase(C[1].begin());
    
    make_D();
    while ((!D.empty()) && D.top().first > K)
    {
        pair<int, int> p = D.top();D.pop();
        if (S.find(p.second) == S.end()){
            int x = p.second;
            for (int i = 1; i < K; i++){
                x = P[x];
            }
            add_S(x);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16244
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
//#define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#include <bits/stdc++.h>
using namespace std;
 
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
// find_by_order(), order_of_key() 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define int long long int 
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
const ld PI  = 3.141592653589793238463;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
int n, m, x;
vector<int> cost;
vector<vector<int>> v;
 
void solve(){
	cin >> n >> m >> x;
	cost.resize(n);
	v.assign(n, vector<int>(m));
	for(int i = 0; i < n; ++i){
		cin >> cost[i];
		for(int j = 0; j < m; ++j){
			cin >> v[i][j];
		}
	}
	int LIM = (1<<n);
	int mncost = (int)1e18;
	for(int mask = 0; mask < LIM; ++mask){
		vector<int> fin(m, 0);
		int ct = 0;
		for(int i = 0; i < n; ++i){
			if( ((mask>>i)&1) ){
				ct += cost[i];
				for(int j = 0; j < m; ++j){
					fin[j] += v[i][j];
				}
			}
		}
		bool valid = true;
		for(auto &y: fin)
			valid &= (y >= x);
		if(valid){
			mncost = min(mncost, ct);
		}
	}
	if(mncost == (int)1e18){
		cout << -1 << '\n';
		return;
	}
	cout << mncost << '\n';
 
 
}
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    //cin >> T;
    for(int i = 1; i <= T; ++i){
        solve();
    }
    return 0;
}
/*
Sample inp
*/

Measured memory_bytes: 3668
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int p1[110000],p2[110000];
int a[110000];
int lb[110000];
inline void jio(){puts("0");exit(0);}
bool lowb[110000];
long long ff[110000];
int ljrose[110000];
long long renleizhihui[110000];
int main()
{
	int n;scanf("%d",&n);
	memset(p1,0,sizeof(p1));
	memset(p2,0,sizeof(p2));
	int lben=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<1||a[i]>n)jio();
		if(a[i]==i)lb[++lben]=i;
		if(p1[a[i]]==0)p1[a[i]]=i;
		else if(p2[a[i]]==0)p2[a[i]]=i;
		else jio();
	}
	int ss=0;
	memset(lowb,false,sizeof(lowb));
	for(int i=1;i<=lben;i++)
	{
		lowb[lb[i]]=true;
		if(p1[lb[i]]!=lb[i])p1[lb[i]]^=p2[lb[i]]^=p1[lb[i]]^=p2[lb[i]];
		if(p2[lb[i]]!=0)lowb[p2[lb[i]]]=true;
		if(p2[lb[i]]==0)ss++;
		else if(p1[p2[lb[i]]]!=0)jio();
	}
	long long lbsl=1;
	for(int i=1;i<=n;i++)
	{
		int xx=0,yy=0;
		long long s=2;
		if(p2[i]!=0&&lowb[i]==false)
		{
			lowb[i]=true;
			xx=p1[i];yy=p2[i];
			lowb[xx]=lowb[yy]=true;
			while(true)
			{
				if(yy>0)
				{
					int xr=xx,yr=yy;
					if(p2[xr]!=0&&p1[yr]!=0)jio();
					if(p1[xr]!=0&&p2[yr]!=0)jio();
					if(p1[xr]!=0&&p1[yr]!=0)xx=p1[xr],yy=p1[yr];
					else if(p2[xr]!=0)xx=p1[xr],yy=p2[xr];
					else if(p2[yr]!=0)xx=p1[yr],yy=p2[yr];
					else if(p1[xr]!=0)xx=p1[xr],yy=0;
					else if(p1[yr]!=0)xx=p1[yr],yy=0;
					else xx=yy=0;
				}
				else
				{
					int xr=xx;
					if(p2[xr]!=0)xx=p1[xr],yy=p2[xr],s=s*2%1000000007;
					else if(p1[xr]!=0)xx=p1[xr],yy=0;
					else xx=yy=0;
				}
				lowb[xx]=lowb[yy]=true;
				if(xx==0&&yy==0)jio();
				if(xx==i||yy==i)
				{
					if(yy==i)xx^=yy^=xx^=yy;
					if(yy==0)break;
					if(p1[yy]!=0)jio();
					else
					{
						if(s%2==0)s=s/2;
						else s=(s+1000000007)/2;
						break;
					}
				}
			}
			lbsl=lbsl*s%1000000007;
		}
	}
	ff[0]=1;ff[1]=1;ff[2]=2;
	for(int i=3;i<=n;i++)ff[i]=(ff[i-1]+ff[i-2]*(i-1)%1000000007)%1000000007;
	memset(ljrose,0,sizeof(ljrose));
	for(int i=1;i<=n;i++)
	{
		if(lowb[i]==false)
		{
			long long sr=1;int j=a[i];
			lowb[i]=true;
			while(j!=i)lowb[j]=true,j=a[j],sr++;
			ljrose[sr]++;
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(i%2==1)
		{
			renleizhihui[0]=1;renleizhihui[1]=2;renleizhihui[2]=4+i;
			for(int j=3;j<=ljrose[i];j++)renleizhihui[j]=(renleizhihui[j-1]*2+renleizhihui[j-2]*(j-1)%1000000007*i%1000000007)%1000000007;
			lbsl=lbsl*renleizhihui[ljrose[i]]%1000000007;
			continue;
		}
		renleizhihui[0]=1;renleizhihui[1]=1;renleizhihui[2]=1+i;
		for(int j=3;j<=ljrose[i];j++)renleizhihui[j]=(renleizhihui[j-1]+renleizhihui[j-2]*(j-1)%1000000007*i%1000000007)%1000000007;
		lbsl=lbsl*renleizhihui[ljrose[i]]%1000000007;
	}
	lbsl=lbsl*ff[ss]%1000000007;
	printf("%lld\n",lbsl);
	return 0;
}

Measured memory_bytes: 3200
n,l =map(int, input().strip().split())
a=-1000000009
b=1000000009
ans=0
for i in range(0,n):
  ans+=l+i
  if(l+i<0):
    a=max(a,l+i)
  elif l+i>=0:
    b=min(b,l+i)
  #print(i,a,b,l+i)
#print(ans)   
if(a==-1000000009):
  print(ans-b)
elif(b==1000000009):
  print(ans-a)
else:
  if(min(a*-1 , b))*-1 ==a:
  	print(ans-a)
  else:
  	print(ans-b)
    

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

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

int main(){
  long n,m,x,g,p,i,j,pn,pm;
  char s[100010],t[100010];
  scanf("%ld %ld",&n,&m);
  scanf("%s",s);
  scanf("%s",t);
  g=gcd(n,m);
  
  p=g*(n/g)*(m/g);
  i=0;
  j=0;
  pn=p/n;
  pm=p/m;
  while(i<p||j<p){
    if(i==j){
      if(s[i/pn]!=t[j/pm]){
        printf("-1\n");
        return 0;
      }
      i+=pn;
      j+=pm;
    }
    else if(i>j)
      j+=pm;
    else
      i+=pn;
  }
  printf("%ld\n",p);
}

Measured memory_bytes: 384
//It is coded by ning-mew on 9.28
#include<bits/stdc++.h>
using namespace std;

const int maxn=220;

int n,l[maxn],ans=0;

bool cmp(const int &x,const int &y){return x<y;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)scanf("%d",&l[i]);
	sort(l+1,l+2*n+1,cmp);
	for(int i=1;i<=2*n;i+=2)ans+=l[i];
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,K;
    cin >> N >> K;
    ll ans = 0;
    rep(i,1,N+1){
        if(i <= K)continue;
        ll k = N / i;
        ans += (i - K) * k;
        //cout << i << " " << k << " " << N - i * k - K << endl;
        ans += max(0LL, N - i * k - max(1LL,K) + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256