akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    ans = []
    for _ in range(n):
        a_num = int(input())
        t = []
        for _ in range(a_num):
            t.append(tuple(map(int, input().split())))
        t = tuple(t)
        ans.append(t)

    r = 0
    for bit in range(1 << n):
        honest = []
        for i1 in range(n):
            mask = 1<<i1
            if bit & mask:
                honest.append(i1)
        flag = 1       
        for eh in honest:
            say = ans[eh]
            for esay in say:
                if esay[0] - 1 in honest:
                    if esay[1] == 0:
                        flag = 0
                else:
                    if esay[1]:
                        flag = 0
        if flag:
            r = max(r, len(honest))
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

vector<int> tu[100005];
vector<LL> cost[100005];
int vis[100005];
LL dis[100005];
int n;
void spfa(int x)
{
	LL c;
	int i,kk,k;
	queue<int> qua;
	memset(vis,0,sizeof(vis));
	for(i=1;i<=n;i++) {
		dis[i]=1LL<<60;
	}
	dis[x]=0;
	qua.push(x);
	vis[x]=1;
	while(!qua.empty())
	{
		kk=qua.front();
		qua.pop();
		for(i=0;i<tu[kk].size();i++)
		{
			k=tu[kk][i];
			c=cost[kk][i];
			if(dis[kk]+c<dis[k])
			{
				dis[k]=dis[kk]+c;
				if(vis[k]==0)
				{
					qua.push(k);
					vis[k]=1;
				}
			}
		}
		vis[kk]=0;
	}
}
int main()
{
	cin>>n;
	int k,q,x,y,i;
	LL c;
	for(i=1;i<n;i++)
	{
		cin>>x>>y>>c;
		tu[x].push_back(y);
		cost[x].push_back(c);
		tu[y].push_back(x);
		cost[y].push_back(c);
	}
	cin>>q>>k;
	spfa(k);
	while(q--)
	{
		cin>>x>>y;
		cout<<dis[x]+dis[y]<<endl;
	}
}

Measured memory_bytes: 14960
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	D := sc.nextInt()
	if D == 25 {
		fmt.Println("Christmas")
	} else if D == 24 {
		fmt.Println("Christmas Eve")
	} else if D == 23 {
		fmt.Println("Christmas Eve Eve")
	} else {
		fmt.Println("Christmas Eve Eve Eve")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int N, Q;
  cin >> N >> Q;
  vector<pair<pair<int, int>, int>> v;
  for (int i = 0; i < N; i++) {
    int s, t, x;
    cin >> s >> t >> x;
    v.push_back({{s - x, 1}, x});
    v.push_back({{t - x, 0}, x});
  }
  for (int i = 0; i < Q; i++) {
    int d;
    cin >> d;
    v.push_back({{d, 2}, 0});
  }

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

  set<int> st;
  for (auto x : v) {
    int id = x.first.second;
    int pl = x.second;

    if (id == 1) {
      st.insert(pl);

    } else if (id == 0) {
      st.erase(pl);

    } else {
      if (st.size() == 0) {
        cout << -1 << endl;
      } else {
        cout << *st.begin() << endl;
      }
    }
  }

  return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9



int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int ans = min(B, D) - max(A, C);
  if(ans < 0){
    cout << 0 << endl;
  }
  else{
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
a, b, t = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

ans = 0
A = a

while A <= t+0.5:
    ans += b
    A += a
    
print(ans)

Measured memory_bytes: 9112
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class ECrestedIbisVsMonster {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int H, N;
	    in >> H >> N;
	    vector<int> dp(H + 1, INF);
	    dp[0] = 0;
	    REP(i, N) {
	        int a, b;
	        in >> a >> b;
	        for (int j = 0; j <= H; ++j) {
                dp[min(j+a, H)] = min(dp[min(j+a, H)], dp[j] + b);
	        }
	    }
	    out << dp[H] << '\n';
	}
};


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

	ECrestedIbisVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;

signed main()
{
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; ++i) {
        if(i % 15 == 0) { ans -= 200; }
        ans += 800;
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

#define ll long long




void solve() {

	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == s[i - 1]) {
			cout << "Bad\n";
			return;
		}
	}
	cout << "Good\n";

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int main(){
	int n;
	std::cin>>n;
	n%=10;
	if(n==3)puts("bon");
	else if(n==0||n==1||n==6||n==8)puts("pon");
	else puts("hon");
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	int p = -1, len = 0, ans = 0;
	rep(i, n){
		int a; cin >> a;
		if(a != p){
			ans += len / 2;
			len = 1;
			p = a;
		}
		else len++;
	}
	ans += len / 2;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P       = pair<int, int>;

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

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string s;
    cin >> s;
    int len = s.size();
    string a, b;
    rep(i, 0, len) {
        if (i % 2 == 0) {
            a += '0', b += '1';
        } else {
            a += '1', b += '0';
        }
    }

    int ans = 0, ans2 = 0;
    rep(i, 0, len) {
        if (s[i] != a[i]) {
            ans++;
        }
        if (s[i] != b[i]) {
            ans2++;
        }
    }
    cout << min(ans, ans2) << endl;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    vll nums(n);
    FOR(i, n) cin >> nums[i];
    sort(nums.begin(), nums.end());
    ll mid = 0;
    FORE(i, nums) mid += i;
    mid /= nums.size();
    ll m = n * 100000;
    FOR(i, 101)
    {
        ll dis = 0;
        FORE(j, nums)
        {
            dis += (i - j) * (i - j);
        }
        m = min(m, dis);
    }
    cout << m << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    cin >> N;
    long long ans = 0;
    int maxnum = 0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i == 0){
            maxnum = a;
            continue;
        }
        if(a < maxnum){
            ans += maxnum - a;
        }
        else{
            maxnum = a;
        }
    }
    cout << ans << endl;
    
}


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

#define n_max  100
#define w_max 10000
int n, w;
int value[n_max+1];
int weight[n_max+1];

int dp[n_max+1][w_max+1];

void knap(){
    for(int i = 1; i <= n; i++){
        dp[i][0] = 0;
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= w; j++){
            if(weight[i] <= j){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
}

int main(){
    cin >> n >> w;

    for(int i = 1; i <= n; i++){
        cin >> value[i] >> weight[i];
    }

    knap();

    printf("%d\n", dp[n][w]);

    return 0;


}


Measured memory_bytes: 7120
n = gets.chop.to_i

k = 1
flag = false
loop do
  k += 1
  num = k * (k-1) / 2
  if num == n
    flag = true
    break
  end
  break if num > n
end

if flag
  ans = Array.new(k, nil).map{Array.new(0)}
  (1..k).to_a.combination(2).to_a.each_with_index do |v, i|
    v.each do |j|
      ans[j-1] << i + 1
    end
  end
  puts 'Yes'
  puts k
  k.times do |i|
    puts "#{ans[i].size} #{ans[i].join(' ')}"
  end
else
  puts 'No'
end

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,sum=0;
  cin >> n;
  
  string sn = to_string(n);
  int length = sn.size();
  for(int i = 0; i<length; i++){
    sum += sn[i] - '0';
  }
  if(n%sum){
    cout << "No";
  }else{
    cout << "Yes";
  }
 

}

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

int main() {
  vector<vector<int>> bcard_num(3,vector<int>(3));
  vector<vector<int>> bcard_c(3,vector<int>(3));
  int N;
  bool bingo = false;
  //カード作成
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> bcard_num.at(i).at(j);
    }
  }
  
  //抽選
  
  cin >> N;
  
  vector<int> num(N);

  for (int k = 0; k < N; k++) {
    cin >> num.at(k);
  }
  //判定用
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < N; k++){
        if (num.at(k) == bcard_num.at(i).at(j)){
          bcard_c.at(i).at(j)=1;
       
        }
      }
     
    }
  }
  //判定処理
  for (int i = 0; i < 3; i++) {
    if(bcard_c.at(i).at(0) && bcard_c.at(i).at(1) && bcard_c.at(i).at(2)){
      bingo=true;
    }
  }
  for (int j = 0; j < 3; j++) {
    if(bcard_c.at(0).at(j) && bcard_c.at(1).at(j) && bcard_c.at(2).at(j)){
      bingo=true;
    }
  }
  //斜め
  if (bcard_c.at(1).at(1)){
    if (bcard_c.at(0).at(0) && bcard_c.at(2).at(2)){
      bingo=true;
    }
    if (bcard_c.at(0).at(2) && bcard_c.at(2).at(0)){
      bingo=true;
    }
  }
 //出力
  if (bingo == true){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> a(N), b(M);
  rep(i, N) { cin >> a[i]; }
  rep(i, M) { cin >> b[i]; }

  irep(i, N - M) irep(j, N - M) {
    bool c = true;

    rep(k, M) rep(l, M) { c = c && (a[i + k][j + l] == b[k][l]); }

    if (c) {
      cout << "Yes\n";
      return 0;
    }
  }

  cout << "No\n";

  return 0;
}

Measured memory_bytes: 256
# coding: utf-8

def getG(N, M):
    G=[list() for i in range(N)]
    for i in range(M):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a].append(b)
        G[b].append(a)

    return G

def solve(G, N):
    ans = 0
    index = -1

    for i in range(1, N):
        for p in G[i]:
            if index < p < i:
                ans += 1
                index = i - 1
    return ans

if __name__ == "__main__":
    N, M = map(int, input().split())
    G = getG(N, M)
    print(solve(G, N))


Measured memory_bytes: 21424
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;
    int N = S.size();

    bool ok = true;
    if (S[0] != 'A') ok = false;

    int cnt = 0;
    FOR(i,2,N-1) {
        if (S[i] == 'C') cnt++;
    }
    if (cnt != 1) ok = false;

    cnt = 0;
    REP(i,N) {        
        if ('A' <= S[i] && S[i] <= 'Z') cnt++;
    }
    if (cnt != 2) ok = false;

    string ans = ok ? "AC" : "WA";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 1e2 + 5, INF = 1e15, MOD = 1e9 + 7, max_V = 1e5 + 50;

ll N, wts[max_N], vals[max_N], W;
ll DP[max_N][max_V];

int main()
{
    cin >> N >> W;
    for (int i = 1; i <= N; ++i)
        cin >> wts[i] >> vals[i];
    for (int i = 0; i < max_N; ++i)
        fill(DP[i], DP[i] + max_V, INF);
    for (int i = 0; i < max_N; ++i)
        DP[i][0] = 0;
    for (int i = 1; i <= N; ++i)
    {
        for (int v = 1; v < max_V; ++v)
        {
            DP[i][v] = DP[i - 1][v];
            if (vals[i] <= v)
                DP[i][v] = min(wts[i] + DP[i - 1][v - vals[i]], DP[i][v]);
        }
    }
    for ( int v = max_V - 1; v >= 0; --v)
    {
        if(DP[N][v] <= W) 
        {
            cout << v << "\n";
            return 0;
        }
    }
    cout << 0 << "\n";
    return 0;
}

Measured memory_bytes: 85668
D, G = map(int, input().split())
PC = [0] + [tuple(map(int, input().split())) for _ in range(D)]
SHORT_OF_SCORE = 10**9


def solve(p, g):
    if p == 0:
        return SHORT_OF_SCORE

    # 問題pを解く場合
    case_solve_p = min(g//(p*100), PC[p][0])
    reward = 100 * p * case_solve_p + \
        (PC[p][1] if case_solve_p == PC[p][0] else 0)

    if reward < g:
        case_solve_p += solve(p-1, g-reward)

    # 問題pを解かない場合
    case_not_solve_p = solve(p-1, g)
    return min(case_solve_p, solve(p-1, g))


print(solve(D, G))


Measured memory_bytes: 3064
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] count = new int[m];
        int[][] a = new int[n][m];

        int[] k = new int[n];
        for (int i = 0; i < n; i++) {
            k[i] = sc.nextInt();
            for (int j = 0; j < k[i]; j++) {
                a[i][j] = sc.nextInt() - 1;
                count[a[i][j]]++;
            }
        }

        int like = 0;
        for (int i = 0; i < m; i++) {
            if (count[i] == n) {
                like++;
            }
        }
        System.out.println(like);
    }

}

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


int main(){


    long long n, m, a, b, i, j;

    long long k = 0;

    long long c = 0;

    vector< pair<long long, long long> > p;

    priority_queue<long long>  q;


    cin >> n >> m;


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> a >> b;

         p.push_back( make_pair( a, -b ) );    
                  
         }


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

    for( i = 1 ; i <= m ; i = i + 1 ){

         for( j = c ; j < n ; j = j + 1 ){

              if( i >= p.at(j).first ){

                  q.push( -p.at(j).second );

                  c = j + 1;

                  }

              else break;

              }

         if( !q.empty() ){

             k += q.top();

             q.pop();

             }

         }


    cout << k << endl;

    
    return 0;


    }

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;


ll A[200005];

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

    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll ans = 0;
    ll mx = 0;
    REP(i, N) {
        mx = std::max(mx, A[i]);
        ans += std::max(0LL, mx - A[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5172
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	S := next()
	N := len(S)
	if S == reverse(S) {
		if S[:(N-1)/2] == reverse(S[:(N-1)/2]) {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
  int a,b;
  cin >> a >> b;


 string ab = "";
    rep(i, b) ab += char('0' + a);

    string ba = "";
    rep(i, a) ba += char('0' + b);

    string ans = min(ab, ba);
    cout << ans << endl;
 
 }


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x == 25){
            System.out.println("Christmas");
        }else if(x==24){
            System.out.println("Christmas Eve");
        }else if(x==23){
            System.out.println("Christmas Eve Eve");
        }else{
            System.out.println("Christmas Eve Eve Eve");
        }
    }
}


Measured memory_bytes: 21716
from collections import deque
n, m = map(int, input().split())
edge = [[] for _ in range(n)]
d, check = [0]*n, [0]*n
check[0] = 1
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
que = deque([0])
count = 1
while que:
    count += 1
    for i in range(len(que)):
        to = que.popleft()
        for j in range(len(edge[to])):
            if check[edge[to][j]]: continue
            check[edge[to][j]] = 1
            d[edge[to][j]] = to+1
            que.append(edge[to][j])

print("Yes")
for i in range(1, n):
    print(d[i])

Measured memory_bytes: 37704
while 1:
    n = input()
    if n==0: break
    r = {}; p = "";
    for i in xrange(n):
        a,b=raw_input().split()
        r[a]=b
    m = input()
    for i in xrange(m):
        s = raw_input()[0]
        p += r.get(s,s)
    print p

Measured memory_bytes: 4304
#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int N;

typedef pair<int,char> T;

vector<T> input;

int eval(int s){
    if (isdigit(input[s].second)) return input[s].second-'0';

    char op=input[s].second;

    int init;
    if (op=='+'){
        init=0;
        for(int i=s+1;i<input.size();i++){
            // printf("init=%d\n",init);
            if (input[i].first<=input[s].first) break;
            if (input[i].first==input[s].first+1) init+=eval(i); 
        }
    }else{
        init=1;
        for(int i=s+1;i<input.size();i++){
            // printf("init=%d\n",init);
            if (input[i].first<=input[s].first) break;
            if (input[i].first==input[s].first+1) init*=eval(i); 
        }
    }

    return init;
}

int main(){

    while(true){
        cin>>N;
        if (!N) break;
        string buf;
        input.clear();
        for(int i=0;i<N;i++) {
            cin>>buf;
            int level=buf.size()-1;
            char v=buf[level];
            input.push_back(T(level,v));
        }

        // for(auto i:input) printf("%d %c\n",i.first,i.second);

        printf("%d\n",eval(0));
    }


    return 0;
}


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int n, k, d;
	cin >> n >> k;
	int snukes[n+12];
	mset(snukes, 0);
	int ans = n;
	while (k--) {
		cin >> d;
		while (d--) {
			int a; cin >> a;
			if (!snukes[a]) {
				ans--;
				snukes[a] = 1; 
			}
		}
	}
	cout << ans << ende;
  return 0;
}


Measured memory_bytes: 3660
N = int(input())

a = list(map(int, input().split()))

b = []
c = []

for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

for x in abc:
    count[x] += 1

print(max(count))


Measured memory_bytes: 20068
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append(sorted([i, lis[-j]]))
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append([i, lis[-j]])
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

Measured memory_bytes: 44764
n = int(input())
A=[]
for x in input().split():
    A.append(int(x))

B=[]
for x in input().split():
    B.append(int(x))

B.append(int(0))    

TOT = sum ( A )

for i in range (n) :
    KILL = min ( A[i], B[i] )
    A [i] = A [i] - KILL
    A [i+1] = A[i+1] - min (A[i+1], B[i] - KILL)
    
print ( TOT - sum ( A ) )

Measured memory_bytes: 19372
n = int(input())
s = input()

sharp_list = [0 for i in range(n)]
dot_list = [0 for i in range(n)]
for i in range(n):
    if s[i] == '#':
        sharp_list[i] = sharp_list[i-1] + 1
    else:
        sharp_list[i] = sharp_list[i-1]
sharp_list = [0] + sharp_list
for i in range(n-1,-1,-1):
    if s[i] == '.':
        dot_list[i] = dot_list[(i+1)%n] + 1
    else:
        dot_list[i] = dot_list[(i+1)%n]
dot_list += [0]
ans = 10**9
for i in range(n+1):
    ans = min(sharp_list[i]+dot_list[i],ans)
print(ans)

Measured memory_bytes: 56188
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  vector<int> v(40000);
  REP(i,200){
    for(int j=i; j<200; ++j){
      if(i*i+j*j>=40000)break;
      for(int k=j; k<200; ++k){
        if(i*i+j*j+k*k>=40000)break;
        for(int l=k; l<200; ++l){
          if(i*i+j*j+k*k+l*l>=40000)break;
          ++v[i*i+j*j+k*k+l*l];
        }
      }
    }
  }
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    cout<<v[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <climits>

using namespace std;

int main() {
    int N;  cin >> N;
    int ans = INT_MAX;
    for (int t = 0; t <= N; t++) {
        int t_ = t;
        int s = N-t;
        int cnt = 0;
        
        while (t_ > 0) {
            cnt += t_%6;
            t_ /= 6;
        }
        while (s > 0) {
            cnt += s%9;
            s /= 9;
        }
        ans = min(cnt, ans);
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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 a, b, c, d;
int main(void) {
    cin >> a >> b >> c >> d;
    if (a + b > c + d) cout << "Left" << endl;
    else if (a + b == c + d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n, t, check, checkc, cnt, flag;
    cin >> n >> t;
    vector<int> c (n);
    vector<int> tc (n);

    cnt = 0;
    flag = 0;
    check = t;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> tc[i];
        if(tc[i] <= t){
            flag = 1;

            if(cnt == 0){
                checkc = c[i];
                check = tc[i];
                cnt = cnt + 1;
            }else if(cnt == 1){
                if(c[i] <= checkc){
                    check = tc[i];
                    checkc = c[i];
                }

            }
        }
    }
    if(flag == 0){
        cout << "TLE" << endl;
    }else{
        cout << checkc << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,dp[21][1<<21];
bool b[25][25];
const ll mod=1e9+7;
ll best(ll d,ll mask)
{
    if(d==n)return 1;
    if(dp[d][mask]!=-1)
    return dp[d][mask];
    dp[d][mask]++;
    for(ll i=0;i<n;i++)
    if(b[d][i]&&((1<<i)&mask)==0)
    dp[d][mask]=(dp[d][mask]+best(d+1,mask|(1<<i)))%mod;
    return dp[d][mask];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(ll i=0;i<n;i++)
for(ll j=0;j<n;j++)
cin>>b[i][j];
memset(dp,-1,sizeof dp);
cout<<best(0,0);
return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, d;
    ll x[200005], y[200005];
    cin >> n >> d;
    for(ll i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }

    ll cnt = 0;
    for(ll i = 0; i < n; i++) {
        double x2 = x[i] * x[i];
        double y2 = y[i] * y[i];
        double dist = sqrt(x2 + y2);
        if(dist <= d) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 6740
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

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

#define MOD ((ll)1000000007)

int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> p(M);
	for (size_t i = 0; i < M; i++)
	{
		int a, b;
		cin >> a;
		cin >> b;
		p[i].first = a;
		p[i].second = b;
	}

	sort(p.begin(), p.end(), [](const pair<int, int> &lhs, const pair<int, int> &rhs) {
		return lhs.second < rhs.second;
	});

	int ans = 0;
	int end = 0;
	for (size_t i = 0; i < M; i++)
	{
		if (p[i].first >= end)
		{
			end = p[i].second;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll K, A, B; cin >> K >> A >> B;
    ll cur = 1;
    ll mon = 0;
    while (K > 0) {
        if (cur < A && (K > A - cur)) {
            K -= A - cur;
            cur = A;
            continue;
        }
        if (cur >= A && B - A > 2 && K >= 2) {
            cur += (B - A);
            K -= 2;
            continue;
        }
        cur += K;
        K = 0;
    }
    cout << cur << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>

#define NMAX 8

using namespace std;

vector<vector<int>> a(NMAX);

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;

		a[x].emplace_back(y);
		a[y].emplace_back(x);
	}

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

	int ans = 0;
	do {
		if (b[0] != 0) {
			break;
		}

		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			if (find(a[b[i]].begin(), a[b[i]].end(), b[i + 1]) == a[b[i]].end()) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans++;
		}
	} while (next_permutation(b.begin(), b.end()));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vi ans(N, 0);
	rep(i, N - 1) {
		int Atmp;
		cin >> Atmp;
		Atmp--;
		ans[Atmp]++;
	}
	rep(i, N)
	cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4052
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] line = Console.ReadLine().Split(' ');
        int N = int.Parse(line[0]);
        int K = int.Parse(line[1]);
        char[] input = Console.ReadLine().ToArray();
        List<int> list = new List<int>();
        int now = 1;
        int ct = 0;
        list.Add(0);
        int ans = 0;
        for(int i = 0; i < N; i++)
        {
            if (now == 1 && input[i] == '0')
            {
                now = 0;
                if (ct - K >= 0) { ans = Math.Max(ans, i - list[ct - K]); }
            }
            else if (now == 0 && input[i] == '1')
            {
                now = 1;
                list.Add(i);
                ct++;
            }
        }
        if (now == 1)
        {
            if ((ct - K) >= 0) { ans=Math.Max(ans,N-1-list[ct-K]+1); }
            else { ans = N; }
        }
        else if ((ct - K + 1) >= 0)
        {
            ans = Math.Max(ans, N - 1 - list[ct - K+1] + 1);
        }
        else
        {
            ans = N;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int a[10004][105][2];
string s;
int k, d;
int mod = 1e9 + 7;
int dp(int pos, int m, int f)
{
	if (pos == s.size()) {
		if (m == 0)
			return 1;
		return 0;
	}
	if (a[pos][m][f] != -1)
		return a[pos][m][f];
	if (!f)
	{
		a[pos][m][f] = 0;
		for (int i = 0; i <= 9; ++i)
			a[pos][m][f] = (a[pos][m][f] + (dp(pos + 1, ((m - i) % d + d) % d, f))) % mod;
	}
	else
	{
		a[pos][m][f] = 0;
		for (int i = 0; i < (s[pos] - '0'); ++i)
			a[pos][m][f] = (a[pos][m][f] + dp(pos + 1, ((m - i) % d + d) % d, 0)) % mod;
		a[pos][m][f] = (a[pos][m][f] + dp(pos + 1, ((m - (s[pos] - '0')) % d + d) % d, 1)) % mod;
	}
	return a[pos][m][f];
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	memset(a, -1, sizeof(a));
	cin >> s;
	cin >> d;
	cout << ((dp(0, 0, 1) - 1) % mod + mod) % mod;
}

Measured memory_bytes: 17408
X,N=map(int,input().split())
P=list(map(int,input().split()))
if X not in P:
    print(X)
    exit()
d=1
while True:
    a=X-d
    b=X+d
    if a not in P:
        print(a)
        break
    if b not in P:
        print(b)
        break
    d+=1

Measured memory_bytes: 9164
S = input().strip()
T = input().strip()

s_dict = {}
for i in range(len(S)):
    if not S[i] in s_dict:
        s_dict[S[i]] = T[i]

    elif s_dict[S[i]] != T[i]:
        print('No')
        exit()

t_dict = {}
for i in range(len(T)):
    if not T[i] in t_dict:
        t_dict[T[i]] = S[i]

    elif t_dict[T[i]] != S[i]:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3632
from collections import deque
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
#黒のマスを探索する
#黒のマスの周囲四マスを黒に変更する
log=[[-1]*W for i in range(H)]
def bfs():
    task=deque([])
    #初め黒のマスをキューに入れる
    for i in range(H):
        for j in range(W):
            if a[i][j]=='#':
                task.append((i,j))
                log[i][j]=0

    dh=[0,1,0,-1]
    dw=[1,0,-1,0]

    while task:
        h,w=task.popleft()
        #四マスを探索する
        for i in range(4):
            nh=h+dh[i]
            nw=w+dw[i]
            if not(0<=nh<H and 0<=nw<W):continue
            if a[nh][nw]=='#':continue
            a[nh][nw]='#'
            log[nh][nw]=log[h][w]+1
            task.append((nh,nw))

def ans_check():
    ans=0
    for i in range(H):
        for j in range(W):
            if ans<log[i][j]:ans=log[i][j]

    print(ans)

bfs()
ans_check()


Measured memory_bytes: 121436
#include <bits/stdc++.h>
using namespace std;
string s,t;
void solve()
{
    getline(cin,t);
    int i,j,tag=0,ls=s.length(),lt=t.length();
    for (i=ls-lt;i>=0;i--)
    {
        int xtag=0;
        for (j=lt-1;j>=0;j--)
            if (s[i+j]=='?'||s[i+j]==t[j]) ;
            else {xtag=1;break;}
        if (!xtag) {tag=1;break;}
    }
    if (tag)
    {
        for (j=0;j<i;j++)
            if (s[j]=='?') s[j]='a';
        for (j=i;j<i+lt;j++)
            if (s[j]=='?') s[j]=t[j-i];
        for (j=i+lt;j<ls;j++)
            if (s[j]=='?') s[j]='a';
        cout<<s;
    }
    else cout<<"UNRESTORABLE";
    cout<<endl;
}
int main()
{
    while(getline(cin,s))
        solve();
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    if (n * a > b) cout << b;
    else cout << n * a;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  for(int i=0;i<N;i++)cin>>X[i];
  Y=X;
  sort(ALL(X));
  for(int i=0;i<N;i++){
    if(Y[i]<=X[N/2-1])cout<<X[N/2]<<endl;
    else cout<<X[N/2-1]<<endl;
  }
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int sikaku1, sikaku2;
	sikaku1 = a * b;
	sikaku2 = c * d;
	if(sikaku1 > sikaku2){
		cout << sikaku1 << endl;
	}else{
		cout << sikaku2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,n;
	while(1){
		cin>>a>>b;
		if(a==0 && b==0)break;
		cin>>n;
		int s[17][17]={0};
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			s[x-1][y-1]=-1;
		}
		s[0][0]=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(s[i][j]!=-1){
					if(s[i+1][j]!=-1) s[i+1][j]+=s[i][j];
					if(s[i][j+1]!=-1) s[i][j+1]+=s[i][j];
				}
			}
		
		}
		
		cout<<s[a-1][b-1]<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3092
H, W, A, B = map(int, input().split())
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if i <= H - B:
            if j <= W - A:
                print(0, end= "")
            else:
                print(1, end= "")
        else:
            if j <= W - A:
                print(1, end= "")
            else:
                print(0, end= "")
    print()



Measured memory_bytes: 5364
import heapq
from collections import deque

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

work = [list(map(int,input().split())) for _ in range(N)]

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Measured memory_bytes: 32320
# B - Grid Compression
H, W = map(int, input().split())
grid = []

for i in range(H):
	a = input()
	
	if '#' in a:
		grid.append(a)

ans = [''] * len(grid)

for i in range(W):
	count = 0
	
	for j in range(len(grid)):
		if grid[j][i] == '#':
			count += 1
	
	if count > 0:
		for j in range(len(grid)):
			ans[j] += grid[j][i]

for a in ans:
	print(a)

Measured memory_bytes: 9152