akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> a(N);
	map<Int, vector<int>> mp;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		mp[a[i]].emplace_back(i);
	}

	sort(a.rbegin(), a.rend());
	a.erase(unique(a.begin(), a.end()), a.end());

	vector<Int> ans(N, 0);
	int idx = 1e9;
	for (auto val : mp[a[0]]) { idx = min(idx, val); }
	Int sum = mp[a[0]].size();
	a.emplace_back(0);
	mp[0].emplace_back(-1);
	for (int i = 0; i + 1 < a.size(); ++i) {
		ans[idx] += sum * (a[i] - a[i + 1]);
		sum += mp[a[i + 1]].size();
		for (auto val : mp[a[i + 1]]) { idx = min(idx, val); }
	}
	for (auto v : ans) { cout << v << endl; }

	return 0;
}


Measured memory_bytes: 16280
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    readln.split.to!(int[]).sort().uniq.array.length.writeln;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

class Vector1D {
public:
    int x;
};

/// @brief Represents a point.
class Vector2D : public Vector1D {
public:
    int y;

    /// @brief Returns Manhattan distance.
    int get_dist(Vector2D *dst) {
        return std::abs(dst->x - this->x) + std::abs(dst->y - this->y);
    }
};

static Vector2D points[90001];
static int d_cum[90001];  ///< Cumulative distance.

/// @brief Prints the distance for each query.
int main() {
    int H, W, D, Q, L, R;
    int A[301][301];
    Vector2D* point;

    scanf("%d %d %d", &H, &W, &D);

    for (int h = 1; h <= H; ++h) {
        for (int w = 1; w <= W; ++w) {
            scanf("%d", &A[h][w]);
            point = &points[A[h][w]];
            point->x = w;
            point->y = h;
        }
    }

    for (int i = 1; i <= H * W; ++i) {
        if (i <= D) {
            d_cum[i] = 0;
        } else {
            d_cum[i] = d_cum[i - D] + points[i].get_dist(&points[i - D]);
        }
    }

    scanf("%d", &Q);

    for (int q = 1; q <= Q; ++q) {
        scanf("%d %d", &L, &R);
        printf("%d\n", d_cum[R] - d_cum[L]);
    }
}


Measured memory_bytes: 2432
A, b = map(int, input().split())

if b == 1:
	print(0)
elif b <= A:
	print(1)
elif b <= 2*A - 1:
	print(2)
elif b <= 3*A - 2:
	print(3)
elif b <= 4*A - 3:
	print(4)
elif b <= 5*A - 4:
	print(5)
elif b <= 6*A - 5:
	print(6)
elif b <= 7*A - 6:
	print(7)
elif b <= 8*A - 7:
	print(8)
elif b <= 9*A - 8:
	print(9)
elif b <= 10*A - 9:
	print(10)
elif b <= 11*A - 10:
	print(11)
elif b <= 12*A - 11:
	print(12)
elif b <= 13*A - 12:
	print(13)
elif b <= 14*A - 13:
	print(14)
elif b <= 15*A - 14:
	print(15)
elif b <= 16*A - 15:
	print(16)
elif b <= 17*A - 16:
	print(17)
elif b <= 18*A - 17:
	print(18)
else:
	print(19)


Measured memory_bytes: 3064
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#include <bits/stdc++.h>
#define endl "\n"
#define ll   unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }	
using namespace std;

ll t,N,a,b,c,d;

map<ll,ll> mp;

ll solve(ll n){
    if(n==0){
        return 0;
    }
if(mp.count(n)){
    return mp[n];
}
ll ans=d*n;
ll val21=(n/2)*2;
ll val22=((n+1)/2)*2;   
ll val31=(n/3)*3;
ll val32=((n+2)/3)*3;
ll val51=(n/5)*5;
ll val52=((n+4)/5)*5;
ans=min(ans,a+d*(n-val21)+solve(val21/2));
ans=min(ans,a+d*(-n+val22)+solve(val22/2));
ans=min(ans,b+d*(n-val31)+solve(val31/3));
ans=min(ans,b+d*(-n+val32)+solve(val32/3));
ans=min(ans,c+d*(n-val51)+solve(val51/5));
ans=min(ans,c+d*(-n+val52)+solve(val52/5));
mp[n]=ans;
return ans;
}


int main(){
    SPEED;
    cin>>t;
    while(t--){
        cin>>N>>a>>b>>c>>d;
        mp.clear();
        mp[0]=0;
        mp[1]=d;
         solve(N);
         cout<<mp[N]<<endl;
    }
}



Measured memory_bytes: 4380
#include<stdio.h>
int main(){
	int n[5],i,j,temp;
	while(scanf("%d%d%d%d%d",&n[0] ,&n[1] ,&n[2] ,&n[3] ,&n[4])!=EOF){
		for(i=0;i<5;i++){
			for(j=0;j<5;j++){
				if(n[i]>n[j]){
					temp=n[i];
					n[i]=n[j];
					n[j]=temp;
				}
			}
		}
		printf("%d %d %d %d %d\n",n[0],n[1],n[2],n[3],n[4]);
	}
	return 0;
}
	

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007

int main(){
    int i,j;
    int n,m;
    cin>>n>>m;
    int a[10];
    for(i=0;i<m;i++) cin>>a[i];
    int h[]={10,2,5,5,4,5,6,3,7,6};

    sort(a,a+m,greater<int>());

    int keta[10101];
    fill(keta,keta+10101,-1);
    keta[0]=0;

    for(i=0;i<n;i++){
        if(keta[i]==-1) continue;
        for(j=0;j<m;j++){
            int t=i+h[a[j]];
            keta[t]=max(keta[t],keta[i]+1);
        }
    }

    int k=n;
    string ans="";

    while(k){
        for(j=0;j<m;j++){
            if(k-h[a[j]]>=0&&keta[k-h[a[j]]]==keta[k]-1) {
                ans+='0'+a[j];
                k=k-h[a[j]];
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	char s[27];
	int che[26] = { 0 };
	cin >> s;

	for (int i = 0; s[i] != '\0'; i++) {
		che[(int)s[i] - 97]++;
	}

	for (int i = 0; s[i] != '\0'; i++) {
		if (che[i] >= 2) {
			cout << "no" << endl;
			return 0;
		}
	}
	
	cout << "yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][5];
 
int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    repd(i,2,n)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}
 
inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

Measured memory_bytes: 9880
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int count=0;
  for(int i=0;i<n-2;i++){
    if(a[i] < a[i+1] && a[i+1] < a[i+2]){
      count++;
    }else if(a[i] > a[i+1] && a[i+1] > a[i+2]){
      count++;
    }
  }
  cout << count;
}


Measured memory_bytes: 256
s = [0] * 13
h = [0] * 13
c = [0] * 13
d = [0] * 13

num = int(input())
for i in range(num):
    m, n = input().split()
    x = int(n) - 1
    if m == "S":
        s[x] = 1
    elif m == "H":
        h[x] = 1
    elif m == "C":
        c[x] = 1
    elif m == "D":
        d[x] = 1
    else:
        break

for i in range(13):
    if s[i] == 0:
        print("S %d" % (i+1))

for i in range(13):
    if h[i] == 0:
        print("H %d" % (i+1))

for i in range(13):
    if c[i] == 0:
        print("C %d" % (i+1))

for i in range(13):
    if d[i] == 0:
        print("D %d" % (i+1))






Measured memory_bytes: 5608
import math
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
temp=[]
pre=[]
ans=1e3
for i in range(n):
    temp.append(t-h[i]*0.006)
    pre.append(abs(temp[i]-a))
    ans=min(ans,pre[i])
for i in range(n):
    if(ans==pre[i]):
        pri=i
        break
print(pri+1)


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

long long int n_C_k(int n,int k){
  long long int a=1;
  long long int b=1;
  for(int i = 0;i<k;i++){
    a*=i+1;
    b*=n-k;
  }
  return b/a;
}

int main(){

  int N,K;
  long long int ans;
  cin>>N>>K;
  ans =1;
  ans *= K;
  ans *= pow(K-1,N-1);

  cout<<ans<<endl;

}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int> w(n), s(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> s[i] >> v[i];
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) { return s[i] - w[j] < s[j] - w[i]; });

  const int MAXS = 20010;
  vector<long long> dp(MAXS);
  for (int i = 0; i < n; i++) {
    for (int j = s[ord[i]]; j >= 0; j--) {
      dp[j + w[ord[i]]] = max(dp[j + w[ord[i]]], dp[j] + v[ord[i]]);
    }
  }
  
  cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, r;
	cin >> n;
	r = n % 10;
	if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9)
		cout << "hon" << "\n";
	else if (r == 0 || r == 1 || r == 6 || r == 8)
		cout << "pon" << "\n";
	else
		cout << "bon" << "\n";
	return 0;
}



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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    string s;
    cin >> s;
    ll n = s.size(), q, cur = 0, x, in;
    cin >> q;
    char ch;
    while(q--){
        cin >> in;
        if(in == 1){
            cur ^= 1;
        }
        else {
            cin >> x >> ch;
            if(x == 1){
                if(cur){
                    s.pb(ch);
                }
                else s.insert(s.begin(),ch);
            }
            else {
                if(cur){
                    s.insert(s.begin(),ch);
                }
                else s.pb(ch);
            }
        }
    }
    if(cur)reverse(all(s));
    cout << s << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pr = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        String X = br.readLine();
        for(int i=0;i<X.length();i++){
            if(i==4){
                sb.append(" ").append(X.charAt(i));
            }
            else{
                sb.append(X.charAt(i));
            }
        }
        
        pr.println(sb.toString());
        pr.close();
        
    }
    
}


Measured memory_bytes: 8276
#include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 105

using namespace std;
int p[Lens];
int C[Lens][Lens];
int N;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> p[i - 1] >> p[i];
		C[i][i] = 0;
	}
	for (int k = 1; k < N; k++)
	{
		for (int i = 1; i <= N-k; i++)
		{
			int j = i + k;
			C[i][j] = C[i][i] + C[i + 1][j]+p[i-1]*p[i]*p[j];
			for (int t = i+1; t < j; t++)
			{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
				C[i][j] = min(C[i][j], C[i][t] + C[t+1][j] + p[i - 1] * p[t] * p[j]);
			}
		}
	}
	cout << C[1][N]<<endl;

	return 0;

}


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

using namespace std;

void solve() {
    string S;
    cin >> S;
    map<char, int> hougaku;
    hougaku['N'] = 0;
    hougaku['W'] = 0;
    hougaku['S'] = 0;
    hougaku['E'] = 0;
    for (int i = 0; i < S.size(); i++)
    {
        hougaku[S[i]]++;
    }
    if (hougaku['N'] * hougaku['S'] == 0 && hougaku['N'] + hougaku['S'] != 0)
    {
        cout << "No" << endl;
        return;
    }
    if (hougaku['W'] * hougaku['E'] == 0 && hougaku['W'] + hougaku['E'] != 0)
    {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3600
program hi;
var 
    s, t: string;
    i, cnt: longint;

begin
    readln(s);
    readln(t);
    cnt := 0;
    for i := 1 to length(s) do 
        if s[i] <> t[i] then
            inc(cnt);
    writeln(cnt);
end.

Measured memory_bytes: 1388
#include <stdio.h>

int main (void)
{
  int n , m , count = 0;
  scanf("%d %d",&n,&m);
  
  int b1[m],b2[m];
  
  for(int i = 0;i < m;i ++){
     scanf("%d %d",&b1[i],&b2[i]);
  }
  
  for(int i = 0;i < n;i ++){
    for(int j = 0;j < m;j ++){
      if(i+1 == b1[j]){
        count ++;
      }
      if(i+1 == b2[j]){
        count ++;
      }}
    printf("%d\n",count);
    count = 0;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second

int main(){
    FAST
    int n, m; cin >> n >> m;
    int h[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    bool good[n + 1];
    memset(good, 1, sizeof(good));
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        if(h[a] <= h[b])good[a] = 0;
        if(h[b] <= h[a])good[b] = 0;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(good[i])ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4132
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });            var N = Sarray()[0];
            var N = Sarray()[0];
            var Ai = Sarray();
            var Aid = Ai.Distinct().ToList();
            Aid.Sort();
            var cnt = Aid.Count();
            if (cnt == 1 && Ai[0] == 0)
            {
                WriteLine("Yes");
                return;
            }
            if (cnt == 2 && Aid[0] == 0)
            {
                if (Ai.Count(a => a == Aid[0]) == N / 3 &&
                    Ai.Count(a => a == Aid[1]) == N / 3 * 2)
                {
                    WriteLine("Yes");
                    return;
                }
            }
            if (cnt == 3 && 0 == (Aid[0] ^ Aid[1] ^ Aid[2]))
            {
                if (
                    Ai.Count(a => a == Aid[0]) == N / 3 &&
                    Ai.Count(a => a == Aid[1]) == N / 3 &&
                    Ai.Count(a => a == Aid[2]) == N / 3
                    )
                {
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 24800
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 X;
  cin >> X;
  i64 now = 100;
  i64 cnt = 0;
  while(now < X) {
    cnt++;
    now += now / 100;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3624
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	int deg = 0;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int i, v, l, r, root = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++) T[i].parent = NIL;
	for(i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(i=0;i<n;i++) print(i);
	
	return 0;
}

/*
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
*/


Measured memory_bytes: 2076
import javax.management.Query;
import javax.print.attribute.SupportedValuesAttribute;
import java.io.*;
import java.security.interfaces.DSAKeyPairGenerator;
import java.sql.Array;
import java.util.*;
import java.util.function.Predicate;


public class Main {

    static class TaskB {

        static int oo = Integer.MAX_VALUE - 1;

        static int MOD = 1000000007;


        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            int[] arr = in.nextIntArray(n);

            int[] dp = new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;
            dp[1] = Math.abs(arr[1]-arr[0]);

            for(int i = 2; i < n; i++)
            {
                for(int g = 1; g <= k; g++)
                {
                    if(i-g < 0)break;
                    int index = i-g;
                    dp[i] = Math.min(dp[i], dp[index]+Math.abs(arr[i]-arr[index]));
                }
            }
            out.print(dp[n-1]);
        }
    }

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



    static void sort(int[] a)
    {
        ArrayList<Integer> list = new ArrayList<>();
        for(Integer i: a)list.add(i);
        Collections.sort(list);
        for(int i = 0; i < a.length; i++)a[i]=list.get(i);
    }


    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

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

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

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
    }
}

Measured memory_bytes: 44204
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 30
#define KOK 32000
#define EPS 0.000000001
using namespace std;

vector<int> a[N];

int main() {
 
	//freopen("input.txt","r",stdin);

	int h,w,n,x,y;

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

	int ans=h;

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

		scanf("%d %d",&x,&y);

		a[y].pb(x);

	}

	int last=1;

	for(int i=1;i<=w;i++) {

		sort(all(a[i]));

		if(sz(a[i])==0) last++;

		for(int j=0;j<sz(a[i]);j++) {

			if(a[i][j]<last) {
			
				if(j==sz(a[i])-1) {

					last++;

					break ;

				}

				continue ;
			
			}

			if(a[i][j]>last) {

				umin(ans,a[i][j]-1);

				last++;

				break ;

			}

			while(j<sz(a[i]) && a[i][j]==last) {

				last++;
				j++;

			}

			if(last>h) break ;

			if(j!=sz(a[i])) {

				umin(ans,a[i][j]-1);
				last++;

				break ;

			}

			last++;

			break ;

		}

		if(last>h) break ;

	}

	printf("%d",ans);

}


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

int main(){
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    int now = n;
    vector<int> ans;
    while(now != 0){
        bool end = true;
        for(int j = m; j >= 1; j--){
            if(now < j) continue;
            if(s[now-j] == '0'){
                now -= j;
                end = false;
                ans.push_back(j);
                break;
            }
        }
        if(end){
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto p:ans) cout << p << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int f[100][10];
    int p[100][11];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>f[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    int ans=-(1e9);
    for(int mask=1;mask<(1<<10);mask++){
        int sum=0;
        for(int i=0;i<n;i++){
            int c=0;
            for(int j=0;j<10;j++){
                if((mask&(1<<j))&&f[i][j])c++;
            }
            sum+=p[i][c];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


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

int32_t main()
{
    string s;
    cin>>s;
    int ans=1;
    for(int i=1;i<s.size();i++)
    {
        if(ans>=3)
        break;
        if(s[i]==s[i-1])
        ans++;
        else
        ans=1;
    }
    if(ans>=3)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    


}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC052B___Increment_Decrement
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();

            int x_max = 0;
            int x = 0;
            foreach (char sc in s)
            {
                string scs = sc.ToString();
                if (scs == "I")
                {
                    x++;
                }
                else if (scs == "D")
                {
                    x--;
                }

                if (x >= x_max)
                {
                    x_max = x;
                }

            }

            Console.WriteLine(x_max);


        }
    }
}


Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&x)
	cnt:=0
	for i:= 0; i<= a; i++ {
		for j:= 0; j<=b; j++ {
			for k:= 0; k<=c; k++ {
				s:= 500*i + 100*j + 50*k
				if x == s {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


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



int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll q;cin>>q;
    set<ll> st[26];
    rep(i,0,n){
        int a=s[i]-'a';
        st[a].insert((ll)i);
    }
    rep(i,0,26){
        st[i].insert(1e7);
    }
    rep(i,0,q){
        ll a;cin>>a;
        if(a==1){
            ll b;cin>>b;
            b--;
            char c;cin>>c;
            int B=s[b]-'a',C=c-'a';
            st[B].erase(b);
            st[C].insert(b);
            s[b]=c;
        }
        else if(a==2){
            ll l,r;cin>>l>>r;
            l--;r--;
            if(l==r){
                cout<<1<<endl;
                continue;
            }
            ll an=0;
            rep(j,0,26){
                int L=*st[j].lower_bound(l);
                int R=*st[j].upper_bound(r);
                if(L!=R)an++;
            }
            cout<<an<<endl;
        }
    }
}

    









Measured memory_bytes: 24196
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int N, c;
    int *A;
    int *ans;
    scanf("%d", &N);
    A = (int *)malloc(sizeof(int) * (N - 1));
    ans = (int *)malloc(sizeof(int) * N);
    for (c = 0; c < N; ++c)
    {
        ans[c] = 0;
    }
    for (c = 0; c < N - 1; ++c)
    {
        scanf("%d", A + c);
        ++ans[A[c] - 1];
    }
    for (c = 0; c < N; ++c)
    {
        printf("%d\n", ans[c]);
    }
    return 0;
}

Measured memory_bytes: 3244
#include <stdio.h>


int main(void) {
    int i, sec, total;

    for (i = 0, total = 0; i < 4; i++) {
        scanf("%d", &sec);
        total += sec;
    }

    printf("%d\n%d\n", total / 60, total % 60);

    return 0;
}

Measured memory_bytes: 592
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(input())for _ in range(n)]
    A.sort()
    ans1=0
    if n%2==0:
        ans1=(2*sum(A[n//2:])-A[n//2])-(2*sum(A[:n//2])-A[n//2-1])
    else:
        ans1=(2*sum(A[n//2:])-A[n//2]-A[n//2+1])-2*sum(A[:n//2])
    ans2=0
    if n%2==0:
        ans2=(2*sum(A[n//2:])-A[n//2])-(2*sum(A[:n//2])-A[n//2-1])
    else:
        ans2=2*sum(A[n//2+1:])-(2*sum(A[:n//2+1])-A[n//2-1]-A[n//2])      
    print(max(ans1,ans2))

if __name__=='__main__':
    main()

Measured memory_bytes: 45532
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;


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

	vector<int> av(n);
	vector<int> bv(n);
	vector<int> cv(n);

	for(int i=0;i<n;++i) cin >> av[i];
	for(int i=0;i<n;++i) cin >> bv[i];
	for(int i=0;i<n;++i) cin >> cv[i];

	sort(av.begin(),av.end());
	sort(bv.begin(),bv.end());
	sort(cv.begin(),cv.end());
	
	unsigned long long int res = 0;	
	for(int i=0;i<n;++i){
		int b = bv[i];
		vector<int>::iterator ait = lower_bound(av.begin(),av.end(),b);
		unsigned long long int a_size = ait -av.begin();

		vector<int>::iterator cit = upper_bound(cv.begin(),cv.end(),b);
		unsigned long long int c_size = cv.end() - cit;
	
		res += a_size * c_size;

	}

	cout << res <<endl;

	return 0;
}




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

public class Main {
	static final int MOD = (int)1e9+7;

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		UnionFind tree = new UnionFind(n);
		
		for(int i = 0; i < q; i++) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			if(com == 0) {
				tree.unite(x, y);
			}else{
				out.println(tree.issame(x, y) ? "1" : "0");
			}
		}
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}

		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class UnionFind {
	int[] par;
	
	public UnionFind(int n) {
		par = new int[n];
		
		for(int i = 0; i < n; i++) par[i] = i;
	}
	
	int root(int x) {
		if(par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	
	void unite(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		
		if(rx == ry) return;
		
		par[rx] = ry;
	}
	
	boolean issame(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}


Measured memory_bytes: 56616
import sys
input = sys.stdin.readline
from itertools import combinations_with_replacement
import copy
def f(A, x, N, M, A_list):
    if len(A) == N:
        A_list.append(A)
        return
    A.append(x)
    for i in range(x, M+1):
        A_copy = copy.copy(A)
        f(A_copy, i, N, M, A_list)
def main():
    N, M, Q = map(int, input().split())
    q_list = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        q_list.append((a, b, c, d))
    # A = combinations_with_replacement(range(1, M+1), N)
    A_list = []
    f([], 1, N, M, A_list)
    ans = 0
    for Ai in A_list:
        v = 0
        Ai = list(map(int, Ai))
        for a, b, c, d in q_list:
            if Ai[b-1]-Ai[a-1] == c:v += d
        ans = max(ans, v)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 91132
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define mkp make_pair
#define fi first
#define se second
int n,a[200004],ans[200004];
set<pii>pq;
int mp[200004],mp1[200004];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		cin>>ans[i];
		mp[ans[i]]++,mp[a[i]]++;
		mp1[ans[i]]++;
	}
	for(int i=1;i<=n;i++)if(mp1[i]>0)pq.insert(mkp(-mp[i],i));
	for(int i=0;i<n;i++){
		pii O=(*pq.begin());
		pq.erase(pq.begin());
		if(O.se!=a[i]){
			ans[i]=O.se;
			O.fi++;
		}else{
			if(pq.empty()){puts("No");return 0;}
			O=(*pq.begin());
			pq.erase(pq.begin());
			pq.insert(mkp(-mp[a[i]],a[i]));
			ans[i]=O.se;
			O.fi++;
		}
		mp1[O.se]--;
		mp[O.se]--;
		if(mp1[O.se]>0)pq.insert(O);
		if(mp1[a[i]]>0){
			if(pq.find(mkp(-mp[a[i]],a[i]))==pq.end())return 0;
			pq.erase(pq.find(mkp(-mp[a[i]],a[i])));
			mp[a[i]]--;
			pq.insert(mkp(-mp[a[i]],a[i]));
		}
	}
	puts("Yes");
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
}

Measured memory_bytes: 16144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, a[N];
array <ll, 2> p[N], s[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int j = 1;
	ll pref = a[1], cur = a[1];
	for (int i = 2; i <= n; i++) {
		pref += a[i];
		while (abs(cur + a[j + 1] - (pref - cur - a[j + 1])) < abs(cur - (pref - cur)))
			cur += a[++j];
		p[i] = {cur, pref - cur};
		if (p[i][0] > p[i][1]) swap(p[i][0], p[i][1]);
	}
	ll suf = a[n];
	cur = a[n], j = n;
	for (int i = n - 1; i >= 1; i--) {
		suf += a[i];
		while (abs(cur + a[j - 1] - (suf - cur - a[j - 1])) < abs(cur - (suf - cur)))
			cur += a[--j];
		s[i] = {cur, suf - cur};
		if (s[i][0] > s[i][1]) swap(s[i][0], s[i][1]);
	}
	ll ans = 1e9 + 123;
	for (int i = 2; i <= n - 2; i++)
		ans = min(ans, max(p[i][1], s[i + 1][1]) - min(p[i][0], s[i + 1][0]));
	cout << ans;
}


Measured memory_bytes: 10700
object Main extends App {
  val N = io.StdIn.readLine.toInt

  val out = (Seq(3,5,7,11,13).combinations(3) ++ Seq(Seq(3,3,3,5),Seq(3,3,3,7))).map(_.product).filter(_ <= N).size

  println(out)
}


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

typedef long long int ll;

int main()
{
    ll n, as = 0, bs = 0;
    bool f = false;
    cin >> n;
    vector<ll> a(n), b(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        as += a[i];
    }
    for(ll i = 0;i < n;i++){
        cin >> b[i];
        bs += b[i];
    }

    ll ac = 0, bc = 0;
    for(ll i = 0;i < n;i++){
        if(a[i] > b[i]){
            ac += a[i] - b[i];
        }
        else{
            bc += (b[i] - a[i]) / 2;
        }
    }

    if(ac <= bc){
        f = true;
    }

    if(f){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int a[3][3],n,i,j,b[10],k;
	for(i=0;i<3;i++)
	for(j=0;j<3;j++)
	cin>>a[i][j];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>b[i];
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<n;k++)
			{if(a[i][j]==b[k])
				a[i][j]=0;
			}
		}
	}
	if(a[0][0]==0&&a[0][1]==0&&a[0][2]==0)
	cout<<"Yes";
	else if(a[1][0]==0&&a[1][1]==0&&a[1][2]==0)
	cout<<"Yes";
	else if(a[2][0]==0&&a[2][1]==0&&a[2][2]==0)
	cout<<"Yes";
	else if(a[0][0]==0&&a[1][0]==0&&a[2][0]==0)
	cout<<"Yes";
	else if(a[0][1]==0&&a[1][1]==0&&a[2][1]==0)
	cout<<"Yes";
	else if(a[0][2]==0&&a[1][2]==0&&a[2][2]==0)
	cout<<"Yes";
	else if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0)
	cout<<"Yes";
	else if(a[0][2]==0&&a[1][1]==0&&a[2][0]==0)
	cout<<"Yes";
	else 
	cout<<"No";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

struct Testimony {
  int x;
  int y;
};

Testimony T[15][15];

void solve(istream& cin, ostream& cout) {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
    REP(j, A[i]) {
      int x, y;
      cin >> x >> y; x--;
      T[i][j].x = x; T[i][j].y = y;
    }
  }
  int ans = 0;
  REP(bit, (1<<N)) {
    bitset<15> bs = bitset<15>(bit);
    bool flag = true;
    REP(i, N) {
      REP(j, A[i]) {
        // 人 i が正直者
        if (bs[i] == 1) {
          // j 個目の証言 -> 人 jx は jy
          int jx = T[i][j].x, jy = T[i][j].y;
          // 矛盾
          if (bs[jx] != jy) {
            flag = false;
            break;
          }
        }
      }
      if (!flag) break;
    }
    if (flag && bs.count() > ans) ans = bs.count();
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto s = rs;
	if(s.count!"a == 'R'" > s.count!"a == 'B'") writeln("Yes");
	else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	n--;
	long long ans=0;
	for(int i=1;i<=n;i++)   /*求从1到n约数个数的和*/ 
	{
		ans+=n/i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3584
#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=ans*10+ch-'0',ch=getchar();
	return ans*fh;
}
const int maxn=4000;
struct node{
	int x,y;
}q[maxn][maxn];
int n,m,f[maxn][maxn],top,ans,xx,yy;
char a[maxn],b[maxn],nh[maxn],vis[maxn],vi[maxn];
int main(){
//	freopen("12.in","r",stdin);
	scanf("%s%s",a+1,b+1);
	n=strlen(a+1),m=strlen(b+1);
	xx=-1,yy=-1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			for(int k1=0;k1<=1;k1++)
				for(int k2=0;k2<=1;k2++){
					if(!k1&&!k2) continue;
					int x=i-k1,y=j-k2,d=0;
					if(a[i]==b[j]&&k1&&k2) d=1;
					if(f[x][y]+d>f[i][j]){
						q[i][j]=(node){x,y};
						f[i][j]=f[x][y]+d;
					}
					if(f[i][j]>ans){
						ans=f[i][j];
						xx=i,yy=j;
					}
				}
		}
	node zhy;
	if(xx==-1) return 0;
	for(int i=xx,j=yy;i||j;zhy=q[i][j],i=zhy.x,j=zhy.y)
		if(a[i]==b[j]&&!vi[j]&&!vis[i]) nh[++top]=a[i],vi[j]=vis[i]=1;
	for(int i=top;i>=1;i--) printf("%c",nh[i]);
	return 0;
}








Measured memory_bytes: 143488
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <climits>
#include <cmath>
#include <cassert>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define ll long long
using namespace std;

string m;
int point = 0;
ll term(void);

bool left() {
    if(point < m.size()) return true;
    else return false;
}

char peek() {
    return m[point];
} 

char pop() {
    return m[point++];
}

void eat(char ch) {
    assert(left() && pop() == ch);
}

ll expr() {
    ll res = term();
    while(left() && (peek() == '+' || peek() == '-')) {
        if(peek() == '+') {
            eat('+');
            res += term();
        } else {
            eat('-');
            res -= term();
        }
    }
    return res;
}

ll number() {
    ll res = 0;
    while(left() && isdigit(peek())) {
        res *= 10;
        res += pop() - '0';
    }
    return res;
}

ll factor() {
    if(peek() == '('){
        eat('(');
        ll res = expr();
        eat(')');
        return res;
    } else {
        return number();
    }
}

ll term() {
    ll res = factor();
    while(left() && (peek() == '*' || peek() == '/')) {
        if(peek() == '*') {
            eat('*');
            res *= factor();
        } else {
            eat('/');
            res /= factor();
        }
    }
    return res;
}

int main(void){
    int n;
    ll ans;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n) {
        cin >> m;
        point = 0;
        ans = expr();
        cout << ans << endl;
        eat('=');
    }
}


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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int n,i,k;
	ll s[N];
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	ll ans = 1e10;
	for(i=0;i<=n-k;i++){
		ll a = s[i];
		ll b = s[i+k-1];
		if(a<=0 && b>0){
			ans=min(ans,min(2*abs(a)+b,2*b+abs(a)));
		}
		else if (a<0 && b<0){
			ans=min(ans,abs(a));
		} else ans = min(ans,b);
	}
	cout << ans << endl;
		
	
		
	return 0;
}

Measured memory_bytes: 1024