akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

long long int comb(int n, int k);

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

	long long int count = 0;
	if (n / k == 1)
		count += 1;
	else if (n / k == 2)
		count += n / k + 6;
	else if (n / k > 2)
		count += n / k + 6 * comb(n / k, 2) + 6 * comb(n / k, 3);

	if(k % 2 == 0) {
		int counter = 0;
		int num = k / 2;
		while(num <= n) {
			counter += 1;
			num += k;
		}

		if(counter == 1)
			count += 1;
		else if(counter == 2)
			count += counter + 6;
		else if(counter > 2)
			count += counter + 6 * comb(counter, 2) + 6 * comb(counter, 3);
	}

	cout << count << endl;

	return 0;
}

long long int comb(int n, int k) {
	long long int result = 1;
	for(int i = n; i > n - k; i--)
		result *= i;
	for(int i = k; i > 0; i--)
		result /= i;

	return(result);
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    if n == 1:
        print("Hello World")
    else:
        a = int(input())
        b = int(input())
        print(a + b)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
# Adjacency matrix graph
class AMGraph
  attr :graph, :visited

  # n: 頂点の数
  def initialize(n)
    @n = n
    reset
  end

  # like: 1, 2
  def set_side(side)
    a, b = side
    @graph[a][b] = 1
    @graph[b][a] = 1
  end

  def visit(node)
    @visited[node] = true
  end

  def recursively_visit(node)
    return if visited?(node)
    visit(node)
    visitable_nodes(node).each do |node|
      recursively_visit(node)
    end
  end

  def visited?(node)
    @visited[node]
  end

  def visitable_nodes(node)
    nodes = []
    @graph[node].each do |node|
      next if node[0] == node
      next if node[1] != 1
      next if visited?(node[0])
      nodes << node[0]
    end
    nodes
  end

  def all_visited?
    @nodes.each do |node|
      return false unless @visited[node]
    end
    true
  end

  def reset_visited
    @visited = Hash.new(false)
  end

  def reset
    @visited = Hash.new(false)
    @graph = {}
    @nodes = []
    @n.times.with_index(1) do |_,i|
      @nodes << i
      @visited[i] = false
      @graph[i] = {}
      @n.times.with_index(1) do |_,j|
        @graph[i][j] = 0
      end
    end
  end
end

n, m = gets.split.map(&:to_i)
$g = AMGraph.new(n)

m.times do
  $g.set_side(gets.split.map(&:to_i))
end

$ans = 0

def dfs(node)
  if $g.all_visited?
    $ans += 1
    return
  end
  $g.visitable_nodes(node).each do |nd|
    next if $g.visited?(nd)
    $g.visit(nd)
    dfs(nd)
    $g.visited[nd] = false
  end
end

$g.visit(1)
dfs(1)

# $g.visitable_nodes(1).each do |node|
#   $g.recursively_visit(node)
#   ans += 1 if $g.all_visited?
#   $g.reset_visited
# end

puts $ans


Measured memory_bytes: 1788
n = int(input())
s = set([])
w = input()
s.add(w)
for i in range(n-1):
  w2 = input()
  s.add(w2)
  if w2[0] != w[-1]:
    print("No")
    quit()
  w = w2
if len(s) == n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
N,M,K = map(int,input().split())


mod = 10 ** 9 + 7
MAX = N*M
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def cominit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod



def cmb(n,r):
    if n < 0 or r < 0 or r > n:return 0
    if r > n/2: r = n-r        
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod
    
cominit()
ans= 0
NCK = cmb(N*M-2,K-2) 
M2 = M**2 * NCK
N2 = N**2 * NCK
for i in range(1,N):
    ans += M2 * i * (N-i)
    ans %= mod
    
for i in range(1,M):
    ans += N2 * i * (M-i)
    ans %= mod
        
print(ans)

Measured memory_bytes: 26740
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(void){
    double a, b, deg;
    cin >> a >> b >> deg;
    double rad = M_PI * deg / 180;
    double h = b * sin(rad);
    double S = 0.5 * h * a;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    double L = a + b + c;
    printf("%f\n%f\n%f\n", S, L, h);
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>

//https://atcoder.jp/contests/abc068/tasks/abc068_b

int main()
{
    std::ios::sync_with_stdio(false); // toggler av synkronisjon mellom c og c++ data streams. kan ikke blade de etter skrudd av
    std::cin.tie(NULL);               //gj;r at man ikke venter på cout og de can printe samtidig tror jeg

    //linjen er opp til 100. det er en linje p[ lengde hundre med hus p[ bare de nevte stedene]]

    int n;
    std::cin >> n;

    int res = 1;
    while (res <= n)
    {
        res = res * 2;
    }
    res = res / 2;

    std::cout << res << "\n";
}


Measured memory_bytes: 3656
#include <stdio.h>
int main(){
  int i,j,n,y,b,r,t,re;
  double genri,max,a;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    scanf("%d",&y);
    for(i=1;i<=n;i++){
      scanf("%d%d%d",&b,&r,&t);
     
      if(t==1){
	genri=1+y*(double)r/100;
      }
      else if(t==2){
        a=1+(double)r/100;
        genri=1+(double)r/100;
        for(j=2;j<=y;j++){
	  genri*=a;
	}
      } 
      if(i==1){
        max=genri;
	re=b;
      }
      if(max<genri){
	max=genri;
	re=b;      

      }
    }
    printf("%d\n",re);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
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...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    set<int> s;
    REP(i, 0, 3) {
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << (s.size() == 2 ? "Yes" : "No") << endl;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N,K,C;
  string s;
  cin >> N >> K >> C >> s;
  vector<ll> L(K), R(K);
  {
    ll day = 0, i = 0;
    while (day < K) {
      if (s[i] == 'o') {
        L[day] = i;
        day++;
        i+=C+1;
      } else {
        i++;
      }
    }
  }
  {
    ll day = K-1, i = N-1;
    while (day >= 0) {
      if (s[i] == 'o') {
        R[day] = i;
        day--;
        i-=C+1;
      } else {
        i--;
      }
    }
  }
  rep(day, K) {
    if (L[day] == R[day]){
      cout << L[day]+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;
  ll len = s.size();

  map<char, ll> m;
  for (int i = 0; i < len; i++) {
    m[s[i]]++;
  }

  string ans = "YES";
  if (len >= 2) {
    ll d = len / 3;
    ll dm = len % 3;

    map<ll, ll> cnt;
    cnt[m['a']]++;
    cnt[m['b']]++;
    cnt[m['c']]++;

    if (cnt[d] == 3 - dm && cnt[d + 1] == dm) {
      ans = "YES";
    } else {
      ans = "NO";
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 512
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# N**2の解法
N, M, Qu = lr()
graph = [[0] * (N+1) for _ in range(N+1)]  # 1-indexed
for i in range(M):
    l, r = lr()
    graph[l][r] += 1

graph = np.array(graph)
np.cumsum(graph, axis=1, out=graph)
np.cumsum(graph, axis=0, out=graph)
P = []; Q = []
for _ in range(Qu):
    p, q = lr()
    P.append(p); Q.append(q)

P = np.array(P); Q = np.array(Q)
answer = graph[Q, Q] - graph[Q, P-1] - graph[P-1, Q] + graph[P-1, P-1]
print('\n'.join(answer.astype(str)))


Measured memory_bytes: 37252
def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a

N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+2)
R = [0]*(N+2)
ans = 0
for i in range(N):
	L[i+1] = (gcd(L[i],A[i]))
	R[N-i] = (gcd(R[N-i+1],A[N-1-i]))
for i in range(N):
	ans = max(ans,(gcd(L[i], R[i+2])))
print(ans)

Measured memory_bytes: 14052
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N, M, now = 0, hole, maxi;
    long long result  = 1;
    bool canDo = true;
    vector<int> step;
    vector<long long> fib;

    scanf("%d %d", &N, &M);

    //連続した階段の数を配列にぶち込む
    for(int i = 0; i < M; i++){
        scanf("%d", &hole);
        step.push_back(hole - now  - 1);
        now = hole + 1;
    }
    step.push_back(N - now);

    //stepをソート  O(N log N)
    sort(step.begin(), step.end());

    if(step.front() < 0){
        printf("0\n");
        return 0;
    }

    maxi = step.back();

    //フィボナッチ数列の計算
    fib.push_back(1);
    fib.push_back(1);
    for(int i = 2; i <= maxi; i++)
        fib.push_back((fib[i - 1] + fib[i - 2]) % 1000000007);

    //結果の計算
    for(const auto &e: step)
        result = result * fib[e] % 1000000007;

    printf("%lld\n", result);
    return 0;
}

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

using namespace std;

const long long mod = 998244353;

long long inverse(long long a){
  long long m = mod, u = 1, v = 0;
  while(m){
    long long t = a / m;
    a -= t * m; swap(a, m);
    u -= t * v; swap(u, v);
  }
  u %= mod;
  if(u < 0) u += mod;
  return u;
}

int main(){
  int N;
  long long A, B, K;
  cin >> N >> A >> B >> K;
  long long factorial[N + 1];
  factorial[0] = 1;
  for(int i = 1; i <= N; i++){
    factorial[i] = factorial[i - 1] * i % mod;
  }
  
  long long paint = 0;
  for(int i = 0; i <= N; i++){
    int j = (K - A * i) / B;
    if(j >= 0 && j <= N && A * i + B * j == K){
      paint += factorial[N] * inverse(factorial[i]) % mod * inverse(factorial[N - i]) % mod * factorial[N] % mod * inverse(factorial[j]) % mod * inverse(factorial[N - j]) % mod;
      paint %= mod;
    }
  }
  
  cout << paint << endl;
  
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i] = (p[i] + 1) / 2;
  }

  vector<double> sum(n + 1);
  rep(i, n) sum[i + 1] = sum[i] + p[i];
  double mx = 0;

  for (int i = 0; i <= n - k; ++i) {
    double var = sum[k + i] - sum[i];
    mx = max(var, mx);
  }

  cout << fixed << setprecision(10) << mx << endl;

  return 0;
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


int main(){
    int N;
    cin >> N;
    int count = 0;
    for(int i=1; i<=N; i++){
        int Ai;
        cin >> Ai;
        if(i % 2 == 1 && Ai % 2 == 1){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3680
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


# n, k = LI()
# s = set()
# for i in range(k):
#     l, r = LI()
#     s |= set(range(l, r + 1))

# # a = len(s)
# dp = [0] * (n + 1)
# dp[1] = 1

# for i in range(1, n+1):
#     for j in range(1, i):
#         if i-j in s:
#             dp[i] += dp[j] % 998244353
#             # dp[i] += dp[j]
# print(dp[n] % 998244353)

# 配るDP
n, k = map(int, input().split())
lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr.append((l, r))
mod = 998244353
dp = [0]*(2*n+1)
dp[0] = 1
dp[1] = -1
now = 1
for i in range(n-1):
    for l, r in lr:
        # 始点に足して終点は引く
        # imos法というらしい
        dp[i+l] += now
        dp[i+r+1] -= now
    now += dp[i+1]
    now %= mod
print(now)


Measured memory_bytes: 71588
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=1e7;
#define int long long
int a[N];
int st[N];
void solve()
{
	int maxv=0;
	int n;
	cin>>n;
	int num=0;
	for(int i=1;i<=n;i++)
		cin>>a[i],maxv=max(maxv,a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=a[i];j<=maxv;j+=a[i])
			st[j]++;
	for(int i=1;i<=n;i++)
		if(st[a[i]]==1)
			num++;
	cout<<num<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
}


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

typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    const int N_ISLAND = 6;

    vector<ll> capa;
    for (ll i = 0; i < N_ISLAND - 1; i++)
    {
        ll a;
        cin >> a;
        capa.push_back(a);
    }

    ll m = capa[0];
    for (ll i = 0; i < N_ISLAND - 1; i++)
        m = min(m, capa[i]);

    cout << (n + m - 1) / m + 4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> num(N, 1);
    vector<bool> red(N, false);
    red[0] = true;
    for (int i = 0, x, y; i < M; i++) {
        cin >> x >> y;
        if (red[x - 1]) {
            red[y - 1] = true;
            if (num[x - 1] == 1) red[x - 1] = false;
        }
        num[x - 1]--;
        num[y - 1]++;
    }
    cout << count(red.begin(), red.end(), true) << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
void sol()
{
    // cout<<compte<<"\n";
    long long int n;
    cin>>n;
    long long int  arr1[n];
    long long int mx[n];
    long long int  max1=-1;
    for (long long int i=0;i<n;i++)
    {
        cin>>arr1[i];
        max1= max(arr1[i],max1);
        mx[i] = max1;
    }
    long long int ans=0;
    for(long long int i=0;i<n;i++)
    {
        ans+= (mx[i]-arr1[i]);
    }
    cout<<ans<<"\n";
}
int main(){
  sol();
  return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    map<char, vector<ll>> m;
    for (char i = 'a'; i <= 'z'; ++i) {
        m[i] = vector<ll>();
    }
    for (ll i = 0; i < n; ++i) {
        m[s[i]].emplace_back(i);
    }

    ll res = 0;
    for (ll i = 0; i < n; ++i) {
        ll cur = 0;
        for (auto & p : m) {
            bool hasSmaller = false;
            bool hasLarger = false;
            for (auto j : p.second) {
                if (j <= i) {
                    hasSmaller = true;
                } else if (j > i) {
                    hasLarger = true;
                    break;
                }
            }
            if (hasSmaller && hasLarger) {
                ++cur;
            }
        }
        cerr << i << ":" << cur << endl;
        res = max(res, cur);
    }
    cout << res << endl;

}


Measured memory_bytes: 256
#include <vector>

template<class T, class E, class U, class To, class Adj, class Ope, class Merge>
std::vector<T> rerooting(const std::vector<std::vector<E>>& G, int r, U ide, To to, Adj adj, Ope ope, Merge merge) {
  int N = G.size();
  std::vector<T> tdp(N);
  std::vector<int> par(N, -1);
  std::vector<int> que(N);
  int qi = 0;
  que[qi++] = r;

  int MAX = 1;
  for(int i = 0;i < qi;i++) {
    int v = que[i];
    for(const auto& e: G[v]) {
      int t = to(e);
      if(t == par[v]) continue;
      par[t] = v;
      que[qi++] = t;
    }
    MAX = std::max(MAX, (int)G[v].size() + 1);
  }

  for(int i = qi; i --> 0;) {
    int v = que[i];
    U sum = ide;
    for(const auto& e : G[v]) {
      int t = to(e);
      if(t == par[v]) continue;
      sum = ope(sum, adj(tdp[t], e));
    }
    tdp[v] = merge(sum, v);
  }

  std::vector<U> f(MAX);
  std::vector<U> b(MAX);

  for(int i = 0; i < qi; i++) {
    int v = que[i];
    for(int j = 0;j < G[v].size();j++) {
      int t = to(G[v][j]);
      f[j + 1] = adj(tdp[t == par[v] ? v : t], G[v][j]);
    }
    b[G[v].size()] = ide;
    for(int j = G[v].size(); j --> 0;) b[j] = ope(f[j + 1], b[j + 1]);
    f[0] = ide;
    for(int j = 0;j < G[v].size(); j++) {
      int t = to(G[v][j]);
      f[j + 1] = ope(f[j], f[j + 1]);
      if(t != par[v]) {
        tdp[t] = merge(ope(f[j], b[j + 1]), v);
      }
      tdp[v] = merge(f[G[v].size()], v);
    }
  }
  return tdp;
}

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

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

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

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


int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  rep(i,0,N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  auto res = rerooting<i64>(G, 0, 1ll,
        [](int t) { return t; },
        [&](i64 t, i64 e) { return (t + 1) == M ? 0 : t + 1; },
        [&](i64 a, i64 b) { return a * b % M; },
        [](i64 a, i64 v) { return a; }
      );

  rep(i,0,N) {
    cout << res[i] << "\n";
  }
}


Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int N, x;

int main() {
	scanf("%d%d", &N, &x);
	if (x == 1 || x == 2 * N - 1) return puts("No"), 0;
	puts("Yes");
	if (N == 2) return puts("1\n2\n3"), 0;
	if (x == 2) {
		for (int i = 1; i <= 2 * N - 1; ++i)
			printf("%d\n", (N + i) % (2 * N - 1) + 1);
		return 0;
	}
	int c = 0;
	for (int i = 1; i <= N - 3; ++i) {
		for (++c; x - 2 <= c && c <= x + 1; ++c) ;
		printf("%d\n", c);
	}
	printf("%d\n%d\n%d\n%d\n", x - 2, x + 1, x, x - 1);
	for (int i = 1; i <= N - 2; ++i) {
		for (++c; x - 2 <= c && c <= x + 1; ++c) ;
		printf("%d\n", c);
	}
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	ll a;
	string s;

	cin >> a >> s;

	ll ans = (s[0] - '0')*a;
	ll rem = (s[2] - '0')*10 + (s[3]  - '0');
	ll prod = a * rem;

	ll an0s = prod / 100;

	ans += (ll)an0s;

	cout << ans << endl;
}

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

void fill(vector<string> &s, int i, int j) {
	if (i>=s.size() or j>=s[0].size() or i<0 or j<0 or s[i][j]=='.') return;

	s[i][j]='.';
	fill(s,i+1,j);
	fill(s,i-1,j);
	fill(s,i,j+1);
	fill(s,i,j-1);
}

bool hasNeighbor(vector<string> &s, int i, int j) {
	bool result=false;
	if (i+1 < s.size() and s[i+1][j] == '#') result=true;
	else if (i-1 >= 0 and s[i-1][j] == '#') result=true;
	else if (j+1 < s[0].size() and s[i][j+1] == '#') result=true;
	else if (j-1 >= 0 and s[i][j-1] == '#') result=true;
	return result;
}

int main() {
	int h,w; cin>>h>>w;
	vector<string> s(h);
	for (int i=0; i<h; i++)
		cin>>s[i];

	for (int i=0; i<h; i++)
		for (int j=0; j<w; j++)
			if (s[i][j] == '#' and hasNeighbor(s,i,j))
				fill(s,i,j);

	bool ans=true;
	for (string x : s)
		for (char c : x)
			if (c=='#') ans=false;

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long 
#define llu long long unsigned int

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, w;
  cin >> n >> w;

  vp wtval(n);
  fl(0, n)
    cin >> wtval[i].first >> wtval[i].second;

  int max_val = 0;
  fl(0, n)
    max_val += wtval[i].second;

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

  vector<vector<llu>> min_wt(n + 1, vector<llu>(max_val + 1));

  fl(0, n + 1){
    for(int j = 0; j <= max_val; j++)
      min_wt[i][j] = -1;
  }

  fl(0, n + 1)
    min_wt[i][0] = 0;

  fl(0, n){
    for(int j = 1; j <= max_val; j++){
      if(wtval[i].second > j)
        min_wt[i + 1][j] = min_wt[i][j];
      else{
        llu take = -1;
        if(min_wt[i][j - wtval[i].second] != -1)
          take = wtval[i].first + min_wt[i][j - wtval[i].second];
        llu no_take = -1;
        if(min_wt[i][j] != -1)
          no_take = min_wt[i][j];
        if(take * no_take < 1)
          min_wt[i + 1][j] = max(take, no_take);
        else if(take > 0)
          min_wt[i + 1][j] = min(take, no_take);
        else
          min_wt[i + 1][j] = -1;
      }
    }
  }

  /*
  fl(0, n + 1){
    for(int j = 0; j < max_val + 1; j++)
      cout << min_wt[i][j] << " ";
    cout << endl;
  }
  */

  int val = 0;
  flr(1, max_val + 1){
    if(min_wt[n][i] != -1 && min_wt[n][i] <= w){
      val = i;
      break;
    }
  }

  cout << val << "\n";

}

Measured memory_bytes: 83164
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
map<long long ,long long>dp;
long long solve(long long x)
{
    if(dp[x])
    {
         return dp[x];
    }
    else
    {
         return dp[x]=((solve(x/2)+solve((x-1)/2)+solve((x-2)/2)))%mod;
    }
}
int main()
{
    dp[0]=1;
    dp[1]=2;
    long long n;
    cin>>n;
    cout<<solve(n)<<endl;
    return 0;
}

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

typedef long long int ll;
ll n, val[100007][3], dp[100007][3];

int main() {
    cin >> n;
    for(ll i = 1; i <= n; ++i) {
        cin >> val[i][0] >> val[i][1] >> val[i][2];
    }

    dp[1][0] = val[1][0], dp[1][1] = val[1][1], dp[1][2] = val[1][2];
    for(ll i = 2; i <= n; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + val[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + val[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + val[i][2];
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    return 0;
}

Measured memory_bytes: 8252
import java.util.*;

public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next() + sc.next() + sc.next();
			if(s.equals("110") || s.equals("001")){
				System.out.println("Open");
			}
			else{
				System.out.println("Close");
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 17120
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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 bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A,B,C;
    cin>> A>> B >> C;
    cout << A + B + C - max(A,max(B,C)) << endl;
}

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

using namespace std;

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

    int R;
    cin >> R;

    if(R < 1200)
    {
        cout << "ABC";
    }
    else if(R >= 1200 && R < 2800)
    {
        cout << "ARC";
    }
    else if(R >= 2800)
    {
        cout << "AGC";
    }
    //cout << N;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n;map<string, int> mp;
signed main(){
  cin>>n;
  rep(i,n){
    string s;cin>>s;
    mp[s]++;
  }
  int mx = -1;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    chmax(mx, itr->second);
  }
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    if(itr->second == mx && (itr->first) != "(base)"){
      cout << (itr->first) << endl;
    }
  }
}


Measured memory_bytes: 25216
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  OUT(180 * (n-2));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

struct mint {
    static constexpr long MOD = 1000000007;
    long value;

    constexpr mint(long value = 0) noexcept : value((value % MOD + MOD) % MOD) {}
    constexpr mint operator-() const noexcept {
        return mint(-value);
    }
    constexpr mint& operator+=(const mint& rhs) noexcept {
        if ((value += rhs.value) >= MOD) value -= MOD;
        return *this;
    }
    constexpr mint& operator-=(const mint& rhs) noexcept {
        if ((value += MOD - rhs.value) >= MOD) value -= MOD;
        return *this;
    }
    constexpr mint& operator*=(const mint& rhs) noexcept {
        (value *= rhs.value) %= MOD;
        return *this;
    }
    constexpr mint operator+(const mint& rhs) const noexcept {
        mint res(*this);
        return res += rhs;
    }
    constexpr mint operator-(const mint& rhs) const noexcept {
        mint res(*this);
        return res -= rhs;
    }
    constexpr mint operator*(const mint& rhs) const noexcept {
        mint res(*this);
        return res *= rhs;
    }
    constexpr mint pow(long e) const noexcept {
        if (e == 0) return 1;
        mint a = pow(e >> 1);
        a *= a;
        if (e % 2 == 1) a *= *this;
        return a;
    }
    constexpr mint inv() const noexcept {
        return pow(MOD - 2);
    }
    constexpr mint& operator/=(const mint& rhs) noexcept {
        return *this *= rhs.inv();
    }
    constexpr mint operator/(const mint& rhs) const noexcept {
        mint res(*this);
        return res /= rhs;
    }
    friend constexpr mint pow(const mint& a, const long& b) noexcept {
        return a.pow(b);
    }
    friend ostream& operator<<(ostream& os, const mint& n) noexcept {
        os << n.value;
        return os;
    }
};


int main() {
    int n;
    cin >> n;
    cout << mint(10).pow(n) - (mint(9).pow(n) - mint(8).pow(n)) * 2 - mint(8).pow(n) << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>

void swap(long long int* a, long long int* b){
    long long int c=*a;
    *a=*b;
    *b=c;
}

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

int main(){
    int n;
    scanf("%d", &n);
    long long int hp[n];
    for(int i=0; i<n; i++){
        scanf("%lld", &hp[i]);
    }
    long long int ans = hp[0];
    for(int i=1; i<n; i++){
        ans = gcd(ans, hp[i]);
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
using P = pair<int, int>;

int c[31][200002];

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

    rep(i, 31) rep(j, 200002) c[i][j] = 0;
    
    rep(i, n){
        int s, t, ch;
        cin >> s >> t >> ch;
        ch--;
        c[ch][2*s-1]++;
        c[ch][2*t]--;
    }
    
    rep(i, m){
        for(int j=1; j<200002; j++) c[i][j] += c[i][j-1];
    }

    int ans = 0;
    rep(i, 200002){
        int sum = 0;
        rep(j, m){
            sum += (c[j][i] != 0);
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 24448
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    string t1 = "",t2;
    rep(i, s.size()){
        if(s[i] != 'x') t1 += s[i];
    }
    t2 = t1;
    reverse(t1.begin(), t1.end());
    if(t1 != t2){
        cout << "-1" << endl;
        return 0;
    }
    vector<int> check;
    rep(i,s.size() + 1){
        int now = 0;
        int id = i;
        while(id < s.size() && s[id] == 'x'){
            id++;
            now++;
        }
        check.push_back(now);
        //cout << "id " << id << " now " << now << endl;
        i = id;
    }
    int ans =  0;
    for(int i = 0; i * 2 < int(check.size()); i++){
        ans += max(check[i], check[check.size() - 1 - i]) - min(check[i], check[check.size() - 1 - i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int64_t N, T, A;
    
    cin >> N;
    
    int64_t t = 1;
    int64_t a = 1;    
    for (int i = 0; i != N; ++i)
    {
        cin >> T >> A;
        
        int64_t x = (t + T - 1) / T;
        int64_t y = (a + A - 1) / A;
        int64_t z = max(x, y);
        
        t = z * T;
        a = z * A;
    }
    
    cout << t + a << endl;

    return 0;
}

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

typedef pair<int, int> P;
const int MAX_N = 101;
const int MAX_DMG = 100001;
const int INF = 1<<24;

int N;
int hp[MAX_N];
vector<P> ms, ma;
int Ts[MAX_DMG], Ta[MAX_DMG];

int solve() {
  Ts[0] = Ta[0] = 0;
  for(int d = 1; d < MAX_DMG; ++d) {
    Ts[d] = Ta[d] = INF;
    for(int i = 0; i < ms.size(); ++i) {
      int t = max(0, d - ms[i].first);
      Ts[d] = min(Ts[d], Ts[t] + ms[i].second);
    }
    for(int i = 0; i < ma.size(); ++i) {
      int t = max(0, d - ma[i].first);
      Ta[d] = min(Ta[d], Ta[t] + ma[i].second);
    }
  }

  int res = INF;
  for(int d = 0; d < MAX_DMG; ++d) {
    //    if(Ta[d] == INF) continue;
    int value = Ta[d];
    for(int i = 0; i < N; ++i) {
      value += Ts[max(0, hp[i]-d)];
    }
    res = min(res, value);
  }
  return res;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) cin >> hp[i];
    int M;
    cin >> M;
    ms.clear(); ma.clear();
    for(int i = 0; i < M; ++i) {
      string name, target;
      int mp, dmg;
      cin >> name >> mp >> target >> dmg;
      dmg = min(dmg, 100000);
      if(target == "Single") {
	ms.push_back(P(dmg, mp));
      } else {
	ma.push_back(P(dmg, mp));
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1704
import java.util.Scanner;
 class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a, b;
        a=input.nextInt();
        b=input.nextInt();

       if (a>b){
           System.out.println("a > b");
       }
       else if (a<b){
           System.out.println("a < b");
       }
       else
           System.out.println("a == b");

    }
}


Measured memory_bytes: 26420
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1000000000;
struct segtree {
  vector<pint> dat; // 値、位置
  static const int N = 1 << 18;
  segtree() : dat(N * 2, pint(INF, -1)){}
  void init(vector<int> &v) {
    for(int i = 0; i < v.size(); i++) dat[i+N-1] = {v[i], i};
    for(int i = N - 2; i >= 0; i--) dat[i] = min(dat[i*2+1], dat[i*2+2]);
  }
  pint get_min(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return pint(INF, -1);
    if(a <= l && r <= b) return dat[k];
    return min(get_min(a,b,k*2+1,l,(l+r)/2),get_min(a,b,k*2+2,(l+r)/2,r));
  }
  pint get_min(int a, int b) {
    return get_min(a,b,0,0,N);
  }
};

int N;
vector<int> p(222222);
vector<vector<int> > G(222222);
segtree even, odd;
int cur;
vector<pint> val(222222);

// [l,r)について
void solve(int l, int r) {
  int x, y;
  if(l % 2 == 0) {
    x = even.get_min(l, r).second;
    y = odd.get_min(x + 1, r).second;
  } else {
    x = odd.get_min(l, r).second;
    y = even.get_min(x + 1, r).second;
  }

  int v = cur;
  val[v] = pint(p[x], p[y]);
  cur++;
  if(x != l) {
    G[v].push_back(cur);
    solve(l, x);
  }
  if(x + 1 != y) {
    G[v].push_back(cur);
    solve(x + 1, y);
  }
  if(y != r - 1) {
    G[v].push_back(cur);
    solve(y + 1, r);
  }
}

struct data{
  pint p; // 2セットの値
  int k; // cur
  data(pint a, int b) {
    p = a, k = b;
  }
};

bool operator < (const data &a, const data &b) {
  return a.p > b.p;
}

int main()
{
  cin >> N;
  FOR(i,0,N) cin >> p[i];
  vector<int> seg(N);
  FOR(i,0,N) {
    if(i % 2 == 0) seg[i] = p[i];
    else seg[i] = INF;
  }
  even.init(seg);
  FOR(i,0,N) {
    if(i % 2 == 1) seg[i] = p[i];
    else seg[i] = INF;
  }
  odd.init(seg);

  cur = 0;
  solve(0, N);
  vector<int> ans;
  priority_queue<data> Q;
  Q.push(data(val[0], 0));
  while(!Q.empty()) {
    pint p = Q.top().p;
    int k = Q.top().k;
    Q.pop();
    ans.push_back(p.first);
    ans.push_back(p.second);
    for(auto nx : G[k]) {
      Q.push(data(val[nx], nx));
    }
  }
  FOR(i,0,N) {
    printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 45812
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
template<typename T> T gcd_(T a,T b){ return (a%b)?gcd_(b,a%b):b; }
template<typename ll_t>
vector<pair<ll_t,ll_t>> factorize(ll_t x){
    vector<pair<ll_t,ll_t>> ret; ll_t x_tmp=x, cnt;
    if(x_tmp%2==0) { cnt=0; while(x_tmp%2==0) {x_tmp/=2; ++cnt;} ret.push_back({2,cnt});}
    for(ll_t p=3;x_tmp>1&&p*p<=x;p+=2) if(x_tmp%p==0) { cnt=0; while(x_tmp%p==0) {x_tmp/=p; ++cnt;} ret.push_back({p,cnt});}
    if(x_tmp>1)ret.push_back({x_tmp,1});
    return ret;
}
int main(){
    ll a,b;
    cin >> a >> b;
    auto factors = factorize(gcd_(a,b));
    cout << factors.size()+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    long long int a;
    cin >> a;

    long long int m = 100;
    long long int ans = 0;

    while (true)
    {
        ans++;
        m = m * 1.01;
        if (m >= a) {
            break;
        }
    }

    cout << ans;




    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	int Min = *min_element(a.begin(), a.end());
	int Max = *max_element(a.begin(), a.end());
	cout << Max - Min << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


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

  int N;
  cin >> N;
  
  if( N < 1000){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
  return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

constexpr ll MOD = 1000000000 + 7;

struct SegmentTree{
    int numNode;
    std::vector<ll> data;

    SegmentTree(int n){
        numNode = 1;
        while(numNode < n){
            numNode *= 2;
        }

        data.assign(numNode * 2, 0);
    }

    void set(int k, ll v){
        k += numNode;
        data[k] = v;

        while(k > 1){
            k /= 2;
            data[k] = (data[k*2] + data[k*2+1]) % MOD;
        }
    }

    ll sum(int l, int r){
        l += numNode;
        r += numNode;

        ll res = 0;
        for(;l<r;l/=2,r/=2){
            if(l & 1){
                res = (res + data[l]) % MOD;
                l += 1;
            }

            if(r & 1){
                r -= 1;
                res = (res + data[r]) % MOD;
            }
        }

        return res;
    }

    ll at(int k){
        return data[k + numNode];
    }
};

int N, K;
int A[110];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> K;

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

    SegmentTree seg(K + 1);
    seg.set(0, 1);

    for(int i=0;i<N;++i){
        for(int j=K;j>=0;--j){
            seg.set(j, seg.sum(std::max(j - A[i], 0), j + 1));
        }
    }

    ll res = seg.at(K);
    std::cout << res << std::endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main()
{
    int s, w;
    cin >> s >> w;
    if (s <= w)
    {
        cout << "unsafe" << endl;
    }
    else
    {

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int a,b; cin>> a >> b;
    if(b%a==0) cout << a+b << endl;
    else cout << b-a << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int dfs(int now,ll sum,int last);
int n;
typedef pair<int,int>P;
vector<P>node[100009];
int ans[100009];

int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    int a,b,c;
    cin>>a>>b>>c;
    node[a].push_back(P(b,c));
    node[b].push_back(P(a,c));
  }
  dfs(1,0,-1);
  for(int i=1;i<=n;i++){
    cout<<ans[i]<<endl;
  }
  return(0);
}

int dfs(int now,ll sum,int last){
  if(sum%2==0){
    ans[now]=1;
  }
  else{
    ans[now]=0;
  }
  for(int i=0;i<node[now].size();i++){
    int next=node[now][i].first;
    ll cost=node[now][i].second;
    if(last!=next){
      dfs(next,sum+cost,now);
    }
  }
}


Measured memory_bytes: 9088