akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toLong)
    var ans = Long.MAX_VALUE / 2
    if (h % 3 == 0L || w % 3 == 0L) ans = 0L
    if (h % 3 == 1L || h % 3 == 2L) ans = Math.min(ans, Math.abs(h * w * (h / 3 + 1) / h - h * w * (h / 3) / h))
    if (w % 3 == 1L || w % 3 == 2L) ans = Math.min(ans, Math.abs(h * w * (w / 3 + 1) / w - h * w * (w / 3) / w))
    var squares = arrayOf(h / 3 * w, (h - h / 3) * (w / 2), (h - h / 3) * (w - w / 2))
    ans = Math.min(ans, squares.max()!! - squares.min()!!)

    squares = arrayOf((h / 3 + 1) * w, (h - (h / 3 + 1)) * (w / 2), (h - (h / 3 + 1)) * (w - w / 2))
    ans = Math.min(ans, squares.max()!! - squares.min()!!)
    
    squares = arrayOf(w / 3 * h, (w - w / 3) * (h / 2), (w - w / 3) * (h - h / 2))
    ans = Math.min(ans, squares.max()!! - squares.min()!!)
    
    squares = arrayOf((w / 3 + 1) * h, (w - (w / 3 + 1)) * (h / 2), (w - (w / 3 + 1)) * (h - h / 2))
    ans = Math.min(ans, squares.max()!! - squares.min()!!)
    
    println(ans)
}

Measured memory_bytes: 38176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    vector<int> cnt(k);
    int rest = k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (k == 1) {
        if (find(a.begin(), a.end(), 1) != a.end()) puts("1");
        else puts("0");
        return 0;
    }
    int l = 0, r = 0;
    constexpr int INF = 1e9 + 6;
    int ans = INF;
    while (r < n) {
        if (a[r] <= k) {
            if (cnt[a[r] - 1] == 0) {
                rest--;
                while (rest == 0) {
                    ans = min(ans, r - l + 1);
                    if (a[l] <= k) {
                        cnt[a[l] - 1]--;
                        if (cnt[a[l] - 1] == 0) {
                            rest++;
                        }
                    }
                    l++;
                }
            }
            cnt[a[r] - 1]++;
        }
        r++;
    }
    if (ans == INF) puts("0");
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
use proconio::{input, fastout};
use num::range;

#[fastout]
fn main() {
    input! {
        k: i32,
        a: i32,
        b: i32,
    }

    let mut result = "NG";
    for i in range(a, b + 1) {
        if i % k == 0 {
            result = "OK";
            break;
        }
    }
    println!("{}", result);
}


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


int main()
{
    int a,b,c,k,cnt=0;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    while(b<=a) b*=2,cnt++;
    while(c<=b) c*=2,cnt++;
    if(cnt<=k) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3760
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n;
    char buf[30];

    // 標準入力から1行bufに格納
    fgets(buf, sizeof(buf), stdin);

    n = atoi(buf);
    n = n + (n*n) + (n*n*n);

    // 標準出力に書き出す
    printf("%d\n", n);
}

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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			String ans = "No";
			if(a == b && a != c) {
				ans = "Yes";
			}else if(b == c && a != b) {
				ans = "Yes";
			}else if(a == c && a != b) {
				ans = "Yes";
			}
			System.out.println(ans);
		}
	}

	static boolean permutation_2(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}

		int[] letters = new int[256];

		char[] s_array = s.toCharArray();
		for (char c : s_array) {
			letters[c]++;
		}

		for (int i = 0; i < t.length(); i++) {
			int c = (int) t.charAt(i);
			if (--letters[c] < 0) {
				return false;
			}
		}
		return true;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

// refer:
// http://dai1741.github.io/maximum-algo-2012/docs/shortest-path/
typedef vector<vector<ll> > Metrics;
Metrics d;

void warshall_floyd(int n) { // n:頂点数
	REP(i, n) {	// 経由する頂点
		REP(j, n) {	// 開始頂点
			REP(k, n) {	// 終端
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}

void debugprint(int n) {
	REP(i, n) {
		REP(j, n) {
			if (i != j && d[i][j] != INF) {
				cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
			}
		}
	}
}

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

	int n, m, r;
	cin >> n >> m >> r;
    n++;

	d = Metrics(n, vector<ll>(n, 100000000000000));
	REP(i, n) d[i][i] = 0;

    vector<int> goal(r);
    REP(i, r) cin >> goal[i];
    sort(goal.begin(), goal.end());
    
    REP(i, m) {
		int from, to;
        ll cost;
		cin >> from >> to >> cost;
		d[from][to] = cost;
		d[to][from] = cost; // if undirected graph
    }

    warshall_floyd(n);

    ll ans = 1000000000000000;
    do {
         ll t = 0;
         REP(i, r-1) {
            t += d[ goal[i] ][ goal[i+1] ];
         }
         ans = min(ans, t);
    } while(next_permutation(goal.begin(), goal.end()));

    cout << ans << endl;

    return 0;
}


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

vector<ll> divisor(int n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }

    return res;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1), cnt(N + 1);
    rep(i, N) cin >> A[i + 1];

    vector<int> ans;
    for (int i = N; i > 0; i--) {
        if ((cnt[i] % 2) != A[i]) {
            cnt[i]++;
            ans.push_back(i);
            vector<ll> res = divisor(i);
            rep(j, res.size()) {
                cnt[res[j]]++;
            }
        }
    }

    cout << (int)ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5440
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] slimes = new int[n];
    for (int i = 0; i < n; i++) {
      slimes[i] = sc.nextInt();
    }
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
      if (slimes[i] == slimes[i - 1] && slimes[i] == slimes[i + 1]) {
        slimes[i] = 101;
      } else if (slimes[i] == slimes[i - 1] && slimes[i] != slimes[i + 1]) {
        slimes[i] = 101;
      }
    }
    if (slimes[n - 1] == slimes[n - 2]) count++;
    for (int i = 0; i < n; i++) {
      if (slimes[i] == 101) {
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23508
#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)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 998244353;
constexpr bool debug = 0;
//---------------------------------//

template<int M>
struct ModInt {
public:
	using value_type = long long;
	
	ModInt(value_type val = 0) : val(val < 0 ? (M - (-val % M)) % M : val % M) {}
	
	explicit operator bool() const noexcept { return val; }
	bool operator ==(const ModInt & rhs) const noexcept { return val == rhs.val; }
	bool operator !=(const ModInt & rhs) const noexcept { return !(*this == rhs); }
	ModInt operator +() const noexcept { return ModInt(*this); }
	ModInt operator -() const noexcept { return ModInt(0) -= *this; }
	ModInt operator +(const ModInt & rhs) const noexcept { return ModInt(*this) += rhs; }
	ModInt operator -(const ModInt & rhs) const noexcept { return ModInt(*this) -= rhs; }
	ModInt operator *(const ModInt & rhs) const noexcept { return ModInt(*this) *= rhs; }
	ModInt operator /(const ModInt & rhs) const noexcept { return ModInt(*this) /= rhs; }
	
	ModInt & operator +=(const ModInt & rhs) noexcept {
		val += rhs.val;
		if (val >= M) val -= M;
		return *this;
	}
	ModInt & operator -=(const ModInt & rhs) noexcept {
		if (val < rhs.val) val += M;
		val -= rhs.val;
		return *this;
	}
	ModInt & operator *=(const ModInt & rhs) noexcept {
		val = val * rhs.val % M;
		return *this;
	}
	ModInt & operator /=(const ModInt & rhs) noexcept {
		*this *= rhs.inverse();
		return *this;
	}
	
	ModInt pow(value_type n) const {
		ModInt res = 1, x = val;
		if (n < 0) { x = x.inverse(); n = -n; }
		while (n) { if (n & 1) res *= x; x *= x; n >>= 1; }
		return res;
	}
	
	ModInt inverse() const {
		long long a = val, a1 = 1, a2 = 0, b = M, b1 = 0, b2 = 1;
		while (b > 0) {
			value_type q = a / b, r = a % b;
			value_type nb1 = a1 - q * b1, nb2 = a2 - q * b2;
			a = b; b = r;
			a1 = b1; b1 = nb1;
			a2 = b2; b2 = nb2;
		}
		assert(a == 1);
		return a1;
	}
	
	const value_type & get() const noexcept { return val; }
	static decltype(M) get_mod() noexcept { return M; }
	
	friend std::ostream & operator <<(std::ostream & os, const ModInt & rhs) { return os << rhs.val; }
	friend std::istream & operator >>(std::istream & is, ModInt & rhs) {
		value_type x;
		is >> x;
		rhs = ModInt(x);
		return is;
	}
private:
	value_type val;
};
using mint = ModInt<MOD>;


mint dp[3100][3100];

int main() {
	int N, S;
	cin >> N >> S;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	dp[0][0] = 1;
	REP(i, N) {
		REP(j, S + 1) {
			if (dp[i][j] == 0) continue;
			dp[i + 1][j] += dp[i][j] * 2;
			if (j + A[i] > S) continue;
			dp[i + 1][j + A[i]] += dp[i][j];
		}
	}
	
	cout << dp[N][S] << endl;
	
	return 0;
}


Measured memory_bytes: 78736
import sys
input = sys.stdin.readline

def main():
    L, R = list(map(int, input().split()))

    ans = 0
    for i in range(L, R):
        for j in range(L+1, R+1):
            tmp = i * j % 2019

            if tmp == 0:
                print('0')
                sys.exit()

            if ans == 0:
                ans = tmp

            if ans > tmp:
                ans = tmp

    print(ans)

main()

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

int main(){
    int n;
    char S[100];
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%c",&S[i]);
    }
    bool flag = false;
    for(int i = 0; i < n; i++){
        if(S[i] == 'Y'){
            flag = true;
            break;
        }
    }
    if(flag){
        printf("Four\n");
    }
    else{
        printf("Three\n");
    }
}


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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

vector<bool>Sieve(1000005,true);
void sieve(){
 Sieve[0]=false;
 Sieve[1]=false;
 for(ll i=2;i*i<=1000000;i++){
  if(Sieve[i]==true){
   for(ll j=i*i;j<=1000000;j+=i){
    Sieve[j]=false;
   }
  }
 }
}
ll getDiv(ll n){
 ll res=0;
 for(ll i=1;i*i<=n;i++){
  if(n%i==0){
   res++;
   if(n/i!=i)res++;
  }
 }
 return res;
}
int main(){
 ll n;
 cin>>n;
 ll ans=0;
 n--;
 for(int i=1;i<=n;i++)ans+=(n/i);
 cout<<ans<<"\n";
 return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

class segtree {

	vi st;
	int n;

	void build(string& s, int node, int low, int high) {
		if(low == high) st[node] = 1 << (s[low] - 'a');
		else {
			int mid = (low + high) / 2;
			build(s, 2 * node + 1, low, mid);
			build(s, 2 * node + 2, mid + 1, high);
			st[node] = st[2 * node + 1] | st[2 * node + 2];
		}
	}

	void update(int node, int k, char c, int low, int high) {
		if(low == high) st[node] = 1 << (c - 'a');
		else { 

			int mid = (low + high) / 2;
			if(k <= mid) update(2 * node + 1, k, c, low, mid);
			else update(2 * node + 2, k, c, mid + 1, high);
			st[node] = st[2 * node + 1] | st[2 * node + 2];
		}
	}

	int query(int node, int l, int r, int low, int high) {
		if(l > r) return 0;
		else if(l == low && r == high) return st[node];
		int mid = (low + high) / 2;
		return query(2 * node + 1, l, min(r, mid), low, mid) | query(2 * node + 2, max(l, mid + 1), r, mid + 1, high);
	}

	public:

	segtree(string& s) {
		n = s.size();
		st.resize((1 << ((int)log2(n) + 2)) - 1);
		build(s, 0, 0, n - 1);
	}

	int query(int l, int r) {
		return __builtin_popcount(query(0, l, r, 0, n - 1));
	}

	void update(int k, char c) {
		update(0, k, c, 0, n - 1);
	}
};

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n, q;
	string s;

	cin >> n >> s;

	segtree st(s);

	cin >> q;

	while(q--) {
		int t, l;
		cin >> t >> l;
		if(t == 1) {
			char c;
			cin.ignore();
			cin >> c;
			st.update(l - 1, c);
		}
		else {
			int r;
			cin >> r;
			cout << st.query(l - 1, r - 1) << '\n';
		}
	}

    return 0;
}


Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define S second
#define F first
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(0)
#define pb push_back
#define mp make_pair
using namespace std ;
typedef long long ll ;
typedef pair<int,int> pii ;
const ll mod=1000*1000*1000+7 ;
 
 
ll pow(ll a , ll b){
    if(b==0){
        return 1;
    }
    ll x = pow(a,b/2) ;
    x = (x*x)%mod ;
    if(b%2){
        x = (x*a)%mod ;
    }
    return x ;
}
 
int main(){
    ll n ;
    cin >> n ;
    ll aub= (pow(10ll , n)-pow(8ll , n)+mod)%mod ;
    ll a= (pow(10ll , n)-pow(9ll , n)+mod)%mod ;
    cout << (a+a-aub+mod)%mod ;
 
    return 0;
}


Measured memory_bytes: 3632
N = gets.chomp.to_i
hs = gets.chomp.split.map(&:to_i)

min = 9999999999999
(N - 1).downto(0) do |i|
  if hs[i] > min
    hs[i] -= 1
  else
    min = hs[i]
  end
end

if [*(0..(N - 2))].all? { |i| hs[i] <= hs[i + 1] }
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 11268
import sys
from collections import defaultdict, Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    N_MAX = 10 ** 6

    min_factor = list(range(N_MAX + 1))
    min_factor[2::2] = [2] * (N_MAX // 2)
    for i in range(3, int(N_MAX ** 0.5) + 2, 2):
        if min_factor[i] != i:
            continue
        for j in range(i * i, N_MAX + 1, 2 * i):
            if min_factor[j] > i:
                min_factor[j] = i

    def prime_factorize_fast(n):
        a = Counter()
        while n != 1:
            a[min_factor[n]] += 1
            n //= min_factor[n]

        return a

    lcm_prime = Counter()
    for a in A:
        for p, n in prime_factorize_fast(a).items():
            if lcm_prime[p] < n:
                lcm_prime[p] = n

    l = 1
    for p, n in lcm_prime.items():
        l = l * pow(p, n, MOD) % MOD

    ans = 0
    for a in A:
        ans = (ans + pow(a, MOD - 2, MOD)) % MOD

    ans = ans * l % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 86120
#include<iostream>
#include<map>

using namespace std;

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

    map<char, int> mp;

    for (int i = 0; i < s.size(); i++) {
        if (mp.count(s[i]) == 0) {
            mp[s[i]] = 1;
        }
        else {
            mp[s[i]]++;
        }
    }

    for (auto x : mp) {
        if (x.second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
//https://www.codechef.com/LTIME59A/problems/GCDDIV
#include <bits/stdc++.h>
using namespace std;

unsigned long long func(unsigned long long x) {
    if(x == 1)
        return 1;
    return (1 + (2 * (func(x / 2))));
}

int main() {
    unsigned long long n;
    cin >> n;
    cout << func(n) << endl;
}


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


using namespace std;


const int N = 1e5 + 10;
struct node{
    int t, x, y;
}A[N];

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

    A[0].t = A[0].x =  A[0].y = 0;

    for(int i = 1; i <= n; i ++)
        cin >> A[i].t >> A[i].x >> A[i].y;
    bool is = true;
    for(int i = 1; i <= n; i++){
        int sum = abs(A[i].x - A[i-1].x) + abs(A[i].y - A[i-1].y);
        if(sum + A[i-1].t > A[i].t) is = false;

        if(((A[i].x + A[i].y)%2) != (A[i].t % 2)) is = false;
    }

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


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll mn=a[0];
    ll ans=0;
    for(int i=1;i<n;i++){
        if(a[i]>mn){
            mn=a[i];
        }
        else{
            ans+=mn-a[i];
        }
    }
    cout<<ans<<endl;

}













































































Measured memory_bytes: 4756
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
edges = [set() for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    edges[a].add(b)
    edges[b].add(a)
    
C = lr()
C.sort(reverse=True)
degrees = [len(x) for x in edges]
deg_1 = [i for i, d in enumerate(degrees) if d == 1]
score = sum(C[1:])
answer = [None] * (N+1)

# start from every leaf
while deg_1:
    leaf = deg_1.pop()
    answer[leaf] = C.pop()
    if not deg_1:
        break
    cand = edges[leaf].pop()
    edges[cand].remove(leaf)
    degrees[cand] -= 1
    if degrees[cand] == 1:
        deg_1.append(cand)

print(score)
print(*answer[1:])


Measured memory_bytes: 7312
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> C(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
    A[i]--;
    C[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cout << C[i] << endl;
  }
  return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> pref(k+1), dp(k+1);
  dp[0] = 1;
  for(int kid = 1;kid<=n;kid++){
    int c;
    cin >> c;
    pref[0] = dp[0];
    for(int i = 1;i<=k;i++)
      pref[i] = (pref[i-1] + dp[i]) % MOD;
    for(int i = 0;i<=k;i++)
      dp[i] = (pref[i] - (i-c>=0 ? pref[i-c-1] : 0)) % MOD;
  }

  int ans = dp[k];
  if(ans < 0) ans += MOD; 
  printf("%d\n",ans);

  return 0;
}


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

using namespace std;
typedef long long ll;

bool table[201];

void make_table() {
  for (ll j=2; j < 201; ++j) {
    table[j] = true;
  }
  for (ll j=2; j < 201; ++j) {
    if (!table[j]) continue;
    for (ll k=j+j; k < 201; k+=j) {
      table[k] = false;
    }
  }
}

int main() {
  ll N; cin >> N;
  ll ans = 0;
  make_table();
  for (ll j=1; j <= N; j+=2) {
    ll num = j;
    ll count = 1;
    for (ll k=j-1; k > 0; --k) {
      if (!table[k]) continue;
      ll ex = 0;
      while (num > 0 && num % k == 0) {
        num /= k;
        ex += 1;
      }
      count *= ex+1;
    }
    if (count == 8) {
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int mod = 1;

struct mint {
    ll x;

    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 {
      mint res(*this);
      return res += a;
    }

    mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
    }

    mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
    }

    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
    }

    mint inv() const {
      return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
      return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
    }
};


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

  int n;
  cin >> n;

  string s;
  cin >> s;

  reverse(s.begin(),s.end());

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') cnt++;
  }

  mod = cnt - 1;
  mint less = 0;

  if(mod > 0) {
    for (int i = 0; i < n; i++) {
      if(s[i] == '1') less = less + mint(2).pow(i);
    }
  }

  mod = cnt + 1;
  mint more = 0;
  for (int i = 0; i < n; i++) {
    if(s[i] == '1') more = more + mint(2).pow(i);
  }


  for (int i = n - 1; i >= 0; i--) {

    if(s[i] == '0') {
      int tmp_cnt = 1;
      mod = cnt + 1;
      mint two = mint(2).pow(i);
      mint mod_ans = more + two;

      int ans = mod_ans.x;
      int int_mod = __builtin_popcount(ans);

      while (true) {
        if(ans == 0) break;
        if(int_mod == 0) break;
        else ans = ans % int_mod;

        int_mod = __builtin_popcount(ans);
        tmp_cnt++;
      }
      cout << tmp_cnt << '\n';

    } else {
      int tmp_cnt = 1;
      mod = cnt - 1;

      if(mod == 0) {
        cout << 0 << '\n';
      } else {

        mint two = mint(2).pow(i);
        mint mod_ans = less - two;

        int ans = mod_ans.x;
        int int_mod = __builtin_popcount(ans);

        while (true) {
          if (ans == 0) break;
          if (int_mod == 0) break;
          else ans = ans % int_mod;

          int_mod = __builtin_popcount(ans);
          tmp_cnt++;
        }
        cout << tmp_cnt << '\n';
      }
    }
  }

  return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<LL> V;
typedef vector<V> VV;
constexpr LL INF=1e15;
int main(){
    int N,M,R;
    cin>>N>>M>>R;
    VV d(N,V(N,INF));
    V r(R);
    cin>>r;
    REP(i,R)r[i]--;
    REP(i,M){
        int a,b;LL c;
        cin>>a>>b>>c;
        a--;b--;
        chmin(d[a][b],c);
        chmin(d[b][a],c);

    }
    REP(i,N)d[i][i]=0;
    REP(k,N)REP(i,N)REP(j,N)
        chmin(d[i][j],d[i][k]+d[k][j]);
    VV dp(1<<R,V(R,INF));
    REP(i,R)dp[1<<i][i]=0;
    REP(i,(1<<R))REP(v,R){
        REP(j,R)
            chmin(dp[i|(1<<j)][j],dp[i][v]+d[r[v]][r[j]]);
    }
    LL ret=INF;
    REP(i,R)chmin(ret,dp.back()[i]);
    cout<<ret<<endl;
    return 0;
}


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

#define lli long long int
#define endl "\n"


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

	vector<int> a(n), b(n), c(n);

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

	
	vector<vector<int> > dp(n+1, vector<int>(3,0));
	const int A = 0, B = 1, C = 2;

	for(int i=1; i<= n ; i++){
		dp[i][A] = a[i-1] + max(dp[i-1][B], dp[i-1][C]);
		dp[i][B] = b[i-1] + max(dp[i-1][A], dp[i-1][C]);
		dp[i][C] = c[i-1] + max(dp[i-1][A], dp[i-1][B]);
	}

	int ans = max(dp[n][A], max(dp[n][B], dp[n][C]));

	cout << ans;
	return 0;
}

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

using namespace std;

int main(void){

	int a=9876,b;
	int cnt=0;
	vector<int> a_arr;
	vector<int> b_arr;	

	while(a != 0){
	
		cin >> a;
		cin >> b;
		a_arr.push_back(a);
		b_arr.push_back(b);
		cnt++;

	}

	for(int test=0;test<cnt-1;test++){
		for(int i=0;i<a_arr[test];i++){
			for(int j=0;j<b_arr[test];j++){
				if(i != 0 && i != a_arr[test]-1){
					if(j != 0 && j != b_arr[test]-1){
						cout << ".";
					}
					else{
						cout << "#";
					}
				}
				else{
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
	cin >> n;
	set<ll>st;
	vi v(n);
	REP(i, n) cin >> v[i];
	REP(i, n) st.insert(v[i]);
	cout << (st.size() % 2 == 1 ? st.size() : st.size() - 1) << Endl;
}

Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

int n,s,ans;
int a[N];
bool tag[N];

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]),s^=a[i];
		a[i]=a[i]^(a[i]-1);
		for (j=0;j<=30&&((a[i]>>j)&1);j++);
		tag[j-1]=1;
	}
	for (i=30;i>=0;i=j){
		j=i;
		if (((s>>i)&1)==0){
			j--;
			continue;
		}
		while (j>=0&&((s>>j)&1)) j--;
		if (tag[i]) ans++;
		else{
			ans=-1;
			break;
		}
		if (j>=0&&tag[j]) ans++;
		else if (j>=0&&!tag[j]){
			ans=-1;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
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};

fn main(){
    input!{
        n:usize,
        k:usize,
        mut hn:[i64;n],
    }
    hn.sort();
    let mut ans = std::i64::MAX;
    for j in 0..(n-k+1){
        let diff = hn[j+k-1] - hn[j];
        ans = min(diff,ans);
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

const int maxT = 3600 * 2;
int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //cout << fixed << setprecision(7);

    int s;
    double w, h;
    vector<int> ans;
    while (scanf("%d,%lf,%lf", &s, &w, &h) != EOF)
    {
        if (w / (h * h) >= 25)
            ans.push_back(s);
    }

    for (auto e : ans)
        cout << e << endl;
    return 0;
}


Measured memory_bytes: 3152
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  H = list(map(int, readline().split()))
  prev = 0
  ans = 'Yes'
  for i in range(n):
    if H[i] -1 >= prev:
      H[i] -= 1
    if H[i] < prev:
      ans = 'No'
      break
    prev = H[i]
  
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 22660
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long int
int ans=0;
int h[1<<21]={0};
int dp[1<<22][22];
main() {
    int n;
    cin>>n;
  	cout<<(n*(n-1))/2<<endl;
    // cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int A[3][3];
    REP(i,3) REP(j,3) cin >> A[i][j];
    int N; cin >> N;
    vector<int> b(N);
    REP(i,N) cin >> b[i];

    bool flag[3][3]={false};
    REP(i,3) REP(j,3) REP(k,N){
        if(A[i][j]==b[k]) flag[i][j]=true;
    }

    REP(i,3){
        int cnt=0;
        REP(j,3){
            if(!flag[i][j]) break;
            else cnt++;
        }
        if(cnt==3){
            cout << "Yes" << endl;
            return 0;
        }
    }

    REP(i,3){
        int cnt2=0;
        REP(j,3){
            if(!flag[j][i]) break;
            else cnt2++;
        }
        if(cnt2==3){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(flag[0][0] and flag[1][1] and flag[2][2]){
        cout << "Yes" << endl;
        return 0;
    }

    if(flag[0][2] and flag[1][1] and flag[2][0]){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;


int main() {
  string s;
  cin >> s;
  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<numeric>
using namespace std;
int main(){
  int l[10], v1, v2, ret;
  while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2)){
    int sum = accumulate( l, l + 10, 0), k = 0;
    double ret = ((double)v1 / ( v1 + v2)) * sum;
    for(int i = 0 ; i < 10 ; i++ ){
      if( (k += l[i]) >= ret ){
        printf("%d\n", i+1);
        break;
      }
    }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;

signed main() {
    int n,m,c;
    cin >> n>> m >> c;
    vector<int> b(m);
    rep(i,m)cin >> b[i];
    int ans = 0;
    rep(i,n) {
        int tmp = c;
        rep(i,m) {
            int a;
            cin >> a;
            tmp += a*b[i];
        }
        if(tmp>0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class Homework {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < m; i++)
                sum += sc.nextInt();
            if (sum > n)
                pw.println(-1);
            else
                pw.println(n - sum);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 34156
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test ll t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define jaldibazi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007




int main() {

	int n, l; cin >> n >> l;
	vector<string> vs;

	for(int i = 0; i<n; ++i) {
		string a; cin >> a;
		vs.push_back(a);
	}

	// for(int i )

	sort(vs.begin(),vs.end());
	string res = "";

	for(int i = 0; i<n; ++i) {
		res+=vs[i];
	}

	cout << res << "\n";
	return 0;

} 


Measured memory_bytes: 3608
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll N;
vll H;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;

    rep(ni,N){
        cin >> ltmp;
        H.push_back(ltmp);
    }

    string ans = "Yes";
    for( ll hi = H.size()-1 ; hi>=1 ; hi-- ){
        if(H[hi] < H[hi-1]){
            if(H[hi] == H[hi-1]-1){
                H[hi-1]--;
            }else{
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int MAX = 200000;
P a[MAX];
int cnt[MAX];
vector<P> vec,tt;
vector<int> G[MAX];
signed main(){
  int n, k, tcnt = 0;
  scanf("%lld%lld",  &n, &k);
  rep(i,n)scanf("%lld%lld", &a[i].se, &a[i].fi);
  
  rep(i,n)vec.pb(a[i]);
  rep(i,n)G[a[i].se].pb(a[i].fi);
  rrep(i,n)sort(all(G[i]), greater<int>());
  rrep(i,n)if(G[i].size())tt.pb(P(G[i][0], i));
  sort(all(tt), greater<P>());
  sort(all(vec));
  
  int total = 0, ans = 0;
  rep(i,k){
    total += vec[n-i-1].fi;
    cnt[vec[n-i-1].se]++;
  }
  rrep(i,n)if(cnt[i])tcnt++;
  ans = max(ans, total+tcnt*tcnt);
  
  int m = tt.size(), idx = 0;
  repi(i,n-k,n){
    if(cnt[vec[i].se] == 1)continue;
    repi(j,idx,m){
      idx = j+1;
      if(cnt[tt[j].se] > 0)continue;
      cnt[vec[i].se]--;
      cnt[tt[j].se]++;
      total -= vec[i].fi;
      total += tt[j].fi;
      tcnt++;
      ans = max(ans, total+tcnt*tcnt);
      break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}






Measured memory_bytes: 16240
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =100010;
ll a[MAX_N]={0};
ll dp[MAX_N];
int main(){
	int n;
	cin>>n;
	fill(dp, dp+n, 10e8);
	for(int i =0;i < n;i++){
		cin>>a[i];
	}
	for(int i =0;i < n;i++){
		int pos = lower_bound(dp, dp+n, a[i])-dp;
		dp[pos] = a[i];
	}
	cout <<lower_bound(dp,dp+n,10e8)-dp<<endl;
	return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int t=700;
  cin>>s;
  REP(i,3){
    if(s[i]=='o') t+=100;
  }
  cout<<t<<endl;
  return 0;
}


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

#define ll long long

struct UnionFind {
    int size;
    int numComponents;
    vector<int> sz;
    vector<int> id;

    UnionFind(int N) {
        size = numComponents = N;
        sz = vector<int>(N, 1);
        id = vector<int>(N);
        for(int i = 0; i < N; i++) {
            id[i] = i;
        }
    }

    int find(int p) {
        int root = p;
        while(root != id[root]) {
            root = id[root];
        }
        while(p != root) {
            int next = id[p];
            id[p] = root;
            p = next;
        }
        return root;
    }

    bool connected(int p, int q) {
        return find(p) == find(q);
    }

    int componentSize(int p) {
        return sz[find(p)];
    }

    void unify(int p, int q) {
        int rootP = find(p);
        int rootQ = find(q);
        if(rootP == rootQ) return;

        if(sz[rootP] < sz[rootQ]) {
            sz[rootQ] += sz[rootP];
            id[rootP] = rootQ;
        } else {
            sz[rootP] += sz[rootQ];
            id[rootQ] = rootP;
        }
        numComponents--;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind UF(N);

    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        UF.unify(a, b);
    }

    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans, UF.componentSize(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4836