akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int mod_0, mod_2, odd;
  mod_0 = mod_2 = odd = 0;

  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      ++mod_0;
    } else if (a % 4 == 2) {
      ++mod_2;
    } else {
      ++odd;
    }
  }

  if (mod_2 != 0) {
    if (odd > mod_0) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  } else {
    if (odd <= mod_0 + 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

using namespace std;

typedef long long int ll;

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

typedef pair<int,int> pair;

//
    ll n,k,r,s,p;
    string t;



int main(){
    cin >> n >> k >> r >> s >> p >> t;
    ll ans=0;
    //char u[n];
    string u;

//change
    for(ll i=0;i<n;i++){
        if(t[i]=='r') u+='p';
        if(t[i]=='s') u+='r';
        if(t[i]=='p') u+='s';

        if(i>=k){
            if(u[i]==u[i-k]){
                if(t[i]=='r') u[i]='a';
                if(t[i]=='s') u[i]='a';
                if(t[i]=='p') u[i]='a';
            }
        }
    }

//kasan
    for(int i=0;i<n;i++){
        //cout << t[i] << u[i] << endl;
        //if(t[i]!=u[i]){
            if(u[i]=='r') ans+=r;
            if(u[i]=='s') ans+=s;
            if(u[i]=='p') ans+=p;
            //puts("a");
        //}
        //cout << ":" << ans << endl;
    }

    //cout << u << endl;

    cout << ans << endl;
}




Measured memory_bytes: 640
import java.util.*;

public class Main {
    static final int MOD = 998244353;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int s = sc.nextInt();
		int[][] dp = new int[n + 1][s + 1];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    for (int j = s; j >= 0; j--) {
		        dp[i + 1][j] = dp[i][j] * 2 % MOD;
		        if (j - x >= 0) {
		            dp[i + 1][j] += dp[i][j - x];
		            dp[i + 1][j] %= MOD;
		        }
		    }
		}
	    System.out.println(dp[n][s]);
	}
}


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

signed main(){
  int N;
  cin>>N;
  vector<int> A(3*N);
  rep(i,3*N)cin>>A[i];
  sort(rbegin(A),rend(A));
  int ans=0;
  int I=0,i=1;
  while(I<N){
    ans+=A[i];
    i+=2;
    I+=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
def gcd(a,b):
  while b:a,b=b,a%b
  return a
aa=a-t*v
ab=a+t*v
ba=b-t*w
bb=b+t*w
if aa<=ba<=bb<=ab:print("YES")
else:print("NO")

Measured memory_bytes: 9192
s=input()
s+='?'
x=[]
ch=1
if s[0]=='>':
    x.append(0)
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        ch+=1
    else:
        x.append(ch)
        ch=1
x.append(0)
a=0
for i in range(len(x)-1):
    if i%2==0 and x[i]<=x[i+1]:
        a+=x[i+1]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
    elif i%2==0 and x[i]>x[i+1]:
        a+=x[i]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
if (len(x)-1)%2==1:
    for j in range(x[len(x)-1]):
        a+=j
print(a)


Measured memory_bytes: 6300
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int X,Y; cin>>X>>Y;
  int ans = 0;
  vector<int> tmp = {300000,200000,100000}; 
  for(int i=1;i<=3;i++){
    if(X==i){
      ans += tmp[i-1];
    }
    if(Y==i){
      ans += tmp[i-1];
    }
  }
  if(X==1 && Y==1){
      ans += 400000;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      int n = in.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = in.nextInt();
      }
      
      StringBuilder sb = new StringBuilder();
      for (int i = n-1; i >= 0; i--) {
        if (i != n-1) {
          sb.append(" ");
        }
        sb.append(a[i]);
      }
      
      out.println(sb);
//    End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 24320
#include <stdio.h>

int main () {

    int n, x, i, j, k, y;

    for (; ; ) {

        y = 0;

        scanf("%d", &n); scanf("%d", &x);

        if (n == 0 && x == 0) {
            break;
        }

        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++){
                for (k = 1; k <= n; k++) {
                    if (i + j + k == x && i < j && j < k) {
                        y += 1;
                    }
                }
            }
        }

        printf("%d\n", y);

    }

    return 0;

}



Measured memory_bytes: 2060
n = int(input())
dic = {}
lis = []
lis2 = []

for i in range(n):
  moji = input()
  if moji not in dic:
    dic[moji] = 0
  dic[moji] += 1
  
for i in sorted(dic.items(), key=lambda x:x[1]):
    lis.append(i)
  
lis.reverse()

for j in lis:
  if lis[0][1] == j[1]:
    lis2.append(j[0])
  else:
    break

lis2.sort()
for i in range(len(lis2)):
  print(lis2[i])

Measured memory_bytes: 45912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // ll t;
    ll t=1;
    // cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int> l(n);
        for(int i=0;i<n;i++){
            cin >> l[i];
        }
        ll ans =0;
        sort(l.begin(),l.end());
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                int k= lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin();
                ans += max(k-j-1,0);
            }
        }

        cout << ans << endl;
    }

}


Measured memory_bytes: 256
import sys

n = int(input())

abl = []
for _ in range(n):
    a,b = map(int,input().split())
    abl.append((b,a))
    
abl = sorted(abl)

need_t = 0
for b, a in abl:
    need_t += a
    if b < need_t:
        print("No")
        sys.exit()
        
print("Yes")


Measured memory_bytes: 66904
#include<stdio.h>
int main(void)
{
	int a, n, k, p, i;
	scanf("%d",&a);
	for(i = 0;i < a ;i++){
	scanf("%d %d",&k,&p);
	n = k % p;
	if(n == 0){
		printf("%d\n",p);
	}
	else if (p >= k){
		printf("%d\n",k);
	}
	else if (k >= p){
		printf("%d\n",n);
	}
		}
	return 0;
}

Measured memory_bytes: 1028
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    
    bool judge=true;
    rep(i,n){
        if(a.at(i)%2==1) continue;
        else if(a.at(i)%3!=0&&a.at(i)%5!=0){
            judge=false;
            break;
        }
    }
    
    if(judge) dunk("APPROVED");
    else dunk("DENIED");
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
	s.Split(bufio.ScanWords)

	n := 0
	if s.Scan() {
		n, _ = strconv.Atoi(s.Text())
	}

	T := make(map[string]int)
	for i := 0; s.Scan() && i < n; i++ {
		cmd := s.Text()
		if cmd[0] == 'f' {
			s.Scan()
			if _, ok := T[s.Text()]; ok {
				fmt.Fprintln(w, "yes")
				continue
			}
			fmt.Fprintln(w, "no")
			continue
		}
		s.Scan()
		T[s.Text()] = 0
	}

	w.Flush()
}



Measured memory_bytes: 33076
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l = 0,r = 0;
  int ans = 0;
  while(r < s.size()){
    if(s[r] == 'A' || s[r] == 'C' || s[r] == 'G' || s[r] == 'T'){
      r++;
      ans = max(ans, r-l);
    }else{
      r++;
      l = r;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.function.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer in = new StringTokenizer("");
		int n=Integer.parseInt(br.readLine());
		in=new StringTokenizer(br.readLine());
		Map<Integer,Integer> mp=new HashMap<>();
		Consumer<Integer> add_mp=(it)->mp.put(it, mp.getOrDefault(it, 0)+1);
		Consumer<Integer> subtract_mp=(it)->mp.put(it, mp.getOrDefault(it, 0)-1);
		for(int i=0;i<n;i++)add_mp.accept(Integer.parseInt(in.nextToken()));
		int m=Integer.parseInt(br.readLine());
		in=new StringTokenizer(br.readLine());
		for(int i=0;i<m;i++)subtract_mp.accept(Integer.parseInt(in.nextToken()));
		mp.values().forEach(it->{
			if(it<0){
				System.out.println("NO");
				System.exit(0);
			}
		});
		System.out.println("YES");
	}
}

class Pair<T extends Comparable<T>, U extends Comparable<U>> implements Comparable<Pair<T, U>> {
	public T first;
	public U second;

	public Pair(T first, U second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public int compareTo(Pair<T, U> ob) {
		if (first.compareTo(ob.first) != 0) return first.compareTo(ob.first);
		else return second.compareTo(ob.second);
	}
}

Measured memory_bytes: 81156
using System;
class Practice
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        if (a < b)
        {
            Console.WriteLine("a < b");
        }
        else if (a > b)
        {
            Console.WriteLine("a > b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
    }
}


Measured memory_bytes: 15884
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ball=sc.next();
        char[] result= ball.toCharArray();
        int j=0;
        for(int i=0;ball.length()>i;i++){
            String str =String.valueOf(result[i]);
            if("1".equals(str)){
                j++;
            }
        }
        System.out.println(j);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=2e5+10;
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
inline ll lcm(ll a,ll b){return a * b / __gcd(a, b);}
int t,n,m,k;
int main() {
    int n;
    cin >> n;
    vector<tuple<bool, int, int, int>> v(n);
    for (auto &e : v) {
    string s;
    cin >> s;
    int l = 0, r = 0;
    for (auto c : s) {
      if (c == '(') {
        l++;
      } else if (l > 0) {
        l--;
      } else {
        r++;
      }
    }
    e = {l <= r, l <= r ? (l==0?inf:-l) : r, l, r};
    }
    sort(v.begin(), v.end());

    bool valid = true;
    int h = 0;
    //for (auto [a, b, l, r] : v)  cerr << a << ' ' << b << ' ' << l << ' ' << r << endl;
    for (auto [a, b, l, r] : v) {
     //cerr << a << ' ' << b << ' ' << r << ' ' << l << endl;
    if (h < r) {
      valid = false;
      break;
    }
    h -= r;
    h += l;
    }
    if (h != 0) valid = false;
    cout << (valid ? "Yes" : "No") << endl;
}


Measured memory_bytes: 18792
from collections import deque

N,M=map(int,input().split())

A,B=[0]*M,[0]*M
graph=[[] for _ in range(N)]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1
    B[i]-=1
    graph[A[i]].append(B[i])
    graph[B[i]].append(A[i])

def bfs(graph,visited,start):
    queue=deque([start])
    visited[start]=True
    while queue:
        vartex=queue.popleft()
        for new_vartex in graph[vartex]:
            if visited[new_vartex]==False:
                visited[new_vartex]=True
                queue.append(new_vartex)
    
    if False in visited:
        return False
    else:
        return True

ans=0
for i in range(M):
    if i == 0:
        graph[A[0]].remove(B[0])
        graph[B[0]].remove(A[0])
    else:
        graph[A[i]].remove(B[i])
        graph[B[i]].remove(A[i])
        graph[A[i-1]].append(B[i-1])
        graph[B[i-1]].append(A[i-1])
    
    visited=[False]*N
    if bfs(graph,visited,0):
        continue
    else:
        ans+=1
print(ans)

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

const long long mod=1e9+7;
long long int power(long long int a,long long int b) {long long int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
long long int inv(long long int x) {return power(x,mod-2);}
int main()
{
    int n,k;
    long long i;
    cin>>n>>k;
    long double ans=0;
    for(i=1;i<=min(n,k-1);i++)
    {
        long double g=i;
        long long low=1,high=20,anss=-1;
        while(low<=high)
        {
            long long mid=(low+high)/2;
            if(power(2,mid)*g>=k)
            {
                anss=mid;
                high=mid-1;
            }
            else
                low=mid+1;
        }
        ans+=((1/(n*1.0))*(1/(1.0*power(2,anss))));
    }
    for(i=min(n,k-1)+1;i<=n;i++)
    {
        ans+=(1/(n*1.0));
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;
}



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

int main(){
  int N, K; cin >> N >> K;
  vector<int> Score(N);
  for (int i=0; i<N; i++){
    cin >> Score.at(i);
  }
  
  for (int i=0; i<N-K; i++){
    if (Score.at(K+i) > Score.at(i)){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
  
  

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  string s;
  cin >> s;
  ll n=s.size();
  ll ans=0;
  for(ll i=0;i<n/2;i++){
    if(s[i]!=s[n-i-1]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
n = int(input())
w = list(map(int, input().split()))

mindiff = 999999

s1 = 0
s2 = sum(w)

for i in range(n):
    mindiff = min(mindiff, abs(s2 - s1))
    s1 += w[i]
    s2 -= w[i]

print(mindiff)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=100005;
//~ const int mod=1e9+7;
const ll oo=1e18+5;

int n,mod;
vector<int> v[N];
int dp_down[N],dp_up[N];

void dfs1(int a,int par){
	dp_down[a]=1;
	//~ cout<<mod<<endl;
	for(int x:v[a]){
		if(x!=par){
			dfs1(x,a);
			dp_down[a]=1ll*dp_down[a]*(dp_down[x]+1)%mod;
			//~ cout<<" vertice["<<a<<"] = "<<dp_down[a]<<endl;
			// dp_down[i] is number way to build the tree that i is root
		}
	}
}

void dfs2(int a,int par){
	vector<int> children;
	for(int x:v[a]){
		if(x!=par){
			children.push_back(x);
		}
	}
	int num=(int)children.size();
	vector<int> pre(num),suf(num);
	if(num){
		pre[0]=(dp_down[children[0]]+1);
		for(int i=1;i<num;++i){
			pre[i]=1ll*pre[i-1]*(dp_down[children[i]]+1)%mod;
		}
		//~ cout<<"pre : ";
		//~ for(int i=0;i<num;++i){
			//~ cout<<pre[i]<<" ";
		//~ }
		//~ cout<<endl;
		//~ cout<<"suf : ";
		suf[num-1]=(dp_down[children[num-1]]+1);
		for(int i=num-2;i>=0;--i){
			suf[i]=1ll*suf[i+1]*(dp_down[children[i]]+1)%mod;
		}
		//~ for(int i=0;i<num;++i){
			//~ cout<<suf[i]<<" -- ";
		//~ }
		//~ cout<<endl;
		//~ cout<<suf[1]<<" ~ "<<dp_up[a]<<endl;
		if(num==1){
			dp_up[children[0]]=1+1ll*dp_up[a]%mod;
			dp_up[children[num-1]]=1+1ll*dp_up[a]%mod;
		}
		else{
			dp_up[children[0]]=1+1ll*suf[1]%mod*dp_up[a]%mod;
			dp_up[children[num-1]]=1+1ll*pre[num-2]%mod*dp_up[a]%mod;
		}
		//~ cout<<dp_up[children[0]]<<" "<<dp_up[children[num-1]]<<endl;
		for(int i=1;i<=num-2;++i){
			dp_up[children[i]]=1+1ll*pre[i-1]*suf[i+1]%mod*dp_up[a]%mod;
		}
	}
	for(int x:v[a]){
		if(x!=par){
			dfs2(x,a);
		}
	}
}
			

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n>>mod;
	for(int i=0;i<n-1;++i){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs1(1,-1);
	//~ for(int i=1;i<=n;++i){
		//~ cout<<"dp_down["<<i<<"] = "<<dp_down[i]<<endl;
	//~ }
	dp_up[1]=1;
	dfs2(1,-1);
	for(int i=1;i<=n;++i){
		cout<<1ll*dp_down[i]*dp_up[i]%mod<<endl;
	}
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, k;
    cin >> n >> k;
    vector<bool> v(n, false);
    int d, a;
    for (int i = 0; i < k; ++i) {
        cin >> d;
        for (int j = 0; j < d; ++j) {
            cin >> a;
            v[--a] = true;
        }
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (!v[i]) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int n,num[2];
int main()
{
	while(cin>>n&&n){
		int card[200];
		fill(card,card+2*n,2);
		num[0]=num[1]=n;
		for(int i=0;i<n;i++){
			int x;cin>>x;x--;
			card[x]=1;
		}
		int m=0,turn=1;
		while(num[0]&&num[1]){
			for(int i=m;i<2*n;i++){
				if(card[i]==turn){
					//printf(turn==1?" Taro ":"Hanako");
					//printf(" submitted %d\n",i+1);
					card[i]=0;m=i;num[turn-1]--;
					break;
				}
				if(i==2*n-1){
					m=0;
					//printf(turn==1?" Taro  passed\n":"Hanako passed\n");
				}
			}
			turn=turn==1?2:1;
		}
		printf("%d\n%d\n",num[1],num[0]);
	}
    return 0;
}

Measured memory_bytes: 1144
const Main = (input) => {
    array = input.split('\n')
    NM = array.shift().split(' ').map(item => parseInt(item))
    H = array.shift().split(' ').map(item => parseInt(item))
    array.pop() // lastが邪魔
    A = array.map(item => item.split(' ').map(value => parseInt(value)))
    // console.log('NM: ', NM)
    // console.log('H: ', H)
    // console.log('A: ', A)
    console.log(F(NM[0], NM[1], H, A))
}

const F = (N, M, H, A) => {
    road = []
    for (i = 0; i <= N; i++) {
        road.push([])
    }
    for (i = 0; i < M; i++) {
        road[A[i][0]].push(A[i][1])
        road[A[i][1]].push(A[i][0])
    }
    count = 0
    // console.log('road: ', road)
    for (i = 1; i <= N; i++) {
        // console.log('i: ', i, road[i])
        if (road[i].length == 0) {
            count++
            continue
        }
        max = 0
        road[i].forEach(item => {
            if (H[item - 1] > max) max = H[item - 1]
        });
        if (max < H[i - 1]) count++
    }
    return count
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

const long long MOD=7+1e9;

int main(){
    int n;
    cin>>n;
    if(n<3){
        cout<<"0"<<endl;
        return 0;
    }
    vector<long long> dp(n+1);
    dp[0]=1;
    for(int i=1;i<=n;i++){
        long long temp=0;
        for(int j=3;j<=n;j++){
            if(i-j<0){
                break;
            }
            temp+=dp[i-j];
            temp%=MOD;
        }
        dp[i]=temp;
    }

    cout<<dp[n]<<endl;

}

Measured memory_bytes: 3612
#include<stdio.h>
#include<queue>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
    string s;
    int score,num;
}p[105];
bool cmp(node s1,node s2)
{
    if(s1.s==s2.s)
        return s1.score>s2.score;
    return s1.s<s2.s;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        p[i].num=i;
        p[i].s=s;
        scanf("%d",&p[i].score);
    }
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",p[i].num);
    }
    return 0;
}


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

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}

int main() {
	int N, M; cin >> N >> M;
	vector<int>as(N);
	for (int i = 0; i < N; ++i) {
		cin >> as[i];
	}
	as.insert(as.end(), as.begin(), as.end());
	int ans = 0;
	for (int i = 0; i < N / gcd(N, M); ++i) {
		int l = (i*M) % N;
		int r = l + M;
		ans += *max_element(as.begin()+l,as.begin()+r) - *min_element(as.begin()+l,as.begin()+r);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3120
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

const int MAXN = 1e5 + 10;
long long x, y, z, n, pre[MAXN], suf[MAXN], ans;
struct itm {
	int g, s, b;
};
itm t[MAXN];
bool cmp(itm a, itm b) {
	return a.g - a.s < b.g - b.s;
}
bool operator <(pair<int, itm> a, pair<int, itm> b) {
	return a.first < b.first;
}

multiset<pair<int, itm> > re;
long long res;

int main() {
	cin >> x >> y >> z;
	n = x + y + z;
	for (int i = 0; i < n; i++)
		cin >> t[i].g >> t[i].s >> t[i].b;
	sort(t, t + n, cmp);
	for (int i = 0; i < n; i++) {
		re.insert({ t[i].b - t[i].s, t[i] });
		multiset<pair<int, itm> >::iterator it = re.end();
		res += t[i].s;
		it--;
		if (re.size() == y + 1) {
			res -= (*it).second.s;
			res += (*it).second.b;
			re.erase(it);
		}
		if (re.size() != y)
			pre[i] = -1;
		else
			pre[i] = res;
	}
	re.clear();
	res = 0;
	suf[n] = -1;
	for (int i = n - 1; i >= 0; i--) {
		re.insert({ t[i].b - t[i].g, t[i] });
		multiset<pair<int, itm> >::iterator it = re.end();
		res += t[i].g;
		it--;
		if (re.size() == x + 1) {
			res -= (*it).second.g;
			res += (*it).second.b;
			re.erase(it);
		}
		if (re.size() != x)
			suf[i] = -1;
		else
			suf[i] = res;
	}
	for (int i = 0; i < n; i++) {
		if (pre[i] == -1 || suf[i + 1] == -1)
			continue;
		ans = max(ans, pre[i] + suf[i + 1]);
	}
	cout << ans;
}

Measured memory_bytes: 8832
#include<stdio.h>

int main(){
  long int operation,bisket=1;
  long int bis_a,bis_b,money=0;
  int tmp=0;
  scanf("%ld %ld %ld",&operation,&bis_a,&bis_b);

  if(bis_b-bis_a<=1){
   bisket = bisket + operation;
   printf("%ld",bisket);
  }
  else{
    while(operation>0){
        tmp = operation-1;
        if(tmp==0){
          bisket++;
          operation--;
        }
        else if(bisket>=bis_a){
          bisket -= bis_a;
          money++;
          operation--;
        }
        else{
          bisket++;
          operation--;
        }
        if(money>0){
          bisket += bis_b;
          money--;
          operation--;
        }	
    }
    printf("%ld",bisket);
  }
  
  return 0;
}



Measured memory_bytes: 128
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
z=(h-2)*(w-2)
p=[]
for i in range(n):
    x,y=map(int,input().split())
    for j in range(3):
        for k in range(3):
            p.append([x+j-1,y+k-1])
p.sort(key=lambda x:(10**10)*x[0]+x[1])
n=len(p)
p.append([10**20,10**20])
ans=[0]*10
f=1
for i in range(n):
    if 2<=p[i][0]<=h-1 and 2<=p[i][1]<=w-1:
        if p[i]==p[i+1]:
            f+=1
        else:
            ans[f]+=1
            f=1
ans[0]=z-sum(ans)
for i in ans:
    print(i)


Measured memory_bytes: 215188
#include <stdio.h>
#define N 100000
#define Q 50000

int main(){
    int n,q,count=0,i,j,l,r,mid,key;
    int S[N],T[Q];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&T[i]);
    }
    for(i=0;i<q;i++){
        l = 0;
        r = n;
        key = T[i];
        while(l<r){
            mid  = (int)((l+r)/2);
            if(S[mid] == key){
                count++;
                break;
            }
            else if(key < S[mid]){
                r = mid;
            }
            else
            l = mid + 1;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int N;
    static void INPUT()
    {
        N = NextInt();
    }
    static void OUTPUT()
    {
        var ans = ((long)N - 1) * (N) / 2;
        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
#else
        INPUT();
#endif
        OUTPUT();
    }

    static void TESTINPUT()
    {
        N = 1000000007;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

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

struct trie{
	int to[26];
	int val;
	trie(){
		val=0;
	}
};

int size=1;
trie t[1<<19];

vector<int> make(const string& str){
	int n=str.size();
	vector<int> ret(n+1);
	ret[0]=-1;
	int j=-1;
	for(int i=0;i<n;i++){
		while(j>=0 && str[i]!=str[j]){
			j=ret[j];
		}
		ret[i+1]=++j;
	}
	return ret;
}

int now=0;
vector<int> ret[201];
int moveto[201];
int koko[201];

void kmp(const string& str,const string& word){
	vector<int> table=make(word);
	int m=0,i=0,n=str.size();
	while(m+i<n){
		if(word[i]==str[m+i]){
			if(++i==(int)(word.size())){
				ret[now].push_back(m);
				m=m+i-table[i];
				i=table[i];
			}
		}else{
			m=m+i-table[i];
			if(i>0)i=table[i];
		}
	}
}

void pushTrie(string str){
	int node=0;
	for(int i=0;i<(int)str.size();i++){
		int b=(str[i]-'a');
		if(t[node].to[b]==0){
			t[node].to[b]=size++;
		}
		node=t[node].to[b];
	}
	t[node].val++;
}

string str;
int n;
ll dp[100001];

void sendValue(int f,ll val){
	int node=0;
	for(int i=0;i<=1000;i++){
		if(i+f>=n)return;
		int b=(str[i+f]-'a');
		if(t[node].to[b]==0)return;
		node=t[node].to[b];
		if(t[node].val>0){
			dp[i+f+1]+=val;
			if(dp[i+f+1]>=MOD)dp[i+f+1]%=MOD;
		}
	}
	return;
}



string s[100001];
int als=0;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	cin >> str;

	for(int i=0;i<n;i++){
		if(s[i].size()<=1000){
			pushTrie(s[i]);
		}else{
			kmp(str,s[i]);
			moveto[now]=s[i].size();
			now++;
		}
	}
	n=str.size();
	dp[0]=1;
	for(int i=0;i<n;i++){
		sendValue(i,dp[i]);
		for(int j=0;j<now;j++){
			int k=koko[j];
			if(k<ret[j].size() && ret[j][k]==i){
				dp[i+moveto[j]]+=dp[i];
				if(dp[i+moveto[j]]>=MOD){
					dp[i+moveto[j]]%=MOD;
				}
				koko[j]++;
			}
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 67436
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long dp[10];
  
int main()
{
  int H,W;
  cin >> H >> W;
  vector<vector<int>> A(10,vector<int>(10));
  REP(i, 10){
    REP(j, 10){
      cin >> A.at(i).at(j);
    }
  }
  vector<vector<int>> B(H,vector<int>(W));
  REP(i, H){
    REP(j, W){
      cin >> B.at(i).at(j);
    }
  }
  
  dp[1]=0;
  REP(i,10){
    dp[i]=A.at(i).at(1);
  }
  REP(k,100){
    REP(i,10){
      REP(j,10){
        chmin(dp[j],dp[i]+A.at(j).at(i));
      }
    }
  }
  ll ans=0;
  REP(i,H){
    REP(j,W){
      if(B.at(i).at(j)!=-1){
        ans+=dp[B.at(i).at(j)];
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int X=0,d=0,c=0,count=0;
    scanf("%d",&X);
    for(int i=1;i<=X;i++)
        {
    for(d=i;d!=0;++c)
    {
        d=d/10;
    }
    if(c%2!=0)
    {
        count++;
    }
    c=0;
}
   printf("%d ",count);
    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll r,D,x;

int main(){
    cin >> r >> D >> x;
    REP(i,10){
        cout << r*x - D << endl;
        x = r*x - D;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def prime(n):
    if n >= 2:
        prime_nums = [2]
        for i in range(3, n + 1):
            for p in prime_nums:
                if i % p == 0:
                    break
            else:
                prime_nums.append(i)
    return prime_nums

def main():
    n=int(input())
    p=prime(55555)
    li=[]
    i=0
    while len(li)<56:
        if p[i]%5==1:
            li.append(p[i])
        i+=1

    print(*li[:n])






if __name__ == '__main__':
    main()

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

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

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

const int horse[8] = {4,1,4,1,2,1,2,1};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> v(8);
  rep(i,8){
    rep(j,8){
      v[i].pb(horse[(i+j)%8]);
    }
  }
  vary(int,c,8,0);
  while(1){
    rep(i,8){
      if(cin >> c[i]){

      }
      else
        break;
    }
    if(cin.eof()) break;
    int ans=0;
    int min = inf;
    rep(i,8){
      int sum =0;
      rep(j,8){
        if(c[j] - v[i][j] > 0){
          sum += c[j] - v[i][j];
        }
      }
      if(sum < min){
        ans = i;
        min = sum;
      }
      else if(sum == min){
        rep(l,8){
          if(v[i][l] < v[ans][l]){
            ans = i;
            break;
          }
          else if(v[i][l] > v[ans][l]){
            break;
          }
        }
      }
    }
    rep(i,7){
      cout << v[ans][i]<< " ";
    }
    cout << v[ans][7] << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

ll n,m;
vector<ll>h,a,b,used;
ll solve(){
   ll ans=n;
    rep(i,m){
        if(h[a[i]]<=h[b[i]]){
            if(!used[a[i]]){
                ans--;
                used[a[i]]=1;
            }
        }
        if(h[a[i]]>=h[b[i]]){
            if(!used[b[i]]){
                ans--;
                used[b[i]]=1;
            }
        }
    }

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

    cin>>n>>m;
    h.resize(n);
    a.resize(m);
    b.resize(m);
    used.resize(n);
    rep(i,n)cin>>h[i];
    rep(i,m){
        ll ai,bi;
        cin>>ai>>bi;
        ai--;bi--;
        a[i]=ai;
        b[i]=bi;
    }
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 6364
INF = (1 << 31) - 1
def init
  x = 1
  while x < $n
    x <<= 1
  end
  $n = x
  $arr = Array.new(2*x-1, INF)
end

def update(i, x)
  i += $n - 1
  $arr[i] = x
  while i > 0
    i = (i - 1) / 2
    $arr[i] = $arr[i*2+1,2].min
  end
end

def query(a,b,k,l,r)
  if r <= a || b <= l then return INF
  end
  if a <= l && r <= b then return $arr[k]
  else
    vl = query(a, b, k*2+1, l, (l+r) / 2)
    vr = query(a, b, k*2+2, (l+r) / 2, r)
    return [vl, vr].min
  end
end

$n, q = gets.split.map(&:to_i)
init
q.times do
  cmd, x, y = gets.split.map(&:to_i)
  if cmd == 0 then update(x, y)
  else puts query(x, y+1, 0, 0, $n)
  end
end

Measured memory_bytes: 10836
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    int n = sc.nextInt();

    int[] a = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();

    for (int i = a.length - 1; i >= 0; i--) {
        pw.print(a[i]);
        pw.print(i == 0 ? "" : " ");
    }
    pw.println();
    pw.flush();

    sc.close();
  }
}


Measured memory_bytes: 32044
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    for(int i = k; i < n; i++) {
        if(a[i] <= a[i - k]) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 4000
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int h1,w1,h2,w2,k;

void solve(){
  cin >> h1 >> w1 >> h2 >> w2 >> k;
  int s1=h1*60+w1;
  int s2=h2*60+w2;
  cout << max(0,s2-s1-k) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3652
lis = []
cnt = 0
for i in range(5):
    val = 0
    a = int(input())
    while a % 10 != 0:
        a += 1
        val += 1
    lis.append(a)
    if val > cnt:
        cnt = val
#print(cnt)
ans = sum(lis)
print(ans - cnt)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

const int N = 100000 + 10;
vector<int> g[N];

bool vis[N];

int k;
int ans;

int rec(int curr, int prev)
{
  int h = 0;
  each (next, g[curr]) {
    h = max(h, rec(next, curr));
  }

  if (prev != -1 && prev != 0 && h == k - 1) {
    ++ans;
    return 0;
  }
  if (prev == 0 && h == k) {
    ++ans;
    return 0;
  }

  return h + 1;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n >> k) {
    fill(g, g + N, vector<int>());
    fill(vis, vis + N, false);

    int r = 0;
    
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      if (i) {
        g[a - 1].push_back(i);
      } else {
        r = (a != 1);
      }
    }

    ans = 0;
    rec(0, -1);
    cout << r + ans  << endl;
  }

  return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, T, minv = inf, ans;

int main()
{
    cin >> N >> T;
    vector<int> A(N), val;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] < minv)
            minv = A[i];
        else
        {
            val.push_back(A[i] - minv);
        }
    }
    sort(val.rbegin(), val.rend());
    for (int i = 0; i < val.size(); i++)
    {
        if (val[0] == val[i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
int n, m, x, y, z;
vector<pair<int, int> > a[2020];
vector<int> b[2020];
vector<int> c[2020];
int d[2020], w[4020];
int st[2020], ed[2020];
bool v[2020];
bool dfs(int x, int y, int t, vector<int> &b) {
	if (x == t) {
		return true;
	}
	for (auto i: a[x]) {
		if (i.X != y) {
			b.push_back(i.Y);
			if (dfs(i.X, x, t, b)) {
				return true;
			}
			b.pop_back();
		}
	}
	return false;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &x, &y);
		a[x].push_back({y, 2 * i});
		a[y].push_back({x, 2 * i + 1});
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &st[i], &ed[i]);
		dfs(st[i], 0, ed[i], b[i]);
		assert(b[i].size() > 0);
		for (int j: b[i]) {
			c[j / 2].push_back(i);
			d[j / 2]++;
		}
	}
	for (int i = 1; i < n; i++) {
		z += min(d[i], 2);
	}
	while (true) {
		int p = 0, q = -1; // p = choose edge, q = choose path
		for (int i = 1; i < n; i++) {
			if (d[i] == 1 && w[i * 2] != w[i * 2 + 1]) {
				p = i;
				break;
			}
		}
		if (p == 0) {
			for (int i = 1; i < n; i++) {
				if (d[i] >= 2) {
					p = i;
					break;
				}
			}
		}
		if (p == 0) {
			break;
		}
		for (int i: c[p]) {
			if (!v[i]) {
				q = i;
				break;
			}
		}
		assert(q >= 0);
		bool rev = false;
		v[q] = true;
		for (int i: b[q]) {
			if (i / 2 == p) {
				if (w[i]) {
					swap(st[q], ed[q]);
					for (int &j: b[q]) {
						j ^= 1;
					}
				}
				for (int &j: b[q]) {
					d[j / 2]--;
					w[j] = 1;
				}
				break;
			}
		}
	}
	printf("%d\n", z);
	for (int i = 0; i < m; i++) {
		printf("%d %d\n", st[i], ed[i]);
	}
	return 0;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int X, N, ans, c;
    cin >> X >> N;
    int p[N];
    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }

    c = 100000;
    bool flag;
    for(int i = 0; i < 102; i++) {
        flag = true;
        for(int z = 0; z < N; z++) {
            if(i == p[z]) flag = false;
        }
        if(flag) {
            if(c > abs(i - X)) {
                ans = i;
                c = abs(i - X);
            }
        }
    }

    cout << ans << endl;

    return 0;

            
}

Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;

int main() {
	int N,M,P;
	double X[120];
	long long sum,ans;
	double zyun_money_per;

	while(cin >> N >> M >> P) {
		if (N==0 && M==0 && P==0) { break; }
		sum=0;
		REP(i,1,N+1) {
			cin >> X[i];
			sum+=X[i];
		}
		if (X[M] == 0) {
			cout << "0" << endl;
		}
		else {
			zyun_money_per = (100-P)*0.01;
			ans = (sum/X[M])* 100 * zyun_money_per;//切り捨て
			cout << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1228
# ALDS1_11_B: Depth First Search

class Timer
  def initialize(start = 0)
    @time = start
  end

  def next
    @time += 1
  end
end

class DepthFirstSearcher
  def initialize(graph)
    @graph = graph
  end

  def search_by(method_name, found, finished)
    last  = @graph.size - 1
    timer = Timer.new
    proc  = self.method "#{method_name.to_s}_search"
    (1..last).each do |id|
      proc.call(id, found, finished, timer)
    end
  end

  private

    def recursive_search(id, found, finished, timer)
      return unless found[id].nil?

      found[id] = timer.next
      @graph[id].each do |d_id|
        recursive_search d_id, found, finished, timer
      end
      finished[id] = timer.next
    end

    def stack_search(id, found, finished, timer = Timer.new)
      return unless found[id].nil?

      stack = [id]
      found[id] = timer.next

      until stack.empty?
        id = stack.last
        next_id = @graph[id].find do |d_id|
          found[d_id].nil?
        end

        if next_id.nil?
          finished[id] = timer.next
          stack.pop
        else
          if found[next_id].nil?
            stack.push next_id
            found[next_id] = timer.next
          end
        end
      end
    end
end

n_vertexes = gets.to_i
max_v      = n_vertexes + 1
graph      = Array.new, max_v

n_vertexes.times do
  id, n_degrees, *degrees = gets.split.map &:to_i
  graph[id] = degrees
end

searcher = DepthFirstSearcher.new graph
found    = Array.new max_v
finished = Array.new max_v
searcher.search_by :recursive, found, finished

(1..n_vertexes).each do |id|
  puts "#{id} #{found[id]} #{finished[id]}"
end

Measured memory_bytes: 8712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=0;
  cin >> n;
  vector<long> a(n);
  for(long i=0;i<n;i++) {
    cin >> a[i];
    a[i]+=n-i;
  }
  sort(a.begin(),a.end());
  for(long i=0;i<n;i++) ans+=max(a[(n-1)/2]-a[i],a[i]-a[(n-1)/2]);
  cout << ans << endl;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[3003][3003];
string ss="";
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s,t;
	cin >> s;
	cin >> t;
	ll n=s.length(),i,j;
	ll m=t.length();
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
				
			else if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				
		}
	}
	i=n,j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ss+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] >dp[i][j-1])
			i--;
			
		else	
			j--;
			
	}
	reverse(ss.begin(),ss.end());
	cout<<ss<<"\n";
}

Measured memory_bytes: 70784
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}

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

  int n;
  cin >> n;
  unordered_map<int, int> m = factor(n);
  int cnt = 0;
  for (auto kv: m){
    int key = kv.fi;
    int val = kv.se;
    int x = 0;
    for (int i = 0; i <= val; i++)
      if (i * (i + 1) / 2 <= val)
	x = i;
      else
	break;
    cnt += x;    
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3592