akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
int main() {
	//file("a");
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c) puts("Yes");
	else puts("No"); 
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
hint=-1
flg=-1
for i in range(N):
  if A[i]==0:
    hint=1
  elif A[i]<0:
    flg= flg*-1
  A[i]=abs(A[i])
A.sort()
ans=0
if hint==1 or hint*flg==1:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])

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

int main()
{
	int N, K, ans;
	cin >> N >> K;
	rep(i, N) {
		if (pow(K, i) > N) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 384
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        ArrayList <Integer> n = new ArrayList<>();

        n.add(A);
        n.add(B);
        n.add(C);

        Collections.sort(n);

        int num [] = new int [3];
        num [0] = n.get(0);
        num[1] = n.get(1);
        num [2] = n.get(2);


        boolean M = false;
        int count = 0;
        while (num[1]<num[2])
        {
            num[1]++;
            num[0]++;
            count++;
        }

        while (num[0]<num[1])
        {
                num[0]+=2;
                count++;
                    }

        if(num[0]-num[1]==1)
        {
            count++;
        }

        System.out.println(count);



    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string str;
  int n;
  cin >> str >> n;
  rep(i, 0, n) {
    int a, b;
    string s;
    cin >> s >> a >> b;
    if (s == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (s == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      string p;
      cin >> p;
      int j = 0;
      rep(i, a, b + 1) {
        str[i] = p[j];
        j++;
      }
    }
  }
}



Measured memory_bytes: 3212
/*  
	Come feed the rain
	Cos I'm thirsty for your love
	Dancing underneath the skies of lust
	Yeah feed the rain...
	Cos without your love my life
	Ain't nothing but this carnival of rust
    _________________________
    _________________________
    864 Hours of Solitude
    Quarantine_Day : 36
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005
#define MOD 1000000007

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

	int n; cin>>n;

	int maxi = INT_MIN;
	int mini = INT_MAX;

	REP(i, n){
		int a; cin>>a;
		maxi = max(maxi, a);
		mini = min(mini, a);
	}
	cout<<maxi - mini<<"\n";

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const int INF = 100000;
const ll MAXN = 1e6;

const int MAX=510000;

int main()
{
    int n,l;
    cin>>n>>l;
    int a[n];
    rep(i,n)
    {
        a[i]=l+i;
    }
    sort(a,a+n);
    int sum=0;
    rep(i,n)
    {
        sum+=a[i];
    }
    int min=INF;
    int ans=0;
    rep(i,n)
    {
        if(abs(a[i])<min)
        {
            min=abs(a[i]);
            ans=sum-a[i];
            
        }
    }
    cout<<ans;
    
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve(K):
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    X = 7
    cnt = 1
    while True:
        if X % K == 0:
            print(cnt)
            return
        cnt += 1
        X = X * 10 + 7
        X %= K


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    K = Scanner.int()
    solve(K)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10676
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

char  A;cin>>A;
  if(A=='a'||A=='i'||A=='u'||A=='e'||A=='o'){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
  
}




Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                count += 1
print(count)


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int L;
int main() {
	cin >> L;
	L = L * L * L;
	double ANS = L;
	ANS /= 27;
	printf("%.7f", ANS);
	return 0;
}

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

const int maxn=1005;

bool vis[maxn];

int main(int argc, char const *argv[])
{
	int aa[4];
	ios::sync_with_stdio(false);
	for(int i=0;i<100;i++) vis[i]=1;
	vis[0]=vis[1]=0;
	for(int i=2;i<100;i++){
		for(int j=i+i;j<100;j+=i){
			vis[j]=0;
		}
	}
	string s;
	while(cin>>s){
		for(int i=0;i<4;i++){
			aa[i]=s[i]-'0';
		}
		int a,b,c,d;
		a=aa[0],b=aa[1],c=aa[2],d=aa[3];
		int temp=0;
		temp=a+b+c+d;
		if(temp==7){
			printf("%d+%d+%d+%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a-b+c+d;
		if(temp==7){
			printf("%d-%d+%d+%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a+b-c+d;
		if(temp==7){
			printf("%d+%d-%d+%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a+b+c-d;
		if(temp==7){
			printf("%d+%d+%d-%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a-b-c+d;
		if(temp==7){
			printf("%d-%d-%d+%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a-b+c-d;
		if(temp==7){
			printf("%d-%d+%d-%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a+b-c-d;
		if(temp==7){
			printf("%d+%d-%d-%d=%d\n",a,b,c,d,temp);
			continue;
		}
		temp=a-b-c-d;
		if(temp==7){
			printf("%d-%d-%d-%d=%d\n",a,b,c,d,temp);
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [0 for i in range(2*(10**5)+1)]
a = [1]
co = 0
for i in range(n):
    k = int(input())
    b = a[-1]
    if l[k] != i and l[k] != 0:
        b += a[l[k]]
    l[k] = i+1
    a.append(b%(10**9+7))
print(a[-1])

Measured memory_bytes: 65612
# coding: utf-8
N = int(input())
li = [True for _ in range(0, 10**6 + 1)]
A = list(map(int, input().split()))
A.sort()
used = {}
for i in range(N):
    if A[i] not in used.keys():
        used[A[i]] = 1
    else:
        used[A[i]] += 1
ans = 0
for k in used.keys():
    if used[k] > 1:
        for j in range(k, 10**6 + 1, k):
            li[j] = False
for i in range(N):
    if li[A[i]] and used[A[i]] == 1:
        ans += 1
    else:
        continue
    for j in range(A[i], 10**6 + 1, A[i]):
        li[j] = False
print(ans)


Measured memory_bytes: 43716
a, b, c, x = *(0..3).collect{ARGF.gets.chomp.to_i}

number_of_resolves = 0

(0..a).each do |number_of_using_a|
  (0..b).each do |number_of_using_b|
    (0..c).each do |number_of_using_c|
      if number_of_using_a * 500 + number_of_using_b * 100 + number_of_using_c * 50 == x
        number_of_resolves += 1
      end
    end
  end
end

puts number_of_resolves

Measured memory_bytes: 14216
#include <iostream>
#include <vector>
#include <cmath>

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

    std::vector<int> X;
    for (int i = 0; i < N; ++i) {
        int x;
        std::cin >> x;
        X.push_back(x);
    }

    std::vector<int> A(N);
    A[N - 1] = X[N - 1];
    int flag = -1;
    for (size_t i = 0; i < N - 1; ++i) {
        A[N - 1] += flag * X[i];
        flag *= -1;
    }
    A[N - 1] /= 2;

    for (int i = N - 2; i >= 0; --i) {
        A[i] = X[i] - A[i + 1];
    }

    for (const auto& a : A) {
        std::cout << 2 * a << " ";
    }

    std::cout << std::endl;


    return 0;
}

Measured memory_bytes: 2168
n, a, b, c = [int(i) for i in input().split()]
p = 10 ** 9 + 7

ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(2 * n)
invf = invfact(2 * n, f)

def comb(a, b):
    if a < b:
        return 0
    if a < 0 or b < 0:
        return 0
    return f[a] * invf[b] * invf[a-b] % p

pow_a = [1]
pow_b = [1]
inv_100 = pow(100, p - 2, p)
a = a * inv_100 % p
b = b * inv_100 % p
c = c * inv_100 % p

ab = pow(a + b, p - 2, p)
a = (a + a * ab * c) % p
b = (b + b * ab * c) % p

for i in range(n):
    pow_a.append(pow_a[-1] * a % p)
    pow_b.append(pow_b[-1] * b % p)

for m in range(n, 2 * n):
    ans += comb(m - 1, n - 1) * (pow_a[n] * pow_b[m - n] + pow_a[m - n] * pow_b[n]) * m
    ans %= p

ans *= pow(1 - c, p - 2, p)

print(ans % p)

Measured memory_bytes: 28308
#include<bits/stdc++.h>
using namespace std;
int n, k, a[200005], ht;
char ipt[200005];

vector<int> gen_seq (int S) {
	vector<int> ret;
	for(int i=S;i<=n;i++) ret.push_back(a[i]^((S+1)%2));
	for(int i=1;i<S;i++) ret.push_back((n-1-(int)ret.size())%2);
	return ret;
}
void solve (int S, int R) {
	vector<int> tmp = gen_seq(S);
	if(R) tmp[0] = 1;
	for(int i=0;i<n;i++) putchar(tmp[i]?'B':'A');
	puts("");
	exit(0);
}

int main()
{
	scanf("%d%d%s",&n,&k,ipt+1);
	for(int i=1;i<=n;i++) a[i] = (ipt[i] == 'B');
	for(int i=n;i>=1;i--) {
		if(a[i] != (n-i)%2) {ht = i; break;}
	}
	for(int i=1;i<=ht;i++) {
		if(k == 0) solve(i, 0);
		if((a[i]+i)%2) {
			if(k == 1) solve(i, 1);
			k -= 2;
		}
		else k--;
	}
	if(n%2 == 0 || k%2 == 0) solve(n+1, 0);
	else solve(n+1, 1);
}


Measured memory_bytes: 2424
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
struct edge { int src, dst, w; };
bool cmp(edge &e, edge &f) { return e.w < f.w; }

class UnionFind {
    vector<int> par, rank;
public:
    explicit UnionFind(int n) : par(n), rank(n) {
        for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 0; }
    }

    int find(int i) {
        if (par[i] == i) return i;
        return par[i] = find(par[i]);
    }

    void unite(int i, int j) {
        int x = find(i), y = find(j);
        if (x != y) {
            if (rank[x] < rank[y])
                par[x] = y;
            else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }
    }

    bool same(int i, int j) {
        return find(i) == find(j);
    }
};

int main() {
    int n, m, k; cin >> n >> m >> k;
    int c[n], p = k;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        if (c[i] == 0) c[i] = p++;
        else c[i]--;
    }
    vector<edge> edges;
    for (int i = 0; i < m; i++) {
        int a, b, w; cin >> a >> b >> w;
        edges.push_back({c[a-1], c[b-1], w});
    }
    sort(edges.begin(), edges.end(), cmp);
    UnionFind uf(p);
    int cnt = 0;
    long long ans = 0;
    for (edge &e : edges) {
        if (uf.same(e.src, e.dst)) continue;
        uf.unite(e.src, e.dst);
        ans += e.w;
        if (++cnt == k-1) break;;
    }
    cout << (cnt == k-1 ? ans : -1) << endl;
}


Measured memory_bytes: 3444
#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() {
    string s;
    cin >> s;
    deque<char> deq;
    rep(i,s.size()) {
        deq.push_back(s[i]);
    }
    int q;
    cin >> q;
    int rev = 1;
    int sum_rev_count = 0;
    rep(i,q) {
        int t;
        cin >> t;
        if (t == 1) {
            rev *= -1;
            sum_rev_count++;
        }
        if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            // 後ろにつける
            if ((f == 2 && rev == 1) || (f == 1 && rev == -1)) {
                deq.push_back(c);
            }
            // まえにつける
            if ((f == 1 && rev == 1) || (f == 2 && rev == -1)) {
                deq.push_front(c);
            }
        }
    }
    string ans;
    int sz = deq.size();
    rep(i,sz) {
        ans += deq.front();
        deq.pop_front();
    }
    if (sum_rev_count % 2 == 1) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

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

    int n;
    ll y;
    cin >> n >> y;

    for(ll i=0;10000*i<=y;i++){
        ll x=y-10000*i;
        for(ll j=0;5000*j<=x;j++){
            ll k=(x-5000*j)/1000;
            if(i+j+k==n){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 3652
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int dp[100010][2];
int main() {
    int M, N; cin >> M >> N;

    if(M >= 3) {
        vector< pair<int, int> > rle;
        for(int i=0; i<N; i++) {
            int v; cin >> v;
            if(rle.empty() or rle.back().first != v) rle.emplace_back(v, 1);
            else rle.back().second++;
        }
        
        int ans = 0;
        for(auto e : rle) {
            ans += e.second / 2;
        }
        
        cout << ans << endl;
    }
    if(M == 2) {
        fill(dp[0], dp[N+1], INF);
        dp[0][0] = dp[0][1] = 0;
        for(int i=0; i<N; i++) {
            int v; cin >> v; v--;
            for(int k=0; k<2; k++) {
                // 前が 1-v で v にする
                dp[i+1][v] = dp[i][1-v];
                dp[i+1][1-v] = dp[i][v] + 1;
            }
        }
        cout << min(dp[N][0], dp[N][1]) << endl;
    }
    
    return 0;
}




Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  int N;
  vector<int> P;
  cin >> N;
  
  string buf;
  while (getline(cin, buf, ' ')) {
    P.push_back(atoi(buf.c_str()));
  }
  
  int ok = 0;
  int min = 99999999;
  for (int i = 0; i < N; i++) {
    if (min > P[i]) {
      min = P[i];
    }
    if (P[i] <= min) {
      ok++;
    }
  }
  
  cout << ok << endl;
  
  return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int k;
string s;

int main(){
    cin >> k >> s;
    if(k>=s.length())cout << s << endl;
    else {
        for(int i=0;i<k;i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 7;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

ll n, ans;

int main(){
    Speedforce
    //fop("", "")
    cin >> n;
    if(n == 2){
        cout << 1;
        return 0;
    }
    for(ll i = 2;i * i <= n - 1;i ++){
        if((n - 1) % i == 0){
            ans++;
            if(i * i != n - 1){
                ans ++;
            }
        }
    }
    ans++;
    for(ll i = 2;i * i <= n;i ++){
        if(n % i == 0){
            ll c = n;
            while(c % i == 0){
                c /= i;
            }
            ans += (c % i == 1);
            if(i * i != n){
                c = n;
                while(c % (n / i) == 0){
                    c /= (n / i);
                }
                ans += (c % (n / i) == 1);
            }
        }
    }
    cout << ans + 1;
}


Measured memory_bytes: 256
main = do
  [a, v] <- map read . words <$> getLine
  [b, w] <- map read . words <$> getLine
  t <- readLn
  if solve (abs (a - b)) (v - w) t
    then putStrLn "YES"
    else putStrLn "NO"

solve x y t
  | y < 0 = False
  | otherwise = ceiling (x / y) <= t

Measured memory_bytes: 3984
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+'){
            ans+=1;
        }
        
        else if(s[i]=='-'){
            ans-=1;
        }
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    // データ何個あるか
    long n, ans;
    n = 0;
    ans = 0;
    std::cin >> n;
    if(n%2==0){ans=n;}
    else {ans=2*n;}
    std::cout << ans << endl;
}


Measured memory_bytes: 256
def get_group(x):
    g = group[x]
    if g == x:
        return x
    group[g] = re = get_group(g)
    return re

def unite(x, y):
    gx = get_group(x)
    gy = get_group(y)
    if gx != gy:
        dx = depth[gx]
        dy = depth[gy]
        if dy > dx:
            gx, gy = gy, gx
        group[gy] = gx
        if dx == dy:
            depth[gx] += 1

n = int(input())
group = {}
depth = {}
edge = []
for _ in range(n):
    x, y = map(int, input().split())
    group.setdefault(x, x)
    group.setdefault(-y, -y)
    depth.setdefault(x, 1)
    depth.setdefault(-y, 1)
    edge += [[x, -y]]

for x, y in edge:
    unite(x, y)

cnt = {}
for k in group.keys():
    g = get_group(k)
    cnt.setdefault(g, [0, 0])
    if k > 0:
        cnt[g][0] += 1
    else:
        cnt[g][1] += 1

ans = 0
for cx, cy in cnt.values():
    ans += cx * cy
print(ans - n)


Measured memory_bytes: 37120
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

fn main() {

    let n = read_t_in_line::<i32>()[0];
    let mut aa = read_t_in_line::<i32>();
    // 負の数と正の数で、それぞれ絶対値が最大のものをもとめる
    // 絶対値が大きいほうを見つけたら、その数値自分以外のすべての要素に加算していく
    // こうすることですべての数が正 or 負にできる
    // その後は一番大きい(正) or 小さい(負)の数字を一番左 or 右に足しこんで、
    // その後は順番に足しこんでいけばできあがり
    
    const INF : i32 = 1 << 30;

    let mut min_neg = INF;
    let mut max_pos = -INF;
    let mut min_idx = 0;
    let mut max_idx = 0;

    let mut ops : Vec<(i32, i32)> = vec![]; // (from, to)
    
    for i in 0..n {
        let a = aa[i as usize];
        if a < 0 && min_neg > a {
            min_neg = a;
            min_idx = i;
        }
        if a >= 0 && max_pos < a {
            max_pos = a;
            max_idx = i;
        }
    }

    let mut is_only_pos = true;

    if max_pos == -INF {
        // only neg
        is_only_pos = false;
    }
    else if min_neg == INF {
        // only pos
    }
    else if max_pos.abs() < min_neg.abs() {
        // apply neg
        for i in 0..n {
            ops.push((min_idx, i));
        }
        // only neg
        is_only_pos = false;

    }
    else{
        // apply pos
        for i in 0..n {
            aa[i as usize] += aa[max_idx as usize];
            ops.push((max_idx, i));
        }
        // only pos
    }

    if is_only_pos {
        ops.push((max_idx, 0));
        for i in 0..n-1 {
            ops.push((i, i + 1));
        }
    }
    else {
        ops.push((min_idx, n - 1));
        for i in (1..n).rev() {
            ops.push((i, i - 1));
        }
    }

    println!("{}", ops.len());
    for (from, to) in ops {
        println!("{} {}", from + 1, to + 1);
    }
    

}


Measured memory_bytes: 4352
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input
    .split("\n")[0]
    .split(" ")
    .map(n => Number(n));
  let max = input[0] + input[1];
  if (max < input[0] - input[1]) {
    max = input[0] - input[1];
  }
  if (max < input[0] * input[1]) {
    max = input[0] * input[1];
  }
  console.log(max);
}


Measured memory_bytes: 7372
// 2011/07/23 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int X, Y, Z;
		cin >> X >> Y >> Z;
		if(X==0&&Y==0&&Z==0)
			break;

		int V[4];
		for(int i=0; i<X; i++)
			cin >> V[i];

		int E[51], A[51];
		for(int i=0; i<=Y; i++)
			E[i] = A[i] = 0;
		for(int i=0; i<Z; i++){
			int n, e, a;
			cin >> n >> e >> a;
			E[n] = e;
			A[n] = a;
		}

		double P[51][5001];
		for(int i=0; i<=Y; i++)
			for(int j=0; j<=5000; j++)
				P[i][j] = 0.0;
		P[0][0] = 1.0;

		for(int i=0; i<Y; i++){
			for(int j=0; j<=5000; j++){
				if(P[i][j]==0.0)
					continue;

				for(int k=0; k<X; k++){
					int pi = i;
					int pj = j;

					pi = i+V[k];
					if(pi>Y)
						pi = Y;

					if(E[pi]==1){
						pi = pi+A[pi];
						if(pi>Y)
							pi = Y;
					}
					else if(E[pi]==2){
						pj = pj+A[pi];
					}
					else if(E[pi]=-3){
						pj = pj-A[pi];
						if(pj<0)
							pj = 0;
					}

					P[pi][pj] += P[i][j]/(double)X;
				}
			}
		}

		double ex = 0.0;
		for(int j=0; j<=5000; j++)
			ex += (double)j*P[Y][j];
		cout << (int)ex << endl;
	}

	return 0;
}

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

typedef long long ll;

int main() {
    int D;
    cin >> D;
    vector<int> c(26), t(D);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26)), last(D + 1, vector<int>(26, 0));
    rep(i, D) rep(j, 26) cin >> s[i][j];
    rep(i, D) cin >> t[i];
    ll p = 0;
    rep(d, D) {
        p += s[d][t[d] - 1];
        rep(i, 26) last[d + 1][i] = last[d][i];
        last[d + 1][t[d] - 1] = d + 1;
        rep(i, 26) {
            p -= c[i] * (d + 1 - last[d + 1][i]);
        }
        cout << p << "\n";
    }
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

void solve2(){
    string str; cin >> str;
    deque<int> op;
    for(int i = 0; i < str.size(); i++) op.PB(str[i]);
    int q; scanf(" %d", &q);
    bool inv = false;
    string a = "", b = "";
    while(q--){
        int t; scanf("%d", &t);
        if(t == 1){
            inv = !inv;
        }else{
            int f; char ch;
            scanf("%d %c", &f, &ch);
            if(f == 1){
                if(inv)
                    op.push_back(ch);
                else
                    op.push_front(ch);
            }else{
                if(inv) 
                    op.push_front(ch);
                else
                    op.push_back(ch);
            }
        }
    }
    if(inv){
        for(int i = op.size()-1; i >= 0; i--)
            printf("%c", op[i]);
        printf("\n");
    }else{
        for(int i = 0; i < op.size(); i++)
            printf("%c", op[i]);
        printf("\n");
    }
}

void solve(){
    string str; cin >> str;
    int q; scanf("%d", &q);
    bool inv = false;
    while(q--){
        int t;  scanf("%d", &t);
        if(t == 1) inv = !inv;
        else{
            int f;
            char ch;
            scanf("%d %c", &f, &ch);
            if(f == 1){
                if(inv){
                    str = str + ch;
                }else{
                    str = ch + str;
                }
            }else{
                if(inv){
                    str = ch + str;
                }else{
                    str = str + ch;
                }
            }
        }
    }
    if(inv) reverse(str.begin(), str.end());
    cout << str << endl;
}


int main(){
    //int t; cin >> t;
    //while(t--) solve();
    solve2();
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000; 
const ll mod = 1e9+7;

int main(){
    ll x;
    cin >> x;
    ll a = 100;
    ll cnt = 0;
    while(true){
        a *= 1.01;
        cnt ++;
        if(a >= x){
            cout << cnt << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
import heapq
N, M = map(int, input().split())

rewards = [[] for _ in range(M + 1)]
for i in range(N):
    a, b = map(int, input().split())
    if a <= M:
        rewards[a].append(b)

heap = []
total = 0
for day in range(1, M + 1):
    for reward in rewards[day]:
        heapq.heappush(heap, -reward)

    if len(heap) > 0:
        max_reward = heapq.heappop(heap)
        total += -max_reward

print(total)


Measured memory_bytes: 18376
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin>>N>>K;

  int ans = N - K;
  if(K == 1) cout<<0<<endl;
  else cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>//文字列の代入に使う                                                                                                 
#include <bits/stdc++.h>//piの利用で必要(M_PI)                                                                                          
#include <algorithm>


int main() {

  int N, count = 0, sum = 0;
  std::string S;
  std::cin >> S;

  N = S.size();
  while(S[count] == S[N - 1 - count]) {
    count++;

  }
  if(count < (N - 1) / 2) {
    std::cout << "No" << std::endl;
    return 0;
  }

  count = 0;
  while(S[count] == S[((N - 1) / 2) - count - 1]) {
    count++;
  }
  if(count < (N - 1) / 4) {
    std::cout << "No" << std::endl;
    return 0;
  }

  count = 0;
  while(S[(N + 3) / 2 + count - 1] == S[N - 1 - count]) {
    count++;
  }
  if(count < (N - 1) / 4) {
    std::cout << "No" << std::endl;
    return 0;
  }
  std::cout << "Yes" << std::endl;


  return 0;
}

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

int N = 0, M = 0;
std::vector< std::string > A;
std::vector< std::string > B;

int main(void){
    std::cin >> N >> M;

    A.resize(N);
    B.resize(M);

    int i, j, k;
    for(i=0;i<N;++i) std::cin >> A[i];
    for(i=0;i<M;++i) std::cin >> B[i];

    int NM = N - M;
    bool f = true;
    for(i=0; i<=NM; ++i){
        for(j=0; j<=NM; ++j){
            f = true;
            for(k=0; k<M; ++k){
                if(A[i+k].substr(j,M) != B[k]){
                    f = false;
                    break;
                }
            }
            if(f){
                goto result;
            }
        }
    }
result:
    if(f){
        std::cout << "Yes\n";
    }else{
        std::cout << "No\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int sum = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		sum += r - l + 1;
	}

	cout << sum << endl;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
 
#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define MAXN 1000000
#define pb push_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
ll maxu = INT_MAX;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    string s;
    cin>>s;

    ll n = s.size(),ans=0;
    fori(i,0,n/2-1)
    {
        if(s[i]!=s[n-i-1])
        {
            ans += 1;
            //cout<<s[i]<<" "<<s[n-i-1];
        }
        //cout<<endl;
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>


const int mod = 1e9 + 7;

using namespace std;

int n, k, x;
int dp[1000000];


int main(){

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    int n, k;
    cin >> n >> k;
    // dp[i] - the number of ways such that we used i candies so far
    dp[0] = 1;
    for(int child = 0; child < n; ++child) {
        int upto;
        cin >> upto;
        vector<int> fake(k + 1);
        for(int used = k; used >= 0; --used) {
            int tmp = dp[used];
            int L = used + 1;
            int R = used + min(upto, k - used);
            if(L <= R) {
                
                fake[L] += tmp;
                if(fake[L] >= mod){
                    fake[L] -= mod;
                }
                if(R + 1 <= k) {
                    fake[R + 1] -= tmp;
                    if(fake[R + 1] < 0){
                        fake[R + 1] += mod;
                    }
                    
                }
            }
        }
        int prefix_sum = 0;
        for(int i = 0; i <= k; ++i) {
            
            prefix_sum += fake[i];
            if(prefix_sum >= mod){
                prefix_sum -= mod;
            }
            
            dp[i] += prefix_sum;
            if(dp[i] >= mod){
                dp[i] -= mod;
            }
        }
    }
    cout << dp[k];
    
}



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

#define ll long long
#define f first
#define s second
#define inf 1e15

#define N 300005

string s;
ll n,m,x,y,d,k;
ll a[N];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    string g;
	    cin>>s>>g;
	    
	    n=s.length();
	    m=g.length();
	    ll ans=inf;
	    
	    for(int i=0;i<=n-m;i++){
	        ll cnt=0;
	        int k=i;
	        for(int j=0;j<m;j++,k++){
	            if(s[k]!=g[j]){
	                cnt++;
	            }
	        }
	       // cout<<cnt<<"$\n";
	        ans=min(ans,cnt);
	    }
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 3664
N,M=map(int,input().split())  
par=[i for i in range(N)]
rank=[0]*(N)
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
  else:
    par[x]=y
    if rank[x]==rank[y]:
      rank[y]+=1

for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  union(a,b)

cnt=0
for i in range(N):
  if i==par[i]:
    cnt+=1
print(cnt)

Measured memory_bytes: 7860
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=100010;
int n,k,ans,first[maxn],nxt[maxn],to[maxn],e;
void AddEdge(int u,int v) {to[++e]=v;nxt[e]=first[u];first[u]=e;}
int mxd[maxn];
void dfs(int x,int fa) {
	for(int i=first[x];i;i=nxt[i]) {
		dfs(to[i],x);
		mxd[x]=max(mxd[x],mxd[to[i]]+1);
	}
	if(mxd[x]==k-1&&fa!=1) ans++,mxd[x]=-1;
}
int main() {
	n=read();k=read();
	rep(i,1,n) {
		if(i==1) {
			if(read()!=1) ans++;
		}
		else AddEdge(read(),i);
	}
	dfs(1,1);
	printf("%d\n",ans);
	return 0;
}


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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	int n;
	ll ans = 0;
	cin >> n;
	for(int i =1; i<=n; i++){
		if(i%3 == 0 || i%5 == 0) {
			continue;
		}
		ans += i;
	}
	cout << ans << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
    int t = 1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;
const int SZE = 3200000;

int p[100009],q[100009];
vector<PII> v;

int main(){
	DRII(w,h);
	REP(i,w){
		RI(p[i]);//hor
		v.PB(MP(p[i],1));
	}
	REP(i,h){
		RI(q[i]);//ver
		v.PB(MP(q[i],2));
	}
	sort(ALL(v));
	int hor=0,ver=0;
	LL ans=0;
	for(PII a:v){
		if(a.S==1){
				ans+=(LL)(h+1-ver)*a.F;
				hor++;
		}
		else{
				ans+=(LL)(w+1-hor)*a.F;
				ver++;
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 2932
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val t, a = sc.nextLong() * 1000
  val hs = (1 to n).map(_ => sc.nextLong())

  val ans = hs
    .zipWithIndex
    .map(tup => (tup._2, t - tup._1 * 6))
    .minBy(tup => math.abs(a - tup._2))

  println(ans._1 + 1)

}


Measured memory_bytes: 27720
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j,h;
    ll Q,M,K,P;
    
    ll a, b,c,d;
    long double x;

    vector<ll> aa;
    vector<ll> bb;
    vector<ll> cc;
    vector<ll> dd, tt;
    string S;

    ll flag=0;
    ll temp=0;

    long double X,A,B,N;

    cin  >> A>>B>>N;
    if(N>B-1){
    ans=floor(A*(B-1)/B)-A*floor((B-1)/B);
    }else{
        ans=floor(A*(N)/B)-A*floor((N)/B);

    }



cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int threshold = (accumulate(a.begin(), a.end(), 0) + 4*m - 1) / (4 * m);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if (a[i] >= threshold) cnt++;
    }
    puts(cnt >= m ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    string s;
    cin >> s;
    bool ans = true;
    rep(i, 3){
        if(s[i] == s[i+1]) ans = false;
    }
    if(ans)cout << "Good" << endl;
    else cout<< "Bad" << endl;
    return 0;
}

Measured memory_bytes: 256