akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int answer = 0;
    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] heights = new int[n + 1];
    boolean[] isGood = new boolean[n + 1];
    Arrays.fill(isGood, true);
    for(int i = 1; i <= n; i++){
      heights[i] = sc.nextInt();
    }
    for(int i = 0; i < m; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(heights[a] > heights[b]){
        isGood[b] = false;
      } else if (heights[a] < heights[b]){
        isGood[a] = false;
      } else {
        // heights[a] == heights[b]
        isGood[a] = false;
        isGood[b] = false;
      }
    }
    // TODO Stream
    for(int i = 1; i <= n; i++){
      if(isGood[i] == true) answer++;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 59660
#define		_CRT_SECURE_NO_WARNINGS
#include <cstdio>

int main()
{
	int		a, b;
	char	op;
	bool	flag = true;

	do
	{
		scanf("%d %c %d", &a, &op, &b);
		switch (op)
		{
		case '+':
			printf("%d\n", a + b);
			break;
		case '-':
			printf("%d\n", a - b);
			break;
		case '*':
			printf("%d\n", a * b);
			break;
		case '/':
			printf("%d\n", a / b);
			break;
		default:
			flag = false;
			break;
		}
	} while (flag);

	return 0;
}

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

t = []
s = []
ans = 0

for i in range(N):
    si = int(input())

    if si % 10 == 0:
        t.append(si)
    else:
        s.append(si)

if len(t) > 0:
    ans += sum(t)
if len(s) > 0:
    ans += sum(s) - (sum(s) % 10 == 0) * min(s)

print(ans * (ans % 10 != 0))

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int H, W;
	int i, j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(i == 0 || i == (H - 1)){
					if(j == (W - 1)){
						printf("#\n");
					}else{
						printf("#");
					}
				}else{
					if(j == 0){
						printf("#");
					}else if(j == (W - 1)){
						printf("#\n");
					}else{
						printf(".");
					}
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=3e5+5;
int w,h,n,top1,top2,ans;
int maxi[maxn<<2],tag[maxn<<2];
int st1[maxn],st2[maxn];
pa p[maxn];
void U(int x){
	maxi[x]=max(maxi[ls],maxi[rs])+tag[x];
}
void B(int x,int l,int r){
	maxi[x]=tag[x]=0;
	if(l==r){
		maxi[x]=-p[l-1].w1;
		return;
	}
	B(ls,l,mid);B(rs,mid+1,r);
	U(x);
}
void M(int x,int l,int r,int ll,int rr,int num){
	if(l==ll&&r==rr){
		maxi[x]+=num,tag[x]+=num;
		return;
	}
	if(rr<=mid)M(ls,l,mid,ll,rr,num);
	else if(ll>mid)M(rs,mid+1,r,ll,rr,num);
	else M(ls,l,mid,ll,mid,num),M(rs,mid+1,r,mid+1,rr,num);
	U(x);
}
void solve(){
	sort(p+1,p+n+1);
	if(p[n].w1!=w)p[++n]=mp(w,-1);
	B(1,1,n);
	top1=top2=0;
	rep(i,1,n)if(p[i].w2>h/2){
		M(1,1,n,i,i,h);
		ans=max(ans,2*(maxi[1]+p[i].w1));
		M(1,1,n,st1[top1]+1,i,p[i].w2-h);
		while(top1&&p[st1[top1]].w2>p[i].w2){
			M(1,1,n,st1[top1-1]+1,st1[top1],p[i].w2-p[st1[top1]].w2),top1--;
		}
		st1[++top1]=i;
	}else{
		M(1,1,n,i,i,h);
		ans=max(ans,2*(maxi[1]+p[i].w1));
		M(1,1,n,st2[top2]+1,i,-p[i].w2);
		while(top2&&p[st2[top2]].w2<p[i].w2){
			M(1,1,n,st2[top2-1]+1,st2[top2],p[st2[top2]].w2-p[i].w2),top2--;
		}
		st2[++top2]=i;
	}
	if(p[n].w2<0)n--;
}
int main(){
	read(w);read(h);read(n);
	rep(i,1,n)read(p[i].w1),read(p[i].w2);
	solve();
	rep(i,1,n)swap(p[i].w1,p[i].w2);
	swap(w,h);
	solve();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll dishu[1005];
ll cnt;
ll zhishu[1005];
void divide(ll n)
{
	for(int i=2;i<=sqrt(n);++i)
	{
		if(n%i==0)
		{
			dishu[++cnt]=i;
			while(n%i==0) n/=i,++zhishu[cnt];
		}
	}
	if(n!=1) dishu[++cnt]=n,zhishu[cnt]=1;
}
ll d[1005];
ll turn(ll n)
{
	for(int i=1;i<=1000;++i)
	if(d[i]>n) return i-1;
}
int main()
{
	ll n;
	ll ans=0;
	for(int i=1;i<=1000;++i)  d[i]=d[i-1]+i;
	cin>>n;
	divide(n);
	for(int i=1;i<=cnt;++i)
		ans+=turn(zhishu[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3692
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    string o, e;
    cin >> o >> e;

    forn(i, o.size() + e.size()) {
        if (i % 2 == 0) {
            cout << o[i / 2];
        } else {
            cout << e[i / 2];
        }
    }
    cout << endl;

    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int N = S.length() + 1;
	vector<long long> LeftBigger(N,0);
	vector<long long> RightBigger(N,0);
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == '<') LeftBigger[i + 1] = LeftBigger[i] + 1;
		if (S[N - 2 - i] == '>') RightBigger[N - 2 - i] = RightBigger[N - 1 - i] + 1;
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) ans += max(LeftBigger[i], RightBigger[i]);
	cout << ans << endl;
}

Measured memory_bytes: 8708
H, W, K, *S = open(0).read().split()

A = []
color = 0
pivot = 0
for i, s in enumerate(S):
    r = s.find("#")
    if r != -1:
        pivot = i
        T = []
        l = -1
        while r != -1:
            color += 1
            T += [color] * (r - l)
            l, r = r, s.find("#", r + 1)
        T += [color] * (len(s) - l - 1)
        A.append(T)
    else:
        A.append(-1)

for i in reversed(range(pivot)):
    if A[i] == -1:
        A[i] = A[i + 1]

for i in range(pivot + 1, len(A)):
    if A[i] == -1:
        A[i] = A[i - 1]

for a in A:
    print(*a)


Measured memory_bytes: 7576
N = int(input())
x = []
y = []
h = []
for i in range(N):
    _x, _y, _h = map(int, input().split())
    x.append(_x)
    y.append(_y)
    h.append(_h)

def solve():
    for cx in range(101):
        for cy in range(101):
            H = -1
            Hmax = 1<<30
            flg = True
            for i in range(N):
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                if h[i] > 0:
                    HH = h[i] + dist
                    if H < 0:
                        H = HH
                    if H != HH or H > Hmax:
                        flg = False
                        break
                else:
                    Hmax = min(Hmax, dist)
                    if H > Hmax or Hmax == 0:
                        flg = False
                        break
            if flg:
                #if Hmax == 1:
                #    H = 1
                print(cx, cy, H)
                return

solve()

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

int N, M, A[100009], par[100009]; vector<int>X[100009];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		X[A[i] % M].push_back(A[i]);
	}
	for (int i = 0; i < M; i++) {
		sort(X[i].begin(), X[i].end());
		for (int j = 0; j < (int)X[i].size() - 1; j++) {
			if (X[i][j] == X[i][j + 1]) { par[i]++; j++; }
		}
	}
	vector<int>A; int sum = 0;
	for (int i = 0; i < M; i++) {
		if (i%M > (M - i) % M) continue;
		if (i%M == (M - i) % M) {
			A.push_back(i);
			continue;
		}
		int Z = min(X[i].size(), X[M - i].size());
		sum += Z;
		sum += min(par[i], ((int)X[i].size() - Z) / 2);
		sum += min(par[M - i], ((int)X[M - i].size() - Z) / 2);
	}
	for (int i = 0; i < A.size(); i++) {
		sum += X[A[i]].size() / 2;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 6144
#pragma region head
#include <bits/stdc++.h>

#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library
using mint = modint998244353;
using P = pair<mint, int>;
using Q = pair<mint, mint>;

P f(P a, P b) {
    P res;
    res.first = a.first + b.first;
    res.second = a.second + b.second;
    return res;
}
P g(Q x, P a) {
    P res = a;
    res.first *= x.first;
    res.first += x.second * a.second;
    return res;
}
Q h(Q a, Q b) {
    Q res;
    res.first = a.first * b.first;
    res.second = a.first * b.second + a.second;
    return res;
}
P idP() {
    return (P){0, 0};
}
Q idQ() {
    return (Q){1, 0};
}
int main() {
    int n, q;
    cin >> n >> q;
    vi a(n);
    rep(i, n) cin >> a[i];
    lazy_segtree<P, f, idP, Q, g, h, idQ> seg(n);
    rep(i, n) {
        seg.set(i, (P){a[i], 1});
    }
    while (q--) {
        int t;
        cin >> t;
        if (t) {
            int l, r;
            cin >> l >> r;
            cout << seg.prod(l, r).first.val() << '\n';

        } else {
            int l, r, b, c;
            cin >> l >> r >> b >> c;
            seg.apply(l, r, Q{b, c});
        }
    }
}

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

int main(){
	int n;
	cin >>n;
	
	int rev[n];
	for (int i=0; i<n; i++){
		int m=n-i-1;
		cin >>rev[m];
	}
	for (int i=0; i<n; i++){
		if (i!=0)cout <<" ";
		cout << rev[i] ;
	}
	cout <<"\n";
	return 0;
}

Measured memory_bytes: 1164
N, T = map(int, input().split())
tlist = list(map(int, input().split()))

tsum = T
for i in range(N-1):
    t1 = tlist[i]
    t2 = tlist[i+1]
    tdif = t2 - t1
    if tdif >= T:
        tsum += T
    else :
        tsum += tdif

print(tsum)

Measured memory_bytes: 25196
#include <iostream>
#include <vector>
#include <deque>
#include <string>
using namespace std;
#define ff(i,s,n) for(int i=s;i<n;i++)
#define fr(i,s,n) for(int i=n-1;i>=s;i--)
#define llu long long int 

int m,n;

int main() {
	cin>>m>>n;
	char maze[m][n];
	int sx,sy,ex,ey;
	cin>>sx>>sy>>ex>>ey;
	sx--;
	sy--;
	ex--;
	ey--;
	int distance[m][n];
	ff(i,0,m){
		ff(j,0,n){
			cin>>maze[i][j];
			distance[i][j]=1e7;
		}
	}
	//memset(distance,INT_MAX,sizeof(distance));
	deque<int> queX;
	deque<int> queY;
	
	distance[sx][sy]=0;
	queX.push_front(sx);
	queY.push_front(sy);
	int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
	while(!queX.empty()){
		int curX=queX.front();
		queX.pop_front();
		int curY=queY.front();
		queY.pop_front();	
		
		for(int sh=0;sh<4;sh++){
			int nx=curX+dx[sh];
			int ny=curY+dy[sh];
			if(nx< 0 || ny<0 || nx>=m || ny>=n || maze[nx][ny]=='#'){
				continue;
			}
			if(distance[nx][ny]>distance[curX][curY]){
				distance[nx][ny]=distance[curX][curY];
				queX.push_front(nx);
				queY.push_front(ny);
			}
		}
		
		for(int xh=curX-2;xh<=curX+2;xh++){
			for(int yh=curY-2;yh<=curY+2;yh++){
				if(xh< 0 || yh<0 || xh>=m || yh>=n || maze[xh][yh]=='#'){
					continue;
				}
				if(distance[xh][yh]>distance[curX][curY]+1){
					distance[xh][yh]=distance[curX][curY]+1;
					queX.push_back(xh);
					queY.push_back(yh);
				}
			}
		}
		
	}
	
	if(distance[ex][ey]>=1e7){
		cout<<-1;
	} else{
		cout<<distance[ex][ey];
	}
	
}

//1
//7 2
//3 5 4 5 1 1 1


Measured memory_bytes: 8104
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000005
bool isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return false;
  return true;
}
int main(){
  int n;
  bool d[MAX]={};
  for(int i=2;i<MAX;i++) d[i]=isPrime(i);
  while(cin>>n,n){
    int ans=0;
    for(int i=2;i<=n/2;i++){
      if(d[i]&&d[n-i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2144
import sys
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
C = Counter(A)
total = sum(A)
for s in sys.stdin.readlines():
    b, c = map(int, s.split())
    k = C[b]
    total += (c - b) * k
    print(total)
    C[b] = 0
    C[c] += k


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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if(K<=A){
        cout << K << endl;
    }
    else if (K<=A+B){
        cout << A << endl;
    }
    else{
        cout << 2*A + B -K << endl;
    }
}


Measured memory_bytes: 3636
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
    int n;
    cin>>n;
    vll v(n,0);
    rep(i,n)
        cin>>v[i];

    sort(all(v));

    ll dif=v[v.size()-1]-v[0];
    cout<<dif<<endl;
}

int main()
{
    fastIO();
    int t;
    t=1;
    while (t--)
    {
        Solve();
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
list1 = list(map(int, input().split()))

sum1 = 0
for i in list1:
    if(i<0):
        sum1 += 1

nl1 = np.array(list1)
np.abs(nl1)
if(sum1%2 == 0):
    a = sum(np.abs(nl1))
else:
    a = sum(np.abs(nl1))-2*min(np.abs(nl1))

print(a)

Measured memory_bytes: 23272
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007

#define int long long

int N_global;


void solve()
{
  int N;
  cin>>N;
  vector<int> vec(N,0);

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

  sort(vec.begin(),vec.end());
  vec[N-1] = vec[N-1]/2;
  cout<<accumulate(vec.begin(),vec.end(),0);
  
  
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    bool ans = (n / 10 == 9) || (n % 10 == 9);

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,x,y,pa,pb,pc;
	cin>>a>>b>>c>>x>>y;
	pa=x*a+y*b;
	pc=(x>y?x:y)*c*2;
	
	if(x<=y)
		pb=(y-x)*b+x*c*2;
	else pb=(x-y)*a+y*c*2;
	
	int res=min(pa,min(pb,pc));
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]

if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N)]
for node in range(1, N):
    a = int(input())
    edge[a-1].append(node)

def dfs(n):
    """
    dfs(n) := nを根としたトーナメントの深さ

    nの深さを浅くしたい
    -> 深い場所に浅い頂点vを割り当てる
    -> 対戦数が少ない人から対戦していく
    """

    if not edge[n]:
        return 0
    
    que = []
    for v in edge[n]:
        que.append(dfs(v))

    que.sort(reverse=True)
    
    res = 0
    for plus, depth in enumerate(que, start=1):
        # 今までの対戦数 + どれくらい深くするか
        res = max(res, depth + plus)
    
    return res

print(dfs(0))

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	string n;
	cin >> n;
	int ans = 0;
	rep(i,n.size()){
		ans += n[i] - '0';
		ans %= 9;
	}
	if(ans == 0){
		coY();
	} else coN();
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]

    return (n,)


def solve(n,):


    a = 0
    b = 0
    c = int(pow(n, 0.5))
    if debug:
        log("c=%s" % c)
    for i in range(c, 0, -1):   

        if n % i == 0:
            a = i
            b = n // i
            if debug:
                log("a=%s" % a)
                log("b=%s" % b)
            break


    return  a - 1 + b - 1


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, end=' ')
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()
	

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

public class Main
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);

		int[] a = new int[5];
		
		while(cin.hasNext())
		{
			for(int i=0; i<5; i++)
				a[i] = cin.nextInt();
			
			Arrays.sort(a);
			
			for(int i=4; i>0; i--)
				System.out.print(a[i]+" ");
				System.out.println(a[0]);
			}
	}
}

Measured memory_bytes: 12000
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt();
        int[][] a = new int[h+2][w+2];
        Arrays.fill(a[0], 0);
        Arrays.fill(a[h+1], 0);
        for(int i = 1; i < h+1; i++){
            a[i][0] = 0;
            a[i][w+1] = 0;
            String s = sc.next();
            for(int j = 1; j < w+1; j++){
                char c = s.charAt(j-1);
                if(c == '#') a[i][j] = 1;
                else if(c== '.') a[i][j] = 0;
            }
        }
        int[][] cnt = new int[h+1][w+1];
        for(int i = 1; i < h+1; i++){
            for(int j = 1; j < w+1; j++){
                if(a[i-1][j] == 1) cnt[i][j]++;
                if(a[i+1][j] == 1) cnt[i][j]++;
                if(a[i][j-1] == 1) cnt[i][j]++;
                if(a[i][j+1] == 1) cnt[i][j]++;
                if(a[i-1][j-1] == 1) cnt[i][j]++;
                if(a[i-1][j+1] == 1) cnt[i][j]++;
                if(a[i+1][j-1] == 1) cnt[i][j]++;
                if(a[i+1][j+1] == 1) cnt[i][j]++;
                if(a[i][j] == 0) System.out.print(cnt[i][j]);
                else System.out.print('#');
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int k = ni();
		int ans = 0;

		for (int i = 1; i <= n; i++) {
			if (i % 2 == 1) {
				ans++;
			}
		}
		if (ans >= k) {
			out("YES");
		} else {
			out("NO");
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int r, g;
    cin >> r >> g;
    cout << g * 2 - r;
    return 0;
}


Measured memory_bytes: 256
let () =
  let n = read_int () in
  for _ = 0 to n - 1 do
    match Scanf.scanf "%d %d %d " (fun x y z -> [x; y; z]) |> List.sort (-) with
    | [x; y; z] -> print_endline (if z*z = x*x + y*y then "YES" else "NO")
    | _ -> ()
  done

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

int main(){
  int n, d, x, a[100], ans = 0;

  cin>>n>>d>>x;

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

  for(int i=0;i<n;i++){
    if(d % a[i] == 0) ans += d / a[i];
    else ans += d / a[i] +1;
  }

  cout<<ans + x<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;
  if (b - a <= 0) cout << "delicious" << endl;
  else if (b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
from collections import Counter

N=int(input())
S=[]

for _ in range(N):
    s=input()
    S.append(s)

c=Counter(S)
arr=c.most_common()

maxnum=arr[0][1]
ans=[]

for i in range(len(arr)):
    if arr[i][1]==maxnum:
        ans.append(arr[i][0])        
    else:
        break
FA=sorted(ans)
for j in FA:
    print(j)

Measured memory_bytes: 49228
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W, N = map(int, input().split())
cand = set()
dot = set()
for _ in range(N):
    x, y = map(int, input().split())
    dot.add((x, y))
    for i in range(-2, 1):
        if 1 <= x + i <= H - 2:
            for j in range(-2, 1):
                if 1 <= y + j <= W - 2:
                    cand.add((x + i, y + j))

ans = [0] * 10
for x, y in cand:
    cnt = 0
    for i in range(3):
        for j in range(3):
            cnt += int((x + i, y + j) in dot)
    ans[cnt] += 1

zero = (H - 2) * (W - 2) - sum(ans)
ans[0] = zero
print(*ans, sep="\n")

Measured memory_bytes: 114932
using System;
class test
{
	static void Main()
    {
        for (int i = 1; i < 10; i++)
        {
            for (int j = 1; j < 10; j++)
            {
                Console.WriteLine("{0}x{1}={2}", i, j, i * j);
            }
        }
	}
}

Measured memory_bytes: 5596
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	string s;
	cin>>s;
	stack<int> curr;
	for(int i=0;i<s.length();i++)
	{
		if(curr.size()>0)
		{
			int a = curr.top();
			int b = s[i] - '0';
			if(a>b)swap(a,b);
			if(a==0&&b==1)
				curr.pop();
			else 
				curr.push(s[i]-'0');
		}
		else
			curr.push(s[i]-'0');
	}
	cout<<s.length()-curr.size()<<endl;
}

Measured memory_bytes: 720
import collections
N=int(input())
A=[]
for i in range(N):
  a=str(input())
  A.append(a)

S = collections.Counter(A)
T=[]
R=[]
ans=0
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[1])
a=T[0][1]
for i in range(len(T)):
  if T[i][1]==a:
    R.append(T[i][0])
R.sort()
for i in R:
  print(i)

Measured memory_bytes: 47784
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	var sum float64
	for i := 0; i < n; i++ {
		var x, u string
		fmt.Scan(&x, &u)
		if u == "JPY" {
			d, _ := strconv.Atoi(x)
			sum += float64(d)
		} else {
			f, _ := strconv.ParseFloat(x, 64)
			sum += float64(380000) * f
		}
	}
	fmt.Printf("%.10f\n", sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int a, b, c, d, e;
    std::cin >> a >> b >> c >> d >> e;
    auto f = [](int n) { return (n + 9) / 10 * 10; };
    int t = f(a) + f(b) + f(c) + f(d) + f(e);
    int m = std::max({ f(a) - a, f(b) - b, f(c) - c, f(d) - d, f(e) - e });
    std::cout << t - m << std::endl;

    return 0;
}


Measured memory_bytes: 256
solve :: Int -> Int -> Int
solve n 0 = n*n
solve n k = sum [ (div n b) * max 0 (b-k) + max 0 (mod n b - k+1)| b <- [1..n]]

main ::IO()
main = do
  [n,k] <- map read.words <$> getLine ::IO[Int]
  print $ solve n k


Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
string s;
cin>>s;
if (s.length()<=19&&s[5]==','&&s[13]==','){

    s[5]=' ' ;
    s[13]=' ';
   cout<<s<<endl;
}



return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}


int main() {
    int n; cin >> n;
    int h = 0;
    bool t = true;
    rep(i,n){
        int a; cin >> a;
        if (h < a) h = a - 1;
        else if (h > a) t = false;
    }
    if (t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main(){
long long  H,W; cin >> H >> W;
  long long ans = 1LL << 60;
  
  //縦に３分割する場合
  if( !(W % 3)){ ans = min( ans , ( long long)0);}
  else{ ans = min( ans , H);}
  
  //横に３分割する場合
  if( !( H % 3)){ ans = min( ans , (long long) 0);}
  else{ ans = min( ans ,W);}
  
  //横に全探索
  for(int i = 1; i <= W - 1; i++){
    long long S1 = i* H; long long S2 = (( H + 1) / 2) * ( W - i);
    long long S3 = (H / 2 )*( W - i);
    long long a = max( S1, S2); long long b = min( S1, S3);
    ans = min( ans, a - b);}
  
  //縦に全探索
  for(int j = 1; j <= H - 1; j++){
    long long S1 = j * W; long long S2 = (( W + 1) / 2) * ( H - j);
    long long S3 = (W / 2 )*(H - j);
    long long a = max( S1, S2); long long b = min( S1, S3);
    ans = min( ans, a - b);}
  
  
  cout << ans << endl; return 0;}

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

using namespace std;

#define ll long long

const int N = 5e3;

void solve(){
	ll n,a[N];
	string s;	
	cin >> n; 
	for(int i = 0; i < n; i++) cin >> a[i];
	cin >> s;
	vector<ll> p;
	for(int i = n-1; i >= 0; i--){
		int len = p.size();
		for(int j = 0; j < len; j++){
			//cout << *j; 
			a[i] = min(a[i],a[i]^p[j]);
		}
		if(a[i]){
			if(s[i] == '1'){
			cout << 1 << endl;
			return;
		}
		p.push_back(a[i]);
	}
}	
	cout << 0 << endl;
}

int main(){
	int t;
	cin >> t;
	while(t--) solve();
} 


Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<vector>
#include<math.h>

using namespace std;

static const int MAX = 200000 + 5;
static const int m = 2019;

typedef long long ll;

int pow10(int n)
{
    if(n == 0)
    {
        return 1;
    }
    else
    {
        return 10 * pow10(n - 1);
    }
}



int main(){
    string s;
    int n;
    cin >> s;
    n = s.size();
    vector<ll> T(n + 1,0);
    int MOD[2019] = {0};
    int x = 1;
    for (int i = n - 1; i > -1; i--)
    {
        T[i] = T[i + 1] + (int)(s[i] - '0') * x;
        x = (x * 10) % m;
        T[i] %= m;
        MOD[T[i] % 2019]++;
    }
    MOD[0]++;
    int ans = 0;
    for (int i = 0; i < 2019; i++)
    {
        ans += MOD[i] * (MOD[i]-1) / 2;
    }

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


Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

bool verify(int x, int y, int z) {

    if(x > y && y > z)
        return true;

    if(x < y && y < z)
        return true;

    return false;
}

int total_num(const vector<int> &v, int n) {
    int total = 0;

    for(int i = 1; i < n - 1; i++) {
        if(verify(v[i - 1], v[i], v[i + 1]))
            total++;
    }

    return total;
}

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);

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

    int r = total_num(v, n);

    cout << r << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<char, int> mp[n];
    vector<char> chs[n];
    vector<ll> lls(n, 0);
    // vector<ll> vals(n);
    rep(i, n){
        string s;
        cin >> s;
        chs[i] = {};
        rep(j, s.size()){
            chs[i].emplace_back(s[j]);
        }
        sort(chs[i].begin(), chs[i].end());
        rep(j, 10){
            lls[i] += (ll)(chs[i][j]-'a')*(ll)pow(26,j);
        }
    }
    
    ll cnt = 1;
    sort(lls.begin(), lls.end());
    ll ans = 0;
    rep(i, n-1){
        if(lls[i]==lls[i+1]){
            cnt++;
        }else{
            ans += cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    ans += cnt*(cnt-1)/2;

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

int main()
{
	int a, b, flag = 1;
	char s[20];

	scanf("%d %d", &a, &b);
	scanf("%s", s);

	for (int i = 0; i < a; i++){
		if (s[i]< '0'||s[i]>'9')
			flag = 0;
	}
	if (s[a] != '-')
		flag = 0;

	for (int i = 1; i <=b; i++){
		if (s[i + a]<'0'||s[i + a]>'9')
			flag = 0;
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;




	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int L;
vector<pi> G[20];

void solve() {
	cin >> L;
	int N = 1;
	while(L >= (1 << N)) N++;
	rep(i, 0, N - 1) {
		G[i].pb(pi(i + 1, (1 << (N - 2 - i))));
		G[i].pb(pi(i + 1, 0));
	}
	L -= (1 << (N - 1));
	int now = (1 << (N - 1));
	rer(i, N - 1, 0) {
		if(L & (1 << i)) {
			G[0].pb(pi(N - 1 - i, now));
			now += (1 << i);
		}
	}
	int M = 0;
	rep(i, 0, N) {
		M += sz(G[i]);
	}
	cout << N << " " << M << "\n";
	rep(i, 0, N) {
		rep(j, 0, sz(G[i])) {
			cout << i + 1 << " " << G[i][j].fst + 1 << " " << G[i][j].sec << "\n";
		}
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

int main(){
  int a[3];
  int ct5 =0, ct7=0;
  for(int i=0;i<3;i++){
    cin>>a[i];
    if(a[i] == 5)
      ct5++;
    else
      ct7++;
  }
  if(ct5 == 2 && ct7 == 1)
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    B[A[i]-1]+=1
C=[0]*n
D=[0]*n
for i in range(n):
    b=B[i]
    C[i]=b*(b-1)//2
    if b==0:
        D[i]=0
    else:
        D[i]=(b-1)*(b-2)//2
ans=sum(C)
for i in range(n):
    a=A[i]-1
    ans_=ans-C[a]+D[a]
    print(ans_)

Measured memory_bytes: 88908
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int N;
struct crd {double x, y;};
vector<crd> dots;

double dist(crd a, crd b) {
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

double f(double x, double y) {
    double d = 0;
    rep(i, N) {
        d = max(d, dist((crd){x, y}, dots[i]));
    }
    return d;
}

double g(double x) {
    double left = 0, right = 1000;
    rep(i, 80) {
        double l2 = (left * 2 + right) / 3;
        double r2 = (left + right * 2) / 3;
        if (f(x, l2) < f(x, r2)) right = r2;
        else left = l2;
    }
    return f(x, left);
}

int main() {
    cin >> N;
    dots = vector<crd> (N);
    rep(i, N) cin >> dots[i].x >> dots[i].y;
    double left = 0, right = 1000;
    rep(i, 80) {
        double l2 = (left * 2 + right) / 3;
        double r2 = (left + right * 2) / 3;
        if (g(l2) < g(r2)) right = r2;
        else left = l2;
    }
    double ans = g(left);
    printf("%.10f\n", ans);
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
#define ff first
#define ss second



int main(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout); 
	#endif
	ll n,i,o, k ;
	cin>>n>>k;
	ll d[k];
	ll A[101][101], num[n]={0} ;
	


	rep(i,k){
		cin>>d[i];
		rep(o,d[i])
			cin>>A[i][o];
	}

	rep(i,k){
		rep(o,d[i])
			num[A[i][o]-1]++;
	}
	ll cnt = 0 ;

	rep(i,n){
		if(num[i]==0)
			cnt++;
	}

	cout<<cnt<<"\n";




		
    //your code here
    return 0;
	
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cmath>

using namespace std;

int main(){
    
    long long int X,Y,result;

    scanf("%lld %lld",&X,&Y);

    if(X%Y == 0){
        printf("%d\n",-1);
        return 0;
    }else{
        if((double)(result=X*(Y-1))>=pow(10,18)){
            printf("%d",-1);
            return 0;
        }
        printf("%lld\n",X*(Y-1));
    }

    return 0;
}

Measured memory_bytes: 256
function Main(input){
input = input.split("\n");
var sum = 0;
for(var i=1;i<input.length;i++){
	var mem = input[i].split(" ");
	if(mem[1]=="JPY"){
		sum += Number(mem[0])
	}else{
		sum += mem[0]*380000;
	}
}
  	console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

int main(){
    int n, a, odd = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 == 1) odd++;
    }
    if(odd % 2 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{

  int s;
  int a[1000005];
  int flag=0;
  int ans;
  int i=2;
  cin >> s;
  
  a[1]=s;
  
  while(1){
    if( a[i-1]%2==0 ){
      a[i]=a[i-1]/2;
    }else{
      a[i]=3*a[i-1]+1;
    }
    
    for( int j=1;j<i;j++ ){
      if( a[j] == a[i] ){
	ans=i;
	flag=1;
      }
    }
    if( flag==1 ){
      break;
    }
    i++;
  }
  
  cout << ans << endl;

  return(0);

}


Measured memory_bytes: 256
<?php
$S = trim(fgets(STDIN));

if (preg_match("/^.*keyence$/",$S)
    || preg_match("/^k.*eyence$/",$S)
    || preg_match("/^ke.*yence$/",$S)
    || preg_match("/^key.*ence$/",$S)
    || preg_match("/^keye.*nce$/",$S)
    || preg_match("/^keyen.*ce$/",$S)
    || preg_match("/^keyenc.*e$/",$S)
    || preg_match("/^keyence.*$/",$S)

){
    echo ("YES") . "\n";
}else{
    echo("NO") . "\n";
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	set<string> ac;
	map<string, int> wa;
	int n, m; cin >> n >> m;
	int ans = 0, acs = 0;
	for(int i = 0; i < m; i++){
		string p, t; cin >> p >> t;
		if(ac.count(p)) continue;
		if(t == "WA") wa[p]++;
		else {
			acs++;
			ac.insert(p);
			ans += wa[p];
		}
	}
	cout << acs << ' ' << ans << '\n';
	return 0;
}


Measured memory_bytes: 15872