akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))

def bubbleSort(a, n):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                flag = 1
                count += 1
        i += 1
    print(*a)
    print(count)
                   
bubbleSort(a,n)

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long& a : A) cin >> a;
  sort(A.begin(), A.end());
  vector<long> B(N);
  long i1 = 0, i2 = N-1, a1 = 0, a2 = 0;
  if (N % 2 == 0) {
    //
    B[N/2] = A[i2--];
    for (long i = 1; i < N / 2; i++) {
      if (i % 2) {
        B[N/2-i] = A[i1++];
        B[N/2+i] = A[i1++];
      } else {
        B[N/2-i] = A[i2--];
        B[N/2+i] = A[i2--];
      }
    }
    B[0] = A[i1];
    for (long i = 0; i < N-1; i++) {
      a1 += abs(B[i] - B[i+1]);
    }

    //
    i1 = 0; i2 = N - 1;
    B[N/2] = A[i1++];
    for (long i = 1; i < N / 2; i++) {
      if (i % 2) {
        B[N/2-i] = A[i2--];
        B[N/2+i] = A[i2--];
      } else {
        B[N/2-i] = A[i1++];
        B[N/2+i] = A[i1++];
      }
    }
    B[0] = A[i2];
    for (long i = 0; i < N-1; i++) {
      a2 += abs(B[i] - B[i+1]);
    }

  } else {
    //
    B[N/2] = A[i2--];
    for (long i = 1; i <= N/2; i++) {
      if (i % 2) {
        B[N/2-i] = A[i1++];
        B[N/2+i] = A[i1++];
      } else {
        B[N/2-i] = A[i2--];
        B[N/2+i] = A[i2--];
      }
    }
    for (long i = 0; i < N-1; i++) {
      a1 += abs(B[i] - B[i+1]);
    }

    //
    i1 = 0; i2 = N - 1;
    B[N/2] = A[i1++];
    for (long i = 1; i <= N/2; i++) {
      if (i % 2) {
        B[N/2-i] = A[i2--];
        B[N/2+i] = A[i2--];
      } else {
        B[N/2-i] = A[i1++];
        B[N/2+i] = A[i1++];
      }
    }
    for (long i = 0; i < N-1; i++) {
      a2 += abs(B[i] - B[i+1]);
    }
  }
  cout << max(a1, a2) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  string S;
  cin >> N >> S;
  
  int cnt = 0;
  vector<char> ans;
  ans.pb(S[0]);
  REP(i,S.size()){
    if(ans[cnt] != S[i]){
      ans.pb(S[i]);
      cnt++;
    }
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <sstream>

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int is_palindrome(string s){
  for(int i=0, j=s.length()-1;i<j;i++,j--){
    if(s[i] != s[j])return i;
  }
  return -1;
}

int main() { 
  string s;
  cin >> s;
  int ans = 0;
  while(true){
    int f = is_palindrome(s);
    if(f == -1)break;
    ans += 1;
    s[f] = s[s.length() - f - 1];
    // cerr << f << " " << s << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<long long>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int MOD=1e9+7;
int INF=1e9+7;
//
int N,P;
int A[50];
//
bool F;
//
int main(){
  cin>>N>>P;
  FOR(i,0,N){
    cin>>A[i];
    if(A[i]%2){
      F=true;
    }
  }
  long long ans=1;
  if(!F){
    if(P==0){
      FOR(i,0,N){
        ans*=2;
      }
      cout<<ans<<endl;
    }else{
      cout<<0<<endl;
    }
  }else{
    FOR(i,0,N){
      ans*=2;
    }
    ans/=2;
    cout<<ans<<endl;
  }
  return 0;
}


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

double ipow(double a, double b) {
	double x = pow(a, 1.0/b);
	double fx = pow(x, b) - a;
	double fxx = pow(x, b - 1) * b;
	return x - fx / fxx;
}

int main() {
    int x;
    cin >> x;
    int max = -1;
    
    for (int i = 2; i < 10; i++){
        int temp = pow((int)ipow(x, i), i);
        if (max < temp){
            max = temp;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<Vec<char>> = (0..h)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();

    let mut ans: u64 = 0;
    let mut q = std::collections::VecDeque::new();
    let mut visit = vec![vec![false; w]; h];
    for i in 0..h {
        for j in 0..w {
            if !visit[i][j] && s[i][j] == '#' {
                visit[i][j] = true;
                q.push_back((i, j));
                let mut kuro: u64 = 1;
                let mut shiro: u64 = 0;
                while let Some((y, x)) = q.pop_front() {
                    for (dy, dx) in vec![(-1, 0), (1, 0), (0, -1), (0, 1)] {
                        let ny = ((y as isize) + dy) as usize;
                        let nx = ((x as isize) + dx) as usize;
                        if nx < w && ny < h && !visit[ny][nx] {
                            if s[ny][nx] == '.' && s[y][x] == '#' {
                                shiro += 1;
                                q.push_back((ny, nx));
                                visit[ny][nx] = true;
                            } else if s[ny][nx] == '#' && s[y][x] == '.' {
                                kuro += 1;
                                q.push_back((ny, nx));
                                visit[ny][nx] = true;
                            }
                        }
                    }
                }
                ans += shiro * kuro;
            }
        }
    }
    println!("{}", ans);
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> p(n,0);
  int a,b;
  rep(i,m){
    cin >> a >> b;
    a--,b--;
    repp(i,a,b){
      p[i]++;
    }
  }
  int ans=n+1;
  rep(i,n) if(p[i]>0) ans+=2;
  cout << ans << endl;
  return 0;
}



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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)



using namespace std;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    string str;
cin >> str;
std::replace_if (str.begin(), str.end(), [](char ch){
                 if(','==ch) return true;
                 return false;
                 }, ' ');

    cout <<str<< endl;
    return 0;
}


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

const int64_t mod=1000000000+7;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i=0;i<n;++i)
	{
		cin >> a[i];
	}

	int64_t sum=0;
	int64_t right=0;
	for (int i=n-2;i>=0;--i)
	{
		right+=a[i+1];
		right%=mod;
		sum+=a[i]*right;
		sum%=mod;
	}
	cout << sum << endl;
}





Measured memory_bytes: 3980
// by syu
package main

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

var in = NewScanner(os.Stdin, 0)

func main() {
	n, k := in.Int(), in.Int()
	if n%k == 0 {
		Pln(0)
	} else {
		Pln(1)
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

//#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion

int solve(VI a){
    for(int j = 19; j > 0;){
        if ((1 << j) > a.size()){
            j--;
            continue;
        }
        VI b(a.size() - (1 << j) + 1);
        int x = 0;
        for(int i = 0; i < (1 << j); ++i){
            x ^= a[i];
        }
        for(int i = 0; i + (1 << j) < a.size(); ++i){
            b[i] = x;
            x ^= a[i];
            x ^= a[i + (1 << j)];
        }
        b.back() = x;
        a = move(b);
    }
    return a[0];
}

int32_t main() {
    make(int, n);
    make(string, s);
    VI a(n - 1);
    VI cnt(3);
    for (int i = 0; i + 1 < n; ++i) {
        int q = s[i] - '0';
        int w = s[i + 1] - '0';
        a[i] = abs(q - w);
        cnt[a[i]]++;
    }
    int d = cnt[1] == 0;
    for (auto &q : a) {
        if (q == 2) {
            q = d;
        }
    }
    int ans = solve(a);
    if (ans == 1 && d){
        ans *= 2;
    }
    cout << ans;
    return 0;
}

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

int cnt[2020];

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    for(int i=1; i<N; ++i) cnt[i] = N-i;
    for(int i=1; i<N; ++i){
        for(int j=i+1; j<=N; ++j){
            int dist = N;
            dist = min(dist, abs(X-i)+1+abs(j-Y));
            dist = min(dist, abs(Y-i)+1+abs(j-X));
            if(j-i > dist){ --cnt[j-i]; ++cnt[dist]; }
        }
    }
    for(int i=1; i<N; ++i) cout << cnt[i] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 998244353;
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i--)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define mem(x,n) memset(x,n,sizeof(x))
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     string s;
     cin>>s;
     ll len=s.length();
     if(s[len-1]=='s')
     cout<<s<<"es";
     else
     cout<<s<<"s";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
	long long n;
	long long a,b;
	cin>>n>>a>>b;
	long long ans=0;
	ans=n/(a+b)*a;
	if(n%(a+b)>=a)
		ans+=a;
	else
		ans+=n%(a+b);
	cout<<ans;
	return 0;
} 


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

using namespace std;
using ll = long long int;

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if (S[i] != S[S.size() - i - 1]){
            ans += 1;
        }
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"
#include <math.h>


using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

int main(void) {
	int n, k;
	cin >> n >> k;
	if (2 * k - 1 <= n) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<cctype>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long n,m;
    while(cin>>n>>m)
    {
        long long sum=0;
        if(n==1||m==1)
        {
            long long t=max(m,n);
            if(t==1)
            {
                sum=1;
            }
            else if(t==2)
            {
                sum=0;
            }
            else
            {
                sum=t-2;
            }
        }
        else if(n==2||m==2)
        {
            sum=0;
        }
        else
        {
            sum=(n-2)*(m-2);
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100000;

typedef long long ll;
int k;

vector<ll> ans;
queue<ll> q;
void bfs() {
	for(ll i = 1; i < 10; i++) q.push(i);
	while(q.size()) {
		ll t = q.front(); q.pop();
		ans.push_back(t);
		if((int)ans.size() >= N) break;
		
		ll now = t % 10;
		if(now - 1 >= 0) {
			ll t1 = t * 10 + now - 1;
			q.push(t1);
		}
		
		q.push(t * 10 + now);
		
		if(now + 1 < 10) {
			ll t1 = t * 10 + now + 1;
			q.push(t1);
		} 
	}
}

int main()
{
	scanf("%d", &k);
	bfs();
	sort(ans.begin(), ans.end());
	printf("%lld\n", ans[k - 1]);
	
	//for(int i = 1; i <= 100; i++) printf("%d\n", ans[i]);
	return 0; 
}

Measured memory_bytes: 2548
from operator import itemgetter
A = []

def main():
    accum = 0
    cost = 0
    N, M = map(int, input().split())
    for i in range(N):
        A.append(list(map(int, input().split())))
    B = sorted(A, key = itemgetter(0))
    while accum < M:
         eB = B.pop(0)
         if accum + eB[1] > M:
             cost += eB[0] * (M - accum)
             accum = M
         else:
             accum += eB[1]
             cost += eB[0] * eB[1]
    print(cost)

main()

Measured memory_bytes: 29740
n = int(input())
G = []
for i in range(n):
    a = []
    for j, c in enumerate(map(int, input())):
        if c == 1:
            a.append(j)
    G.append(a)

from collections import deque

def bfs(i):
    used = [-1]*n
    used[i] = 0
    que = deque()
    que.append(i)
    depth = 0
    while que:
        nxt = deque()
        while que:
            a = que.pop()
            for to in G[a]:
                if used[to] >= 0 and (used[to] != depth-1 and used[to] != depth+1):
                    return 0
                if used[to] < 0 :
                    nxt.append(to)
                    used[to] = depth+1
        que = nxt
        depth += 1
    for i in used:
        if i < 0:
            return 0
    return depth

ans = max(bfs(i) for i in range(n))
if ans == 0:
    ans = -1
print(ans)

Measured memory_bytes: 42608
import java.util.Scanner;

/**
 * 2018-04-08
 * https://beta.atcoder.jp/contests/abc079/tasks/abc079_a
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        Character c1 = s.charAt(0);
        Character c2 = s.charAt(1);
        Character c3 = s.charAt(2);
        Character c4 = s.charAt(3);

        String ans = null;

        if(c1==c2 && c1==c3 ){
            ans ="Yes";
        }else if(c4==c3 && c4==c2){
            ans ="Yes";
        }else{
            ans ="No";
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		long A = s.nextLong();
		double B = s.nextDouble();
		
		BigDecimal ret = BigDecimal.valueOf(B).multiply(BigDecimal.valueOf(A));
		
		System.out.println(ret.setScale(0, BigDecimal.ROUND_DOWN));
    }
}

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

using namespace std;

vector<int> M[10000];
vector<int> m[10000];
int mark[10000]={0};

int main(){
  int V;
  int E;
  int s,t;
  cin >> V >> E;
  for(int i=0;i<E;i++){
    cin >> s >> t;
    M[s].push_back(t);
    m[t].push_back(s);
  }

  int j;
  for(int i=0;i<V;i++){
    for(j=0;j<V;j++){
      if(m[j].size()==0&&mark[j]!=1){
        mark[j]=1;
        for(int k=0;k<M[j].size();k++){
          for(int l=0;l<m[M[j][k]].size();l++){
            if(m[M[j][k]][l]==j){
              m[M[j][k]].erase(m[M[j][k]].begin() + l);
            }
          }
        }
        break;
      }
    }
    if(j==V){
      cout << "1" <<endl;
      return 0;
    }
  }
  cout << "0" << endl;
  return 0;
}

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

int main() {
    int a, b, c, d;
    int l, r;

    cin >> a >> b >> c >> d;

    l = a + b;
    r = c + d;

    if (l > r) {
        cout << "Left" << endl;
    } 
    else if (l == r) {
        cout << "Balanced" << endl;   
    }
    else {
        cout << "Right" << endl;   
    }

}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;

    mat cnt(10, vec(10, 0));

    for (int i = 1; i <= N; i++) {
        string n = to_string(i);
        int a = n[0] - '0';
        int b = n[n.size()-1] - '0';
        cnt[a][b]++;
    }

    ll ans = 0;
    Rep (i, 10) {
        Rep (j, 10) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import collections,sys
d=collections.deque()
input()
for e in sys.stdin.readlines():
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.pop()
  else:d.popleft()
print(*d)


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

using namespace std;

using ll = long long;

const int maxN = 1e5 + 5, MOD = 1e9 + 7;

vector<vector<int>> eg(maxN);
vector<int> q;
vector<ll> dpw(maxN), dpb(maxN);
bool visited[maxN];

int main() {
    int n, x, y;
    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        cin >> x >> y;
        eg[x].push_back(y);
        eg[y].push_back(x);
    }
    q.push_back(1);
    int ci = 0, cn;
    while(q.size() != n) {
        cn = q[ci];
        //cout << "vertices ";
        for(int i = 0; i < eg[cn].size(); i++) {
            if(!visited[eg[cn][i]]) {
                q.push_back(eg[cn][i]);
                //cout << eg[cn][i] << ' ';
            }
        }
        visited[q[ci]] = true;
        ci++;
        //cout << endl << "size " << q.size() << endl;
    }
    //cout << "yyay" << endl;
    fill(visited, visited + n + 1, false);
    for(auto it = q.rbegin(); it != q.rend(); it++) {
        ll mw = 1, mb = 1;
        cn = *it;
        //cout << "visited is "; for(int i = 1; i <= n; i++) cout << visited[i] << ' '; cout << endl; 
        for(int i = 0; i < eg[cn].size(); i++) {
            //cout << eg[cn][i] << endl;
            if(visited[eg[cn][i]]) {
                mw = (mw * (dpw[eg[cn][i]] + dpb[eg[cn][i]]) % MOD) % MOD;
                mb = (mb * dpw[eg[cn][i]]) % MOD;
                //cout << dpw[eg[cn][i]] << ' ' << dpb[eg[cn][i]] << endl;
            }
        }
        dpw[cn] = mw;
        dpb[cn] = mb;
        visited[cn] = true;
        //cout << "current node " << cn << ' ' << dpw[cn] << ' ' << dpb[cn] << endl;
        //cout << "yay" << endl;
    }
    //for(int i = 1; i <= n; i++) cout << dpw[i] << ' ' << dpb[i] << endl;
    cout << (dpw[1] + dpb[1]) % MOD;
    return 0;
}


Measured memory_bytes: 11452
from sys import stdin, setrecursionlimit


def main():

    setrecursionlimit(2000001)

    current, q = [int(x) for x in stdin.readline().split()]

    tree = [[] for _ in range(current + 1)]
    for _ in range(current - 1):
        a, b = [int(x) for x in stdin.readline().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (current + 1)
    for _ in range(q):
        parent, x = [int(x) for x in stdin.readline().split()]
        cnt[parent] += x

    stack = []
    visited = [False] * (current + 1)

    stack.append((0, 1))

    while len(stack) > 0:
        parent, current = stack.pop()
        visited[current] = True
        cnt[current] += cnt[parent]
        for child in tree[current]:
            if not visited[child]:
                stack.append((current, child))

    print(*cnt[1:])


main()

Measured memory_bytes: 58264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(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 pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    int a,b,t;
    cin >> a >> b >> t;
    cout << (b*(t/a)) << endl;
    return 0;
}


Measured memory_bytes: 384
n_ks = gets.chomp
n_ks = n_ks.split(" ")
n = n_ks[0].to_i
k = n_ks[1].to_i
h = Array.new()
for i in 0..n-1
	h[i] = gets.chomp.to_i
end

h.sort!

min_dif = nil
for i in 0..n-k
	dif = h[k+i-1]-h[i]
	if min_dif == nil || dif <= min_dif
		min_dif = dif
	end
end

puts min_dif.to_s

Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint dp[200005];

int main() {
    int N;
    cin >> N;
    vector<P> robots(N);
    rep(i, N) cin >> robots[i].first >> robots[i].second;
    sort(robots.begin(), robots.end());
    vector<int> affect(N);
    dp[N] = 1;
    dp[N-1] = 2;
    set<P> cand;
    cand.emplace(robots[N-1].first, N-1);
    rep(i, N) affect[i] = i;
    for (int i = N-2; i >= 0; i--) {
        int temp = i;
        int pos = robots[i].first;
        int d = robots[i].second;
        while (sz(cand) && cand.begin()->first < pos + d) {
            temp = cand.begin()->second;
            cand.erase(cand.begin());
        }
        affect[i] = affect[temp];
        cand.emplace(pos, i);
        dp[i] = dp[i+1] + dp[affect[i]+1];
    }
    cout << dp[0] << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 11964
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <list>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define INFTY (1<<21)
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int main(){
  int N; cin >> N;
  int A[N+1][5];
  for (int i=0; i<N; i++){
    cin >> A[i][0] >> A[i][1] >> A[i][2];
  }
  bool ans = true;
  for (int i=0; i<N; i++){
    if ((A[i][0] >= A[i][1]+A[i][2])  && A[i][0] % 2 == (A[i][1]+A[i][2])%2){
      ans &= true; 
    } else {
      ans &= false;
    }
  }
  if (ans == false) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

signed main(){
	ll n,m; cin>>n>>m;
	vl vec(n+1);
	rep(i,0,n){
		cin>>vec[i];
		vec[i]-=m;
	}
	vvl dp(55,vl(20100));
	dp[0][10000]=1;
	rep(i,0,n){
		rep(j,-10000,10000){
			ll k=j+10000;
			dp[i+1][k]=dp[i][k];
			if(k-vec[i]>=0 && k-vec[i]<20100)dp[i+1][k]+=dp[i][k-vec[i]];
		}
	}
	cout<<dp[n][10000]-1<<endl;
	return 0;
}

Measured memory_bytes: 12164
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

	

int main(){
  ll n, m, d; cin >> n >> m >> d;
  if(d!=0) cout << fixed << setprecision(10) << (long double)(n-d)*2*(m-1)/(n*n) << endl;
  else cout << fixed << setprecision(10) << (long double)(n-d)*(m-1)/(n*n) << endl;
}

Measured memory_bytes: 3724
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let x: usize = read!();
    let m = f(x % 100);

    let ans = if m * 100 <= x { 1 } else { 0 };
    println!("{}", ans);
}

fn f(n: usize) -> usize {
    if n > 5 {
        f(n - 5) + 1
    } else {
        1
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct SuffixArray {
  int N, k;
  string S;
  vector<int> sa, rank, tmp;
  vector<int> lpc, rank_lpc;
  SuffixArray(string S) : S(S) {
    N = S.size();
    sa.resize(N+1), rank.resize(N+1), tmp.resize(N+1);
    construct_sa();
  }

  bool compare_sa(int i, int j) {
    if (rank[i] != rank[j]) {
      return rank[i] < rank[j];
    } else {
      int ri = i + k <= N ? rank[i + k] : -1;
      int rj = j + k <= N ? rank[j + k] : -1;
      return ri < rj;
    }
  }

  void construct_sa() {
    for (int i = 0; i <= N; i++) {
      sa[i] = i;
      rank[i] = i < N ? S[i] : -1;
    }

    for (k = 1; k <= N; k *= 2) {
      sort(sa.begin(), sa.end(), [&] (const int & i, const int & j) { return compare_sa(i, j); });

      tmp[sa[0]] = 0;
      for (int i = 1; i <= N; i++) {
        tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i]) ? 1 : 0);
      }
      for (int i = 0; i <= N; i++) rank[i] = tmp[i];
    }
  }

  bool contain(string T) {
    int left = 0, right = N;
    while (left - right > 1) {
      int mid = (left + right) / 2;
      (S.compare(sa[mid], T.length(), T) < 0 ? left : right) = mid;
    }
    return S.compare(sa[right], T.length(), T) == 0;
  }

  void construct_lpc() {
    lpc.resize(N), rank_lpc.resize(N+1);
    for (int i = 0; i <= N; i++) rank_lpc[sa[i]] = i;

    int h = 0;
    lpc[0] = 0;
    for (int i = 0; i < N; i++) {
      int j = sa[rank[i] - 1];

      if (h > 0) h--;
      for (; j + h < N and i + h < N; h++) {
        if (S[j + h] != S[i + h]) break;
      }

      lpc[rank[i] - 1] = h;
    }
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int K; cin >> K;
  string S; cin >> S;
  int N = S.size();
  SuffixArray sa(S);

  /*
  cout << N << endl;

  REP(i, sa.sa.size()) {
    cout << sa.sa[i] << ' ' << S.substr(sa.sa[i]) << endl;
  }
  */

  vector<int> cand;
  int L = ((int)S.size() + K) / (K + 1);
  //cout << L << endl;
  REP(i, sa.sa.size()) {
    if (sa.sa[i] + L <= N) cand.push_back(sa.sa[i]);
  }

  /*
  cout << endl;
  for (int i : cand) cout << S.substr(i) << endl;
  cout << endl;
  */

  function<bool (int)> check = [&](int mid) {
    int cnt = 0, cur = 0, prev = 0;
    while (cur < N) {
      if (sa.rank[cur] <= sa.rank[cand[mid]]) {
        cur += L;
        //cout << 0 << ' ' << cur << endl;
      } else {
        cur += L - 1;
        //cout << 1 << ' ' << cur << endl;
      }
      cnt++;
      if (cnt - 1 > K or prev == cur) return false;
      prev = cur;
    }
    return cnt - 1 <= K;
  };

  int left = -1, right = cand.size() - 1;
  while (left + 1 < right) {
    int mid = (left + right) / 2;
    (check(mid) ? right : left) = mid;
  }

  cout << S.substr(cand[right], L) << endl;

  return 0;
}


Measured memory_bytes: 2252
#include <iostream>
#include <set>

int main() {

  int A1;
  int A2;
  int A3;

  std::multiset<int> mst;
  std::cin >> A1 >> A2 >> A3;
  mst.insert(A1);
  mst.insert(A2);
  mst.insert(A3);

  int tmp = 0;
  int sum = 0;
  for (int a : mst) {
    if (tmp == 0) {
      tmp = a;
      continue;
    }
    sum += a - tmp;
    tmp = a;
  }
  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 256
let input_int_array n =
  Array.init n (fun _ -> Scanf.scanf "%d " (fun v -> v))

let () =
  let n = read_int ()
  in let ar = input_int_array n
  in let min_k = Array.fold_left (fun u v ->
    let rec f0 p =
      if p mod 2 = 1 then 0 else (1 + f0 (p/2))
    in let k = f0 v
    in min u k
  ) max_int ar
  in min_k |> string_of_int |> print_endline

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
ll next(ll i)
{
    ll div = 1;
    while (i / div != 0)
    {
        int d = (i / div) % 10;
        while (d != 3 and d != 5 and d != 7)
        {
            i += div;
            d = (i / div) % 10;
        }
        div *= 10;
    }
    return i;
}
bool is753(int n)
{
    bool in7 = false, in5 = false, in3 = false;
    do
    {
        if (n % 10 == 7)
            in7 = true;
        else if (n % 10 == 5)
            in5 = true;
        else if (n % 10 == 3)
            in3 = true;
        else
            return false;
        n /= 10;
    } while (n != 0);
    return in7 && in5 && in3;
}
int main()
{
    ll n, ans = 0;
    cin >> n;
    if (n < 357)
    {
        cout << 0 << endl;
        return 0;
    }
    for (ll i = 10; i <= n;)
    {

        if (is753(i))
        {
            ans++;
            // cout << i << endl;
            i++;
        }
        else
            i++;
        i = next(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
const DIV:usize = 1000000007;
fn main(){
    input!{
        a:i64,
        b:i64,
        c:i64,
        x:i64,
        y:i64,
    }
    let mut ans = 1e10 as i64;
    for j in 0..1000001 {
        ans = min(a*max(0,x-j)+ b *max(0,y-j)+ c*2*j, ans);
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define ll long long
#define maxn 0x3f3f3f3f
using namespace std;
int f[101000];
int w[1000],v[1000];
int main()
{
	int m,n;
	cin>>m>>n;
	for(int i=1;i<101000;i++) f[i] = maxn;
	for(int i=1;i<=m;i++)
    {
        cin>>v[i]>>w[i];
    }
    for(int i=1;i<=m;i++)
    for(int j=100010;j>=w[i];j--)
    {
    	f[j] = min(f[j],f[j-w[i]]+v[i]);
	}
	int sum=0;	
	for(int i=1;i<=100010;i++)
	{
		if(f[i]<=n)
		sum=max(sum,i);
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S, T;
    cin >> S >> T;

    bool flg = false;
    rep(i, S.size()) {
        if(S == T) {
            flg = true;
            break;
        }
        string sub = S.substr(0, S.size() - 1);
        S = S.at(S.size() - 1) + sub;
    }

    cout << (flg ? "Yes" : "No") << endl;
}

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

using namespace std;

inline int highest(int num)
{
  int c = num;
  while (c >= 10) {
    c /= 10;
  }
  
  return c;
}

int main()
{
  int N;
  cin >> N;
  int db[100];
  for (int i = 0; i < 100; i++) {
    db[i] = 0;
  }

  for (int i = 1; i < N+1; i++) {
    int high = highest(i);
    int low = i % 10;
    db[high*10 + low]++;
  }
  
  int matched = 0;
  for (int i = 1; i < N+1; ++i) {
    int high = highest(i);
    int low = i % 10;
    matched += db[low*10 + high];
  }
  
  cout << matched << endl;
  
  return 0;
}

Measured memory_bytes: 256
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc131/tasks/abc131_e
# E - Friendships
"""

"""

N = gi()
K = gi()


def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

    print(M)
    for v in range(2, N + 1):
        print(1, v)

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u)


run()


Measured memory_bytes: 21536
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main(void){
	vector<int> input(5);
	int i=0,j=0,k=0;
	bool is_none  = true;
	for(i=0;i<5;i++){
		cin >> input[i];
	}
	cin >> k;
	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			int dif = input[i]-input[j];
		       	if(abs(dif)>k)is_none=false;
		}
	}
	if(is_none){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
	return 0;
}


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

int main()
{
  int n; cin >> n;
  
  int a[n], b[n];
  for (int i=0; i<n; i++)	b[i] =0;
  
  for (int i=1; i<n; i++)
  {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (int i=0; i<n; i++)
  {  
  cout << b[i] << endl;
  }
}


Measured memory_bytes: 5196
n, m, q = map(int, input().split())
judge = []
for i in range(q):
    judge.append(tuple(map(int, input().split())))

import itertools
ans = 0

for a in itertools.combinations_with_replacement(range(1, m+1), n):
    score = 0
    for j in judge:
        if a[j[1]-1] - a[j[0]-1] == j[2]:
            score += j[3]
    ans = max(ans,score)

print(ans)

Measured memory_bytes: 81384
#include <iostream>
#include <vector>
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++) {
				if ((500 * i + 100 * j + 50 * k)==x) { ans++; }
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
long long n,a[7],i,j,k,ans,max1;
int main(){	
	cin>>n;
	for(i=1;i<=6;i++)
		cin>>a[i];
	if(a[1]<=a[4]&&a[2]>=a[5]&&a[3]>=a[6]){
		n=n/a[1]*a[4]+n%a[1];
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[5]+j%a[6]+i/a[5]*a[2]+j/a[6]*a[3]);
		}
	}
	else if(a[1]>=a[4]&&a[2]<=a[5]&&a[3]>=a[6]){
		n=n/a[2]*a[5]+n%a[2];
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[4]+j%a[6]+i/a[4]*a[1]+j/a[6]*a[3]);
		}
	}
	else if(a[1]>=a[4]&&a[2]>=a[5]&&a[3]<=a[6]){
		n=n/a[3]*a[6]+n%a[3];
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[4]+j%a[5]+i/a[4]*a[1]+j/a[5]*a[2]);
		}
	}
	else if(a[1]<=a[4]&&a[2]<=a[5]&&a[3]<=a[6]||a[1]>=a[4]&&a[2]>=a[5]&&a[3]>=a[6]){
		for(i=0;i<=n;i++)
			for(j=0;i+j<=n;j++){
				k=n-i-j;
				ans=max(i/a[1]*a[4]+i%a[1],i/a[4]*a[1]+i%a[4])+
					max(j/a[2]*a[5]+j%a[2],j/a[5]*a[2]+j%a[5])+
					max(k/a[3]*a[6]+k%a[3],k/a[6]*a[3]+k%a[6]);
				max1=max(max1,ans);
			}
	}
	else if(a[1]>=a[4]){//a[2]<=a[5]
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[2]+j%a[3]+i/a[2]*a[5]+j/a[3]*a[6]);
		}
		max1=max1/a[4]*a[1]+max1%a[4];
	}
	else if(a[2]>=a[5]){
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[1]+j%a[3]+i/a[1]*a[4]+j/a[3]*a[6]);
		}
		max1=max1/a[5]*a[2]+max1%a[5];
	}
	else{
		for(i=0;i<=n;i++){
			j=n-i;
			max1=max(max1,i%a[1]+j%a[2]+i/a[1]*a[4]+j/a[2]*a[5]);
		}
		max1=max1/a[6]*a[3]+max1%a[6];
	}
	cout<<max1<<endl;
    return 0;
}

Measured memory_bytes: 384
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let N =Number(xs[0]);
   let ans = 0;
   for(let i=1; i<=N; i++){
   	 ans = Math.pow(2,i);  
     if(N==1){
     ans = 1;
     break;
     }else if(ans>N){
        ans =Math.pow(2,i-1)
        break;
     }
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 11468
H, W, K = list(map(int, input().split()))
c = []
for i in range(H):
    c.append(list(input()))

ans = 0
for i in range(2**H):
    for j in range(2**W):
        count = 0
        for k in range(H):
            for l in range(W):
                if (i>>k) & 1:
                    if (j>>l) & 1:
                        if c[k][l] == "#":
                           count += 1
        if count == K:
            ans += 1

print(ans)


Measured memory_bytes: 9080
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	string s, t;  cin >> s >> t;
	cout << t << s << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        int area = a * b;
        int longth = (a + b) * 2;

        System.out.println(area+" "+longth);
        sc.close();

    }

}


Measured memory_bytes: 26276
n,d=map(int,input().split())

x=[]
for i in range(n):
    x+=[list(map(int,input().split()))]

cnt=0

for i in range(n):
    for j in range(i+1,n):
        res=0
        for xa,xb in zip(x[i],x[j]):
            res+=abs(xa-xb)**2

        tmp=int(res**0.5)
        if int(tmp**2)==res:
            cnt+=1

print(cnt)

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

int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll cnt = x/d;
    if(cnt >= k) {
        x -= d*k;
        cout << x << endl;
        return 0;
    }
    k -= cnt;
    ll now = x%d;
    ll next = now-d;
    if(k%2==0) cout << now << endl;
    else cout << abs(next) << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,k,s;
    cin>>n>>k>>s;
    int ans=0;
    rep(i,n){
        ans++;
        if(ans<=k){
            cout<<s<<" ";
        }
        else{
            if(s==1||s==2){
                cout<<s+1<<" ";
            }
            else{
                cout<<s-1<<" ";
            }
        }
    }
    cout<<endl;
}


Measured memory_bytes: 1280