akhauriyash/Code-Regression huggingface dataset:
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

const int INF = 1e18+5;

signed main() {
   tezz
   
   int n,k,w,v;
   cin >> n >> k;
   int sum_val=0;
   vector<int> weight(n), value(n);
   for(int i=0; i<n; i++){
       cin >> weight[i] >> value[i];
       sum_val+=value[i];
   }
   vector<int> dp(sum_val+1,INF);
   dp[0]=0;
   for(int i=0; i<n; i++){
       for(int j=sum_val; j>=value[i]; j--){
           dp[j]=min(dp[j-value[i]]+weight[i],dp[j]);
       }
    //   for(int j=0; j<=sum_val; j++)cout << dp[j] << " ";   
    //             cout << endl;
   }
   int ans=0;
   for(int i=0; i<=sum_val; i++){if(dp[i]<=k)ans=max(ans,i);}
    cout << ans << endl;

   return 0;
}


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

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;

  int count = 0;
  for (size_t i = 0; i < 3; ++i) {
    if (S.at(i) == T.at(i)) {
      count += 1;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		String out;
		// 文字列の入力
		if((a <= c && c <= b) || (b <= c && c <= a)) {
			out = "Yes";
		}
		else {
			out = "No";
		}
 		// 出力
		System.out.println(out);
	}
}

Measured memory_bytes: 21844
N,M=map(int,input().split())
t=set()
s=set()
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        s.add(b)
    if b==N:
        t.add(a)
for i in s:
    if i in t:
        print("POSSIBLE")
        quit()
print("IMPOSSIBLE")


Measured memory_bytes: 19024
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int main(void) {
	int a, b, c; cin >> a >> b >> c;
	int x = a + b, y = b + c, z = c + a;
	cout << Min(x, y, z) << endl;
	return 0;
}

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


int main(){
	int x,y,a [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
cin >> x >> y;
if(a[x] == a[y]){
	cout << "Yes" << endl;
}
else{
	cout << "No" << endl;
}

	}

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

#define ff first
#define ss second

const ll MOD = 1e9 + 7;
int H, W;
char grid[1000][1000];
ll dp[1000][1000];

inline ll addMod(ll a, ll b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll f (int row, int col) {
	if (row < 0 || row >= H || col < 0 || col >= W || grid[row][col] == '#') {
		return 0;
	}

	if (dp[row][col] == -1) {
		dp[row][col] = addMod(f(row+1, col), f(row, col+1));
	}

	return dp[row][col];
}

int main()
{
	ios::sync_with_stdio(0);

	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> grid[i][j];
		}
	}

	memset(dp, -1, sizeof(dp)); dp[H-1][W-1] = 1;
	cout << f(0, 0) << endl;

	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    ll n,t,a;
    ll ansnum;
    ll ans;
    cin>>n>>t>>a;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        if (i==0||abs((t*1000-tmp*6)-a*1000)<abs((t*1000-ansnum*6)-a*1000)){
            ans=i+1;
            ansnum=tmp;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      int counter  =0;
       String a = sc.next();
       String b = sc.next();
       String[] aa = a.split("");
      String[] bb = b.split("");
      String[] cc = new String[aa.length];
      for(int i =0; i< aa.length;i++){
      	if(aa[i].equals(bb[i])){
          
        }else{
        	counter++;
           
        }
      }
      System.out.println(counter);
      
    }
}

Measured memory_bytes: 67488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a + b == 15)System.out.println("+");
        else if(a * b == 15) System.out.println("*");
        else System.out.println("x");
    }
}


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

int main() {
	int n;
	int x;
	cin>>x;
	string y= to_string(x);
	
	n=y.length();
	
	// int arr[1009];
	// for(int i=0;i<n;i++){
		
	// }
	bool ans=true;
	for(int i=0;i<=(n-1)/2;i++){
		if(y[i]!=y[n-1-i]){
			ans=false;
			break;
		}
	}
	if(ans==true){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}

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

using namespace std;

const int MAXN = 2e5 + 5;
typedef long long ll;

int A[MAXN], N, b1, b2;
ll res1, res2;

int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; ++i){ scanf("%d", &A[i]); A[i] -= i; }
	sort(A + 1, A + N + 1);
	b1 = A[N / 2], b2 = A[(N + 1) / 2];
	for(int i=1; i<=N; ++i) res1 += abs(A[i] - b1), res2 += (abs(A[i] - b2));
	printf("%lld\n", min(res1, res2));
	return 0;
}	
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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 long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;

    ll ans = 0;
    REP(i, 1, n) {
        ans += i;
    }

    cout << ans << endl;


    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<string> w(n);
  rep(i, n) cin >> w[i];
  set<string> seen;
  bool ok = true;
  rep(i, n) {
    if (!seen.insert(w[i]).second) {
      ok = false;
      break;
    }
    if (i > 0 && w[i][0] != w[i - 1].back()) {
      ok = false;
      break;
    }
  }
  out(ok ? "Yes" : "No");
}


Measured memory_bytes: 3632
from collections import deque
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


def main():
    n, q = map(int, input().split())
    node = [[]for _ in range(n)]
    looked = [1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        node[b - 1].append(a - 1)
        node[a - 1].append(b - 1)
    counter = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)

main()


Measured memory_bytes: 60692
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	w := nextInt(sc)
	h := nextInt(sc)
	x := nextInt(sc)
	y := nextInt(sc)
	r := nextInt(sc)
	fmt.Println(resolve(w, h, x, y, r))
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func resolve(w, h, x, y, r int64) string {
	const no = "No"
	const yes = "Yes"
	if x-r < 0 {
		return no
	}
	if x+r > w {
		return no
	}
	if y-r < 0 {
		return no
	}
	if y+r > h {
		return no
	}
	return yes
}



Measured memory_bytes: 1112
fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    val robots = Array(N) { val (X, L) = readInputLine().split(" ").map { it.toLong() }; Pair(X, L)}.sortedBy { r -> val (X, L) = r; X + L }

    var pos = Long.MIN_VALUE
    var ans = 0

    for (r in robots) {
        val (X, L) = r
        if (pos <= X - L) {
            ans++
            pos = X + L
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int r = 0;
	for (int i = 0; i < s.length() / 2; ++i) {
		if (s[i] != s[s.length() - i - 1]) {
			++r;
		}
	}
	cout << r;
}

Measured memory_bytes: 256
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut primes = vec![0; n + 1];
    for i in 1..(n + 1) {
        let mut i = i;
        let mut p = 2;
        while p <= i {
            while i % p == 0 {
                primes[p] += 1;
                i /= p;
            }
            p += 1;
        }
    }
    let mut ret = 0;
    for i in 0..(n + 1) {
        for j in (i + 1)..(n + 1) {
            for k in (j + 1)..(n + 1) {
                match (primes[i], primes[j], primes[k]) {
                    (x, y, z) if x >= 4 && y >= 4 && z >= 4 => ret += 3,
                    (x, y, z) if x >= 4 && y >= 4 && z >= 2 => ret += 1,
                    (x, y, z) if x >= 4 && y >= 2 && z >= 4 => ret += 1,
                    (x, y, z) if x >= 2 && y >= 4 && z >= 4 => ret += 1,
                    _ => (),
                }
            }
        }
    }
    for i in 0..(n + 1) {
        for j in (i + 1)..(n + 1) {
            if primes[i] >= 2 && primes[j] >= 24 {
                ret += 1;
            }
            if primes[j] >= 2 && primes[i] >= 24 {
                ret += 1;
            }
            if primes[j] >= 4 && primes[i] >= 14 {
                ret += 1;
            }
            if primes[j] >= 14 && primes[i] >= 4 {
                ret += 1;
            }
        }
    }
    for i in 0..(n + 1) {
        if primes[i] >= 74 {
            ret += 1;
        }
    }
    println!("{}", ret);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    vector<long long>a(n+1);
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=1;i<n;i++)a[i+1]+=a[i];
    long o=0,oc=0,e=0,ec=0;
    for(i=1;i<=n;i++){
        if(i%2){
            if(a[i]+o<1)oc+=1-a[i]-o,o+=1-a[i]-o;
            if(a[i]+e>-1)ec+=1+a[i]+e,e-=1+a[i]+e;  
        }
        else{
            if(a[i]+o>-1)oc+=1+a[i]+o,o-=1+a[i]+o;
            if(a[i]+e<1)ec+=1-a[i]-e,e+=1-a[i]-e;  
        }
    }
    cout<<min(oc,ec)<<endl;
    return 0;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (h, w, n) = get!(i64, i64, usize);
    let ps = get!(i64, i64; n);

    let mut rects = HashMap::new();
    for &(y, x) in &ps {
        for i in 0..3 {
            for j in 0..3 {
                let y = y - i - 1;
                let x = x - j - 1;

                if y >= 0 && y < h - 2 && x >= 0 && x < w - 2 {
                    let n = y * (w - 2) + x;
                    *rects.entry(n).or_insert(0) += 1;
                }
            }
        }
    }

    let mut sum = vec![0; 10];

    for &c in rects.values() {
        sum[c] += 1;
    }

    sum[0] = (h - 2) * (w - 2) - sum[1..].iter().sum::<i64>();

    for &a in &sum {
        println!("{}", a);
    }
}


Measured memory_bytes: 42260
#include <bits/stdc++.h>
using namespace std;
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;
}


int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a.at(i).at(j);
        }
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            bool flag = true;
            for (int k = 0; k < n; k++) {
                if (i == k || j == k) {
                    continue;
                }
                // if (i == 2 && j == 0 && k == 1) {
                //     cout << "!!!!" << a.at(i).at(j) << endl;
                //     cout << "!!!!" << a.at(i).at(k) << a.at(k).at(j) << endl;
                //     cout << (a.at(i).at(j) > a.at(i).at(k) + a.at(k).at(j)) << endl;
                // }
                if (a.at(i).at(j) > a.at(i).at(k) + a.at(k).at(j)) {
                    // cout << "hello 1" << endl;
                    ans = -1;
                    break;
                }
                else if (a.at(i).at(j) == a.at(i).at(k) + a.at(k).at(j)) {
                    flag = false;
                }
            }
            if (ans == -1) {
                // cout << "hello 2" << endl;
                break;
            }
            if (flag) {
                ans += a.at(i).at(j);
            }
        }
        // if (ans == -1) {
        //     cout << "hello 3" << endl;
        //     break;
        // }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3972
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, A, B, bX, X, count = 0;
	cin >> N >> A >> B >> bX;
	for (int i = 1; i < N; i++) {
		cin >> X;
		count += min((X - bX) * A, B);
		bX = X;
	}
	cout << count;
}

Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

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

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

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

  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  debug("a");
  cout << (A1 + A2 + A3 >= 22 ? "bust" : "win") << endl;
  debug("b");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n;
  cin >> n;
  if(n%2==0){
    cout << n << " " << n << " " << n/2 << endl;
    return 0;
  }
  rep1(h,3500){
    ll a=4*h-n;
    ll b=n*h;
    rep1(w,3500){
      if(a*w!=b){
	      ll y=(b*w)/(a*w-b);
    	  if(y>0 && y*(a*w-b)==b*w){
		cout << h << " " << w << " " << y << endl;
		return 0;
        }
      }
    }
  }

  
  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
string s;
 ll a=0;
  ll b=0;
  ll c=0;
  
cin >>s;
  if(s[0]=='a'){
  a++;
  }
  else if(s[0]=='b'){
  b++;
  }
  else{
  c++;
  }  if(s[1]=='a'){
  a++;
  }
  else if(s[1]=='b'){
  b++;
  }
  else{
  c++;
  }  if(s[2]=='a'){
  a++;
  }
  else if(s[2]=='b'){
  b++;
  }
  else{
  c++;
  }
  if(a==1&&b==1&&c==1)
    cout << "Yes";
  else
     cout << "No";
return 0;

}

Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
    }
    vector<ll> dp(n);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(ll i=2;i<n;i++)
    {
        ll minv=INT_MAX;
        for(ll j=1;j<=k && (i-j)>=0;j++)
        {
            minv=min(minv,dp[i-j]+abs(v[i]-v[i-j]));
        }
        
        dp[i]=minv;
    }
    cout<<dp[n-1];
    return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1000005

ll N;
vector<ll> V;




int main(){

	scanf("%lld",&N);

	ll tmp;
	ll b = -1;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&tmp);
		V.push_back(tmp);
	}

	sort(V.begin(),V.end());

	ll left,right,mid,loc;

	for(ll i = N-1; i < N; i++){

		//((V[i]+1)/2)以上の最小の数
		left = 0,right = i-1,mid = (left+right)/2;
		loc = -1;

		while(left <= right){
			if(V[mid] >= (V[i]+1)/2){

				loc = mid;
				right = mid-1;
			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}
		if(loc != -1){

			b = V[loc];
			//printf("b:%lld\n",b);
		}

		//((N+1)/2)未満の最大の数
		left = 0,right = i-1,mid = (left+right)/2;
		loc = -1;

		while(left <= right){
			if(V[mid] < (V[i]+1)/2){

				loc = mid;
				left = mid+1;
			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		if(loc != -1){

			//printf("V[loc]:%lld\n",V[loc]);
			tmp = V[i]-V[loc];
			if(tmp < b || b == -1){

				b = V[loc];
			}
		}
	}

	printf("%lld %lld\n",V[N-1],b);

	return 0;
}


Measured memory_bytes: 4364
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
struct angka
{
    string s;
    int len;
};
struct angka node[1000010];
int cnt;
int now;
bool desc(struct angka a, struct angka b)
{
    if(a.len == b.len) return a.s < b.s;
    return a.len < b.len;
}
void dfs(int pos, string s)
{
    if(pos == 0) {
        node[cnt].s = s;
        node[cnt].len = s.length();
        cnt++;
        return;
    }
    int i;
    for(i=0;i<10;i++) {
        char c = '0' + i;
        if(pos == now) {
            if(i > 0) dfs(pos-1, s + c);
        } else {
            char last = s[now - pos - 1];
            if(abs(last - c) <= 1) {
                dfs(pos-1, s + c);
            }
        }
    }
}
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    cin >> n;
    cnt = 1;
    for(i=1;i<=10;i++) {
        now = i;
        dfs(i, "");
    }
    sort(node+1, node+cnt, desc);
    cout << node[n].s << endl;
    return 0;
}


Measured memory_bytes: 27904
#include<stdio.h>
int main()
{
    int N,a,b,c;
    scanf("%d",&N);
     a=N%10;
     N=(N-a)/10;
     b=N%10;
     N=(N-b)/10;
     c=N;
     if(a==7||b==7||c==7)
     printf("Yes\n");
     else
       printf("No\n");
    return 0;
}



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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

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

    for(int i = 0; i < 1009; i++){
        int a = i * 0.08;
        int b = i * 0.1;

        if( A == a && b == B ){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}



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

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define REPR(i,n) for (int i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 3e3+10;
const int MOD = 1e9+7;
int N;
string S;
ll dp[MAX][MAX];

ll solve(int n, int m) {
    if (n == 0) return 1;
    if (dp[n][m] >= 0) return dp[n][m];

}

int main () {
	cin >> N >> S;
    REP (j, N) dp[0][j] = 1;
    
    FOR (i, 1, N) {
        bool g = (S[i-1] == '<');
        if (g) {
            REPR (j, N-i)
                dp[i][j] = (dp[i][j+1] + dp[i-1][j+1]) % MOD;
        } else {
            dp[i][0] = dp[i-1][0];
            FOR (j, 1, N-i)
                dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
        }
    }
    cout << dp[N-1][0] << endl;
}

Measured memory_bytes: 70016
#include <iostream>
#include <cstdio>
#define N 300005
using namespace std;

int k, n, a[N];
int main()
{
	int i, j;
	cin >> k >> n;
	if (k % 2 == 0) {
		cout << k / 2 << ' ';
		for (i = 1; i < n; i++) printf("%d ", k);
	} else {
		for (i = 0; i < n; i++) a[i] = k / 2 + 1;
		for (i = 0, j = n - 1; i < n / 2; i++) {
			a[j]--;
			if (a[j]) j = n - 1;
			else a[j--] = k;
		}
		for (i = 0; i <= j; i++) printf("%d ", a[i]);
	}
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
	int k=0;
	vector<int> prid(MAX);
	vector<int> pre(MAX);
	for(int i=0;i<MAX;i++)
		prid[i]=1;
	prid[0]=0;
	prid[1]=0;
	for(int i=0;i*i<MAX;i++)
		if(prid[i]){
			for(int j=i*2;j<MAX;j+=i)
				prid[j]=0;
		}
	for(int i=0;i<MAX;i++)
		if(prid[i])
			pre[k++]=i;
	int n,v;
	while(cin>>n,n){
		k=0;
		while(pre[k++]<=n)
		v=k-1;
		for(int j=v;j>=0;j--)
			if(pre[j]-pre[j-1]==2){
				cout<<pre[j-1]<<" "<<pre[j]<<endl;
			break;
			
			
		}
		
	}
	
	return 0;
}

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

using namespace std;

int main(void) {
	int L,R;
	cin >> L >> R;
	const int LIM = 2019;
	int count = 0;
	long long res = (1 << 28);
	for (long long i = L; res != 0 && count < LIM*LIM && i < R; ++i) {
		for (long long j = i+1; res != 0 && count < LIM*LIM && j < R+1; ++j) {
			res = min((i*j)%LIM,res);
			++count;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	string str;
	cin>>str;
    int n=(int)str.size();
    int i=1;
	int ans1=1;
	char ch=str[0];
	int prev_=1;
	while(i!=(int)str.size())
	{
		if(prev_==2)
		{
			ch=str[i];
			prev_=1;
		}
		else
		{
			if(str[i]==ch)
			{
				if(i==n-1)
					break;
				i++;
				prev_=2;
			}
			else
			{
				prev_=1;
				ch=str[i];
			}
		}
		i++;
		ans1++;
	}
	int ans2=1;
	i=2;
	prev_=2;
	while(i!=(int)str.size())
	{
		if(prev_==2)
		{
			ch=str[i];
			prev_=1;
		}
		else
		{
			if(str[i]==ch)
			{
				if(i==n-1)
					break;
				i++;
				prev_=2;
			}
			else
			{
				prev_=1;
				ch=str[i];
			}
		}
		i++;
		ans2++;
	}
	cout<<max(ans1,ans2);
	return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

class Union_Find_size{
public:
  vector<int> Parent;
  //コンストラクタ
  Union_Find_size(int N){
    Parent=vector<int>(N,-1);
  }
  //木の根を求める
  int root(int x){
    //x（自分）が親ならxを返す
    if(Parent.at(x)<0)  return x;
    //経路圧縮しながら return する
    return Parent.at(x)=root(Parent.at(x));
  }
  //xの属する木の要素数を調べる
  int size(int x){
    return -Parent.at(root(x));
  }
  //xとyが同じ集合に属するかを判定する
  bool same(int x,int y){
    return root(x)==root(y);
  }
  //xとyの属する集合を併合する
  void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)  return;
    if(size(x)<size(y)) swap(x,y);
    Parent.at(x)+=Parent.at(y);
    Parent.at(y)=x;
  }
};

//abc097d,abc120d,abc126e

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  Union_Find_size uni(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    uni.unite(a,b);
  }

  int ans=0;
  rep(i,N)  chmax(ans,uni.size(i));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  int i,count = 0;
  cin >>s;
  s = s + '2';
  for(i = 0; i < s.length(); i++){
    if(s[i] == '2' || s[i+1] == '2') break;
    if(s[i] == '1' && s[i+1] == '0'){
      s.erase(i,2);
      i -= 2;
      count += 2;
    }else if(s[i] == '0' && s[i+1] == '1'){
      s.erase(i,2);
      i -= 2;
      count += 2;
    }
    if (i == -2)i++;
  }
  cout << count << endl;
}

Measured memory_bytes: 512
#include<iostream>
int main(){
  int a, b;
  std::cin >> a >> b;
  if (a < b) {
    std::cout << "a < b" << std::endl;
  }
  else if (b < a){
    std::cout << "a > b" << std::endl;
  }
  else {
    std::cout << "a == b" << std::endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<ll> calc_next(const vector<ll> &ar) {
    vector<ll> res;
    for (auto val : ar) {
        for (int j = -1; j <= 1; ++j) {
            int add = (val % 10) + j;
            if (add >= 0 && add <= 9) res.push_back(val * 10 + add);
        }
    }
    return res;
}

int main() {
    int K;
    cin >> K;
    vector<ll> all;
    vector<ll> cur;
    for (int v = 1; v < 10; ++v) cur.push_back(v), all.push_back(v);
    for (int d = 1; d < 10; ++d) {
        cur = calc_next(cur);
        for (auto val : cur) all.push_back(val);
    }
    cout << all[K-1] << endl;
}

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

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

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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX


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

	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0)
		cout<<1;
	else if(b==0)
		cout<<2;
	else if(c==0)
		cout<<3;
	else if(d==0)
		cout<<4;
	else
		cout<<5;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;



ll gcd(ll a, ll b) {
	if (a < b) {
		ll t = a;
		a = b;
		b = t;
	}
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

ll lcm(ll a,ll b) {
	return a * b / gcd(a, b);
}





int main() {
	int i, j, k;
	ll N, M, K;
	ll ans = 0;

	cin >> N;
	ll A[10][10];
	rep(i, 0, 10) {
		rep(j, 0, 10) {
			A[i][j] = 0;
		}
	}
	int ten = 1;
	int count = 0;
	rep(i, 1, N+1) {
		count++;
		if (i == 10*ten) {
			ten *= 10;
		}
		A[i / ten][i%10]++;
		
	}
	rep(i, 0, 10)rep(j, 0, 10) {
		ans += A[i][j] * A[j][i];
	}


	cout << ans;
	return 0;




}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0;
  char c[3],t[3];
  for(int i=0;i<3;i++)
    cin>>c[i];
  for(int i=0;i<3;i++)
    cin>>t[i];
  for(int i=0;i<3;i++){
    if(c[i]==t[i])
      a++;
  }
  cout<<a<<endl;
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int compare(const void* a, const void* b)
{
	const int* x = (int*) a;
	const int* y = (int*) b;
	if (*x > *y)
		return 1;
	else if (*x < *y)
		return -1;
	return 0;
}
int main(void)
{
	int n;
	cin>>n;
	double ans;
	int ar[1009];
	for (int i = 0; i < n; ++i)
	{
		cin>>ar[i];
	}
	qsort(ar , n, sizeof(int),compare);
	ans = (double)(ar[0]);
	for (int i = 1; i < n; ++i)
	{
		ans = (ans+ (double)ar[i])/2.0;
	}
	cout<<setprecision(10)<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{

  double w,h,x,y;
  cin>>w>>h>>x>>y;
  cout<<fixed<<setprecision(6)<<w*h/2<<" ";
  cout<<(w==2*x && h==2*y ? 1 : 0 );

go;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

int N,W,w0;
vi w,v;
int dp[110][110][500];
int rec(int i,int k,int sw) {
    if(dp[i][k][sw] != INF) return dp[i][k][sw];
    if(i==N) {
        if(sw+w0*k <= W) return dp[i][k][sw] = 0ll;
        else return dp[i][k][sw] = -INF;
    }
    return dp[i][k][sw] = max(rec(i+1,k+1,sw+w[i])+v[i],rec(i+1,k,sw));
}
signed main() {
    REP(i,110) REP(j,110) REP(k,500) dp[i][j][k]=INF;
    cin>>N>>W;
    w=vi(N),v=vi(N);
    REP(i,N) cin>>w[i]>>v[i];

    w0=w[0];
    REP(i,N) w[i]-=w0;

    cout<<max(rec(0,0,0),0ll)<<endl;
    return 0;
}


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

#define ll long long int
using namespace std;
int main()
{
    ll n,i,j,k,a,p,c=0;
    vector<ll>v,u;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    u=v;
    sort(v.begin(),v.end());
    for(i=0;i<n;i++)
    {
        if(u[i]!=v[i])
        {
            c++;
        }
    }
    if(c<=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}


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

int main() {
	int N, M, x, elem ;
	priority_queue<int> pq ;

	cin >> N >> M ;
	for(int i = 0 ; i < N ; i++) {
		cin >> x ;
		pq.push(x) ;
	}

	while(M > 0) {
		elem = pq.top() ; pq.pop() ;
		elem = elem >> 1 ;
		--M ;
		pq.push(elem) ;
	}

	long long min_cost = 0 ;
	while(!pq.empty()) {
		min_cost += pq.top() ;
		pq.pop() ;
	}

	cout << min_cost << endl ;

	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int b, c, n, m, k;
    int d[100];

    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            int tmp;
            cin >> tmp;
            tmp--;
            a[tmp]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define mod 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
//#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<LL> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL
#define f first
#define s second



int main(){

  
	LL n,k;
	mii subord;
     cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		LL a;
		cin>>a;
		subord[a]++;
	}
	for(int i=1;i<=n;i++)
	   cout<<subord[i]<<"\n";
		   

return 0;
   
}

Measured memory_bytes: 16096
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    int front = n / 100;
    int back = n - (n/100)*100;
    bool fok,bok, all_ok = true;//trueなら月,年に使える
    if(0 < front && front <= 12)fok = true;
    else if(front <= 99)fok = false;
    else all_ok = false;
    if(0 < back && back <= 12)bok = true;
    else if(back <= 99)bok = false;
    else all_ok = false;

    if(!all_ok){cout << "NA" << endl;return 0;}
    if(fok){
        cout << (bok ? "AMBIGUOUS" : "MMYY") << endl;
    }
    else{
        cout << (bok ? "YYMM" : "NA") << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF (1 << 30)
using namespace std;
using ll = long long;
ll N, GCD;
ll A[100000];
ll gcd(ll u, ll v) {
    while ( v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}

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

    cin >> N;
    for (int n = 0; n < N; ++n) {
        cin >> A[n];
        if (n > 0)
            GCD = gcd(A[n], GCD);
        else
            GCD = A[n];
    }

    cout << GCD << endl;

    return 0;
}

Measured memory_bytes: 1024
def build_line(width, i):
    s = ''
    if i % 2 == 0:
        while len(s) < width:
            if len(s) % 2 == 0:
                s += '#'
            else:
                s += '.'
    else:
        while len(s) < width:
            if len(s) % 2 == 0:
                s += '.'
            else:
                s += '#'
    return s

while True:
    h,w = [int(i) for i in input().split()]
    if not (h and w):
        break
    for i in range(h):
        print(build_line(w, i))
    print()



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

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, s: str):
    def is_valid(v, prev, cur, nex):
        if (v == 'o' and nex == (prev + cur) % 2 or
            v == 'x' and nex == (prev + cur + 1) % 2):
            return True
        return False

    r = None
    for c0 in [0, 1]:
        for c1 in [0, 1]:
            ret = [0] * N
            ret[0] = c0
            ret[1] = c1
            for i in range(1, N - 1):
                if s[i] == 'o':
                    ret[i + 1] = (ret[i - 1] + ret[i]) % 2
                else:
                    ret[i + 1] = (ret[i - 1] + ret[i] + 1) % 2
            if (is_valid(s[N - 1], ret[N - 2], ret[N - 1], ret[0]) and 
                is_valid(s[0], ret[N - 1], ret[0], ret[1])):
                r = ['W' if t else 'S' for t in ret]
                #print(c0, c1, r)
                break
    if r:
        print(''.join(r))
    else:
        print(-1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()


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

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

len_l = [0] * 51
plen_l = [0] * 51

# calc len_l
len_l[0] = 1
plen_l[0] = 1
for i in range(50):
    len_l[i + 1] = 2 * len_l[i] + 3
    plen_l[i + 1] = 2 * plen_l[i] + 1

def p_num(l, x):
    if l == 0:
        return 0 if x <= 0 else 1
    elif x <= len_l[l-1] + 1:
        return p_num(l - 1, x - 1)
    elif x == len_l[l-1] + 2:
        return plen_l[l-1] + 1
    else:
        return plen_l[l-1] + 1 + p_num(l - 1, x - len_l[l-1] - 2)

print(p_num(N, X))

Measured memory_bytes: 3064
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
s 100
 */
string s;

int main(){
  cin>>s;
  int l = s.size();
  cout<< s[0] << l - 2 << s[l-1]<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x is not None: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def delete(target):
    def remove_node(p, c, a):
        if p.left == c: p.left = a
        else: p.right = a
    p, c = None, root
    while c.key != target: p, c = c, c.left if target < c.key else c.right
    if c.left is None:
        remove_node(p, c, c.right)
    elif c.right is None:
        remove_node(p, c, c.left)
    elif c.right.left is None:
        c.right.left = c.left
        remove_node(p, c, c.right)
    else:
        g = c.right
        while g.left.left is not None: g = g.left
        c.key = g.left.key
        g.left = g.left.right

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'd': delete(int(e[7:]))
    elif e[0] == 'f': print(['yes','no'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 56376