akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const ll MAXN=2e5+10;
const ll MOD=1e9+7;
struct Node{
    ll ind,nxt;
}node[MAXN*2];
ll n,head[MAXN],cnt;
ll sz[MAXN],dp[MAXN],ans[MAXN];
ll fac[MAXN]={1};
void add(ll x,ll y){
    node[++cnt].ind=y;
    node[cnt].nxt=head[x];
    head[x]=cnt;
}
ll inv(ll a,ll m){
    if(a==1) return 1;
    return inv(m%a,m)*(m-m/a)%m;
}
void DFS1(ll cur,ll pre){
    sz[cur]=dp[cur]=1;
    for(ll i=head[cur];i;i=node[i].nxt){
        ll ind=node[i].ind;
        if(ind==pre) continue;
        DFS1(ind,cur);
        sz[cur]+=sz[ind];
        dp[cur]=dp[cur]*inv(fac[sz[ind]],MOD)%MOD*dp[ind]%MOD;
    }
    dp[cur]=dp[cur]*fac[sz[cur]-1]%MOD;
}
void DFS2(ll cur,ll pre){
    ans[cur]=dp[cur];
    for(ll i=head[cur];i;i=node[i].nxt){
        ll ind=node[i].ind;
        if(ind==pre) continue;
        dp[cur]=dp[cur]*inv(dp[ind],MOD)%MOD*fac[sz[ind]]%MOD*fac[sz[cur]-sz[ind]-1]%MOD*inv(fac[sz[cur]-1],MOD)%MOD;
        sz[cur]-=sz[ind];
        sz[ind]+=sz[cur];
        dp[ind]=dp[ind]*dp[cur]%MOD*inv(fac[sz[cur]],MOD)%MOD*fac[sz[ind]-1]%MOD*inv(fac[sz[ind]-sz[cur]-1],MOD)%MOD;
        DFS2(ind,cur);
        dp[ind]=dp[ind]*inv(dp[cur],MOD)%MOD*fac[sz[cur]]%MOD*inv(fac[sz[ind]-1],MOD)%MOD*fac[sz[ind]-sz[cur]-1]%MOD;
        sz[ind]-=sz[cur];
        sz[cur]+=sz[ind];
        dp[cur]=dp[cur]*dp[ind]%MOD*inv(fac[sz[ind]],MOD)%MOD*inv(fac[sz[cur]-sz[ind]-1],MOD)%MOD*fac[sz[cur]-1]%MOD;
    }
}
int main(){
    for(ll i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%MOD;
    scanf("%lld",&n);
    for(ll i=1;i<n;i++){
        ll x,y;scanf("%lld %lld",&x,&y);
        add(x,y);add(y,x);
    }
    DFS1(1,0);DFS2(1,0);
    for(ll i=1;i<=n;i++){
        printf("%lld\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
#define coutd if(DEBUG) cout 
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vii = vector<ii>;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(){
	ios::sync_with_stdio(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	ll ans=0;
	for(int i=0; i<n; ++i){ 
		cin >> vs[i];
		if(vs[i]>=k) ++ans;
	}
	cout << ans << endl;
} 


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

int main() {
	double N;
	int n;
	cin >> N;
	n = N;
	if (n % 2 == 0) {
		cout << n / 2 / N;
	}
	else {
		cout << (n / 2 + 1) / N;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    REP (r, 0, N + 1) {
        REP (g, 0, N + 1) {
            int b = N - r * R - G * g;
            if (b % B != 0 || b < 0) continue;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
#define maxn 1e6;
int main()
{
	int x, y, z;
	int k, s;
	int i, j;
	int ans = 0;
	scanf("%d %d", &k, &s);
	for(i = 0; i <=  k; i++)
		for(j = 0; j <= k; j++)
		{
			z = s - (i + j);
			if(z <= k && z >= 0)
				ans++;
		}
		printf("%d\n", ans);
		return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,k;
  cin>>n>>k;
  vector<int> ans(n,false);
  rep(i,k){
    int d;
    cin>>d;
    rep(_,d){
      int a;cin>>a;a--;
      ans[a]=true;
    }
  }
  int cnt = 0;
  rep(i,n)if(ans[i]==0)cnt++;
  cout<<(cnt)<<endl;

}

Measured memory_bytes: 3624
use proconio::input;
use proconio::marker::Usize1;
use std::cmp;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        M: usize,
        H: [u64; N],
    }
    let mut max = vec![0; N];
    for _ in 0..M {
        input! {
            A: Usize1,
            B: Usize1,
        }

        max[A] = cmp::max(max[A], H[B]);
        max[B] = cmp::max(max[B], H[A]);
    }

    let mut ans = 0;
    for (h, m) in H.iter().zip(max.iter()) {
        if h > m {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

int main(){
    ll n,q;
    cin>>n;
    map<ll,ll> mp;
    vector<ll> ans;
    ll sum=0;
    rep(i,n){
        ll a;
        cin>>a;
        sum+=a;
        mp[a]+=1;
    }
    cin>>q;
    rep(i,q){
        ll b,c;
        cin>>b>>c;
        sum += mp[b]*(c-b);
        mp[c]+=mp[b];
        mp[b]=0;
        ans.push_back(sum);
    }
    for(auto v:ans){
        cout<<v<<endl;
    }

    return 0;
}

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

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

    if(N % 2 == 0) {
        for(int i=N-1; i>0; i -= 2) cout << A[i] << ' ';
        for(int i=0; i<=N-2; i += 2) cout << A[i] << (i==N-2 ? '\n' : ' ');
    } else {
        if(N == 1) cout << A[0] << endl;
        else {
            for(int i=N-1; i>=0; i -= 2) cout << A[i] << ' ';
            for(int i=1; i<=N-2; i += 2) cout << A[i] << (i==N-2 ? '\n' : ' ');
        }
    }
}

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

int main(){
    int N,W;
    cin >> N >> W;
    int v[101],w[101];
    for(int i=0;i<N;i++) cin >> v[i] >> w[i];

    int dp[10001];
    for(int i=0;i<10001;i++) dp[i]=0;

    for(int i=0;i<N;i++){
        for(int j=W;j>=0;j--){
            if(j-w[i]>=0) dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
        }
    }

    cout << dp[W] << endl;
}

Measured memory_bytes: 1200
def int2(x):
    try:
       return int(x)
    except:
        return x

N = int(input())
st = [list(map(int2,input().split())) for i in range(N)]
X = input()

ans = 0
flg = False
c = 0
for s,t in st:
    if s == X:
        flg = True
    if flg:
        if c ==0:
            c += 1
        else:
            ans += t
            c += 1
print(ans)
    


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
bool check(string s, string t)
{
    rep(i, s.size())
    {
        if (s[i] == '?')
        {
            continue;
        }
        else
        {
            if (s[i] != t[i])
            {
                return false;
            }
        }
    }
    return true;
}
int main()
{
    string s, t;
    cin >> s >> t;
    int slen = s.size();
    int tlen = t.size();
    set<string> se;
    rep(i, slen - tlen + 1)
    {
        string a = s.substr(i, tlen);
        if (check(a, t))
        {
            string ans = s;
            rep(j, tlen)
            {
                ans[j + i] = t[j];
            }
            rep(j, slen)
            {
                if (ans[j] == '?')
                {
                    ans[j] = 'a';
                }
            }
            se.insert(ans);
        }
    }
    if (se.size() == 0)
    {
        cout << "UNRESTORABLE" << endl;
    }
    else
    {
        auto ite = se.begin();
        cout << *ite << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class HandV:
    def __init__(self, H, W, K, C):
        self.H = H
        self.W = W
        self.K = K
        self.C = C
        self.H_bar = [False] * H
        self.W_bar = [False] * W
        self.result = 0

    def solve(self):
        for i in range(2 ** self.H):
            for j in range(2 ** self.W):
                H_bar = [False] * self.H
                W_bar = [False] * self.W

                for n in range(H):
                    if (i & (2 ** n)) == 2 ** n:
                        H_bar[n] = True
                for n in range(W):
                    if (j & (2 ** n)) == 2 ** n:
                        W_bar[n] = True

                self.H_bar = H_bar
                self.W_bar = W_bar

                self.check()

    def check(self):
        black_count = 0
        for i in range(self.H):
            for j in range(self.W):
                if self.H_bar[i] or self.W_bar[j]:
                    continue
                if self.C[i][j] == "#":
                    black_count += 1
        if black_count == self.K:
            self.result += 1
 
H, W, K = map(int, input().split())

C = [ [None] * W for i in range(H) ]
for i in range(H):
    c_line = input()
    for j, c in enumerate(c_line):
        C[i][j] = c

handv = HandV(H, W, K, C)
handv.solve()
print(handv.result)


Measured memory_bytes: 73964
//
//  main.cpp
//  Exercise
//
//

#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <array>
#include <set>

using namespace std;

using int_t = long long;

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) {
        printf("Yes");
    } else {
        printf("No");
    }
    printf("\n");
    return 0;
}


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

const long long MOD=(long long)(1e9+7);
const int NAX=1005;
Int N,M,K;
Int W,H;
Int X,Y,Z;
vector<Int> A;

Int perform(Int x){
    return (x*(x+1))/2LL;
}
int main()
{
    cin>>N;
    vector<pair<Int,Int>> pairs;
    for(int i=0;i<N;++i){
        Int u,v;
        cin>>u>>v;
        pairs.pb({u,v});
    }
    
    bool fine=false;
    int K=3;
    Int times=0;
    for(int i=0;i<K;++i){
        times+=(pairs[i].first==pairs[i].second);
    }
    if(times==3){
        fine=true;
    }
    
    for(int i=K;i<N;++i){
        times+=pairs[i].first==pairs[i].second;
        times-=pairs[i-K].first==pairs[i-K].second;
        if(times==3) fine=true;
    }
    cout<<(fine ? "Yes\n":"No\n");
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T,typename U> inline double dist(pair<T,T>& a,pair<U,U>& b) {return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));}

template<typename T>
pair<pair<double,double>,double> min_circle(vector<pair<T,T>>& v) {
    int n = v.size();
    mt19937 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    shuffle(v.begin(),v.end(),r);
    pair<pair<double,double>,double> d = make_pair(make_pair((v[0].first+v[1].first)/2.0,(v[0].second+v[1].second)/2.0),dist<T,T>(v[0],v[1])/2);
    
    for (int i = 2;i < n;++i) if (dist<double,T>(d.first,v[i]) > d.second+1e-12) {
        d = make_pair(make_pair((v[0].first+v[i].first)/2.0,(v[0].second+v[i].second)/2.0),dist<T,T>(v[0],v[i])/2);
        for (int j = 1;j < i;++j) if (dist<double,T>(d.first,v[j]) > d.second+1e-12) {
            d = make_pair(make_pair((v[i].first+v[j].first)/2.0,(v[i].second+v[j].second)/2.0),dist<T,T>(v[i],v[j])/2);
            for (int k = 2;k < j;++k) if (dist<double,T>(d.first,v[k]) > d.second+1e-12) {
                double a = dist<T,T>(v[j],v[k]),b = dist<T,T>(v[i],v[k]),c = dist<T,T>(v[i],v[j]);
                a *= a;b *= b;c *= c;
                double A = a*(b+c-a),B = b*(c+a-b),C = c*(a+b-c);
                d.first.first = (A*v[i].first+B*v[j].first+C*v[k].first)/(A+B+C);
                d.first.second = (A*v[i].second+B*v[j].second+C*v[k].second)/(A+B+C);
                d.second = dist<double,T>(d.first,v[i]);
            }
        }
    }
    
   return d;
}

int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    for (int i = 0;i < n;++i) cin >> a[i].first >> a[i].second;
    cout << fixed << setprecision(12) << min_circle(a).second << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{

    string s, t;
    cin >> s >> t;
    int count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != t[i])
            count++;
    }

    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int K,N,dis[200000];
int main()
{
	int maxd = 0;
	cin >> K >> N;
	cin >> dis[0];
	for(int i = 1 ; i < N ; i ++)
	{
		cin >> dis[i];
		int temp = dis[i] - dis[i- 1];
		if(maxd < temp)
			maxd = temp;
	}
	int temp =K - dis[N-1] + dis[0];
	if(maxd < temp)
		maxd = temp;
	cout <<  K - maxd << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    X = ii()
    X = X//100
    if 4 <= X < 6:
        print(8)
    elif 6 <= X < 8:
        print(7)
    elif 8 <= X < 10:
        print(6)
    elif 10 <= X < 12:
        print(5)
    elif 12 <= X < 14:
        print(4)
    elif 14 <= X < 16:
        print(3)
    elif 16 <= X < 18:
        print(2)
    elif 18 <= X < 20:
        print(1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
int a[110000];

main()
{
int q;
scanf("%d",&q);
map<string , int> mp;
while(q--){
        string s;
cin>>s;
mp[s]++;
}
cout<<"AC x "<<mp["AC"]<<endl;
cout<<"WA x "<<mp["WA"]<<endl;
cout<<"TLE x "<<mp["TLE"]<<endl;
cout<<"RE x "<<mp["RE"]<<endl;

}




Measured memory_bytes: 3696
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n int
  fmt.Scan(&n)
  cards := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&cards[i])
  }
  sort.Sort(sort.Reverse(sort.IntSlice(cards)))
  var list []int
  for _, v := range cards {
    count := 0
    for _, w := range list {
      if v == w {
        count++
      }
    }
    if count == 0 {
      list = append(list, v)
    }
  }
  fmt.Println(len(list))
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long d = sc.nextInt();
		d = d * d;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			long x = sc.nextInt();
			long y = sc.nextInt();
			if (d >= x * x + y * y)
				cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 60612
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();    
    int C = sc.nextInt();

    if(A == B){
      if(A!=C){
        System.out.println("Yes");
        return;
      }
    }
    if(A == C){
      if(B!=C){
        System.out.println("Yes");
        return;
      }
    }
    if(B == C){
      if(A!=C){
        System.out.println("Yes");
        return;
      }
    }

    System.out.println("No");
    return;


    
  }
}



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

int main(){
  int mp[6][2];
  for(int i=0;i<6;i++)
    for(int j=0;j<2;j++) 
      mp[i][j] = -1;

  mp[0][0] = 2;
  mp[0][1] = 3;
  mp[1][0] = 3;
  mp[1][1] = 2;
  mp[2][0] = -1;
  mp[2][1] = 4;
  mp[3][0] = 2;
  mp[3][1] = -1;
  mp[4][0] = 5;
  mp[4][1] = 1;
  mp[5][0] = 1;
  mp[5][1] = 3;

  string str;
  while(1) {
    cin >> str;
    if(str[0] == '#') break;


    int ima = 0;
    for(int i=0;i<str.size();i++) {
      ima = mp[ima][str[i]-'0'];
      if(ima == -1) break;
    }
    if(ima == 1) cout <<"Yes" << endl;
    else cout << "No" << endl;

  }

  return 0;

}

Measured memory_bytes: 1176
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = list(map(int, input().split()))
    count = [0]*N
    answer=[]
    M = 0
    for i in range(N)[::-1]:
        j = i+1
        if count[i]%2 != A[i]:
            answer.append(j)
            M += 1
            div = make_divisors(j)
            for k in div:
                count[k-1] += 1
    print(M)
    print(*answer)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

if __name__ == '__main__':
    main()

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

int n,x,a[110],sum;

int main(){
    while(cin>>n>>x){
        sum = 0;
        for(int i=0; i<n; i++){
            cin>>a[i];
        }
        sort(a,a+n,less<int>());
        for(int i=0; i<n; i++){
            if(a[i]>x){
                x = 0;
                break;
            }
            x = x - a[i];
            //cout<<" #"<<x<<endl;
            sum++;
        }
        if(x!=0&&sum>0)
            sum--;
        cout<<sum<<endl;
    }
    return 0;
}


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

using namespace std;

class Node {
  private:
    int id;
    int parent_id;
    int sibling;
    int degree;
    int depth;
    int height;
    const char * type;
    Node *parent;
    Node *left;
    Node *right;
  public:
    Node()
        : id(-1),parent_id(-1),sibling(-1),degree(0),depth(0),height(0),
          type("internal node"), parent(NULL), left(NULL), right(NULL) { }
    int GetId() const { return id; }
    int GetParentId() const { return parent_id; }
    int GetSiblingId() const {
        return sibling;
    }
    int GetDegree() const { return degree; }
    int GetDepth() const { return depth; }
    int GetHeight() const { return height; }
    const char *GetType() const {
        if (this->parent == NULL) {
            return "root";
        }
        else if (this->left == NULL && this->right == NULL) {
            return "leaf";
        }
        return type;
    }
    void IncrementHeight() {
        if (parent == NULL) { return; }
        int tmp_height = this->height + 1;
        if (tmp_height > parent->height) {
            parent->height = tmp_height;
            parent->IncrementHeight();
        }
    }
    void IncrementDepth() {
        this->depth = this->parent->depth + 1;
        if (this->left) {
            this->left->IncrementDepth();
        }
        if (this->right) {
            this->right->IncrementDepth();
        }
    }
    Node* SetId(int id) {
        this->id = id;
        return this;
    }
    Node* SetParent(Node* parent) {
        this->parent = parent;
        this->parent_id = parent->id;
        IncrementHeight();
        IncrementDepth();
        return this;
    }
    Node* SetLeft(Node *left) {
        this->left = left;
        this->left->SetParent(this);
        if (this->right) {
            this->right->sibling = this->left->id;
            this->left->sibling = this->right->id;
        }
        ++this->degree;
        return this;
    }
    Node* SetRight(Node* right) {
        this->right = right;
        this->right->SetParent(this);
        if (this->left) {
            this->left->sibling = this->right->id;
            this->right->sibling = this->left->id;
        }
        ++this->degree;
        return this;
    }
};


int n;
Node nodes[25];

int main(void) {

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        nodes[i].SetId(i);
    }

    for (int i = 0, id, left, right; i < n; ++i) {
        scanf("%d %d %d", &id, &left, &right);
        Node& node = nodes[id];
        if (left != -1) {
            node.SetLeft(&nodes[left]);
        }
        if (right != -1) {
            node.SetRight(&nodes[right]);
        }
    }

    for (int i = 0; i < n; ++i) {
        Node& node = nodes[i];
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", node.GetId(), node.GetParentId(), node.GetSiblingId(),node.GetDegree(), node.GetDepth(), node.GetHeight(), node.GetType());
    }

    return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
//const long double PI =3.14159265358979323846264338327950;
//const long double PI =3.141592653589793238462
#define PI 3.14159265358979323846264338327950L
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

int main()
{FAST
ld a,b,h,m,ang;
cin>>a>>b>>h>>m;
ang = PI*2*((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
ld k=pow(a,2)+pow(b,2)-2*a*b*cos((ang));
cout << fixed << setprecision(20)<<pow(k,0.5);
return  0;
}





Measured memory_bytes: 4184
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

fn main(){
    let line = read_as_vec::<i32>();
    let (a, b) = (line[0], line[1]);

    if (a*b)%2 == 1{
        println!("Yes");
    }else{
        println!("No");
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll dist[111][111];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, E;
    cin >> N >> E;
    REP(i,N) REP(j,N) if(i != j) dist[i][j] = LINF;

    REP(i,E){
        ll s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    REP(k,N) REP(i,N) REP(j,N) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    bool ok = true;
    REP(k,N) REP(i,N) REP(j,N) if(chmin(dist[i][j], dist[i][k] + dist[k][j])) ok = false;
    if(!ok){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    REP(i,N){
        REP(j,N){
            if(dist[i][j] > 1e10) cout << "INF";
            else cout << dist[i][j];
            if(j != N - 1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3308
#include <stdio.h>  
int main()
{
    int n, x, a, b, c, ans;
 
    while(1)
    {
        ans = 0;
 
        scanf(" %d %d", &n, &x);
 
        if(n == 0 && x == 0) return 0;
 
        for(a=1; a<n+1; a++)
        {
            for(b=a+1; b<n+1; b++)
            {
                for(c=b+1; c<n+1; c++)
                {
                    if(x == (a+b+c))
                    {
                        ans++;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }       
    return 0;
}
 

 

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.Scanner;
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[m];
		ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
		int[] p = new int[m];

		for(int i = 0;i < m;i++){
			k[i] = sc.nextInt();
			ArrayList<Integer> sub = new ArrayList<Integer>();
			for(int j = 0;j < k[i];j++){
				sub.add(sc.nextInt()-1);
			}
			list.add(sub);
		}
		for(int i = 0;i < m;i++){
			p[i] = sc.nextInt();
		}
		
		

		int bit = 0;
		int ans = 0;
		for(;bit < 1<<n;bit++){
			if(checkswitch(bit,k,list,p,m)){
				ans++;
			}
		}
		System.out.print(ans);




	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){
		
//		System.out.println("bit " + bit);
			
		for(int i = 0;i < m;i++){
			
			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
//					System.out.println("on  ");
				}
				
			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}
			
		}
		

		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




Measured memory_bytes: 24148
#include <stdio.h>

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

    int a[n];
    int min=0, max=0;

    scanf("%d", &a[0]);
    min = a[0];
    max = a[0];

    for(i=1; i<n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i] < min)
        {
            min = a[i];
        }
        else if(a[i] > max)
        {
            max = a[i];
        }
    }
    printf("%d\n", max-min);

    return 0;
}

Measured memory_bytes: 128
import copy

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def correct_same_num_suits(l, num, first):
    suits = []
    for i in range(first, N):
        if num == l[i][1]:
            suits.append(l[i][0])
    return suits

def is_stable():
    idx = 0
    while idx < N-1:
        idx_incr_flg = True
        if A[idx][1] == A[idx+1][1]:
            num = A[idx][1]
            sorted_suits = correct_same_num_suits(A, num, idx)
            orig_suits = correct_same_num_suits(orig_list, num, 0)
            if sorted_suits != orig_suits:
                return False
            idx += len(sorted_suits)
            idx_incr_flg = False
        if idx_incr_flg:
            idx += 1
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


Measured memory_bytes: 39508
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
using namespace std;

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

long long lcm(long long a, long long b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	long long A, B;
	cin >> A >> B;
	cout << lcm(A, B);
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")

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

using namespace std;

#define F first
#define S second
#define MAX_N 1e5+10
#define inf 10000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vbl;

int main() {
  //freopen("input.in", "r", stdin);
  int n, W;
  cin >> n >> W;
  ll v[n+1];
  int w[n+1];
  ll dp[W+1];
  for (int i = 1 ; i <= n ; i++) {
    cin >> w[i] >> v[i];
  }
  for (int i = 1 ; i <= W ; i++) {
    dp[i] = -1;
  }
  dp[w[1]] = v[1];
  dp[0] = 0;
  for (int i = 2 ; i <= n ; i++) {
    for (int j = W-w[i] ; j >= 0 ; j--) {
      if (dp[j] != -1) {
        dp[j+w[i]] = max(dp[j+w[i]],dp[j]+v[i]);
      }
    }
  }

  ll res = 0;

  for (int i = 1 ; i <= W ; i++) {
    res = max(res,dp[i]);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1024
//
//  main.cpp
//  all-algorithm
//
//  Created by JAEYONG BAE on 11/01/2020.
//  Copyright © 2020 JAEYONG BAE. All rights reserved.
//

#include <iostream>

using namespace std;

int N;
string S;
int answer;

int main(int argc, const char * argv[]) {
    
    cin>>N;
    cin>>S;
    
    for(int i=0; i<N-2; i++)
    {
        if(S[i]=='A' && S[i+1]=='B' && S[i+2] =='C')
        {
            answer++;
        }
    }
    
    cout<<answer<<'\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int dp[160][15][100];

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

  while (1)
  {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    vector<vector<pair<int, int>>> xd(n + 2);
    for (int i = 0; i < n; i++)
    {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++)
      {
        int x, d;
        cin >> x >> d;
        x--;
        xd[i].push_back({x, d});
      }
    }

    for (int i = 0; i < 160; i++)
    {
      for (int j = 0; j < 15; j++)
      {
        for (int l = 0; l < 100; l++)
        {
          dp[i][j][l] = INT_INF;
        }
      }
    }

    for (int j = 0; j < xd[0].size(); j++)
      dp[0][j][m] = 0;

    if (m)
      for (int j = 0; j < xd[1].size(); j++)
      {
        dp[1][j][m - 1] = 0;
      }

    for (int i = 0; i < n - 1; i++)
    {
      for (int j = 0; j < xd[i].size(); j++)
      {
        for (int l = 0; l < m + 1; l++)
        {

          for (int t = 0; t < xd[i + 1].size(); t++)
          {
            int cost = (xd[i][j].second + xd[i + 1][t].second) * abs(xd[i][j].first - xd[i + 1][t].first);
            dp[i + 1][t][l] = min(dp[i + 1][t][l], dp[i][j][l] + cost);
          }

          if (l > 0)
            for (int t = 0; t < xd[i + 2].size(); t++)
            {
              int cost = (xd[i][j].second + xd[i + 2][t].second) * abs(xd[i][j].first - xd[i + 2][t].first);
              dp[i + 2][t][l - 1] = min(dp[i + 2][t][l - 1], dp[i][j][l] + cost);
            }
        }
      }
    }
    int ans = INT_INF;
    for (int j = 0; j < xd[n - 1].size(); j++) {
      for (int l = 0; l < m + 1; l++) {
        ans = min(ans, dp[n - 1][j][l]);
      }
    }
    for (int j = 0; j < xd[n - 2].size(); j++) {
      for (int l = 1; l < m + 1; l++) {
        ans = min(ans, dp[n - 2][j][l]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

// dp[i][j][k]:= i行j列に到達したときの危険度の合計の最小値　kは1行飛ばしを行った回数　
// グリッドDPの実装ヤバい版　DPはまず漸化式を考える　ある行iにいるときに次にどこに行くのかを考える．　i == 0のときとi == n + 1のときは例外処理をする　jを全て試してmも全て試す　行先をlとしてlも全部試す



Measured memory_bytes: 4136
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	am := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		am[a]++
	}
	if len(am) > k {
		var sl []int
		for _, v := range am {
			sl = append(sl, v)
		}
		sort.Ints(sl)

		var sum int
		for i := 0; i < len(am)-k; i++ {
			sum += sl[i]
		}
		fmt.Println(sum)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n-1; i >= 0; i--)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd2(i, s, n) for (ll i = n-1; i >= (s); i--)

int main() {
    string n;
    cin >> n;
    ll count = 0;
    rep(i, n.size()) {
        count += n[i] - '0';
    }
    if (count%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3732
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

string s;
LL k;

int main() {
	cin >> s >> k;
	bool is1 = true;
	int num = 0;
	REP(i, min((LL)s.size(),k)) {
		if (s[i] != '1') {
			is1=false;
			num = s[i];
			break;
		}
	}
	if (is1) {
		cout << 1 << endl;
	}
	else {
		cout << num-'0' << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i = 0; i < 3; i++){
		string s;
		cin >> s;
		cout << s[i];
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int k,t,tmp;    cin>>k>>t;
    vector<int>a;
    for(int i=0;i<t;i++){cin>>tmp;a.push_back(tmp);}
    sort(a.begin(),a.end());
    int c1=0,c2=0;
    while(!a.empty()){
        if(c1>c2){c2+=a.back();a.pop_back();}
        else {c1+=a.back();a.pop_back();}
    }
    cout<<max(abs(c1-c2)-1,0)<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    double approx = round(n/1.08);
    double approx2 = ceil(n/1.08);

    if((int)(approx*1.08) == n) cout<<int(approx)<<endl;
    else if((int)(approx2*1.08) == n) cout<<int(approx2)<<endl;
    else cout<<":("<<endl;
}


Measured memory_bytes: 256
max = 104743

$primes = (2..Math.sqrt(max).ceil).inject([*2..max]) do |nums, sieve|
  nums.reject { |num| num % sieve == 0 && num != sieve }
end

def s(x)
  answer = 0
  while x >= 0
    answer += $primes[x]
    x -= 1
  end
  answer
end

while line = gets
  n = line.chomp.to_i
  break if n == 0
  puts s(n - 1)
end

Measured memory_bytes: 38872
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    cout<<max(0,C-(A-B))<<endl;
    return 0;
}

Measured memory_bytes: 256
let NM: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
var num: [Int] = Array(repeating: 0, count: NM[1])
for _ in 1...NM[0] {
    
    for A in readLine()!.split(separator: " ").map({ Int($0)! }).dropFirst() {
        num[A-1] += 1
    }
}
var res: Int = 0
for a in num {
    if a == NM[0] { res += 1}
}
print(res)

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
cout.tie(0);
int a [32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a[ (k-1)] << "\n";
  return 0;
}


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

#define _GLIBCXX_DEBUG
#define rep(i, V) for (int i = 0; i < V; i++)
#define repr(i, V) for (int i = V-1; i >= 0; i--)
#define repval(i, a, V) for (int i = a; i < V ; i++)
#define all(x) x.begin(), x.end()
#define ld long double
#define eps 0.0000000001
#define mod 1000000007
#define inf 1e16
#define vec vector
#define each(i, mp) for(auto& i:mp)

struct Edge {
    ll to, cost;
};

int main(){
    int n, m; //points, edge
    cin >> n >> m;
    vec<vec<Edge>> graph(n);
    vec<ll> dist(n, inf);
    ll a, b, c;
    rep(i, m){
        cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back((Edge){b, -c});
    }

    bool negative = false;
    dist[0] = 0;
    rep(i, n){
        rep(v, n){
            rep(k, (int)(graph[v].size())){
                Edge e = graph[v][k];
                if (dist[v]!= inf && dist[e.to] > dist[v] + e.cost){
                    dist[e.to] = dist[v] + e.cost;
                    if (i == n-1 && e.to == n-1){
                        negative = true;
                    }
                }
            }
        }
    }
    if (!negative){
        cout << -dist[n-1] << endl;
    } else {
        cout << "inf" << endl;
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int k, a, b;
    cin >> k >> a >> b;
    if (a % k == 0 || b % k == 0 || a / k != b / k) {
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(w: f64, h: f64, x: f64, y: f64);

    // 直線が中心を通るようにすれば、面積は等分割できる
    let area = w * h / 2.0;
    // 等分割できるような直線を複数引けるのは、x, y自体が中心の場合のみ
    let center = if (w / 2.0 == x) && (h / 2.0 == y) {
        1
    } else {
        0
    };
    println!("{} {}", area, center);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    double x1,x2,y1,y2;
    double d,dx,dy;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    dx = x1-x2;
    dy = y1-y2;
    d = sqrt(dx*dx+dy*dy);
    printf("%lf",d);
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
#define mod 1000000007
#define N 4009
using namespace std;

int n,m,p,dp[N][N],s[N];
int main(){
	scanf("%d%d%d",&n,&m,&p);
	int i,j,k,l,ans=0,len=(m+n)/(p-1);
	dp[0][0]=1;
	for (i=1; i<=len; i++){
		for (j=1,s[0]=dp[i-1][0]; j<=n; j++)
			s[j]=(s[j-1]+dp[i-1][j])%mod;
		for (j=0; j<=n; j++){
			dp[i][j]=s[j];
			if (j>=p) dp[i][j]=(dp[i][j]-s[j-p]+mod)%mod;
		}
		for (j=0; j<=n; j++){
			k=i*(p-1)-j+1;
			if (k<0 || k>m) continue;
			if ((n-j)%(p-1) || (m-k)%(p-1)) continue;
			for (l=1; l<p && l<=j; l++)
				ans=(ans+dp[i-1][j-l])%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 62080
#include <stdio.h>
  
#define MAX 25

void Preorder(int);

void Inorder(int);

void Postorder(int);

typedef struct {
  int P;
  int L;
  int R;
}tree;

tree T[MAX];

int n;

int main()
{
  int i,j,id,k,kodomo,root;

  scanf("%d",&n);

  /*入力編*/

  for(i=0;i<n;i++)/*一旦全部の親を-1にする。*/
    {
      T[i].P=-1;
      T[i].R=-1;
      T[i].L=-1;
    }
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&id);/*idとkの入力*/
      scanf("%d",&T[id].L);
      kodomo=T[id].L;
      if(kodomo!=-1)T[kodomo].P=id;
      scanf("%d",&T[id].R);
      kodomo=T[id].R;
      if(kodomo!=-1)T[kodomo].P=id;
    }

  for(i=0;i<n;i++)
    {
      if(T[i].P==-1)
	{
	  root=i;
	  break;
	}
    }
  
  printf("Preorder\n");
  Preorder(root);
  printf("\n");
  
  printf("Inorder\n");
  Inorder(root);
  printf("\n");
  
  printf("Postorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}

void Preorder(int i)
{
  static int j;

  printf(" %d",i);
  j++;

  if(j!=n)
    {
      if(T[i].L!=-1)Preorder(T[i].L);
      if(T[i].R!=-1)Preorder(T[i].R);
    }
}

void Inorder(int i)
{
  static int j;
  
  if(j!=n)
    {
      if(T[i].L!=-1)Inorder(T[i].L);
       
      printf(" %d",i);
      j++;

      if(T[i].R!=-1)Inorder(T[i].R);
    }
}

void Postorder(int i)
{
  static int j;

  if(j!=n)
    {
      if(T[i].L!=-1)Postorder(T[i].L);
      
      if(T[i].R!=-1)Postorder(T[i].R);

      printf(" %d",i);
      j++;
    }
      
}




Measured memory_bytes: 2132
#include <iostream>
#include <string>

using namespace std;



int main(){
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < 3; i++){
		if(s[i] == t[i]){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll n;

int main(){
	IOS
	cin >> n;
	ll batas=sqrt(n);
	for(int i=batas;i>0;i--){
		if(n%i==0){
			cout << (n/i)+i-2 << '\n'; return 0;
		}
	}	
}


Measured memory_bytes: 3680