akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int INF = 1e8;


class Edge{
    public:
        int to, cost;
        Edge(int to, int cost) : to(to) ,cost(cost) {}
};

class Node{
    public:
        int dis;
        bool isUsed;
        Node(){
            this->dis = INF;
            this->isUsed = 0;
        }
};

typedef vector<vector<Edge>> AdjList;

void dijkstra(AdjList const g, int start, int n, int f, int t,vector<Node> node[2]){
    priority_queue<int, vector<pair<int, int>>, greater<pair<int, int>>> q;

    q.push(make_pair(0, start));
    node[f][start].dis = 0;

    pair<int, int> u;
    while(not q.empty()){
        u = q.top(); q.pop();
        int current = u.second;
        node[f][current].isUsed = 1;

        rep(i,g[current].size()){
            int next = g[current][i].to;
            if(node[f][next].isUsed == 0){
                if(node[f][next].dis > node[f][current].dis + g[current][i].cost){
                    node[f][next].dis = node[f][current].dis + g[current][i].cost;
                    q.push(make_pair(node[f][next].dis, next));
                }
            }
        }
    }
}

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;

    AdjList g(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(Edge{b,1});
        g[b].emplace_back(Edge{a,1});
    }
    vector<Node> node[2];
    node[0] = vector<Node>(n);
    node[1] = vector<Node>(n);
    dijkstra(g,s,n,0,t,node);
    dijkstra(g,t,n,1,t,node);

    long long cnt[2][100005] = {{0}};
    rep(i,n){
        if(node[0][i].dis != INF) cnt[0][node[0][i].dis]++;
        if(node[1][i].dis != INF) cnt[1][node[1][i].dis]++;
    }
    int dist = node[0][t].dis;

    long long ans = 0;
    rep(i,dist - 1) ans+=cnt[0][i] * cnt[1][dist - i - 2];

    cout << ans << endl;
}

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

#define int long long 
#define KETSUBAN (1000000001)

main()
{
  int H, W, h, w;
  int a[505][505];
  int d;
  int posi;

  fill_n(*a, 505 * 505, KETSUBAN);
  
  cin >> H >> W >> h >> w;

  d = h * w - 1;
  
  int val = 1000000000;
  if(d > 1) {
    while(val % d != 1) val--;
  }
  if(d <= 1) posi = val - 1;
  else posi = val / d;
  
  for(int i = h - 1; i < H; i += h) {
    for(int j = w - 1; j < W; j += w) {
      a[i][j] = -val;
    }
  }

  int sum = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(a[i][j] == KETSUBAN) {
	a[i][j] = posi;
      }
      sum += a[i][j];
    }
  }

  if(sum <= 0) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
	cout << a[i][j];
	if(j == W - 1) cout << endl;
	else cout << " ";
      }
    }
  }

  return (0);
}
  
  


Measured memory_bytes: 4864
#include <iostream>
    #include <stdio.h>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <string.h>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #include <time.h>
    #define _USE_MATH_DEFINES
    #define LL long long
    #define UN unsigned
    using namespace std;
    const double PI = acos(-1.0);
     
    int max_num(int ary[], int length) {
    	int max = ary[0];
    	for (int i = 1; i < length; i++)
    		if (max < ary[i]) max = ary[i];
    	return max;
    }
     
    int max_ord(int ary[], int length) {
    	int max;
    	max = max_num(ary, length);
    	for (int i = 0; i < length; i++) {
    		if (ary[i] == max) return i;
    	}
    	return -1;
    }
     
    int min_num(int ary[], int length) {
    	int min = ary[0];
    	for (int i = 1; i < length; i++)
    		if (min > ary[i]) min = ary[i];
    	return min;
    }
     
    int min_ord(int ary[], int length) {
    	int min;
    	min = min_num(ary, length);
    	for (int i = 0; i < length; i++) {
    		if (ary[i] == min) return i;
    	}
    	return -1;
    }
     
    int main() {
    	int n;
     
     
    	cin >> n;
    	if (n % 10 == n / 100) {
    		cout << "Yes" << endl;
    	}
    	else
    		cout << "No" << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
std::string s;
cin>>s;
if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<"\n";
}
else{
    cout<<"No"<<"\n";
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,dem=0;
    cin>>n>>k;
    long long t=(k-1)*(k-2)/2;
    long long x=n*(n+1)/2-(n-k+1)*(n-k)/2;
    x-=n-k+1;
    for(int i=k;i<=n+1;i++)
    {
        t+=i-1;
        x+=n+1-i;
        dem+=x-t+1;
        //cout<<t<<' '<<x<<endl;
    }
    cout<<dem%1000000007;
}


Measured memory_bytes: 3636
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n;  cin >> n;
    bool flag = false;
    for(int i = 1; i < 10; i++){
        if(n%i == 0 && n/i < 10)    flag = true;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
	int i, j, n, m, kyori, ans, cp;
	int a[50], b[50], c[50], d[50];
	
	
	scanf("%d %d", &n, &m);
	
	for(i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	
	for(i = 0; i < m; i++) {
		scanf("%d %d", &c[i], &d[i]);
	}
	
	for(i = 0; i < n; i++) {
	    for(j = 0; j < m; j++) {
	        kyori = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			
	        if(j == 0) {
	            ans = kyori;
				cp = 0;
	        }else if(ans > kyori) {
	            ans = kyori;
	            cp = j;
	        }
	    }
	    cp++;
	    printf("%d\n", cp);
	}
}

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

using namespace std;

const auto MAX = 100000 + 5;
const auto MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    COMinit();
    long long ans = 0;
    for (int i = M - 1; i < N; ++i) {
        ans += a[i] * COM(i, M - 1);
        ans %= MOD;
    }

    reverse(a.begin(), a.end());
    for (int i = M - 1; i < N; ++i) {
        ans -= a[i] * COM(i, M - 1);
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    println!(
        "{}",
        if (1..10).any(|x| {
            let z = s.trim().parse::<i32>().unwrap();
            return z % x == 0 && z / x < 10;
        }) {
            "Yes"
        } else {
            "No"
        }
    );
}


Measured memory_bytes: 4352
#include<cstdio>

int A[1000000], n;

int binarySearch(int key){
	int left = 0;
	int right = n;
	int mid;
	while(left < right){
		mid = (left + right) / 2;
		if(key == A[mid])return 1;
		if(key > A[mid]) left = mid + 1;
		else if(key < A[mid]) right = mid;
	}
	return 0;
}

int main(){
	int i, q, k, sum = 0;
	scanf("%d", &n);
	for(i = 0; i < n; ++i){
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for(i = 0; i < q; ++i){
		scanf("%d", &k);
		if(binarySearch(k))sum++;
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1416
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x := nextInt()

	ans := 10 - x/200
	puts(ans)
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b){
	while(b) a %= b, swap(a, b);
	return a;
}
int f[222][222];
int gcd(int a, int b){
	return f[a][b];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long ans = 0;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) f[i][j] = Gcd(i, j);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int k = 1; k <= n; k++){
		ans += gcd(i, gcd(j, k));
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3748
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = Math.toRadians(sc.nextDouble());


        double S,L,h;
        S  = a*b*Math.sin(c)/2;
        L = a+b+Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)-(2*a*b*Math.cos(c)));
        h = 2*S/a;


        System.out.printf("%f\n%f\n%f\n",S,L,h);

        sc.close();
	}


}



Measured memory_bytes: 28252
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

template<class... Args>
auto nvect(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector(n, args...);
	else
		return vector(n, nvect(args...));
}

void madd(ll& a, ll b){
	a += b;
	if (a >= MOD) a -= MOD;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	auto dp = nvect<ll>(n+1, 2, 2, 0);	
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int has0 = 0; has0 <= 1; has0++) {
			for (int has9 = 0; has9 <= 1; has9++) {
				for (int d = 0; d <= 9; d++) {
					int n0 = (d == 0 or has0) ? 1 : 0;
					int n9 = (d == 9 or has9) ? 1 : 0;
					dp[i+1][n0][n9] += dp[i][has0][has9];
					dp[i+1][n0][n9] %= MOD;
				}
			}
		}
	}
	cout << dp[n][1][1];
}

Measured memory_bytes: 151452
#include <bits/stdc++.h>
using namespace std;
/*******************??????********************/
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {//??????
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {//??????
	return real(conj(a)*b);
}

struct L : public vector<P> {//??????
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};

typedef vector<P> G;
struct C {//???
	P p; double r;
	C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {//??????????????????
	b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L& l,const L& m){
	//non-parallel || sameline
	return abs(cross(l[1]-l[0],m[1]-m[0])) > EPS || abs(cross(l[1]-l[0],m[0]-l[0])) < EPS;
}
bool intersectLS(const L& l,const L& s){
	// s[0] is left of l,s[1] is right of l
	return cross(l[1]-l[0],s[0]-l[0]) * cross(l[1]-l[0],s[1]-l[0]) < EPS;
}
bool intersectLP(const L& l,const P& p){
	return abs(cross(l[1]-p,l[0]-p)) < EPS;
}
bool intersectSP(const L& s,const P& p){
	return abs(s[0]-p)+abs(s[1]-p) - abs(s[1]-s[0]) < EPS;// triangle inequality
}

P projection(const L& l,const P& p){
	double t = dot(p-l[0],l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
P reflection(const L& l,const P& p){
	return p + 2. * (projection(l,p) - p);
}
double distanceLP(const L& l,const P& p){
	return abs(p - projection(l,p));
}
double distanceLL(const L& l,const L& m){
	return intersectLL(l,m) ? 0 : distanceLP(l,m[0]);
}
double distanceLS(const L& l,const L& s){
	if(intersectLS(l,s)) return 0;
	return min(distanceLP(l, s[0]),distanceLP(l, s[1]));
}

int main(void){
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	P p1(x1,y1),p2(x2,y2);
	L l(p1,p2);

	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int x,y;cin >> x >> y;
		P p3(x,y);
		P t = projection(l,p3);
		cout << setprecision(20) << real(t);cout << " ";
		cout << setprecision(20) << imag(t) << endl;
	}

	return 0;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }
template <class... Args> inline void rf(Args&... args) { (cin >> ... >> args); }
template <class... Args> inline void pr(Args&&... args) { (cout << ... << args); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	ll n; rd(n);

	set<ll> st;
	st.emplace(1);

	vector<pair<ll, int>> divi;
	for (ll i = 2; i * i <= n; i++) {
		if (n%i == 0) {
			divi.eb(i, 0);
			while(n%i == 0) {
				divi.back().second++;
				n /= i;
			}
		}
	}

	auto is_prime = [](ll n) {
		if (n == 1) return false;
		for (ll i = 2; i * i <= n; i++) {
			if (n%i == 0) return false;
		}
		return true;
	};

	if (is_prime(n)) divi.eb(n, 1);

	int ans = 0;
	for (auto [x, cnt] : divi) {
		ll lo = 1, hi = 1e6, mi;
		while(lo < hi) {
			mi = (lo + hi + 1) / 2;
			if (mi * (mi + 1) / 2 <= cnt) lo = mi;
			else hi = mi-1;
		}
		ans += lo;
	}

	printf("%d\n", ans);
}

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

int main() {
	int a, b,c,d;
	int L, R;
	cin >> a >> b >> c >> d;
	L = a+b;
	R = c + d;
	if ( L>R) {
		cout << "Left" << endl;
	}
	else if (R > L) {
		cout << "Right" << endl;
	}
	else if(R == L){
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 256
ans = 0
d = []
11.times do |i|
  ans += 26 ** (i+1)
  d << ans
end

n = gets.to_s.to_i
base = d.bsearch{ n <= _1 }
count = d.bsearch_index{ n <= _1 }
count += 1 #桁数
n -= base / 26

a = []
count.times do
  a << n % 26
  n /= 26
end
puts a.map{ (_1 + 97).chr }.reverse.join

Measured memory_bytes: 14340
//
// Created by yamunaku on 2020/01/26.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int h,a;
    cin >> h >> a;
    cout << (h-1+a)/a << endl;
    return 0;
}

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

int main() {
	// your code goes here
	ll n, k;
	cin>>n>>k;
	vector<int> a(n);
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());
	for(int i=0;i<k;i++) sum+=(ll)a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int ans=1,i,n;
	cin >> n;
    string s;
    vector<string> vec;
	for (i=0;i<n;i++){
      cin >> s;
      vec.push_back(s);
    }
	sort(vec.begin(),vec.end());
    i=1;
    while(vec.size()>i){
      if (vec[i]!=vec[i-1]) ans++;
      i++;
    }

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


Measured memory_bytes: 9048
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);

int main(){
    ll mod = 1000000007;
    ll n;cin >> n;
    vec A(n);
    ll sum = 0;
    rep(i,n){
        cin >> A[i];
        if(A[i] > mod/2){
            A[i] -= mod;
        }
        sum += A[i];
        sum %= mod;
        //cout << "a" <<A[i] << endl;
    }
    sum -= A[0];
    //cout << sum << endl;
    //cout << sum << endl;
    ll ans = 0;
    for(int i = 0;i < n-1;i++){
        ans += (A[i]%mod)*sum;
        //cout << sum << endl;
        ans %= mod;
        sum = sum - A[i+1];
        sum %= mod;
    }
    if(ans < 0){
        ans += mod;
    }
    cout << ans << endl;
}

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

vector<pair<int,int>> X(200010,{0,0});
vector<set<int>> Y(200010);

pair<int,int> dfs(int s,int t){ //親はsです 子はtです
  int fir=0,sec=0,ff=0;
  pair<int,int> P;
  auto it=Y[t].begin();
  auto it2=Y[t].end();
  while(it!=it2){
    if(*it!=s){
      P=dfs(t,*it);
      if(P.second>=fir)
        sec=fir,fir=P.second;
      else if(P.second>sec)
        sec=P.second;
      ff=max(ff,P.first);
    }
    it++;
    continue;
  }
  ff=max(ff,fir+sec);
  return {ff,fir+1};
}

int main(){
  int N;
  cin>>N;
  int a,b;
  for(int i=0;i<N-1;i++){
    cin>>a>>b;
    Y[a].insert(b);
    Y[b].insert(a);
  }
  pair<int,int> ans=dfs(0,1);
  //cout<<ans.first<<endl;
  if(ans.first%3==1)
    cout<<"Second"<<endl;
  else
    cout<<"First"<<endl;
}

Measured memory_bytes: 44928
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
B_C = [list(map(int, input().split())) for i in range(M)]
B_C.sort(key = lambda x : x[1], reverse = True)
for i in range(M):
    cnt = 0
    while cnt < B_C[i][0]:
        x = heappop(A)
        if x < B_C[i][1]:
            heappush(A, B_C[i][1])
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))

Measured memory_bytes: 90648
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    int cnt=0;
    rep(i,n){
        cin>>p[i];
        if(i+1!=p[i]){
            ++cnt;
        }
    }
    if(cnt<=2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N,M;

void solve(){
    if(N==M)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> N >> M;

    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a,b;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A'&&i<a){
			a=i;
		}
		else if(s[i]=='Z'&&i>a){
			b=i;
		}
	}
	cout<<b-a+1<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=1e5+7;
const ll modn=1e9+7;
const int inf=2e9+7;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
ll n,i;
int main()
{
    while(scanf("%lld%lld",&n,&i)==2)
    {
        printf("%lld\n",n-i+1);
    }
}


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

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

  ll N; cin >> N;
  ll S; cin >> S;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll MOD = 998244353;
  vector<vector<ll>> dp(N + 1, vector<ll>(S + 1, 0));

  dp[0][0] = 1;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < S + 1; j++) {
      dp[i + 1][j] = (dp[i][j] * 2) % MOD;
      if (j >= A[i]) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - A[i]]) % MOD;
    }
  }

  cout << dp[N][S] << '\n';
  return 0;
}

Measured memory_bytes: 73676
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

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

   int right = 0;
   ll sum = 0;
   ll ans = 0;
   for (int left = 0; left < N; left++) {
      while (right < N && (sum ^ a[right]) == (sum + a[right])) {
         sum += a[right];
         right++;
      }
      ans += right - left;
      if (right == left) right++;
      else sum -= a[left];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

const int mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    ll ans = 1;
    
    if (
        ((N == 0) && (M == 0)) ||
        ((N + 1) < M) ||
        ((M + 1) < N)
    ) {
        cout << 0 << endl;
        return 0;
    }
    
    reps(i, 2, N + 1) {
        ans = ans * i % mod;
    }
    
    reps(i, 2, M + 1) {
        ans = ans * i % mod;
    }
    
    if (N == M) {
        ans = ans * 2 % mod;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long int n;
  cin>>n;
  int a[n],k;
  for(int i=0;i<n;i++)
  {
      a[i]=0;
  }
  while(cin>>k)
  {
      a[k-1]=a[k-1]+1;
  }
  for(int i=0;i<n;i++)
  {
      cout<<a[i]<<"\n";
  }
}


Measured memory_bytes: 4404
/*
 * Click `Run` to execute the snippet below!
 */

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int A = sc.nextInt();
    System.out.println((int) (Math.ceil(1.0 * H / A)));
  }
}


Measured memory_bytes: 35688
N=int(input())
l = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N):
    t=0
    for j in range(i,N-1):
        if t>l[j][1]:
            while 1:
                if t%l[j][2]==0:
                    break
                else:
                    t+=1
            t+=l[j][0]
        else:
            t=l[j][1]+l[j][0]
    print(t)   

Measured memory_bytes: 45148
#include<cstdio>
#include<cmath>
using namespace std;
int dp[10010];

int prime(int n) {
	int i, j,d;
	if (n == 1) { return dp[1] = 2; };
	d = dp[n - 1];
	for (i = d+1;; i++) {
		for (j = 2;; j++) {
			if (i%j == 0)break;
			if (j == (int)sqrt(i)+1) { return dp[n] = i; }
		}
	}
}

int main() {
	int n, i;
	long long sum = 0;
	while (scanf("%d", &n) && n){
		if (n == 0)break;
		for (i = 1; i <= n; i++)sum += prime(i);
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 1064
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let colors = vec![
        (1..=399),
        (400..=799),
        (800..=1199),
        (1200..=1599),
        (1600..=1999),
        (2000..=2399),
        (2400..=2799),
        (2800..=3199),
    ];
    let mut set = std::collections::BTreeSet::new();
    let mut w = 0;
    for &a_i in a.iter() {
        match colors.iter().position(|r| r.contains(&a_i)) {
            Some(p) => {
                set.insert(p);
            }
            None => w += 1,
        }
    }
    println!("{} {}", std::cmp::max(1, set.len()), set.len() + w);
}


Measured memory_bytes: 2128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={1,0,-1,1,-1,1,0,-1};
char in[60][60];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(in[i][j]=='#')continue;
			int cnt=0;
			for(int k=0;k<8;k++){
				int tr=i+dx[k];
				int tc=j+dy[k];
				if(tr>=0&&tc>=0&&tr<a&&tc<b&&in[tr][tc]=='#')cnt++;
			}
			in[i][j]='0'+cnt;
		}
	}
	for(int i=0;i<a;i++)printf("%s\n",in[i]);
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        long[] m = new long[n];
        long[] l = new long[n + 1];
        long[] r = new long[n + 1];
        for (int i = 0; i < n; i++) {
            l[i + 1] = gcd(l[i], a[i]);
        }
        for (int i = n - 1; i >= 0; i--) {
            r[i] = gcd(r[i + 1], a[i]);
        }

        long ans = 0;
        for (int i = 0; i < n; i++) {
            long num = gcd(l[i], r[i + 1]);
            ans = Math.max(ans, num);
        }
        System.out.println(ans);
    }
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 26168
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val (n, m) = readLongList()
    val s = readString()
    val t = readString()

    val l = lcm(n, m)
    val tmp = mutableMapOf<Long, Char>()
    s.forEachIndexed { index, c ->
        tmp[index * l / n] = c
    }

    t.forEachIndexed { index, c ->
        if(tmp[index * l / m]?.let { it != c } == true) {
            println(-1)
            return
        }
    }
    println(l)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

// 最大公約数
fun gcd(p: Long, q: Long): Long = if (p % q == 0L) q else gcd(q, p % q)

// 最小公倍数
fun lcm(p: Long, q: Long): Long = p / gcd(p, q) * q

Measured memory_bytes: 47596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    VL a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    int left = 0, right = 0;
    VI d2(30);
    while(right < n){
        rep(i, 30) d2[i] += ((a[right] >> i) & 1);
        bool ok = true;
        rep(i, 30) if (d2[i] >= 2) ok = false;

        if (!ok){
            while(left < right){
                rep(i,30) d2[i] -= ((a[left] >> i) & 1);
                left++;
                bool ch = true;
                rep(i, 30) if (d2[i] >= 2) ch = false;
                if (ch) break;
            }
        }

        ans += (right - left + 1LL);
        right++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i = 0; i < (int)(n);i++)
typedef long long ll;
using namespace std;
int n;
vector<pair<int, int> > tasks;
int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
	tasks.emplace_back(b, a); 	
	}
	sort(tasks.begin(), tasks.end());
    int sum = 0;
    bool isyes = true;
    for (auto v : tasks) {
    sum += v.second;
			
	     if (sum > v.first) {
             isyes = false;
              break;
	     }
	}
    cout << (isyes ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>

using namespace std;
int main(){
    int a,b,c = 0;
    cin >> a >> b >> c;
    if (a <= b && a <= c){
        if (c <= b){
            int k = b;
            b = c;
            c = k;
        }
    } else if (b <= a && b <= c){
        int k = a ;
        a = b ;
        b = k ;
        if (c <= b){
            int k = b;
            b = c;
            c = k;
        }
    } else if (c <= a && c <= b){
        int k = a ;
        a = c ;
        c = k ;
        if (c <= b){
            int k = b;
            b = c;
            c = k;
        }
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N;
    cin >> N;
    ll mod = 1000000007;
    ll ans = 0;
    vector<int> A(N);
    vector<ll> B(N+1, 0); //累積和
    rep(i, N) {
        cin >> A[i];
        B[i+1] = B[i]+A[i];
    }

    rep(i, N) {
        ll sum = (B[N]-B[i+1])%mod;
        ans += A[i]*sum;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5588
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, M) = Slice2<long>();
            if (N == 1 && M == 1)
            {
                WriteLine(1);
                return;
            }
            if (N == 1 || M == 1)
            {
                WriteLine(N * M - 2);
                return;
            }
            WriteLine((N - 2) * (M - 2));
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27540
#include <algorithm>
#include <cstdio>
#include <set>
int fa[100005];
std::set<int> adj[100005];
std::set<std::pair<int, int> > que;
int getfa(int u)
{
	if (u == fa[u])
		return u;
	return fa[u] = getfa(fa[u]);
}
inline void add_edge(int u, int v)
{
	if (adj[u].count(v))
	{
		adj[u].erase(v);
		if (u > v)
			std::swap(u, v);
		que.insert({u, v});
	}
	else
		adj[u].insert(v);
}
int main()
{
	// freopen("AGC014-E.in", "r", stdin);
	int n, ans = 0;
	scanf("%d", &n);
	for (int i = 2; i < n << 1; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add_edge(--u, --v);
		add_edge(v, u);
	}
	for (int i = 0; i < n; i++)
		fa[i] = i;
	while (!que.empty())
	{
		auto e = *que.begin();
		que.erase(que.begin());
		ans++;
		int u = getfa(e.first), v = getfa(e.second);
		if (adj[u].size() > adj[v].size())
			std::swap(u, v);
		fa[u] = v;
		for (auto x : adj[u])
		{
			adj[x].erase(u);
			add_edge(x, v);
			add_edge(v, x);
		}
		adj[u].clear();
	}
	puts(ans == n - 1 ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 24064
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val read = scala.io.StdIn.readLine()
  val array =  read.split(" ").map(_.toInt).toVector
  val array_sorted = array.sorted
  var diff = 0
  array.zipWithIndex.foreach { case (j, index) =>
    if(j != array_sorted(index)) {
      diff = diff + 1
    }
  }
  if (diff <= 2) {
    println("YES")
  } else {
    println("NO")
  }
}

Measured memory_bytes: 27332
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(long long i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;
 
  int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a;
  char c;
  string s="";
  cin>>a;
  while(a!=0){
    c='a'+(a-1)%26;
    s=c+s;
    a=(a-1)/26;
  }
  cout<<s;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    ans+=min(k,a);
    k-=min(a,k);
    k-=min(k,b);
    ans-=min(k,c);
    k-=min(k,c);
    cout<<ans<<"\n";
}


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

using namespace std;

int N;
vector< int > g[100000];

int rec(int idx)
{
  vector< int > depth;
  for(auto &to : g[idx]) {
    depth.push_back(rec(to));
  }
  // 深さをなるべくならしたい
  // 深い人たちから最初に対戦したほうがよいため
  sort(depth.rbegin(), depth.rend());
  int ret = 0;
  for(int i = 0; i < depth.size(); i++) {
    ret = max(ret, depth[i] + i + 1);
  }
  return (ret);
}

int main()
{
  cin >> N;
  for(int i = 1; i < N; i++) {
    int x;
    cin >> x;
    --x;
    g[x].push_back(i);
  }
  cout << rec(0) << endl;
}

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

int main()
{
    int n, q, l, r, i;
    string s;
    cin >> n >> q;
    cin >> s;
    int a[n + 1] = {};

    for (i = 0; i < n; i++)
    {
        if (i != 0 && s[i - 1] == 'A' && s[i] == 'C')
            a[i] = a[i - 1] + 1;
        else if (i == 0)
            a[i] = a[i];
        else
            a[i] = a[i - 1];
    }
    while (q--)
    {
        cin >> l >> r;
        l--, r--;
        if (l == 0)
            cout << a[r] << endl;
        else
            cout << a[r] - a[l] << endl;
    }
}

Measured memory_bytes: 1408
// //Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
#include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
using namespace std;
int n, ans;

void Solve(vector<pair<int, int>>& cams)
{
    priority_queue<int> pq;
    // int result = 0;
    int initalAns = ans;

    for(auto i : cams)
    {
        pq.push(-i.second);
        ans+=i.second;
        //we assume its left is best
        while(pq.size()>i.first)ans+=pq.top(),pq.pop();
    }

}

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

    int testcases;
    cin >> testcases;
    while(testcases--)
    {

        cin>>n;ans=0;

        std::vector<pair<int, int>> f;
        std::vector<pair<int, int>> b;

        for(int i = 1; i <=  n; i++)
        {
            int K, L, R;
            cin >> K >> L >> R;

            if(L>R)
            {
                ans+=R;
                f.push_back({K,L-R});
            }
            else{
                ans+=L;
                b.push_back({n-K,R-L});
            }
        }

    // rep(i,1,n)cin>>k[i]>>l[i]>>r[i];
    // rep(i,1,n){
    //     if(l[i]>r[i]){
    //         ans+=r[i];
    //         f.pb({k[i],l[i]-r[i]});
    //     }
    //     else{
    //         ans+=l[i];
    //         b.pb({n-k[i],r[i]-l[i]});
    //     }
    // }
    sort(all(f));
    sort(all(b));

    Solve(f);
    Solve(b);

        std::cout << ans << "\n";

    }

    return 0;
}


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

int main() {
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int total = (h2-h1)*60+m2-m1;
    total = total - k;
    cout<<total<<endl;
    
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define M 200005
int sl[M],mp[M],vs[M];
char S[M];
inline void rd(int &l){
	l=0;int f=0;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){l=l*10+ch-'0';ch=getchar();}
	if(f)l=-l;
}
int main(){
	int N,K,C,tp=1;
	rd(N);rd(K);rd(C);
	scanf("%s",S+1);
	for(int i=1;i<=N;++i)mp[i]=(S[i]=='x');
	for(int i=1;i<=K;++i){
		while(tp<=N&&mp[tp])++tp;
		sl[i]=tp;
		tp+=C+1;
	}
	if(K&&sl[K]){
		tp=N;
		for(int i=K;i;--i){
			while(tp&&mp[tp])--tp;
			vs[i]=tp;
			// printf("%d %d\n",sl[i],vs[i]);
			tp-=C+1;
		}
		for(int i=1;i<=K;++i)if(vs[i]==sl[i])printf("%d\n",vs[i]);
	}
	// getchar();
	// getchar();
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s; cin>>s;
	int count=1;
	for (int i=1; i<4; i++) {
		if (count>=3) break;
		if (s[i]==s[i-1])
			count++;
		else
			count=1;
	}
	if (count>=3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N;
	cin >> N;

	vector <ll> A(N);
	for (ll ii = 0; ii < N; ++ii){
		cin >> A[ii];
	}
	A.push_back(0);

	ll m = 1000;
	ll s = 0;
	for (ll ii = 0; ii < N; ++ii){
		m += s*A[ii];
		s = 0;
		if (A[ii] < A[ii+1]){
			s = m / A[ii];
			m -= s*A[ii];
		}
	}

	cout << m << "\n";

	return 0;
}


Measured memory_bytes: 3580