akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(m), dist(m - 1), csum(m + 1);
  rep(i, m) cin >> x[i];
  sort(x.begin(), x.end());
  rep(i, m - 1) dist[i] = x[i + 1] - x[i];
  sort(dist.rbegin(), dist.rend());
  int ans = x[m - 1] - x[0];
  rep(i, n - 1) ans -= dist[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  string s;
  cin >> n >> s;
  ll h = s.length();
  s = s + "nn";
  ll f = 0;
  rep(i,h){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2]=='C'){
      f++;
    }
  }
  pri(f);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

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

	ll n, m;
	cin >> n >> m;
	vector<ll> a(n + 1, 0);
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	partial_sum(a.begin(), a.end(), a.begin());

	ll ans = 0;
	map<ll, ll> occ;
	for (auto &&x : a) {
		x %= m;
		ans += occ[x]++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#include<map>
#include<utility>
#include<cstdlib>
#include<vector>
#include<functional>
#include<string>
#include<set>
#include<map>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MAX = 2000000;
char maze[20][25];
int ans=0,sx,sy,H,W;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){

	int N,A,B;
	cin >> N >> A >> B;
	if((B-A)%2==0) cout <<"Alice" <<endl;
	else cout << "Borys" <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num, surplus;

	scanf("%d", &num);

	surplus = num % 10;

	if (surplus == 3)
	{
		printf("bon\n");
	}
	else if(surplus == 0 || surplus == 1 || surplus == 6 || surplus == 8)
	{
		printf("pon\n");
	}
	else
	{
		printf("hon\n");
	}

	return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main() {
    int n;
  	int t, a;
    cin >> n;
  	cin >> t >> a;
  	double h[n];
  	int i;
  	int candi;
  	double dif; 
  	double good = 100000.;
  	double conf = (t-a)*1000/6;
  for(i=0;i<n;i++){
    cin >> h[i];
    dif = abs(h[i]- conf);
    if(good > dif){
    good = dif;
    candi = i;
    };
  };
    cout << candi+1 <<"\n";
}

Measured memory_bytes: 256
N = int(input())
A = []
cnt = []

for i in range(N):
    a = input()
    A.append(a)
for i in range(N):
    cnt.append(A.count(A[i]))
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        cnt.append(1)
if cnt.count(1) == (N  + (N-1)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline


def main():
    N = int(input())

    ans = 0
    for i in range(1, N + 1):
        if (i % 3 != 0) and (i % 5 != 0):
            ans += i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
n = int(input())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7
ans = 1
d = [0,0,0]
for x in a:
  tmp = 0
  for k in range(3):
    if x == d[k]:
      if tmp == 0:
        d[k] += 1
      tmp += 1
  ans *= tmp
  ans %= mod
print(ans)

Measured memory_bytes: 14056
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N, M = [int(x) for x in input().split()]
    ps = []
    ac = set()
    acnum = 0
    wanum = Counter()
    for _ in range(M):
        p, s = [x for x in input().split()]
        if s == "WA":
            if int(p) not in ac:
                wanum[int(p)] += 1
        if s == "AC":
            if int(p) not in ac:
                acnum += 1
                ac.add(int(p))
        #ps.append(int(p), s)

    wanum2 = 0
    for i in wanum.keys():
        if i in ac:
            wanum2 += wanum[i]

    print(acnum, wanum2)





if __name__ == '__main__':
    main()



Measured memory_bytes: 12260
import collections

N, M = map(int,input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = input().split()
C = A + B
D = collections.Counter(C)
for i in D:
    if D[i] % 2 == 0:
        continue
    else:
        print('NO')
        exit()
print('YES')


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

using namespace std;

int a, b, n;

int caut_binar(int st, int dr, int x, vector <int>&v)
{
    int ans = st - 1;

    while (st <= dr)
    {
        int mij = (st + dr) / 2;
        if (v[mij] < x)
        {
            ans = mij;
            st = mij + 1;
        }
        else
        {
            dr = mij - 1;
        }
    }

    return ans;

}

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

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


    for (int i = 0; i < n ; i++)
        for (int j = i + 1; j < n; j++)
    {
        int x = V[i] + V[j];
        int mij = caut_binar(j + 1, n - 1, x, V);
        //cout << mij << " ";
        NumberOfSolution += mij - j;
    }

    cout  << NumberOfSolution;
    return 0;
}


Measured memory_bytes: 256
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<long long int>>;
using wgraph = vector<vector<pair<long long int, long long int>>>;
long long int INF = 1001001001001001LL;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(long long int i = 0; i < (n); i++)
#define rrep(i,n) for(long long int i = 1; i <= (n); i++)
#define drep(i,n) for(long long int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(long long int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int n, k, q; cin >> n >> k >> q;
  vector<int> score(n, k - q);

  for(int i = 0; i < q; i++) {
    int a; cin >> a;
    a--;
    score[a]++;
  }

  for(int i = 0; i < n; i++) {
    if(score[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


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

INF = float("inf")


def main():
    n, k = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    h.sort()
    ans = INF
    for i in range(n - k + 1):
        ans = min(ans, h[i+k-1] - h[i])
    print(ans)

if __name__ == '__main__':
    main()

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

const int maxn = 2e5;
ll n, T, prevT, ans;

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

	cin >> prevT;
	for(ll i=0, temp; i<n-1; i++){
		cin >> temp;
		if(temp-prevT>T){
			ans += T;
		}
		else{
			ans += temp-prevT;
		}
		prevT = temp;
	}

	ans+=T;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a));
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define MP make_pair
#define ULL unsigned long long
#define LL   long long
#define inf 0x3f3f3f3f
#define md ((ll+rr)>>1)
#define ls (i<<1)
#define rs (ls|1)
#define eps 1e-5
#define ree freopen("in.txt","r",stdin);
#define bug pf("----------------");
#define N 300010



bool ok[N];
int main(){
    int n;sf("%d",&n);
    int cnt=0;
    int ans=0;
    bool wait=false;
    mem(ok,false);
    rep(i,1,n){ int x;sf("%d",&x);if(x==i)ok[i]=true; }
    for(int i=1;i<=n;++i){
        if(i==n&&ok[i])ans++;
        if(ok[i]&&ok[i+1]&&i<n){ok[i]=ok[i+1]=false;ans++;}
        if(ok[i]&&!ok[i+1]&&i<n){ok[i]=false;ans++;}
    }

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


Measured memory_bytes: 512
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x,y = map(int, input().split())
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import sys


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return list(map(int, input().split()))


def main():
    x, n = tuple(input_ints())
    pp = input_ints()

    d = 0
    while True:
        if not x-d in pp:
            print(x - d)
            break
        if not x+d in pp:
            print(x + d)
            break
        d += 1

main()


Measured memory_bytes: 9188
import numpy as np
def resolve():
    n, k = map(int, input().split())
    a = np.array(input().split(), dtype=np.int64)
    a.sort()

    zero = np.count_nonzero(a == 0)
    positive = a[a > 0]
    negative = a[a < 0]

    def count(x):  # 積が x 以下のペアは何個あるか？
        ans = 0
        if x >= 0:  # 片側が 0 の場合
            ans += n * zero
        ans += np.searchsorted(a, x // positive, side="right").sum()  # 片側が正の場合
        ans += n * len(negative) - np.searchsorted(a, -(-x // negative), side="left").sum()  # 片側が負の場合 切り上げは -(-a//b)
        ans -= np.count_nonzero(a * a <= x)  # 同じもの2つは選べない
        return ans // 2

    ok = 10 ** 18
    ng = -ok - 1
    while ok - ng > 1:  # 二分探索
        cen = (ok + ng) // 2
        if count(cen) >= k:
            ok = cen
        else:
            ng = cen
    print(ok)

if __name__ == "__main__":
    resolve()


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

int main() {
  int64_t n;
  cin >> n;
  if (n % 2 == 1) {
    cout << 0;
  } else {
    int64_t result = 0;
    for (int64_t i = 5; i <= n; i *= 5) {
      result += n / i / 2;
    }
    cout << result;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 59
#define LL long long
int main(){
	int n,m;
	cin>>n>>m;
	LL a[MAXN], b[MAXN], c[MAXN], d[MAXN];
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=m;i++){
		cin>>c[i]>>d[i];
	}
	for(int i=1;i<=n;i++){
		LL dist;
		LL min=abs(a[i]-c[1])+abs(b[i]-d[1]);
		int ind=1;
		for(int j=1;j<=m;j++){
			dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(dist<min){
				min=dist;
				ind=j;
			}
		}
		cout<<ind<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    //system("chcp 65001");

    int N;
    cin >> N;
    if(N <= 999)
    {
        cout << "ABC";
    }
    else
    {
        cout << "ABD";
    }
    
    //cout << N;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

dp = [0] * N

dp[0] = P[0]

for i in range(1, N):
    dp[i] = min(dp[i - 1], P[i])

res = 0
for i in range(N):
    if dp[i] >= P[i]:
        res += 1

print(res)

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

using namespace std;

int main(){
    int T;
    cin >> T;
    for (int t = 0; t < T; t++){
    [](){
        int n;
        cin >> n;
        vector<int64_t> K(n), L(n), R(n);
        for (int i = 0; i < n; i++){
            cin >> K[i] >> L[i] >> R[i];
            K[i]--;    
        }

        vector<vector<int64_t>> LL(n), RR(n + 1);
        int64_t ans = 0;
        for (int i = 0; i < n; i++){
            if (L[i] > R[i])
                LL[K[i]].push_back(L[i] - R[i]);
            else
                RR[K[i] + 1].push_back(R[i] - L[i]);
            ans += max(L[i], R[i]);
        }

        priority_queue<int64_t, vector<int64_t>, greater<int64_t>> Q;
        for (int i = 0; i < n; i++){
            for (const auto &ll: LL[i])
                Q.push(ll);
            while (Q.size() > i + 1){
                ans -= Q.top();
                Q.pop();
            }
        }

        while (!Q.empty())
            Q.pop();
        for (int i = n; i >= 0; i--){
            for (const auto &rr: RR[i])
                Q.push(rr);
            while (Q.size() > n - i){
                ans -= Q.top();
                Q.pop();
            }
        }

        cout << ans << endl;
    }();
    }
}

Measured memory_bytes: 23040
using System;
class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    int l = int.Parse(s.Substring(0, 2));
    int r = int.Parse(s.Substring(2, 2));
    
    if ((1 <= l && l <= 12) && (1 <= r && r <= 12)) {
      Console.WriteLine("AMBIGUOUS");
    } else if ((1 <= l && l <= 12) && !(1 <= r && r <= 12)) {
      Console.WriteLine("MMYY");
    } else if (!(1 <= l && l <= 12) && (1 <= r && r <= 12)) {
      Console.WriteLine("YYMM");
    } else {
      Console.WriteLine("NA");
    }
  }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

int main() {
    int n;
    cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++){
        cin>>d.at(i);
    }
    sort(d.begin(),d.end());
    int m;
    cin>>m;
    vector<int>t(m);
    for(int i=0;i<m;i++){
        cin>>t.at(i);
    }
    sort(t.begin(),t.end());
    int j=0;
    for(int i=0;i<m;i++){
        while(j<n){
            if(t.at(i)==d.at(j)){
                j++;
                break;
            }
            else{
                if(t.at(i)<d.at(j)){
                    cout<<"NO"<<endl;
                    return 0;
                }
                j++;
            }
        }
    }
    cout<<"YES"<<endl;




    return 0;
}


Measured memory_bytes: 1792
H, W = map(int, input().split())
cnt = [[0] * W for _ in range(H)]
S = [list(input()) for _ in range(H)]

for i in range(H):
    done = [0] * W
    for j in range(W):
        if S[i][j] == '#':
            continue
        if done[j]:
            continue
        l = 0
        while j + l < W:
            if S[i][j+l] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i][j+k] += l
            done[j+k] = 1

for j in range(W):
    done = [0] * H
    for i in range(H):
        if S[i][j] == '#':
            continue
        if done[i]:
            continue
        l = 0
        while i + l < H:
            if S[i+l][j] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i+k][j] += l
            done[i+k] = 1
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, cnt[i][j]-1)
print(ans)

Measured memory_bytes: 221320
#include <iostream>
#include <vector>
#define NIL (-1)
using namespace std;

struct BinaryTreeNode {
	int p;// parent
	int l;// left child
	int r;// right child
	int sibling;
	int d;// depth
	int h;// height
};

void set_depth (int id, int depth, vector<BinaryTreeNode> &T) {
	if (id == NIL) return;
	T[id].d = depth;
	set_depth(T[id].l, depth + 1, T);
	set_depth(T[id].r, depth + 1, T);
}

int set_height (int id, vector<BinaryTreeNode> &T) {
	if (id == NIL) return -1;// leaf nodeのheightが0になるように-1とする.
	// left and right heights
	int lh = 1 + set_height(T[id].l, T);
	int rh = 1 + set_height(T[id].r, T);
	T[id].h = (lh > rh) ? lh : rh;
	return T[id].h;
}

void set_sibling_id (int id, vector<BinaryTreeNode> &T) {
	if (id == NIL || T[id].p == NIL) { T[id].sibling = NIL; return; }
	if (T[T[id].p].l != id) T[id].sibling = T[T[id].p].l;
	else if (T[T[id].p].r != id) T[id].sibling = T[T[id].p].r;
	else T[id].sibling = NIL;
}

// an example of an output line;
// node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf
//
void print (vector<BinaryTreeNode> &T) {
	for (int i=0; i<T.size(); ++i) {
		int degree = ((T[i].l != NIL) ? 1 : 0) + ((T[i].r != NIL) ? 1 : 0);
		string type;
		if (T[i].p == NIL) {
	 		type = "root";
		} else if (T[i].l == NIL && T[i].r == NIL) {
			type = "leaf";
		} else {
			type = "internal node";
		}		
		cout << "node " << i << ": parent = " << T[i].p << ", ";
		cout << "sibling = " << T[i].sibling << ", degree = ";
		cout << degree << ", depth = " << T[i].d << ", height = ";
		cout << T[i].h << ", " << type; 
		cout << endl;
	}
}

int main() {
	int n;
	cin >> n;
	vector<BinaryTreeNode> T(n);
	/// initialization
	for (int i=0; i<n; ++i) {
		T[i].p = T[i].l = T[i].r = NIL;
		T[i].d = T[i].h = NIL;
	}
	/// settings input information
	for (int i=0; i<n; ++i) {
		int id, lc, rc; // id, left child, right child
		cin >> id >> lc >> rc;
		BinaryTreeNode &t = T[id];
		t.l = lc;
		t.r = rc;
		if (lc != NIL) T[lc].p = id;
		if (rc != NIL) T[rc].p = id;
	}
	/// finding the root node
	int root_id = NIL;
	for (int i=0; i<n; ++i) {
		if (T[i].p == NIL) root_id = i;
	}
	/// setting depths
	set_depth(root_id, 0, T);
	/// setting heights	
	set_height(root_id, T);
	/// setting sibling ids
	for (int i=0; i<n; ++i) set_sibling_id(i, T);
	/// print
	print(T);
	return 0;
}




Measured memory_bytes: 3192
from collections import defaultdict
from heapq import heappush, heappop
from collections import deque
n, x, y = list(map(int, input().split()))
G = [[]*n for _ in range(n)]

for i in range(n-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[x-1].append(y-1)
G[y-1].append(x-1)

N = n
# G[v]: 頂点vに隣接する頂点list
# N: 頂点数
dd = []
for i in range(n):
    dist = [-1]*N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    dd.append(dist)
ans = defaultdict(lambda: 0)
for dist in dd:
    for t in dist:
        ans[t] += 1
for i in range(n-1):
    print(ans[i+1]//2)


Measured memory_bytes: 81756
N = int(input())
str_numbers = input().split(" ")
numbers = [int(str_num) for str_num in str_numbers]
memo = []
match = 1
count = 0
for i in range(len(numbers)):
  if numbers[i] == match:
    match += 1
    count += 1

if count > 0:
  print(N - count)
elif count == 0:
  print(-1)


Measured memory_bytes: 26012
#include <stdio.h>

int main(void){
    int h, w;
    char s[50+5][50+5];
    scanf("%d %d", &h, &w);
    for(int i=0; i<h; i++)scanf("%s", s[i]);
    
    int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
    int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
    
    for(int y=0; y<h; y++){
        for(int x=0; x<w; x++){
            if(s[y][x]=='.'){
                int cnt=0;
                for(int d=0; d<8; d++){
                    if(y+dy[d]>=0 && y+dy[d]<h && x+dx[d]>=0 && x+dx[d]<w){
                        if(s[y+dy[d]][x+dx[d]]=='#')cnt++;
                    }
                }
                printf("%d", cnt);
            }else{
                printf("#");
            }
        }
        printf("\n");
    }
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> v,p,q;
    for(int i=0;i<n;i++){
        int pp; cin >> pp;
        p.push_back(pp);
        v.push_back(i+1);
    }
    for(int i=0;i<n;i++){
        int qq; cin >> qq;
        q.push_back(qq);
    } 
    int a,b,cnt=1;
    do{
        bool pf=true,qf=true;
        for(int i=0;i<n;i++){
            if(p[i]!=v[i]) pf=false;
            if(q[i]!=v[i]) qf=false;
        }
        if(pf) a=cnt;
        if(qf) b=cnt;
        cnt++;
    } while(next_permutation(v.begin(), v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

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

ans=(60+(60+120*((N//15)-1)))*(N//15)/2

if N%15==0: print(int(ans))
if N%15==1: print(int(ans+1+15*(N//15)))
if N%15==2 or N%15==3: print(int(ans+1+2+30*(N//15)))
if N%15>=4 and N%15<=6: print(int(ans+1+2+4+45*(N//15)))
if N%15==7: print(int(ans+1+2+4+7+60*(N//15)))
if N%15>=8 and N%15<=10: print(int(ans+1+2+4+7+8+75*(N//15)))
if N%15==11 or N%15==12: print(int(ans+1+2+4+7+8+11+90*(N//15)))
if N%15==13: print(int(ans+1+2+4+7+8+11+13+105*(N//15)))
if N%15==14: print(int(ans+1+2+4+7+8+11+13+14+120*(N//15)))


Measured memory_bytes: 9284
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    cout << (s < t ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args:Array[String]):Unit = {
    val sc:Scanner = new Scanner(System.in)
    
    val a = Array(sc.nextInt, sc.nextInt, sc.nextInt)
    
    if (a.sorted sameElements Array(5, 5, 7)) println("YES") else println("NO")
  }
}

Measured memory_bytes: 25516
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(12)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
#define    fbo    find_by_order
#define    ook    order_of_key
#define    upb    upper_bound
#define    lowb   lower_bound 
#define    lte(v,x)   upb(all(v),x)-v.be()
#define    gte(v,x)   v.end()-lowb(all(v),x)
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{


string s,t;
cin>>s>>t;

if(s.length()==t.length()-1&&t.substr(0,s.length())==s)
cout<<"Yes";
else
cout<<"No";













}return 0;}

Measured memory_bytes: 3616
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFINITY 1000000000
#define NIL -1

int Array[MAX][MAX];

int prim(int n){
	int u,min;
	int d[MAX],p[MAX],color[MAX];
	int i,j;
	int cnt = 0;

	for(i=0;i<n;i++){
		d[i] = INFINITY;/* ∞ */
		p[i] = NIL;
		color[i] = WHITE;
	}/*初期化*/

	d[0] = 0;

	while(1){
		min = INFINITY;
		u = NIL;
		for(i=0;i<n;i++){
			if(min > d[i] && color[i] != BLACK){
				u=i;
				min = d[i];
			}
		}
		////if(u == NIL) break;
		if(min == INFINITY) break;
		color[u] = BLACK;
		for(j=0;j<n;j++){
			////if(color[j] != BLACK && Array[u][j] != INFINITY){
			if(color[j] != BLACK && Array[u][j] < d[j]){
				if(d[j] > Array[u][j]){
					d[j] = Array[u][j];
					p[j] = u;
					color[j] = GRAY;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		if(p[i] != NIL) cnt = cnt + Array[i][p[i]];
	}
	return cnt;
}

int main(){

	int n,i,j;
	scanf("%d",&n);

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&Array[i][j]);
			if(Array[i][j] == NIL) Array[i][j] = INFINITY;
		}
	}

	printf("%d\n",prim(n));

	return 0;
}


Measured memory_bytes: 2052
x = gets.strip.to_i

include Math

#素数の配列を返すメソッド
def fetch_prime_list(max)
  table = Array.new(max + 1,true)
  prime_list = []

  (2..max).each do |num|
      if table[num] == true
        prime_list << num
      k = num * num
      while k <= max
        table[k] = false
        k += num
      end
    end
  end
  return prime_list
end

#配列を返すメソッド
list = fetch_prime_list(100003)
(0..list.length).each do |i|
  if list[i] >= x
    puts list[i].to_s
    exit
  end 
end

Measured memory_bytes: 2684
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

nmax=8
graph=[[False for __ in range(nmax)]for _ in range(nmax)]

def dfs(v,n,visited):
  visited[v]=True

  all_visited=True
  for i in range(n):
    if visited[i]==False:
      all_visited=False
  if all_visited:
    return 1

  ret=0
  for i in range(n):
    if graph[v][i]==False:
      continue
    if visited[i]:
      continue
    visited[i]=True
    ret+=dfs(i,n,visited)
    visited[i]=False

  return ret

def main():
  n,m=LI()
  for _ in range(m):
    a,b=LI()
    graph[a-1][b-1]=True
    graph[b-1][a-1]=True

  visited=[False for _ in range(n)]
  visited[0]=True
  return dfs(0,n,visited)

# main()
print(main())


Measured memory_bytes: 6612
/*
 
Sviatoslav Bidzilia 2020
CF: anakib1
 
*/
 
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <functional>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a), [](int x, int y){return x > y;})
#define pii pair<int, int>
#define tii triple<int, int, int>
#define sz(x) (int)(x.size())
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
 
template<typename A, typename B, typename C>
struct triple
{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a)
{
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
    return min(a, min(b, c));
}
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
signed main()
{
    //freopen(".in", "r", stdin);a
    //freopen(".out", "w", stdout);
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n, x, y; cin >> n >> x >> y; x--; y--;
    vi ans(n);
    rngi(i, n) for(int j = i + 1; j < n; j++) ans[min(j-i, abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j))]++;
    for(int i =  1; i < n; i++) cout<<ans[i]<<'\n';
}
//check corner case (interactives!)
//check n=1 or n=2
//check size of arrays
//more asserts
//scanf printf
//read everything normaly



Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
	ll n,m,k; cin>>n>>m>>k;
	vector<ll>pref(n);

	ll ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	ll mx=0;
	pref[0]=ar[0];
	if(ar[0]<=k)
	{
		mx=1;
	}
	for(int i=1;i<n;i++)
	{
		pref[i]=pref[i-1]+ar[i];
		if(pref[i]<=k)
		{
			mx=max(mx,(ll)i+1);
		}
	}
	ll sm=0;
	
	for(int i=0;i<m;i++)
	{
	
		ll x; cin>>x;
		//if(sm<=k){mx=max(mx,(ll)i);}
		sm+=x;
		if(sm<=k){
		ll it=upper_bound(pref.begin(),pref.end(),k-sm)-pref.begin();
        ll value=i+it+1;
		mx=max(mx,value);
		}
		
		
		
	}
	cout<<mx;
	
	
	
	
	
	
	
}


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

int main(){
	int L, A, B, C, D;
	int jap, mat;
	
	scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
	
	jap = (A + C - 1) / C;
	mat = (B + D - 1) / D;
	
	printf("%d\n", L - max(jap, mat));
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(void) {
   int i;
   int n, d;
   int cnt = 0;

   scanf("%d %d", &n, &d);

   double x[n], y[n];
   double d0[n];

   for(i = 0; i < n; i++) {
      scanf("%lf %lf", &x[i], &y[i]);
   }

   for(i = 0; i < n; i++) {
      d0[i] = sqrt(x[i]*x[i] + y[i]*y[i]);

      if(d0[i] <= d) {
         cnt++;
      }
   }

   printf("%d\n", cnt);

   return 0;
}


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

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

	int ans = 1;
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		int num = i;
		int j = 0;
		while(num % 2 == 0) {
			num /= 2;
			j++;
		}
		if(j > cnt) {
			cnt = j;
			ans = i;
		}
	}

	cout << ans << endl;

 	return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;

int n;

int main(){
	scanf("%d", &n);
	ll ans = 1, res = 1, res2 = 1;
	FOR(i, 0, n){
		(ans *= 10) %= INF;
		(res *= 9) %= INF;
		(res2 *= 8) %= INF;
	}
	((ans -= res * 2 % INF) += INF) %= INF;
	(ans += res2) %= INF;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

vector<vector<ll>> g;
vector<ll> memo;
ll ind = 0;
vector<ll> c, t;
ll tot = 0;
ll dfs(ll v, ll p, ll& ind){
    if(memo[v]) return 0;
    memo[v] = c[ind++];
    if(p != -1){
        tot += min(memo[v],memo[p]);
    }
    for(auto& u:g[v]){
        dfs(u,v,ind);
    }
}


int main(){
    ll N, a, b;
    cin >> N;
    vector<Pll> h(N);
    
    g = vector<vector<ll>>(N);
    memo = vector<ll>(N);
    c = vector<ll>(N);
    //d = vector<ll>(N);

    rep(i,N-1){
        cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    rep(i,N){
        cin >> c[i];
    }
    sort(c.begin(),c.end(),greater<ll>());
    dfs(0,-1,ind);
    cout << tot << endl;
    PR(memo,N);
    /*ll tot = 0;
    rep(i,N){
        tot += c[i];
    }
    tot -= c[0];
    cout << tot << endl;
    
    /*
    rep(i,N){
        h[i] = Pll(g[i].size(), i);
    }
    sort(h.begin(),h.end(),greater<Pll>());
    ll tot = 0;
    ll cur = 0;
    rep(i,N){
        if(cur >= N) break;
        rep(j,g[h[cur].second].size()){
            if(t[g[h[cur].second][j]] != 0){
                t[g[h[cur].second][j]] = c[i];
                i++;
            }
        }
        t[h[cur].second] = c[i];
        cur++;
        //tot += c[i]*h[i].first;
    }
    rep(i,N){
        rep(j,g[i].size()){
            tot += min(t[i], t[g[i][j]]);
        }
    }
    cout << tot/2 << endl;*/    
}

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

int main(void){
    int N;cin>>N;
    vector<int>S(N);
    int count=0;
    for(int i=0;i<N;i++){
        cin>>S[i];
        count+=S[i];
    }
    if(count%10!=0){
        cout<<count<<endl;
        return 0;
    }
    sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        int tmp=count-S[i];
        if(tmp%10!=0){
            cout<<tmp<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj;
bool vis[N];
int dp[N];
int help( int s )
{
	vis[s] = 1;
	int ans = 0;
	if (dp[s] != -1 ) return dp[s];
	for ( auto i : adj[s] )
	{
		ans = max(ans, 1 + help( i ) );
	}
	return dp[s] = ans;
}
void solve()
{
	int n, m;
	cin >> n >> m;
	adj.resize(n + 1);
	loop(i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
	}
	mset(dp, -1);
	int ans = 0;
	loop(i, 1, n + 1)
	{
		if (!vis[i])
		{
			ans = max(ans, help(i));
		}
	}
	cout << ans;
	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 10240
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n, k;
  while(cin >> n >> k, n||k) {
    int a[n];
    REP(i, n) cin >> a[i];
    int Ck = 1;
    REP(ii, n-k+1) {
      int tmp = 1;
      REP(jj, k) {
        tmp *= a[ii+jj];
      }
      Ck = max(tmp, Ck);
    }

    int ma = -1;
    REP(i, n) {
      REP(j, i) {
        swap(a[i], a[j]);
        int t = 1;
        REP(ii, n-k+1) {
          int tmp = 1;
          REP(jj, k) {
            tmp *= a[ii+jj];
          }
          t = max(tmp, t);
        }
        if (t >= Ck) {
          ma = max(ma, t-Ck);
        }
        swap(a[i], a[j]);
      }
    }
    if (ma == -1) {
      cout << "NO GAME" << endl;
    } else {
      cout << ma << endl;
    }
  }
}

Measured memory_bytes: 868
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
	int N;
	vector<int> H;
	cin >> N;
	rep(i, N) {
		int h;
		cin >> h;
		H.push_back(h);
	}

	int cnt = 0, ans = 0;
	int cur = H[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		if ( H[i] >= cur) {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			cnt = 0;
		}
		cur = H[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        # nがi（の累乗）で割り切れるかを調べる
        while n % i == 0:
            # nがiで割り切れる場合、iを素因数としてリストに追加する
            prime_factors.append(i)
            # nをiで割った商で更新しておく
            n //= i
    # nの平方根より大きい素因数が存在する場合
    if n > 1:
        prime_factors.append(n)

    return prime_factors

n = int(input())
import collections
l = trial_division(n)
c = collections.Counter(l)

count = 0
for v in c.values():
  n = 1
  while v >= n*(n+1)/2:
    count += 1
    n +=1
    
print(count)

Measured memory_bytes: 9720
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const long long MAXN = 500005;
long long dist[MAXN],ways[MAXN],rdist[MAXN],rways[MAXN];
vector<pair<ll,ll> > adj[MAXN];
const long long mod = 1e9+7;
void dijkstra(long long st,long long dist[MAXN],long long ways[MAXN]){
    priority_queue<pair<ll,ll> > pq;
    for(long long i=0;i<MAXN;i++){
        dist[i] = 1e18;
    }
    dist[st] = 0; ways[st] = 1;
    pq.push(make_pair(0,st));
    while(!pq.empty()){
        long long here = pq.top().second;
        ll cst = -pq.top().first;
        pq.pop();
        if(cst > dist[here]) continue;
        for(long long i=0;i<adj[here].size();i++){
            long long there = adj[here][i].first;
            ll w = adj[here][i].second;
            if(dist[there] > dist[here]+w){
                dist[there] = dist[here] + w;
                pq.push(make_pair(-dist[there],there));
                ways[there] = ways[here];
            }
            else if(dist[there] == dist[here] + w){
                ways[there] = (ways[here] + ways[there]) % mod;
            }
        }
    }
}
long long a[MAXN],b[MAXN],c[MAXN];
int main(){
    long long n,m; cin>>n>>m;
    long long s,e; cin>>s>>e;
    for(long long i=1;i<=m;i++){
        cin>>a[i]>>b[i]>>c[i];
        adj[a[i]].push_back(make_pair(b[i],c[i]));
        adj[b[i]].push_back(make_pair(a[i],c[i]));
    }
    dijkstra(s,dist,ways);
    dijkstra(e,rdist,rways);
    long long tot = dist[e];
    long long ans = ways[e] * rways[s];
    ans %= mod;
    if(tot % 2 == 0){
        for(long long i=1;i<=n;i++){
            if(dist[i] == tot/2 && rdist[i] == tot/2){
                long long c = ways[i] * rways[i]; c %= mod;
                c = (c * c) % mod;
                ans = (ans - c + 1000 * mod) % mod;
            }
        }
    }
    double half = tot / 2.0;
    for(long long i=1;i<=m;i++){
        long long u = a[i]; long long v = b[i]; long long w = c[i];
        if(dist[u] + rdist[v] + w == tot){
            if(dist[u] < half && rdist[v] < half){
                long long c = ways[u] * rways[v]; c %= mod;
                c = c * c; c %= mod;
                ans = (ans - c + 1000 * mod) % mod;
            }
        }
        
        swap(a[i],b[i]);
    }
    for(long long i=1;i<=m;i++){
        long long u = a[i]; long long v = b[i]; long long w = c[i];
        if(dist[u] + rdist[v] + w == tot){
            if(dist[u] < half && rdist[v] < half){
                long long c = ways[u] * rways[v]; c %= mod;
                c = c * c; c %= mod;
                ans = (ans - c + 1000 * mod) % mod;
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 47828
N, K = map(int,input().split())
BIG_NUM = 10**9+7

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def calc_ans(i):
    if N-K < i-1:
        return 0

    else:
        return cmb(N-K+1,i)*cmb(K-1,i-1)%BIG_NUM

for j in range(1,K+1):
    print(calc_ans(j))

Measured memory_bytes: 3444