akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
namespace SOLVE {
    void main(){
    }
}


int main() {

    
    
    
    
    
    SOLVE::main();
    
    
    ll n;in(n);
    VLL v(n);
    for(auto&i:v)in(i);
    REP(i,0,n)v[i]-=i;
    sort(all(v));
    ll ans = 0;
    REP(i,0,n)ans+=abs(v[i]-v[n/2]);
    cout<<ans;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rem = list(b)
sum = 0
rem[0] = b[0]-a[0] if a[0]<b[0] else 0
sum += b[0]-rem[0]
for i in range(1,n):
	if a[i]-rem[i-1]<0:
		sum += a[i]
	else:
		rem[i] = b[i]-(a[i]-rem[i-1]) if a[i]-rem[i-1]<b[i] else 0
		sum += rem[i-1]+b[i]-rem[i]
sum += rem[n-1] if a[n]>rem[n-1] else a[n]
print(sum)

Measured memory_bytes: 19000
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPatisserieABC solver = new DPatisserieABC();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPatisserieABC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 8 pattern
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<Vec3l>[] cake = new ArrayList[8];
            for (int i = 0; i < 8; i++) {
                cake[i] = new ArrayList<>();
            }
            for (int i = 0; i < n; i++) {
                long x = in.nextLong();
                long y = in.nextLong();
                long z = in.nextLong();
                for (int j = 0; j < 8; j++) {
                    int fx = (j & 1) > 0 ? 1 : -1;
                    int fy = (j & 2) > 0 ? 1 : -1;
                    int fz = (j & 4) > 0 ? 1 : -1;
                    cake[j].add(new Vec3l(x * fx, y * fy, z * fz));
                }
            }

            long max = Long.MIN_VALUE;
            for (int i = 0; i < 8; i++) {
                cake[i].sort(Comparator.comparing(v -> -(v.x + v.y + v.z)));
                long sum = 0;
                for (int j = 0; j < m; j++) {
                    sum += cake[i].get(j).x + cake[i].get(j).y + cake[i].get(j).z;
                }
                max = Math.max(max, sum);
            }
            out.println(max);


        }

    }

    static class Vec3l {
        public long x;
        public long y;
        public long z;

        public Vec3l(long x, long y, long z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

    }
}



Measured memory_bytes: 44752
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
}q[101];
bool cmp(node x,node y){
	return x.b<y.b;
}
int main(){
	int n,t;
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>q[i].a>>q[i].b;
	}
	sort(q+1,q+n+1,cmp);
	int m=1001;
	if(q[1].b>t)  cout<<"TLE";
	else {
		for(int i=1;i<=n;i++){
			if(q[i].b<=t&&q[i].a<m)
				m=q[i].a;
		}
		cout<<m;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, k;  scanf("%d %d", &n, &k);
    int arr[100005];
    int count = 0, a;
    while(n--)
    {
        scanf("%d", &a);
        if(a>=k)
            count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int n,m,h,w;
int p[22222],q[100][100];
signed main(){
	int i,j,k;
	cin>>h>>w;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>p[i];
	bool f=false;
	k=0;
	for(i=0;i<h;i++){
		if(f)
			for(j=w-1;j>=0;j--){
				if(p[k]==0)
					k++;
				q[i][j]=k+1;
				p[k]--;
			}
		else
			for(j=0;j<w;j++){
				if(p[k]==0)
					k++;
				q[i][j]=k+1;
				p[k]--;
			}
		f=!f;
	}
	for(i=0;i<h;i++)
		for(j=0;j<w;j++)
			if(j<w-1)
				cout<<q[i][j]<<" ";
			else
				cout<<q[i][j]<<endl;
}

Measured memory_bytes: 384
OFFSET = 97
def main():
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    total = 0
    a_index = 0
    b_index = 0
    while a_index != len(A):
        if total + A[a_index] <= k:
            total += A[a_index]
            a_index += 1
        else:
            break
    
    
    while b_index != len(B):
        if total + B[b_index] <= k:
            total += B[b_index]
            b_index += 1
        else:
            break

    
    ans = a_index + b_index 
    a_index -= 1
    while a_index != -1:
        total -= A[a_index]
        a_index -= 1
        while b_index != len(B):
            if total + B[b_index] <= k:
                total += B[b_index]
                b_index += 1
            else:
                break

        if ans < a_index + 1 + b_index :
            ans = a_index + 1 + b_index

    print(ans)



    


if __name__ == '__main__':
    main()

Measured memory_bytes: 117936
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ctos(c) string(1,c)
#define all(c) (c).begin(), (c).end()
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  vector<ll> v;
  v.pb(a);
  v.pb(b);
  v.pb(c);
  sort(all(v));
  reverse(all(v));
  cout << v[0]*10+v[1]+v[2] << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let vec: Vec<&str> = input.split_whitespace().collect();

    let input1: u32 = vec[0].parse().unwrap_or(0);
    let input2: u32 = vec[1].parse().unwrap_or(0);


    println!("{} {}", input1*input2, (input1+input2)*2);
}



Measured memory_bytes: 5032
#include<iostream>
#include<stdlib.h>
using namespace std;

int n, q;
int *a;

bool solve(int p, int t){
        if(t==0){
                return true;
        }else if(t<0||p==n){
                return false;
        }else{
                return solve(p+1, t) || solve(p+1, t-a[p]);
        }
}

int main(){
        cin>>n;
        a = (int *)malloc(sizeof(int)*n);
        for(int i=0;i<n;i++) cin>>a[i];
        cin>>q;
        int m[q];
        for(int i=0;i<q;i++) cin>>m[i];
        for(int i=0;i<q;i++){
                if(solve(0,m[i])) cout<<"yes"<<endl;
                else cout<<"no"<<endl;
        }
        free(a);
        return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<cassert>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
  string str;
  getline(cin, str);
  int n;
  cin >> n;
  cin.ignore();
  string buf;
  int cur = 0;
  rep (_, n) {
    assert(0 <= cur && cur <= (int)str.size());
    getline(cin, buf);
    if (buf == "forward char") {
      cur = min(cur + 1, (int)str.size());
    } else if (buf == "forward word") {
      while ((int)str.size() != cur && str[cur] == ' ') ++cur;
      while ((int)str.size() != cur && str[cur] != ' ') ++cur;
    } else if (buf == "backward char") {
      cur = max(cur - 1, 0);
    } else if (buf == "backward word") {
      while (0 != cur && str[cur - 1] == ' ') --cur;
      while (0 != cur && str[cur - 1] != ' ') --cur;
    } else if (buf == "delete char") {
      if (cur == (int)str.size()) continue;
      str = str.substr(0, cur) + str.substr(cur + 1);
    } else if (buf == "delete word") {
      int s = cur;
      while ((int)str.size() != s && str[s] == ' ') ++s;
      if (s == (int)str.size()) continue;
      while ((int)str.size() != s && str[s] != ' ') ++s;
      str = str.substr(0, cur) + str.substr(s);
    } else if (buf.substr(0, 6) == "insert") {
      int s = buf.find('"');
      int t = buf.find('"', s + 1);
      string ins = buf.substr(s + 1, t - s - 1);
      str = str.substr(0, cur) + ins + str.substr(cur);
      cur += ins.size();
    } else {
      assert(0);
    }
  }
  assert(0 <= cur && cur <= (int)str.size());
  cout << str.substr(0, cur) << "^" << str.substr(cur) << endl;
}

int main() {
  int t;
  cin >> t;
  cin.ignore();
  rep (i, t) solve();
}

Measured memory_bytes: 1224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<vector<int> > wakaru(n);
  vector<pair<int, int> > cnt(n);
  REP(i, n) cnt[i] = {0, i};
  int ans = 0;
  while (m--) {
    int x, y, z; cin >> x >> y >> z; --x; --y;
    wakaru[x].emplace_back(y);
    wakaru[y].emplace_back(x);
    ++cnt[x].first;
    ++cnt[y].first;
  }
  sort(ALL(cnt), greater<pair<int, int> >());
  vector<bool> known(n, false);
  queue<int> que;
  REP(i, n) if (!known[cnt[i].second]) {
    que.emplace(cnt[i].second);
    ++ans;
    known[cnt[i].second] = true;
    while (!que.empty()) {
      int e = que.front(); que.pop();
      for (int nx : wakaru[e]) if (!known[nx]) {
        known[nx] = true;
        que.emplace(nx);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;


void solve() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    vector<string> pre = {"dream", "dreamer", "erase", "eraser"};
    for (auto& x: pre) {
        reverse(x.begin(), x.end());
    }
    int i = 0, n = s.size();
    while (i < n) {
        if (s.substr(i, 5) == pre[0] || s.substr(i, 5) == pre[2])
            i += 5;
        else if (s.substr(i, 6) == pre[3])
            i += 6;
        else if (s.substr(i, 7) == pre[1])
            i += 7;
        else {
            cout << "NO"; return;
        }
    }
    cout << "YES";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

S = str(input())
Q = int(input())

head = []
tail = []
main = []

main = list(S)

status = 0

def query():
  global head
  global tail
  global main
  global status
  l = list(map(str,input().split()))
  if l[0] == "1":
    status = (status+1)%2
  else:
    letter = l[2]
    if l[1] == "1":
      if status == 0:
        head.append(letter)
      else:
        tail.append(letter)
    else:
      if status == 0:
        tail.append(letter)
      else:
        head.append(letter)

      


while Q:
  Q -= 1
  query()

if status == 0:
  print("".join(head[::-1])+"".join(main)+"".join(tail))
else:
  print("".join(tail[::-1])+"".join(main[::-1])+"".join(head))
  


Measured memory_bytes: 76536
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.(fold_left (fun m a -> fold_left (fun m b -> max m @@ abs @@ a - b) m a_s) 0 a_s) |> Printf.printf "%d\n"

Measured memory_bytes: 384
from math import sqrt
from collections import defaultdict
n,p = (int(i) for i in input().split())
d,ans = defaultdict(int),1
while 1:
	f = p
	for i in range(2,int(sqrt(p))+1):
		if p%i==0:
			d[i]+=1
			p//=i
			break
	if f==p:
		d[p]+=1
		break
for i,j in d.items(): ans*=i**(j//n)
print(ans)

Measured memory_bytes: 3564
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0:
                print("#",end="")
            elif j==0:
                print("#",end="")
            elif i==H-1:
                print("#",end="")
            elif j==W-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    long long a[200100];
    long long start = 1;
    long long end = 1;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    long long sum = a[1];
    long long checker = a[1];
    long long ans = 1;
    while(end < n){
        end++;
        sum += a[end];
        checker = checker xor a[end];
        while(checker != sum){
            sum -= a[start];
            checker = checker xor a[start];
            start++;
        }
        ans += (end - start + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

//---------------------------------------------
// priority queue
//---------------------------------------------
type pqi struct{ a int }

type priorityQueue []pqi

func (pq priorityQueue) Len() int            { return len(pq) }
func (pq priorityQueue) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue) Less(i, j int) bool  { return pq[i].a < pq[j].a }
func (pq *priorityQueue) Push(x interface{}) { *pq = append(*pq, x.(pqi)) }
func (pq *priorityQueue) Pop() interface{} {
	x := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return x
}

type edge struct {
	to, cost int
}

var node [][]edge
var dist []int

const inf = 100100100100000

func dijkstra(s, N int) {
	dist = make([]int, N)
	for i := 0; i < N; i++ {
		dist[i] = inf
	}
	pq := priorityQueue{}
	heap.Push(&pq, pqi{s})
	dist[s] = 0
	for len(pq) > 0 {
		n := heap.Pop(&pq).(pqi).a
		for _, e := range node[n] {
			if dist[e.to] > dist[n]+e.cost {
				dist[e.to] = dist[n] + e.cost
				heap.Push(&pq, pqi{e.to})
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	node = make([][]edge, N)
	for i := 0; i < N-1; i++ {
		f, t, c := getInt()-1, getInt()-1, getInt()
		node[f] = append(node[f], edge{t, c})
		node[t] = append(node[t], edge{f, c})
	}
	Q, K := getInt(), getInt()-1
	dijkstra(K, N)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < Q; i++ {
		x, y := getInt()-1, getInt()-1
		fmt.Fprintln(w, dist[x]+dist[y])
	}

}


Measured memory_bytes: 19420
#include <stdio.h>
#include <string.h>

int Check(char *s,int len){
  int t,i;
  t = 0;
  for(i=0; i<(len/2); i++){
    if(s[i] != s[len-i-1])
      t++;
  }
  return t;
}

int main(void){
  char St[100];
  int a,len;
  scanf("%s", St);
  len = strlen(St);
  a = Check(St,len);
  printf("%d" ,a);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <stack>
#define N_MAX 100000
using namespace std;
//常に心してかかれ
//簡単なことを簡単にできるように練習する
//びっくりするくらいつまらないことで詰まってることも多い

int n;

int partition(int A[],int p,int r){//rは配列の最後を指す添え字
	int x = A[r];
	int i = p;
	int tmp;
	
	for(int j=p;j<r;j++){
		if(A[j] <= x){
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
			i++;
		}
	}
	tmp = A[i];
	A[i] = A[r];
	A[r] = tmp;

	return i;//iはx以下の数の数ともいえる
}

int main(){
	int A[N_MAX+1];
	int p;

	scanf("%d",&n);

	//確認用
	//printf("%d\n",n);
	
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);

		//確認用
		//printf("%d ",A[i]);
	}

	p = partition(A,0,n-1);
	
	if(n == 1){
		printf("[%d]\n",A[0]);
		return 0;
	}
	if(p == 0){
		printf("[%d]",A[0]);
	}else
		printf("%d",A[0]);
		for(int i=1;i<n;i++){
			if(i == p){
				printf(" [%d]",A[i]);
			}else
				printf(" %d",A[i]);
	}
	printf("\n");
}

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

using namespace std;

const int N = 100000;
int wrong[N];
bool accepted[N];
char s[3];

int main() {
  int n, m; cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int p;
    cin >> p >> s; --p;
    if(accepted[p]) continue;
    if(s[0] == 'W') wrong[p]++;
    else accepted[p] = 1;
  }
  int a = 0, p = 0;
  for(int i = 0; i < n; ++i) {
    if(accepted[i]) {
      a++;
      p += wrong[i];
    }
  }
  cout << a << " " << p << endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int f[100005];
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    f[0]=1;
    for(int i=1;i<s.size();i++){
        f[i]=f[i-1];
        if(s[i]!=s[i-1])
            f[i]++;
    }
    cout<<f[n-1]<<endl;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

mat& mul(mat& a,mat& b,lli mod){
  mat* c = new mat(a.size(),vll(b.size()));
  for(lli i = 0;i < a.size();i++){
    for(lli j = 0;j < b.size();j++){
      for(lli k = 0;k < a[i].size();k++){
        (*c)[i][j] += (a[i][k]*b[k][j])%mod;
        (*c)[i][j] %= mod;
      }
    }
  }
  return *c;
}

lli a,b,c,k;
mat i,o;

int main(){
  cin >> a >> b >> c >> k;

  // i = mat(3,vll(3));
  // i[0][0] = i[1][1] = i[2][2] = 1;
  // o = mat(3,vll(3,1));
  // o[0][0] = o[1][1] = o[2][2] = 0;
  // for(;k != 0;k >>= 1){
  //   if(k & 1ll != 0){
  //     i = mul(o,i,LONG_MAX);
  //   }
  //   o = mul(o,o,LONG_MAX);
  // }
  // for(lli x = 0;x < 3;x++){
  //   for(lli y = 0;y < 3;y++){
  //     cout << i[x][y] << " ";
  //   }
  //   cout << endl;
  // }
  if(k%2 == 0){
    cout << a-b << endl;
  }else{
    cout << b-a << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#define pi 3.14159265358979323846
#define max max_element
#define min min_element
using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

int main() {
	char r[4];
	char op[3];
	int sum = 0;
	scanf("%s", r);
	int yaju[4];
	for (int i = 0;i < 4;i++) {
		yaju[i] = r[i] - '0';
	}
	for (int i = 0;i < 8;i++) {
		sum = yaju[0];
		for (int j = 0;j < 3;j++) {
			if (i & ( 1 << j)) {
				op[j] = '+';
				sum += yaju[j+1];
			}
			else {
				op[j] = '-';
				sum -= yaju[j+1];
			}
		}
        if(sum == 7) break;
	}
	for (int i = 0;i < 3;i++) printf("%d%c", yaju[i], op[i]);
	cout << yaju[3] << "=7" << endl;
}

Measured memory_bytes: 256
import math
import functools

def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
ave = sum(v[:a]) / a
x, y = v.count(v[a-1]), v[:a].count(v[a-1])

if v[0] == v[a-1]:
    comb = sum([C(x,i) for i in range(a,min(b,x)+1)])
else:
    comb = C(x,y)

print(ave)
print(comb)


Measured memory_bytes: 3700
#include <stdio.h>

int main(void) {
	char buf[16];
	int i, j;
	int ptn[4][2];
	int p;
	int ofs_x, ofs_y;

	do{
		p = 0;
		ofs_x = -1;
		for(i=0;i<8;i++) {
			if(scanf("%s\n", buf)!=1) return 0;
			for(j=0;j<8;j++) {
				if(buf[j] == '1') {
					if(ofs_x == -1) {
						ofs_y = i;
						ofs_x = j;
					}
					ptn[p][0] = i - ofs_y;
					ptn[p][1] = j - ofs_x;
					p++;
				}	
			}
		}
		
		if(ptn[3][0] == 1 && ptn[3][1] == 1) {
			printf("A\n");
		} else if(ptn[3][0] == 3) {
			printf("B\n");
		} else if(ptn[3][1] == 3) {
			printf("C\n");
		} else if(ptn[3][1] == -1) {
			printf("D\n");
		} else if(ptn[3][1] == 2) {
			printf("E\n");
		} else if(ptn[3][0] == 2) {
			printf("F\n");
		} else {
			printf("G\n");
		}
	} while(scanf("%*")==0);
	
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    rep(i,n/4+1)rep(j,n/7+1){
        if(4*i+7*j==n){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
  if (i == 10) return true;
  if (b > balls[i] && c > balls[i]) return false;
  if (b < balls[i]) fork(balls, i + 1, balls[i], c);
  if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(fork(Balls, 0, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3068
def main():
    S = input()

    N = len(S)
    ans = 1

    i = 1
    chars = ''
    buf = S[0]
    while i < N:
        chars += S[i]
        if buf == chars:
            pass
        else:
            ans += 1
            buf = chars
            chars = ''
        i += 1
    print(ans)
main()

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	for(int i=0;i<1000;i++){
		if((a*i)%b==c){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> ts(5);
  for(int i = 0; i < 5; ++i) {
    cin >> ts[i];
  }
  sort(ts.begin(), ts.end());
  ll neck = ts[0];
  ll times = N / neck + min(N % neck, 1LL) + 4LL;

  cout << times << endl;
  return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
var n=Arr.shift()-0;
for(var I=0;I<n;I++){
   var s=Arr.shift();
   var str="";
   for(i=0;i<s.length;i++){
      var v=s[i];
      if(v=="0")str+="0000";
      else if(v=="1")str+="0001";
      else if(v=="2")str+="0010";
      else if(v=="3")str+="0011";
      else if(v=="4")str+="0100";
      else if(v=="5")str+="0101";
      else if(v=="6")str+="0110";
      else if(v=="7")str+="0111";
      else if(v=="8")str+="1000";
      else if(v=="9")str+="1001";
      else if(v=="a")str+="1010";
      else if(v=="b")str+="1011";
      else if(v=="c")str+="1100";
      else if(v=="d")str+="1101";
      else if(v=="e")str+="1110";
      else if(v=="f")str+="1111";
   }
   var arr=str.split("").map(Number);
   arr.reverse();
   var num=0;
   var j=7;
   for(var i=0;i<7;i++){
      num+=Math.pow(0.5,j)*arr[i];
      j--;
   }
   var j=0;
   for(var i=7;i<31;i++){
      num+=Math.pow(2,j)*arr[i];
      j++;
   }
   num=num+"";
   if((num.split(".")).length==1)num+=".0";
   console.log((arr[31]==0)?num:"-"+num);
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
; 

#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n;
  cin >> n;
  vll l(n);
  rep(i,0,n) cin >> l[i];

 ll res=0; 
  
  sort(l.begin(),l.end());
  
  for(ll i=n-1;i>=1;i--){
    for(ll j=i-1;j>=0;j--){
     ll d=upper_bound(l.begin(),l.end(),l[i]-l[j])-l.begin();
     if(j-d>0) res+=(j-d); 
    }
  }
   cout << res << endl;
}


Measured memory_bytes: 256
a,b,x = gets.chomp.split.map(&:to_f)

include Math

ans = 0
if a*a*b/2 <= x
  ans = atan(2 * (a*a*b - x) / (a*a*a))
else
  ans =  PI / 2 - atan(2*x / (a*b*b))
end

puts ans * 180 / PI


Measured memory_bytes: 1788
a = [list( input().split()) for _ in range(3)]

n = int(input())
for i in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = "0"

for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == "0":
        print("Yes")
        exit()
    if a[0][i] == a[1][i] == a[2][i] == "0":
        print("Yes")
        exit()
if a[0][0] == a[1][1] == a[2][2] == "0":
    print("Yes")
    exit()
if a[0][2] == a[1][1] == a[2][0] == "0":
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();

    vl x(26);
    rep(i, n) {
        x[s[i] - 'a']++;
    }

    vl y(26);
    rep(i, n) {
        y[t[i] - 'a']++;
    }
    
    sort(all(x));
    sort(all(y));

    rep(i, 26) {
        if(x[i] != y[i]) {
            out("No");
            re0;
        }
    }

    out("Yes");
    re0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n;
  cin >> n;
  vi32 a(n + 1);
  cin >> a;
  i64 sum = 0;
  repc(i, n) sum += a[i];
  i64 ans = 0;
  i64 now = 1;
  repc(i, n) {
    ans += now;
    if (now - a[i] < 0) {
      cout << -1 << endl;
      return;
    }
    now -= a[i];
    sum -= a[i];
    // next
    now = min(now * 2, sum);
  }
  cout << ans << endl;
}


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


int main(){
    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
l1 = set()
l2 = set()
for i in range(m):
    a,b = map(int,input().split())
    if a==1:
        l1.add(b)
    elif b==n:
        l2.add(a)
print('POSSIBLE' if len(l1&l2) >=1 else 'IMPOSSIBLE')

Measured memory_bytes: 24104
var abk;function ex(a,n){abk[a]%2==1&&--abk[a],abk[a]/=2,abk[n]+=abk[a]}function Main(a){for(var n=(abk=a.split("\n")[0].split(/\s/).map(function(a){return a-0}))[2],e=1;e<=n;e++)e%2==1?ex(0,1):ex(1,0);console.log("%d %d",abk[0],abk[1])}Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a,b,c=0,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        d = i;
        c=0;
        for(int j=0;j<5;j++){
            c += d % 10;
            d /= 10;
        }
        if(c>=a&&c<=b){
            ans += i;
        }
    }
    cout << ans <<endl; 
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define NINF -1000000000000
using namespace std;
typedef long long ll;
struct Ed{
  int to,cost;
  Ed(int a,int b){
    to=a;
    cost=b;
  }
};
int main(){
  ll n,m,p,a,b,t=1,c,loss,diff;
  ll d[2501];
  bool chan;
  fill(d,d+2501,NINF);
  d[1]=0;
  vector<Ed> G[5001];
  cin >> n >> m >> p;
  for(int i=0;i<m;i++){
    cin >> a >> b>>c;
    G[a].push_back(Ed(b,c));
  }
  while(t<=n-1){
    loss=t*p;
    for(int i=1;i<=n;i++){
      if(d[i]==NINF) continue;
      for(int j=0;j<G[i].size();j++){
        if(d[G[i][j].to]<d[i]+G[i][j].cost-p){
          d[G[i][j].to]=d[i]+G[i][j].cost-p;
        }
      }
    }
    t++;
  }
  chan = false;
  t=1;
  while(t<=n-1){
    loss=t*p;
    for(int i=1;i<=n;i++){
      if(d[i]==NINF) continue;
      for(int j=0;j<G[i].size();j++){
        if(d[G[i][j].to]<d[i]+G[i][j].cost-p){
          d[G[i][j].to]=d[i]+G[i][j].cost-p;
          if(G[i][j].to==n) {
            chan=true;
          }
        }
      }
    }
    t++;
  }
  if(chan) cout << -1<<endl;
  else cout << max(ll(0),d[n]) <<endl;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n;i++){
    buf1+=a[i];
    if(i%2==1)buf2+=a[i];
  }
  buf=buf1-2*buf2;
  cout<<buf<<endl;
  for(i=1;i<n;i++){
    buf=(a[i-1]-buf/2)*2;
    cout<<buf<<endl;
  }

  return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int N=100010;

int a[N];
int n, k;

VI es[N]; int dep[N];
int ans;

void dfs(int x) {
    dep[x]=1;
    for(int y: es[x]) {
        dfs(y);
        if(dep[y]<k) setmax(dep[x], dep[y]+1);
            else ++ans;
    }
}

int main() {
    scanf("%d%d", &n,&k);
    rep(i, 1, n) scanf("%d", &a[i]);

    ans=0;
    if(a[1]!=1) ++ans, a[1]=1;

    rep(i, 2, n) es[a[i]].pb(i);
    for(int x: es[1]) dfs(x);
    printf("%d\n", ans);


    return 0;
}


Measured memory_bytes: 11136
function Main(input) {
  const lines = input.split("\n");
  const [a, b, c] = lines[0].split(' ');
  const isPoor = a == b && b != c || a == c && b != c || b == c && a != b;

  console.log(isPoor ? 'Yes' : 'No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	one := map[int]int{}
	nn := map[int]int{}
	for i := 0; i < m; i++ {
		a := getNextInt(scanner)
		b := getNextInt(scanner)
		if a == 1 {
			one[b] = 1
			continue
		}
		if b == n {
			nn[a] = 1
			continue
		}
	}
	for c := range one {
		if nn[c] == 1 {
			fmt.Fprintln(writer, "POSSIBLE")
			return
		}
	}
	fmt.Fprintln(writer, "IMPOSSIBLE")
}


Measured memory_bytes: 14072
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

bool solve(){
  int n;
  cin>>n;
  vector<int> a(n+1),b(n+1);
  rep(i,n+1) cin>>a[i];
  rep(i,n+1) cin>>b[i];

  int sa=0,sb=0,edges=0;
  rep(i,n+1){
    sa += a[i];
    sb += b[i];
    edges += i * (a[i]-b[i]);
  }
  if(sa!=n || sb!=n || edges!=0) return false;

  vector<vector<int>> vec(n,vector<int>(n,0));

  vector<int> in(n), out(n);

  {
    int idx=0;
    for(int i=n; i>=0; i--) rep(_,a[i]) in[idx++]=i;

    idx = 0;
    for(int i=n; i>=0; i--) rep(_,b[i]) out[idx++]=i;
  }

  priority_queue<pair<int,int>> pq;
  // <left_edge, idx>

  rep(i,n) if(in[i]>0) pq.push(mp(in[i],i));

  rep(i,n){
    priority_queue<pair<int,int>> nxt;
    rep(_,out[i]){
      int p = pq.top().se; pq.pop();
      vec[i][p] = 1;
      in[p]--;
      if(in[p]>0) nxt.push(mp(in[p], p));
    }
    while(!pq.empty()){
      nxt.push(pq.top());
      pq.pop();
    }
    swap(nxt, pq);
  }
  assert(pq.empty());

  cout << "YES" << endl;
  rep(i,n) rep(j,n) cout << vec[i][j] << " \n"[j==n-1];

  return true;
}

int main(){
  if(solve()==false) cout << "NO" << endl;

  return 0;
}

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

int main() {
    int n, a, ans = 1000100100, cnt;
    cin >> n;
    rep(i, n) {
        cin >> a;
        cnt = 0;
        while(a % 2 == 0) {
            cnt++;
            a /= 2;
        }
        if(cnt < ans) {
            ans = cnt;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map_as(H, replace={'#': 1, '.': 0}, pad=0):
    '''
    文字列のmapを置換して読み込み。デフォでは#→1,.→0
    '''
    # TODO paddingの機能入れたいね
    ret = [[pad] * (W + 2)]
    for _ in range(H):
        ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    ret.append([pad] * (W + 2))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc096/tasks/abc096_c
# 普通に上下左右の連結成分が全部2以上か調べれば良い
# というか上下左右の連結成分がない場合に即時終了すれば良い
H, W = read_ints()
S = read_map_as(H)
for i, j in product(ra(1, H + 1), ra(1, W + 1)):
    if S[i][j] == 0:
        continue
    for di, dj in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if S[ni][nj] == 1:
            break
    else:
        print('No')
        exit()

print('Yes')


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

int main(){
  int n; cin>>n;
  if (n==0){
    cout<<0<<endl;
    return 0;
  }
  
  string ans="";
  while (n!=0){
    int r=n%(-2);
    if (r<0) r+=2;
    ans+=(char)('0'+r);
    n-=r;
    n=n/(-2);
  }
  reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long int N, a, b, c = 0;
    scanf("%ld", &N);
    for(long int i = 1; i <= N; i++){
        a = i % 3;  b = i % 5;
        if(a != 0){
            if(b != 0){
                c += i;
            }
        }
    }
    printf("%ld", c);
  return 0;
}

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

int main() {
  int a, b, c, x; cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        int sum = 500 * i + 100 * j + 50 * k;
        if (sum == x) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int n,m;
  cin>>n>>m;
  int a;
  int sum=0;
  REP(i,m){
    cin>>a;
    sum+=a;
  }
  if(n<sum){
    cout<<-1<<endl;
  }else{
    cout<<n-sum<<endl;
  }
}

Measured memory_bytes: 3600