akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    
    ll ans = 1e18;

    for (ll P = 0; P <= 100; ++P){
        ll sum = 0;
        for (ll i = 0; i < N; ++i){
            sum += (X[i] - P) * (X[i] - P);
        }
        ans = min(ans, sum);
    }

    print(ans);

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll A[100010],B[100010],Y[100010];
ll X[100010];
vector<vector<pair<int,ll>>> v(100010);
vector<pair<ll,int>> edges;
int p[100010] = {0},r[100010] = {0};
ll s[100010] = {0};
void init(int N){
	for(int i=0;i<=N;++i){
		p[i] = i;
		s[i] = X[i];
	}
}
 
int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}
 
bool is_same_set(int a,int b){
	return root(a) == root(b);
}
 
void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
		s[b] += s[a];
		s[a] = s[b];
	}else{
		p[b] = a;
		s[a] += s[b];
		s[b] = s[a];
		if(r[a] == r[b]) r[a]++;
	}
}

int visited[100010] = {},ans = 0;
void dfs(int n,int c){
	for(auto& a:v[n]){
		int b = a.first;ll id = a.second;
		if(visited[id]==0 && Y[id]<=c){
			visited[id] = 1; ans++;
			dfs(b,c);
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=1;i<=N;i++){
		cin >> X[i];
	}
	init(N);
	for(int i=1;i<=M;i++){
		cin >> A[i] >> B[i] >> Y[i];
		v[A[i]].push_back({B[i],i});
		v[B[i]].push_back({A[i],i});		
		edges.push_back({Y[i],i});
	}
	sort(edges.begin(),edges.end());
	deque<int> Q;
	for(int i=0;i<M;i++){
		int id = edges[i].second;
		unite(A[id],B[id]);
		if(s[root(A[id])]>=Y[id]) Q.push_front(id);
	}
	while(!Q.empty()){
		int a = Q.front(); Q.pop_front();
		if(visited[a]==0) dfs(A[a],Y[a]);
	}
	cout << M-ans << endl;
}

Measured memory_bytes: 19184
//https://atcoder.jp/contests/abc155/tasks/abc155_c
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    map<string,ll> tbl;
    ll max =0;
    FOR(i,0,N){
        string s; cin>>s;
        tbl[s]++;
        max=std::max<ll>(tbl[s],max);
    }    
    vector<string> strs;
    for(auto& p:tbl){
        if (p.second==max){
            //auto tmp=p.first;
            strs.emplace_back(p.first);
        }
    }
    sort(strs.begin(),strs.end());
    for(const auto& s:strs){
        cout<<s<<endl;
    }
    //cout<<strs.at(0)<<endl;
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  map<int,int> mp;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    mp[x]++;
  }
  int ans = 0;
  for(auto e:mp){
    ans += e.second % 2 == 1;
  }
  cout << ans << endl;
}



Measured memory_bytes: 8292
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> X(x);
    vector<ll> Y(y);
    vector<ll> Z(z);
    vector<ll> XY;
    rep(i, x){
        cin >> X[i];
    }
    rep(i, y){
        cin >> Y[i];
        rep(j, x){
            XY.push_back(X[j] + Y[i]);
        }
    }
    sort(all(XY), greater<ll>());

    vector<ll> ans;
    rep(i, z){
        cin >> Z[i];
        rep(j, min(k, x*y)){
            ans.push_back(XY[j] + Z[i]);
        }
    }
    sort(all(ans), greater<ll>());

    rep(i, k){
        cout << ans[i] << endl;
    }


}

Measured memory_bytes: 44116
n, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(0, n-1):
    if A[i] + A[i+1] > x:
        diff = A[i] + A[i+1] - x
        ans += diff
        A[i+1] = max(0, A[i+1]-diff)

print(ans)


Measured memory_bytes: 19900
import fractions
a, b= (int(i) for i in input().split())
m=fractions.gcd(a,b)

pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m > 1:
    pf[m]=1

print(len(pf)+1)

Measured memory_bytes: 5088
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e18
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;



int main(){
   string s;
   cin >> s;
   int n = s.size();
   bool f = true;
   rep(i, n){
      if(i == 0)continue;
      else if(s[i] != s[i - 1])f = false;
   }
   if(f){
      cout << 0 << endl;
      return 0;
   }
   map<char, int> mp;
   rep(i, 26){
      char c = ('a' + i);
      int cnt = 0;
      rep(j, n){
         if(s[j] == c){
            mp[c] = max(mp[c], cnt);
            cnt = 0;
         }
         else cnt++;
      }
      mp[c] = max(mp[c], cnt);
   }
   int res = INF;
   for(auto m : mp){
      res = min(res, m.second);
   }
   cout << res << endl;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

    int ans=1,cnt=0;
    for (int i=1;i<=N;i++){
	int x=i,cnt2=0;
	while ((x%2 == 0) && (x > 0)){
	    cnt2++;
	    x/=2;
	}
	if (cnt < cnt2){
	    ans=i;
	    cnt=cnt2;
	}
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main() {
    int n, l;

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

    int apple_taste[n];
    int i, sum_taste = 0;
    for ( i = 0; i < n; i++ ) {
        apple_taste[i] = l + i;
        sum_taste += apple_taste[i];
    }
    int min_taste_abs = INT_MAX, min_taste_id;
    for ( i = 0; i < n; i++ ) {
        if ( min_taste_abs > abs(apple_taste[i]) ) {
            min_taste_abs = abs(apple_taste[i]);
            min_taste_id = i;
        }
    }

    int ans = sum_taste - apple_taste[min_taste_id];
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <cstdio>
#include <iomanip>

struct point {
    float x;
    float y;
};
const float pi = 3.141592;

void DumpKochCurve(point p1, point p2, int n)
{
    point s, t, u;
    s.x = (2*p1.x + p2.x) / 3;
    s.y = (2*p1.y + p2.y) / 3;

    t.x = (p1.x + 2*p2.x) / 3;
    t.y = (p1.y + 2*p2.y) / 3;

    u.x = (t.x - s.x) * cos(pi/3) - (t.y - s.y) * sin(pi/3) + s.x;
    u.y = (t.x - s.x) * sin(pi/3) + (t.y - s.y) * cos(pi/3) + s.y;

    if (n > 0) {
        DumpKochCurve(p1, s,  n-1);
        std::cout << s.x << " " << s.y << std::endl;
        DumpKochCurve(s,  u,  n-1);
        std::cout << u.x << " " << u.y << std::endl;
        DumpKochCurve(u,  t,  n-1);
        std::cout << t.x << " " << t.y << std::endl;
        DumpKochCurve(t,  p2, n-1);
    }
}

int main(int argc, char *argv[])
{
    point start, end;
    start.x = 0.0;
    start.y = 0.0;
    end.x   = 100.0;
    end.y   = 0.0;

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

    std::cout.precision(8);
    std::cout << std::showpoint;
    std::cout << start.x << " "
              << start.y << std::endl;
    DumpKochCurve(start, end, n);
    std::cout << end.x << " "
              << end.y << std::endl;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	string a, b;
	cin >> a >> b;
	int n = a.size();
	int m = b.size();
	int dp[n + 1][m + 1] = {}, dp2[n + 1][m + 1] = {};
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			if (dp[i + 1][j] >= dp[i][j + 1]) {
				dp[i + 1][j + 1] = dp[i + 1][j];
				dp2[i + 1][j + 1] = 2;
			}
			else {
				dp[i + 1][j + 1] = dp[i][j + 1];
				dp2[i + 1][j + 1] = 1;
			}
			if (a[i] == b[j] && dp[i][j] + 1> dp[i + 1][j + 1]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
				dp2[i + 1][j + 1] = 3;
			}
		}
	}
	int i = n, j = m;
	string ans = "";
	while (i != 0 || j != 0) {
		if (dp2[i][j] == 1) {
			i--;
		}
		else if (dp2[i][j] == 2) {
			j--;
		}
		else if (dp2[i][j] == 3) {
			i--;
			j--;
			ans += a[i];
		}
		else {
			break;
		}
	}
	reverse(all(ans));
	cout << ans << '\n';
}


Measured memory_bytes: 70656
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <queue>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll max_n = 100000;
const ll max_m = 100000;
using namespace std;
typedef pair<ll,ll> P;
const ll maxv = 100000;
const ll money_first = 1e15;

struct edge{
    ll to;
    ll cost;
};

template<class Abel> struct Dijkstra{
    priority_queue<P,vector<P>,greater<P> > que;
    vector<vector<edge> > G;
    vector<Abel> d;
    vector<ll> prev;
    Dijkstra(ll s){
        G.resize(maxv);
        d.resize(maxv,INF);
        prev.resize(maxv);
        d[s] = 0;
        que.push(P(0,s));
    }
    
    void dijkstra(){
        while(!(que.empty())){
            P p = que.top(); que.pop();
            ll v = p.second;
            if(d[v] < p.first)continue;
            for(ll i = 0; i < G[v].size(); i++){
                edge e = G[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    prev[e.to] = v;
                    que.push(P(d[e.to], e.to));
                }
            }

        }
    }

};

bool compare(P a,P b){
    if(a.second == b.second){
        return a.first > b.first;
    }
    return a.second < b.second;
}
ll n,m,s,t;
int main(){
    cin >> n >> m >> s >> t;
    s--; t--;
    Dijkstra<ll> yen(s), snook(t);
    REP(i,m){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        edge yen_u = {.to = v,.cost = a};
        edge yen_v = {.to = u,.cost = a};
        edge snook_u = {.to = v,.cost = b};
        edge snook_v = {.to = u,.cost = b};
        yen.G[u].push_back(yen_u);
        yen.G[v].push_back(yen_v);
        snook.G[u].push_back(snook_u);
        snook.G[v].push_back(snook_v);
    }

    yen.dijkstra();
    snook.dijkstra();

    vector<P> mincost;
    REP(i,n){
        //cout << yen.d[i] << " " << snook.d[i] << endl;
        P p(i+1, yen.d[i] + snook.d[i]);
        mincost.push_back(p);
    }

    sort(ALL(mincost),compare);
    /*REP(i,n){
        cout << mincost[i].first << " " << mincost[i].second << endl;
    }*/


    ll itr = 0;
    //int min_itr = 0;
    REP(i,n){       
        while(mincost[itr].first <= i){
            itr++;
        }
        
        cout << money_first - mincost[itr].second << endl;
    }

}

Measured memory_bytes: 22644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    vector<long long> h(N);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    long long ans = 1000000000;
    for(int i = 0; i <= N - K; i++){
        ans = min(ans,h[i+K-1]-h[i]);
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {

    int h, w; cin >> h >> w;

    vector<string> s(h);

    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }

    //スタート位置からの距離
    vector<vector<int>> d(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            d[i][j] = -1;
        }
    }

    //BFS
    queue<pair<int, int>> que;

    que.push(make_pair(0, 0));
    d[0][0] = 0;

    while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();

        //ゴール
        if (p.first == h - 1 && p.second == w - 1) break;

        //4方向
        for (int i = 0; i < 4; ++i) {
            int nx = p.second + dx[i];
            int ny = p.first + dy[i];

            if (nx < 0 || w - 1 < nx) continue;
            if (ny < 0 || h - 1 < ny) continue;

            if (s[ny][nx] == '#') continue;

            if (d[ny][nx] != -1) continue;

            que.push(make_pair(ny, nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }

    if (d[h-1][w-1] == -1) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '.') ++ans;
        }
    }

    cout << ans - d[h-1][w-1] - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;
int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
void solve()
{
	int a;
	while(cin >> a)
	{
		bool flag[10];
		memset(flag, 0, sizeof(bool)  * 10);
		for(int i = 9; i >= 0; --i)
		{
			if(a / weight[i])
			{
				flag[i] = true;
			}
			a %= weight[i];
		}
		int pos = 0;
		for(int i = 0; i < 10; ++i)
		{
			if(flag[i])
			{
				cout << weight[i];
				pos = i;
				break;
			}
		}
		for(int i = pos + 1; i < 10; ++i)
		{
			if(flag[i])
			{
				cout << " " << weight[i];
			}
		}
		cout << endl;
	}
}

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

Measured memory_bytes: 0
from collections import deque

N = int(input())
data = [[] for i in range(N+1)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    data[u].append([v,w])
    data[v].append([u,w])

que = deque([1])
seen = [-1]*(N+1)
seen[1] = 0
cnt = 1
while cnt < N:
    cur = que.pop()
    for item in data[cur]:
        if seen[item[0]] == -1:
            seen[item[0]] = (seen[cur]+item[1]%2)%2
            cnt += 1
            que.append(item[0])

for i in range(1,N+1):
    print(seen[i])
    




Measured memory_bytes: 45360
#include<bits/stdc++.h>
using namespace std;
long long n,sum[100001],pr[100001],ans;
std::map <long long,int>ps;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>sum[i];pr[i]=sum[i];
	}
	sort(pr+1,pr+n+1);
	for(int i=1;i<=n;i++)
		ps[pr[i]]=i;
	for(int i=1;i<=n;i++)
		if(i%2!=ps[sum[i]]%2)
			ans++;
	ans/=2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, m, a, b, k;
  cin >> h >> m;
  a = h*60+m;
  cin >> h >> m;
  b = h*60+m;
  cin >> k;
  cout << b-a-k << endl;
}

Measured memory_bytes: 3656
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)
	for x := 0; x <= N; x++ {
		for y := 0; y+x <= N; y++ {
			z := N - x - y
			if x*10000+y*5000+z*1000 == Y {
				fmt.Println(x, y, z)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner ob=new Scanner(System.in);
		long n=ob.nextLong();
		long x=ob.nextLong();
		long t=ob.nextLong();
		long ans=(long)Math.ceil(n*(1.0)/x);
		System.out.println(ans*t);
	}
}


Measured memory_bytes: 27056
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<int> len(n);
        for(int i = 0 ; i < n ; i++){
            string w;
            cin >> w;
            len[i] = w.size();
        }

        int ans = -1;
        int tanku[] = {5, 7, 5, 7, 7};
        for(int i = 0 ; i < n ; i++){
            int cnt = 0, now = 0;
            bool ok = true;
            for(int j = i ; j < n ; j++){
                cnt += len[j];
                if(cnt == tanku[now]){
                    now++;
                    cnt = 0;
                }else if(cnt > tanku[now]){
                    ok = false;
                }
                if(now >= 5){
                    break;
                }
            }
            if(ok){
                ans = i + 1;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            String str = sc.nextLine();
            int N = nint(sc);
            StringBuilder result = new StringBuilder(str.charAt(0));
           for(int i = 0; N*i <str.length() ;i++){
               result.append(str.charAt(N*i)); }
            out.println(result.toString());
        }
    }


    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }


}

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

struct node
{
	long long int a,b;
};

bool cmp(node e,node f)
{
	if(e.a!=f.a)

	return e.a<f.a;

	else

	return e.b>f.b;

}

int main()
{
	
	long long int n,m,y=0;
	
	cin>>n>>m;
	
	node d[n+1];
	
	for(int i=1;i<=n;i++)
	   cin >> d[i].a>> d[i].b;
	
	sort(d+1, d+n+1, cmp);
	
	for(int i=1;i<=n;i++)
	{
		if(d[i].b<m)
		{
	
			y+=d[i].a*d[i].b;
	
			m-=d[i].b;
	
		}
		else
		{
			y+=d[i].a*m;
			break;
		}
	}
	cout<<y;
}

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
//#define MOD 1000000007
#define MOD 998244353
#define INF LLONG_MAX/2
#define int long long

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int gcd(int a,int b){
    int r;
    if(a<b) swap(a,b);
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int atcoder(){
    int n,k;
    cin>>n>>k;
    Vi v(n);
    REP(i,0,n){
        cin>>v[i];
        if(v[i]==k){cout<<"POSSIBLE"<<ENT;return 0;}
    }
    int g=v[0];
    REP(i,1,n) g=gcd(g,v[i]);
    
    if(k%g==0 && k<=*max_element(ALL(v))) cout<<"POSSIBLE"<<ENT;
    else cout<<"IMPOSSIBLE"<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int X=nextInt();
		int sum=X;
		int ans=1;
		while(sum%360!=0){
			sum+=X;ans++;
		}
		out.println(ans);
		out.flush();
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}


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


int main() {
  int N,H;
  cin >> N >> H;
  int bi = H;
  for (int i=0; i<N-1; i++) {
    cin >> H;
    if (bi > H+1) {
      cout << "No" << endl;
      return 0;
    }
    bi = max(bi,H);
  }
  cout << "Yes" << endl;
  return 0;
}

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

int     main() {
        int A, B, C;
        int X, Y;
        cin >>A >>B >>C >>X >>Y;
        int S=X*A+B*Y;
        for (int i=0; i<=max(X, Y); i++) {
                int SS=i*C*2;
                SS += max(0, X-i)*A + max(0, Y-i)*B;
                S = min(S, SS);
        }
        cout <<S <<endl;
        return 0;
};

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

ll dp[1010][1 << 13];  // i番目まで考えた時、集合を{~~}にする為に必要な最小費用

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

int main() {
  ll n, m;
  cin >> n >> m;

  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= (1 << n); j++) {
      dp[i][j] = INFL;
    }
  }
  dp[0][0] = 0;

  for (ll k = 0; k < m; k++) {
    ll a, b;
    cin >> a >> b;
    ll s = 0;
    for (ll i = 0; i < b; i++) {
      ll c;
      cin >> c;
      s = s | (1 << (c - 1));
    }

    // 全ての組み合わせから配るDP
    for (ll i = 0; i < (1 << n); i++) {
      dp[k + 1][i] = min(dp[k + 1][i], dp[k][i]);  // 使わなかった
    }
    for (ll i = 0; i < (1 << n); i++) {
      dp[k + 1][i | s] = min(dp[k + 1][i | s], dp[k][i] + a);  // 使った
      // cout << bitset<8>(i | s) << endl;
    }
  }

  // for (int i = 0; i <= m; i++) {
  //   for (int j = 0; j < (1 << n); j++) {
  //     cout << ((dp[i][j] == INFL) ? -1 : dp[i][j]) << " ";
  //   }
  //   cout << endl;
  // }

  if (dp[m - 1][(1 << n) - 1] >= INFL) {
    cout << -1 << endl;
  } else {
    cout << dp[m - 1][(1 << n) - 1] << endl;
  }
}


Measured memory_bytes: 63104
"use strict"
 
function Main(s) {
  s = s.trim().split('\n');
  const robos = s.slice(1, s.length);
 
  const l = robos.map(robo => {
    let t = robo.split(' ').map(Number);
    return [t[0]-t[1], t[0]+t[1]];
  })
  l.sort((a, b) => a[1] - b[1]);

  let range =-1e10;
  let cnt = 0;
  for(let i=0; i <l.length; ++i){
    const min = l[i][0];
    const max = l[i][1];

    if(range <= min) {
      range = max;
      cnt++;
    }
  }
 
  console.log(cnt);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 53312
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int h, w, n; cin >> h >> w >> n;
    int si, sj; cin >> si >> sj;
    string S; cin >> S;
    string T; cin >> T;

    int l = sj;
    int r = sj;
    int u = si;
    int d = si;

    for(int i = 0; i < n; i++){
        if(S[i] == 'U') u--;
        if(S[i] == 'R') r++;
        if(S[i] == 'D') d++;
        if(S[i] == 'L') l--;
        
        if(d <= 0 || h < d || u <= 0 || h < u || l <= 0 || w < l || r <= 0 || w < r){
            cout << "NO" << endl;
            return 0;
        }

        if(T[i] == 'U') if(d != 1) d--;
        if(T[i] == 'D') if(u != h) u++;
        if(T[i] == 'L') if(r != 1) r--;
        if(T[i] == 'R') if(l != w) l++;
        

    }

    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 776
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int k = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                set.add(sc.nextInt());
            }
        }
        System.out.println(n - set.size());
    }


}

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

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A(Q), B(Q), C(Q), D(Q);
    for(int i=0; i<Q; i++){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--; B[i]--;
    }

    vector<vector<int>> V[11];
    for(int i=1; i<=M; i++) V[1].push_back({i});
    for(int i=1; i<N; i++) for(auto& v : V[i]){
        int b = v.back();
        for(int a=b; a<=M; a++){
            auto v2 = v;
            v2.push_back(a);
            V[i+1].push_back(v2);
        }
    }

    int ans = 0;
    for(auto& v : V[N]){
        int res = 0;
        for(int i=0; i<Q; i++) if(v[B[i]] - v[A[i]] == C[i]) res += D[i];
        ans = max(ans, res);
    }

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


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

int main(){
  int H, N; cin >> H >> N;
  int M=0;
  for(int i=0;i<N;i++){
    int a; cin >> a;
    M+=a;
  }
  if(M>=H){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string t;
  cin >> t;
  
  
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '?') cout << "D";
    else cout << t[i];
  }
  cout << '\n';
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

ll gcd(ll a,ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a%b);
}

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> x(n + 1);
  rep(i, n) cin >> x[i];
  x[n] = s;

  sort(x.begin(), x.end());
  ll ans = x[1] - x[0];
  rep(i, n) ans = gcd(ans, x[i + 1] - x[i]);
  cout << ans << endl;




  
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int max1 = 0, max2 = 0;
    int a;

    int p = 0;

    for(int i = 0; i < n; i++){
        cin >> a;
        if(a >= max1){
            max2 = max1;
            max1 = a;
            p = i;
        }else if(max1 > a && max2 <= a){
            max2 = a;
        }
    }

    for(int i = 0; i < n; i++){
        if(i == p){
            cout << max2 << endl;
        }else{
            cout << max1 << endl;
        }
    }

    return 0;
}

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

#define false 0
#define true (!false)

int A[3][3];
int N;
int B[100];

/***************************************
    存在するかどうかをチェック
***************************************/
int check( int n )
{
    int i;

    for( i=0; i<N; i++ ) if( B[i] == n ) return( true );

    return( false );
}

/***************************************
    main
***************************************/
int main( int argc, char *argv[] )
{
    int n, i;

    for( i=0; i<3; i++ ) {
        if( scanf( "%d%d%d", &A[i][0], &A[i][1], &A[i][2] ) != 3 ) {
            puts( "Input error." );
            exit( 0 );
        }
    }

    if( scanf( "%d", &N ) != 1 ) {
        puts( "Input error." );
        exit( 0 );
    }

    for( i=0; i<N; i++ ) {
        if( scanf( "%d", &B[i] ) != 1 ) {
            puts( "Input error." );
            exit( 0 );
        }
    }

//printf( "\n" );
//for( i=0; i<3; i++ ) printf( "%2d %2d %2d\n", A[i][0], A[i][1], A[i][2] );
//for( i=0; i<N; i++ ) printf( "%2d ", B[i] );
//printf( "\n" );

    for( i=0; i<3; i++ ) {
        if( check(A[i][0]) && check(A[i][1]) && check(A[i][2]) ) {
            puts( "Yes" );
            exit(0);
        } else if( check(A[0][i]) && check(A[1][i]) && check(A[2][i]) ) {
            puts( "Yes" );
            exit(0);
        }
    }

    if( check(A[0][0]) && check(A[1][1]) && check(A[2][2]) ) {
            puts( "Yes" );
            exit(0);
    } else if( check(A[0][2]) && check(A[1][1]) && check(A[2][0]) ) {
            puts( "Yes" );
            exit(0);
    }

    puts( "No" );
}


Measured memory_bytes: 128
A,B,C,D,E,F = map(int,input().split())
W=set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        W.add(a+b)
S=set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        S.add(c+d)
rate = -1
for w in W:
    for s in S:
        if 0 < w+s <= F and s <= w*E//100:
            if s/(w+s) > rate:
                rate = s/(w+s)
                ans = w+s, s
print(ans[0],ans[1])

Measured memory_bytes: 3828
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, P = NMI()
    
    if N == 1:
        print(P)
        sys.exit()
    else:
        ans = 1
        for n in range(2,int(P**0.5)+1):
            if P % n != 0:
                continue
            else:

                cnt = 0
            while P % n == 0:
                P = P //n
                cnt += 1
            if cnt//N >= 1:
                ans = ans * n **(cnt // N )
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9712
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

using namespace std;

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

	transform(a.begin(), a.end(), a.begin(), ::toupper);
	transform(b.begin(), b.end(), b.begin(), ::toupper);
	transform(c.begin(), c.end(), c.begin(), ::toupper);
	cout<<a[0]<<b[0]<<c[0]<<endl;

	return 0;

}

Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2]=='AC' else 0)
for _ in range(Q):
  l, r = map(int,input().split())
  print(index[r-1] - index[l-1])

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

using namespace std;

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

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

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

struct Vertex {
    vector<ll> node;
};

Vertex V[100005];
ll T[100005];
ll A[100005];

int main() {
    ll N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    REP(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }

    {
        memset(A, -1, sizeof(A));
        A[v] = 0;
        queue<pll> q;
        q.push(pll(v, 0));
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            REP(i, V[t.first].node.size()) {
                ll n = V[t.first].node[i];
                if (A[n] >= 0)
                    continue;
                A[n] = t.second + 1;
                q.push(pll(n, t.second + 1));
            }
        }
    }

    ll max = 0;
    {
        memset(T, -1, sizeof(T));
        T[u] = 0;
        queue<pll> q;
        q.push(pll(u, 0));
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            ll k = t.first;
            max = std::max(max, T[k]);
            if (V[k].node.size() >= 2) {
                ll m = (A[k] - T[k] + 1) / 2;
                max = std::max(max, std::min(T[k] + m * 2, A[k]));
            }
            REP(i, V[t.first].node.size()) {
                ll n = V[t.first].node[i];
                if (T[n] >= 0)
                    continue;
                T[n] = t.second + 1;
                if (T[n] > A[n])
                    continue;
                max = std::max(max, T[n]);
                if (V[n].node.size() >= 2) {
                    ll m = (A[n] - T[n] + 1) / 2;
                    max = std::max(max, std::min(T[n] + m * 2, A[n]));
                }
                if (T[n] < A[n])
                    q.push(pll(n, t.second + 1));
            }
        }
    }

    cout << max <<
         endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    vector<int> lis;
    if(s[0] == '0') lis.push_back(0);
    for (int i = 0; i < n; ++i){
        if(i > 0 && s[i] != s[i - 1]){
            lis.push_back(cnt);
            cnt = 1;
        }else cnt++;
    }
    lis.push_back(cnt);
    if(s[s.size() - 1] == '0') lis.push_back(0);
    vector<int> accum(lis.size() + 1, 0);
    for (int i = 0; i < lis.size(); ++i) accum[i + 1] += accum[i] + lis[i];
    if(2 * k + 1 >= lis.size()){
        cout << accum[accum.size() - 1] << endl;
        return 0;
    }else{
        int ans = 0;
//        rep(i, lis.size()) cout << lis[i] << endl;
        for (int i = 1; i + 2 * k < accum.size(); i += 2) {
            ans = max(ans, accum[i + 2 * k] - accum[i - 1]);
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 1272
class Node:
    def __init__(self, num=None, parent=None, left=None, right=None, depth=None, height=None, sibling=None
                 , degree=None, type=None):
        self.num = num
        self.parent = parent
        self.left = left
        self.right = right
        self.depth = depth
        self.height = height
        self.sibling = sibling
        self.degree = degree
        self.type = type

    def __str__(self):
        if self.parent is None:
            resParent = '-1'
        else:
            resParent = str(self.parent.num)

        if self.sibling is None:
            resSibling = '-1'
        else:
            resSibling = str(self.sibling.num)

        return 'node ' + str(self.num) + ': parent = ' + resParent + ', sibling = ' + resSibling \
               + ', degree = ' + str(self.degree) + ', depth = ' + str(self.depth) + ', height = ' + str(self.height) \
               + ', ' + self.type

def setDepth(node, depth):
    """
    :param node: Root node (in order to set height value to all nodes underneath
    :param depth: Depth of root node (=0)
    :return: nothing
    """
    if node == None:
        return
    node.depth = depth
    setDepth(node.left, depth+1)
    setDepth(node.right, depth+1)

def setHeight(node):
    """
    :param node: Root node (in order to set height value to all nodes underneath
    :return: height + set height value to all nodes underneatha
    """
    h1, h2 = 0, 0
    if node.left is not None:
        h1 = setHeight(node.left) + 1
    if node.right is not None:
        h2 = setHeight(node.right) + 1
    height = max(h1, h2)
    node.height = height
    return height

def getSibling(node):
    parent = node.parent
    if parent is None:
        return None
    elif parent.left != node and parent.left is not None:
        return parent.left
    elif parent.right != node and parent.right is not None:
        return parent.right
    return None

def getDegree(node):
    if node.left is None and node.right is None:
        return 0
    elif node.left is None or node.right is None:
        return 1
    else:
        return 2

def getType(node):
    if node.parent is None:
        return 'root'
    elif node.left is None and node.right is None:
        return 'leaf'
    else:
        return 'internal node'

# import sys
# sys.stdin = open('input.txt', 'r')

n = int(input())
nodes = []

# Initiate all nodes
for i in range(n):
    node = Node(i)
    nodes.append(node)

# Set parent, left and right from input
for i in range(n):
    num, leftNum, rightNum = map(int, input().split())
    node = nodes[num]
    if leftNum != -1:
        node.left = nodes[leftNum]
        node.left.parent = node
    if rightNum != -1:
        node.right = nodes[rightNum]
        node.right.parent = node

for node in nodes:
    node.sibling = getSibling(node)
    node.degree = getDegree(node)
    node.type = getType(node)
    if node.type == 'root':
        root = node

setDepth(root, 0)
setHeight(root)

for node in nodes:
    print(node)



Measured memory_bytes: 5660
#include<iostream>
#include<cmath>
using namespace std;
struct node{
	int t,x,y;
}a[100010];
int main()
{
	int n,i;
	cin >> n;
	a[0].x=0;a[0].y=0;a[0].t=0;
	for(i=1;i<=n;i++)
		cin >> a[i].t>>a[i].x>>a[i].y;
	for(i=1;i<=n;i++){
		int minn=abs(a[i].x-a[i-1].x)+abs(a[i].y-a[i-1].y);
		int realt=a[i].t-a[i-1].t;
		if(minn%2!=realt%2||realt<minn) break;
	}
	if(i>n) cout << "Yes"<<endl;
	else cout <<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

int gcd(int l, int r){
    if(r == 0) return l;
    else return gcd(r, l % r);
}

int lcd(int l, int r){
    return min(l, r) / gcd(l, r) * max(l, r);
}

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

    int n; cin >> n;
    int num[n];

    for(int i=0; i<n; i++) cin >> num[i];

    int ans = lcd(num[0], num[1]);
    for(int i=2; i<n; i++){
        ans = lcd(ans, num[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3228
#include <iostream>
using namespace std;
int main() {
	int n, d;
	cin >> n >> d;
	if (n % (d * 2 + 1) == 0)
		cout << (n / (d * 2 + 1));
	else
		cout << (n / (d * 2 + 1)) + 1;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e15;
const int MB = 20;
const int MOD = 1e9 + 7;


void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	vector<int> c(n);
	for (int i = 0; i < n; i++) cin >> c[i];
	int ans = -INF;
	for (int i = 0; i < n; i++) {
		vector<int> t = { i };
		int now = p[i];
		while (now != i) {
			t.push_back(now);
			now = p[now];
		}
		int sum = 0;
		for (int i = 0; i < t.size(); i++) {
			sum += c[t[i]];
		}
		now = 0;
		for (int i = 0; i < t.size() && k >= i + 1; i++) {
			int res = 0;
			now += c[t[i]];
			if (sum > 0) res += ((k - i - 1) / t.size()) * sum;
			ans = max(ans, now + res);
		}
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

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

int main() {
    int n;
    cin >> n;
    int A[10][10] = {0};
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int h = s[0] - '0', b = s.back() - '0';
        A[h][b]++;
    }
    int ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            if(j == i) ans += A[i][j] * A[i][j];
            else ans += A[i][j] * A[j][i] * 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

void YES(bool f){
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    int n,k;
    cin>>n>>k;
    YES((n+1)/2>=k);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 100;
int V,E;
vector<int> g[MAX];
int s[MAX];
int flag = false;

void visit(int x) {
    int ver;
    s[x] = 1;
    for(int i=0; i<g[x].size(); i++) {
        ver = g[x][i];
        if(s[ver] == 1) {
            flag = true;
            break;
        }
        else if(s[ver] == -1) continue;
        else visit(ver);
    }
    s[x] = -1;
}

void dfs() {
    for(int i=0; i<V; i++) s[i] = 0;
    for(int i=0; i<V; i++) {
        if(s[i] == 0) visit(i);
        if(flag) break;
    }
}

int main() {
    int s,t;
    cin >> V >> E;
    for(int i=0; i<E; i++) {
        cin >> s >> t;
        g[s].push_back(t);
    }
    dfs();

    if(flag) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}



Measured memory_bytes: 3144
#include <stdio.h>

int main()
{
	int x;
	int count = 1;
	int num = 1;
	scanf("%d", &x);
	int c;
	for (int i = 1;i <= x;i++)
	{
		scanf("%d", &c);
		count *= 3;
		if (c % 2 == 1)
		{
			num *= 1;
		}
		else
		{
			num *= 2;
		}
	}
	printf("%d", count - num);
    return 0;
}



Measured memory_bytes: 256
n = int(input())
L = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x:x[2], reverse = True)

#もし全部の条件で h = 0 だったら。。。
#if L[0][2] == 0:
#    H = 1
#    for i in range(101):
#        for j in range(101):
#            for k in range(n):
#                if 



for i in range(101):
    for j in range( 101):
        nescond = float("inf")
        H = abs(L[0][0] - i) + abs(L[0][1] - j) + L[0][2]
        cond = True
        for k in range(n):
            absX = abs(i - L[k][0])
            absY = abs(j - L[k][1])
            
            if L[k][2] == 0:
                nescond = min([nescond, absX + absY])
            else:
                if H != absX + absY + L[k][2]:
                    cond = False
                    break
        if cond and H <= nescond:
            for q in[i,j,H]:
                print(q, end = " ")


Measured memory_bytes: 3064