akhauriyash/Code-Regression huggingface dataset:
def digits(N):
    num = N
    sum = 0
    while num > 0:
        sum += num%10
        num //= 10
    return sum
    
def main():
    N = int(input())
    min = N
    for A in range(1,(N//2+1)):
        B = N - A
        if min > digits(A)+digits(B):
            min = digits(A)+digits(B)
    print(min)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

LL a[N];
LL before[N],last[N];
int main() {
    int n;
    scanf("%d",&n);

    LL maxSum=0,minSum=0;
    priority_queue<LL> minSumQ;
    priority_queue<LL, vector<LL>, greater<LL> > maxSumQ;
    for(int i=1;i<=3*n;i++){
        scanf("%d",&a[i]);
        if(i<=n){
            maxSum+=a[i];
            maxSumQ.push(a[i]);
        }
        else if(i>2*n){
            minSum+=a[i];
            minSumQ.push(a[i]);
        }
    }

    before[n]=maxSum;
    for(int i=n+1;i<=2*n;i++) {
        LL temp=maxSumQ.top();
        if(temp<a[i]){
            maxSum+=a[i]-temp;
            maxSumQ.pop();
            maxSumQ.push(a[i]);
        }
        before[i]=maxSum;
    }

    last[2*n]=minSum;
    last[2*n+1]=minSum;
    for(int i=2*n-1;i>=n;i--){
        LL temp=minSumQ.top();
        if(temp>a[i+1]){
            minSum+=a[i+1]-temp;
            minSumQ.pop();
            minSumQ.push(a[i+1]);
        }
        last[i]=minSum;
    }

    LL res=before[n]-last[n];
    for(int i=n+1;i<=2*n;i++)
        res=max(res,before[i]-last[i]);
    printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 8820
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n, m = read_list(int)
    as_ = read_list(int)
    all_voting = sum(as_)
    if len(list(filter(lambda v: v >= all_voting / (4 * m), as_))) >= m:
        print("Yes")
        return
    print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
from sys import stdin
n, q = map(int, stdin.readline().split())
ans = []
ans_append = ans.append
high = [0] * n
par = [i for i in range(n)]
def findSet(x):
    if par[x] == x: return x
    par[x] = findSet(par[x])
    return par[x]
def unite(x, y):
    x = findSet(x)
    y = findSet(y)
    if x == y: return
    if high[x] > high[y]: par[y] = x;
    else:
        par[x] = y
        if high[x] == high[y]: high[y] += 1
def same(x, y):
    return findSet(x) == findSet(y)
for i in range(q):
    t, a, b = map(int, stdin.readline().split())
    if t == 0: unite(a, b);
    elif t == 1: ans_append(1 if same(a, b) else 0)
print(*ans, sep='\n')

Measured memory_bytes: 10004
#include<bits/stdc++.h>
using namespace std;
int a[3];
int ans;
int main(){
	int i,t;
	for(i=0;i<3;i++) cin>>a[i];
	if(a[0]==a[1]&&a[1]==a[2]){
		cout<<0<<endl;
		exit(0);
	}
	sort(a,a+3);
	while(1){
		if(a[1]-a[0]>=2){
			a[0]+=2;
			ans++;
		}else{
			a[0]++;
			a[1]++;
			ans++;
		}
		sort(a,a+3);
		if(a[0]==a[1]&&a[1]==a[2])break;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int n,m,o[100];
  string b[100];
  string l;
  int ans;

  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    ans = 0;
    for(int i=0;i<n;i++)cin >> b[i] >> o[i];
    for(int i=0;i<m;i++){
      cin >> l;
      for(int j=0;j<n;j++){
	bool f = true;
	for(int k=0;k<8;k++){
	  if(b[j][k] != '*' && b[j][k] != l[k])f = false;
	}
	if(f)ans += o[j];
      }
    }

    cout << ans << endl;
  }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int d;
  cin >> d;
  if(d == 25) {
    cout << "Christmas" << endl;
  } else if(d == 24) {
    cout << "Christmas Eve" << endl;
  } else if(d == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


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

using namespace std;

int p_rep(int p, int N){
  int acc = 0;
  while(N / p > 0){
    acc += N % p;
    N /= p;
  }
  return acc + N;
}

int main(){
  int N;
  cin >> N;
  int ans = 100000;
  for(int i = 0; i <= N; i++){
    int t = N - i;
    ans = min(p_rep(6,i) + p_rep(9,t),ans);
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	char s[100],a[100];
	cin>>s>>a;
	int n=strlen(s);
	int m=strlen(a);
	if(m==n+1)
	{
		int flag=1;
		for(int i=0;i<n;i++)
		{
			if(s[i]!=a[i])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
				cout<<"No"<<endl;
		}
		
	} 
	else
	{
		cout<<"No"<<endl;
	}
	
	
	
	return 0;	
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n+2);
  a[0]=0;
  a[n+1]=0;
  int nom=0;
  rep(i,n){
    cin>>a[i+1];
  }
  for(int i=1; i<=n+1; i++){
    nom+=abs(a[i]-a[i-1]);
  }
  for(int i=1; i<=n; i++){
    int now_ans=0;
    if((a[i-1]<a[i] && a[i]>a[i+1]) || (a[i-1]>a[i] && a[i]<a[i+1])){
      now_ans=nom-min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))*2;
    }else now_ans=nom;
    cout<<now_ans<<endl;
  }
}


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

		String s = sc.next();
        String[] sp = s.split("");
        int i = 0;
        for(String spr : sp){
            if(i%2 == 0){
                System.out.print(spr);
            }
            i++;
        }
	}
}

Measured memory_bytes: 35700
#include<iostream>
#include<set>

using namespace std;

int main(){
        set<int> a;
        set<int> b;
        set<int> c;
        a.insert(1);
        a.insert(3);
        a.insert(5);
        a.insert(7);
        a.insert(8);
        a.insert(10);
        a.insert(12);
        b.insert(4);
        b.insert(6);
        b.insert(9);
        b.insert(11);
        c.insert(2);
        int x, y;
        cin>>x>>y;
        if(a.find(x)!=a.end() && a.find(y)!=a.end()){
                cout<<"Yes"<<endl;
        }else if(b.find(x)!=b.end() && b.find(y)!=b.end()){
                cout<<"Yes"<<endl;
        }else if(c.find(x)!=c.end() && c.find(y)!=c.end()){
                cout<<"Yes"<<endl;
        }else{
                cout<<"No"<<endl;
        }

}

Measured memory_bytes: 256
from collections import deque

N = int(input())
numbers = input().split()

d = deque()

for i in range(N):
    if i % 2 == 0:
        d.append(numbers[i])
    else :
        d.appendleft(numbers[i])
        
if N % 2 == 1:
    d.reverse()
    
output = ' '.join(d)

print(output)

Measured memory_bytes: 26564
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int A, B;
    cin >> A >> B;
    if (A + B >= 10) cout << "error" << endl;
    else cout << A + B << endl;

    return 0;
}


Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
# N = gets_i

def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

q, h, s, d = gets_i_list
n = gets_i

min1 = [q * 4, h * 2, s].min

if d > min1 * 2
  puts n * min1
else
  puts (n / 2) * d + (n % 2) * min1
end

Measured memory_bytes: 14468
#include <iostream>
#include <vector>
using namespace std;
int
main(int argc, char** argv) {
  int N; cin >> N;
  vector<int> V(N);
  for (auto& v : V) {
    cin >> v;
  }
  vector<int> C(N);
  for (auto& c : C) {
    cin >> c;
  }
  int value = 0;
  for (int i = 0; i < N; i++) {
    int temp = V[i] - C[i];
    if (temp > 0) { value += temp; }
  }
  cout << value << endl;
}

Measured memory_bytes: 256
#if 0
time: 15min
using e[] as a indicator to find whether a node has been searched.						
#endif
#include <iostream>
#include <queue>

using namespace std;

int p[100+10][100+10];
int D[100+10],e[100+10],f[100+10];
int n,a,b,c,t;

void dfs(int cur){
	D[cur] = 1;
	t += 1;
	for (int i=1; i<=n; i++){
		if (p[cur][i]>0 && !D[i]){
			f[i] = t+1;
			dfs(i);
		}
	}
	t += 1;
	e[cur] = t;
}

int main(){
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a >> b;
		for (int j=1; j<=b; j++){
			cin >> c;
			p[a][c] = 1;
		}
	}
	f[1] = 1;
	for (int i=1; i<=n; i++){
		if (!D[i]){
			f[i] = !f[i] ? t+1 : f[i];
			dfs(i);
		} 	
	}
	

	for (int i=1; i<=n; i++){
		cout << i << ' ' << f[i] << ' ' << e[i] << endl;
	}
}

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

namespace Atc_0030
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 N = Int64.Parse(Console.ReadLine());

            Int64[] A = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray();

            Int64[] B = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray();

            Int64 result = 0;

            for (int i = 0; i < B.Length; i++)
            {
                if (B[i] <= A[i])
                {
                    A[i] = A[i] - B[i];

                    result += B[i];

                    B[i] = 0;   
                }
                else
                {
                    B[i] = B[i] - A[i];

                    result += A[i];
                }

                if (B[i] == 0)
                {
                    continue;
                }

                if (B[i] <= A[i + 1])
                {
                    A[i + 1] = A[i + 1] - B[i];

                    result += B[i];
                }
                else
                {
                    result += A[i + 1];

                    A[i + 1] = 0;

                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 45588
h, n = gets.split.map(&:to_i)
 
obs = Hash.new(0b00000000)
n.times do
    x, y = gets.split.map(&:to_i)
    obs[y] |= (1 << x)
end
 
patterns = {
    0b11111111 => 2,
    0b11001100 => 1,
    0b01100110 => 1,
    0b00110011 => 1,
    0b00000000 => 0,
}
 
tab = {obs[0] => 0}
(1..h-1).each do |i|
    new_tab = Hash.new(-Float::INFINITY)
    tab.keys.each do |b|
        x = ((b & 0b1111) << 4) | obs[i]
        patterns.each do |pattern, k|
            if x & pattern == 0
                y = (x | pattern)
                c = tab[b] + k
                new_tab[y] = c if c > new_tab[y]
            end
            pattern <<= 1
        end
    end
    tab = new_tab
end

p tab.values.max



Measured memory_bytes: 10284
class Node
  attr_accessor :state, :depth
  attr_reader :parent

  def initialize(state, parent)
    @state = state
    @parent = parent
    @depth = parent.nil? ? 0 : parent.depth + 1
  end

  def goal?(limit, max)
    nums.size == limit && sum == max
  end

  def bad_end?(limit, max)
    nums.length > limit || sum > max
  end

  def nums
    parent.nil? ? [state] : parent.nums << state
  end

  def sum
    nums.inject(:+)
  end
end

readlines.each do |line|
  limit, max = line.split.map(&:to_i)

  next if limit == 0 && max == 0

  goals = []
  10.times do |i|
    init_node = Node.new(i, nil)
    queue = [init_node]
    black_list = [init_node.nums.sort]

    loop do
      break if queue.empty?

      elem = queue.shift

      goals << elem if elem.goal?(limit, max)

      next if elem.bad_end?(limit, max)

      10.times do |j|
        next if elem.nums.include?(j)
        new_node = Node.new(j, elem)
        new_nums = new_node.nums.sort
        next if black_list.include?(new_nums)
        black_list << new_nums
        queue << new_node
      end
    end
  end

  puts goals.map { |e| e.nums.sort }.uniq.size
end

Measured memory_bytes: 10900
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
int main(){ //srand((unsigned)time(NULL));
  ll x,ap=0,bp=0;
  string a,b;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> a >> b;
    if(a > b)ap+=3;
    else if(a < b)bp+=3;
    else{ap++;bp++;}
  }
  cout << ap << " " << bp << endl;
}



Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<int> demical(ll n, int k, int l = -1) {
	vector<int> rtn;
	if (l < 0) {
		while (n > 0) {
			rtn.push_back(n % k);
			n /= k;
		}
		
	} else {
		rtn.resize(l);
		REP(i, l) {
			rtn[i] = n % k;
			n /= k;
		}
	}
	return rtn;
}

int main() {
	IOS;
	ll n;
	cin >> n;
	vector<ll> x(n);
	REP(i, n) {
		cin >> x[i];
	}
	ll res = LLONG_MAX;
	REP(i, 101) {
		ll tmp = 0;
		REP(j, n) {
			tmp += (x[j] - i) * (x[j] - i);
		}
		chmin(res, tmp);
	}
	put(res);
	return 0;
}

Measured memory_bytes: 256
s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)
r=1

for i in range(l):
	dp+=int(s[l-1-i])*r
	dp%=2019
	r*=10
	r%=2019
	d[dp]+=1

res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

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

int main(void) {
    int t, d[6];
    string c;
    for (int i = 0; i < 6; i++) cin >> d[i];
    cin >> c;
    for (int i = 0; i < c.size(); i++) {
        if (c[i] == 'E') {
            t = d[0];
            d[0] = d[3];
            d[3] = d[5];
            d[5] = d[2];
            d[2] = t;
        }
        if (c[i] == 'W') {
            t = d[0];
            d[0] = d[2];
            d[2] = d[5];
            d[5] = d[3];
            d[3] = t;
        }
        if (c[i] == 'S') {
            t = d[0];
            d[0] = d[4];
            d[4] = d[5];
            d[5] = d[1];
            d[1] = t;
        }
        if (c[i] == 'N') {
            t = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = d[4];
            d[4] = t;
        }
    }
    cout << d[0] << endl;
    return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<iostream>
#define MAXN 100005
using namespace std;

int n,f[MAXN][4],a[MAXN],b[MAXN],c[MAXN];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	scanf("%d%d%d",&a[i],&b[i],&c[i]);
	f[1][1]=a[1];f[1][2]=b[1];f[1][3]=c[1];
	for(int i=2;i<=n;++i)
	{
		f[i][1]=max(f[i-1][2],f[i-1][3])+a[i];
		f[i][2]=max(f[i-1][1],f[i-1][3])+b[i];
		f[i][3]=max(f[i-1][1],f[i-1][2])+c[i];
	}
	int ans=max(f[n][1],max(f[n][2],f[n][3]));
	printf("%d",ans);
	return 0; 
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

    cin>>n>>d>>x;
    rep(i,0,n){
        cin>>a;
        if(d%a==0){
            ans += d /a;
        }else{
            ans += d / a + 1;
        }
    }
    cout<<ans+x<<endl;
}

Measured memory_bytes: 384
#!python3.8
# -*- coding: utf-8 -*-
# abc168/abc168_d
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    tree = [set() for _ in range(N + 1)]
    sign = [None] * (N + 1)
    cnt = 0
    for _ in range(M):
        A, B = i2nn()
        tree[A].add(B)
        tree[B].add(A)
    que = deque([1])
    while que:
        # print(que)
        seek = que.popleft()
        for n in tree[seek]:
            if sign[n] is not None:
                continue
            cnt += 1
            sign[n] = seek
            tree[n].discard(seek)
            que.append(n)
    if cnt < N - 1:
        print('No')
        return
    print('Yes')
    for s in sign[2:]:
        print(s)
    return

main()


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

typedef long long int llint;

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

  int s = 0;
  while(n != 0) {
    s += n % 10;
    n /= 10;
  }

  if(nn % s == 0) cout<< "Yes" <<endl;
  else            cout<< "No"  <<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

s, s_dict = 0, {0: 1}
for i in range(n):
    s += a[i]
    s_dict[s] = s_dict.get(s, 0) + 1

comb = 0
for j, k in s_dict.items():
    if k > 1:
        comb += k * (k-1) // 2

print(comb)


Measured memory_bytes: 39532
#include <stdio.h>
#define MAXN 105

typedef struct _pair {
  int id, score;
} pair;

int N;
pair arr[MAXN];
int rank[MAXN];

void bubleSort() {
  int i, j;
  pair p;
  for(i = 0; i < N; ++i) {
    for(j = 1; j < N-i; ++j) {
      if(arr[j-1].score < arr[j].score) {
        p = arr[j-1];
        arr[j-1] = arr[j];
        arr[j] = p;
      }
    }
  }
}

int main() {
  int i, j;
  int A, B, C, D;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    arr[i].id = i;
    arr[i].score = 0;
  }
  for(i = 0; i < N*(N-1)/2; ++i) {
    scanf("%d %d %d %d", &A, &B, &C, &D);
    --A; --B;
    if(C == D) {
      arr[A].score += 1;
      arr[B].score += 1;
    } else if(C > D) {
      arr[A].score += 3;
    } else if(C < D) {
      arr[B].score += 3;
    }
  }

  bubleSort();
  for(i = 0, j = 1; i < N; ++i) {
    if(i-1 >= 0 && arr[i].score == arr[i-1].score) {
    } else {
      j = i+1;
    }
    rank[arr[i].id] = j;
  }

  for(i = 0; i < N; ++i) {
    printf("%d\n", rank[i]);
  }

  return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

using namespace std;
int main(void){
    // Your code here!
    int a,b,d,r;
    double a_d,b_d,f;
    scanf("%d %d",&a,&b);
    a_d=static_cast<double>(a);
    b_d=static_cast<double>(b);
    printf("%d %d %.8f",a/b,a%b,a_d/b_d);
    return 0;
}


Measured memory_bytes: 2716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll linf=1e18;
const int inf=1001001001;
const ll mod=1e9+7; // 998244353 = (119<<23)+1
// head
const int nax=1e5+7;
vector<pii> edge[nax];
int n,mc,col[nax];
void bfs(int v) {
	queue<pii> q;
	q.push(mp(v,0));
	while(!q.empty()) {
		pii u=q.front();
		q.pop();
		mc=max(mc,sz(edge[u.fi]));
		int des=1;
		for(auto a:edge[u.fi]) {
			if(col[a.se]) continue;
			if(des==u.se) des++;
			col[a.se]=des;
			des++;
			q.push(mp(a.fi,col[a.se]));
		}
	}
}
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>n;
		rep(i,0,n-1) {
			int a,b;
			cin>>a>>b;
			edge[a].eb(mp(b,i));
			edge[b].eb(mp(a,i));
		}
		bfs(1);
		cout<<mc<<'\n';
		rep(i,0,n-1) cout<<col[i]<<'\n';
		return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std ;
#define ll          long long int
#define fast        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int recursive(vector<int>&nums,int dp[],int K) {
    if(dp[K]) return dp[K] ;
    for(int i = 0;i<nums.size();i++) {
        if(K>=nums[i]) {
            if(recursive(nums,dp,K-nums[i])==2){
                dp[K] = 1 ;  return dp[K] ;
            }
        }
            
    }
  
    dp[K]=2 ;
    return dp[K] ;
}


int main() {
    fast
    int m,n;
    cin >> m >> n ;
    vector<int> arr(m)  ; 
    for(int i =0 ;i<m;i++)  cin>>arr[i] ; 
    int dp[1000007]  = {0} ;
    dp[0] =2 ;
    
    int ans =recursive(arr,dp,n) ;
    if(ans==1) cout << "First" ;
    else if(ans==2) cout << "Second" ;
    
   return 0 ;     
}


Measured memory_bytes: 8832
class Segtree:
    def __init__(self, original, func, element):
        self.n = len(original)
        self.element = element
        self.func = func
        self.N0 = 1 << (n-1).bit_length()
        self.seg = [element]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = func(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            y = self.seg[i ^ 1]
            i >>= 1
            x = self.func(x, y)
            self.seg[i] = x
                
    def query(self, l, r):
        res = self.element
        l += self.N0
        r += self.N0
        while l < r:
            if r & 1:
                res = self.func(res, self.seg[r-1])
            if l & 1:
                res = self.func(res, self.seg[l])
                l += 1
            l >>= 1
            r >>= 1
     
        return res

import sys
input = sys.stdin.readline
read = sys.stdin.read
from itertools import accumulate

def compress(arr):
    *XS, = set(arr)
    XS.sort()
    d = {e: i for i, e in enumerate(XS)}
    return [d[e] for e in arr]

n, k = map(int, input().split())
if n == 1:
  print(int(int(input()) >= k))
  exit()
A = list(map(lambda x:int(x)-k, read().split()))
L = [0] + list(accumulate(A))
L = compress(L)
seg = Segtree([0]*(max(L)+1), lambda x, y:x+y, 0)
ans = 0
for l in L:
  ans += seg.query(0, l+1)
  t = seg.get(l)
  seg.update(l, t+1)
print(ans)

Measured memory_bytes: 119468
N = int( input() )
# V[i][j][0]: vertex i からj番目に伸びる vertex の値
# V[i][j][1]: vertex i からj番目に伸びる vertex までの距離
V = [ [] for _ in range(N) ]
for _ in range(N-1):
    a, b, c = map( int, input().split() )
    V[a-1].append( (b-1, c) )
    V[b-1].append( (a-1, c) )
Q, K = map( int, input().split() )

dist = [0]*N
q = [K-1]
while q:
    tmp = q.pop()
    for v in V[tmp]:
        if dist[v[0]] == 0:
            dist[v[0]] = dist[tmp] + v[1]
            q.append( v[0] )

for _ in range(Q):
    x, y = map( int, input().split() )
    print( dist[x-1]+dist[y-1] )

Measured memory_bytes: 45104
s = int(input())
tmp = s
number = [s]
output = 1

while True:
    if tmp % 2 == 0:
        tmp //= 2
        output += 1

    else:
        tmp = tmp * 3 + 1
        output += 1

    if not tmp in number:
        number.append(tmp)

    elif tmp in number:
        print(output)
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    int odd = 0;
    REP(i, N){
        int x;
        cin >> x;
        if(x%2 == 1) odd++;
    }
    cout << (odd%2 == 0 ? "YES" : "NO") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

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

    if (b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
}


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

using namespace std;

int N;

int popcnt(int x) {
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if ((x >> i) & 1)
            ++ans;
    }
    return ans;
}

int main() {
    cin >> N;

    vector<vector<pair<int, int>>> X(N);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        for (int k = 0; k < a; ++k) {
            int x, y;
            cin >> x >> y;
            x -= 1;
            X[i].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    for (int bits = 0; bits < (1 << N); ++bits) {
        bool ok = true;
        for (int i = 0; i < N; ++i) {
            if (((bits >> i) & 1) == 0)
                continue;

            for (auto p : X[i]) {
                auto k = (bits >> p.first) & 1;
                if (k != p.second) {
                    ok = false;
                    break;
                }
            }
            if (!ok)
                break;
        }
        if (ok)
            ans = max(ans, popcnt(bits));
    }
    cout << ans << endl;
}

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

int main(){
  int K,S;
  cin>>K>>S;
  int sum=0;
  for(int i=0;i<=min(K,S);i++){
    for(int j=0;j<=min(K,S);j++){
      if(S-i-j<=K&&S-i-j>=0){
        sum++;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int X;
    cin >> X;
    int count=0;
    int i=0;
    while(count<X){
        count+=i;
        i++;
    }
    cout << i - 1 << endl;
    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,x,y,b,p;
    int bh,ph;
    int yasu;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d %d",&x,&y,&b,&p);
        yasu=x*b+y*p;
        bh=max(0,5-b),ph=max(0,2-p);
        yasu=min(yasu,(yasu+(x*bh+y*ph))*4/5);
        printf("%d\n",yasu);
    }
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int N;
string s;

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

	int nr=0, nb=0;
	for (int i = 0; i < N; i++)
	{
		if (s[i] == 'R')
			nr++;
		else
			nb++;
	}
	string ans;
	if (nr > nb)
		ans = "Yes";
	else
		ans = "No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

void sort(int a[],int n)
{
	int i = 0,j = n - 1;
	int pivot = a[(i+j)/2];

	while(true)
	{
		while(a[i] > pivot)i++;
		while(a[j] < pivot)j--;

		if(i >= j)break;

		int hold = a[i];
		a[i] = a[j];
		a[j] = hold;
		i++;
		j--;
	}

	if( i > 1 )sort(a,i);
	if( n-j-1 > 1)sort(a+j+1,n-j-1);
}

int main()
{
	int l[55];
	int N,K;
	int sum = 0;

	cin >> N >> K;

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

	sort(l,N);

	for(int i=0;i<K;i++)
	{
		sum += l[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int a, b, c;

	cin >> a >> b >> c;

	if (a + b < c) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}






	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int n = scanner.nextInt();
        scanner.nextLine();
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }
        if(h > list.stream().mapToInt(m -> m).sum()){
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

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

int main(){
  scanf("%lld",&N);
  W.resize(N);
  for(int i=0; i<N; i++) {
    scanf("%lld", &W[i]);
  }

  vector<ll> top(N,-1);
  vector<ll> bottom(N,-1);

  for(int i=0; i<N;i++) {
    if(i==0) bottom[i]= W[i];
    else bottom[i]=bottom[i-1]+W[i];
  }
  for(int i=N-1; i>=0;i--) {
    if(i==N-1) top[i]= 0;
    else top[i]=top[i+1]+W[i+1];
  }

  ll dif=INT_MAX;
  for(int i=0; i<N; i++) {
    dif=min(dif,   abs(bottom[i]-top[i]));
  }

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


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn dfs(k: usize, t: i64, X: &[i64], done: &mut [bool]) -> i64 {
    if k == X.len() {
        return t;
    }

    let t = if t % 10 == 0 { t } else { t + 10 - t % 10 };

    let mut min_t = std::i64::MAX;

    for i in 0..X.len() {
        if done[i] {
            continue;
        }

        done[i] = true;
        min_t = min(min_t, dfs(k + 1, t + X[i], X, done));
        done[i] = false;
    }

    min_t
}

fn main() {
    let N = 5;
    let X = read![i64; N];
    let mut done = vec![false; N];

    println!("{}", dfs(0, 0, &X, &mut done));
}


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

const int MAX = 2001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; 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;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  for (int i=1; i<=k; i++) {
    cout << (COM(n-k+1, i) * COM(k-1, i-1)) % MOD << endl;
  }

  return 0;
}

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

#define       pb                 push_back
#define       sf                 scanf
#define       pf                 printf
#define       sz                 200005
#define       MOD                1000000007
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

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

int dx[] = {0, 0, +1, -1};
int dy[] = {+1,-1, 0,  0};
/*============GRAPH MOVES==================*/
//const int fx[] = {1, -1, 0, 0};
//const int fy[] = {0, 0, 1, -1};
//const int fx[] = {0, 0, 1, -1, -1, 1, -1, 1};  // Kings move
//const int fy[] = {-1, 1, 0, 0, 1, 1, -1, -1};  // Kings move
//const int fx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; // Knights move
//const int fy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; // Knights move
/*=========================================*/

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return m-(abs(a)%m); else if(a<m) return a; else return (a%m); }
inline string tstring(ll a) {stringstream ss; ss << a; string str = ss.str(); return str; }

int main()
{
	// READ
	optimize

	int n;

	cin >> n;

	int total = modPow(10, n);

	int minus = modMul(2, modPow(9, n));
	int add = modPow(8, n);

	int ans = modAdd(modSub(total, minus), add);

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	vector<int> a(4);
	REP(i, 4) cin >> a[i];
	vector<int> ans = {1, 9, 7, 4};
	sort(ALL(ans));
	sort(ALL(a));
	if(ans == a) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion

VI dv(int n) {
    VI d;
    for(int i = 2; i * i <= n; ++i){
        if (n % i == 0){
            d.push_back(i);
            if (i * i != n){
                d.push_back(n / i);
            }
        }
    }
    sort(ALL(d));
    if (n != 1){
        d.push_back(n);
    }
    return d;
}

int32_t main() {
    make(int, n);
    int ans = 0;
    for(auto& val : dv(n)){
        int num = n;
        while(num % val == 0){
            num /= val;
        }
        if (num % val == 1){
            ans++;
        }
    }
    cout << ans + dv(n - 1).size();
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int to[200010],vis[200010],now,st;
long long n,k,huan;
void dfs(int x,int y)
{
     vis[x]=y;
     if(vis[to[x]]==0) dfs(to[x],y+1);
     else
     {
         st=to[x];
         huan=y-vis[to[x]]+1;
         return;
     }
}
int main()
{
    int i;
    cin>>n>>k;
    for(i=1;i<=n;i++) cin>>to[i];
    dfs(1,1);
    if(k>999999) 
    {
        now=1;
        for(;now!=st;now=to[now]) k--;
        k=k%huan;
        for(;k>0;now=to[now],k--);
    }
    else
    {
    now=1;
    for(i=1;i<=k;i++) now=to[now];
    }
    cout<<now;
    cin>>i;
}


Measured memory_bytes: 5156
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var n = long.Parse(ReadLine());

            var isPrime = new bool[n + 1];
            for(var i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }
            var sqrtN = Sqrt(n) + 0.1;
            for(var i = 2; i <= sqrtN; i++)
            {
                if(!isPrime[i])
                {
                    continue;
                }
                for(long j = i * i; j <= n; j += i)
                {
                    isPrime[j] = false;
                }
            }

            var primes = new List<int>();
            for(var i = 2; i <= n; i += 2)
            {
                if(isPrime[i])
                {
                    primes.Add(i);
                }
                if(i == 2)
                {
                    i--;
                }
            }

            var divisorNums = new long[n + 1];
            divisorNums[1] = 1;
            if (n > 1)
            {
                divisorNums[2] = 2;
            }

            for(var i = 3; i <= n; i++)
            {
                if(isPrime[i])
                {
                    divisorNums[i] = 2;
                    continue;
                }
                var target = i;
                var sqrt = Sqrt(target);
                long divisorNum = 1;
                var canDivide = false;
                for(var j = 0; j < primes.Count; j++)
                {
                    var prime = primes[j];
                    if(prime > sqrt)
                    {
                        break;
                    }
                    if(!isPrime[prime])
                    {
                        continue;
                    }
                    var count = 0;
                    while(target % prime == 0 && target != 1)
                    {
                        target /= prime;
                        count++;
                        canDivide = true;
                    }
                    divisorNum *= count + 1;
                    if(canDivide)
                    {
                        divisorNum *= divisorNums[target];
                        break;
                    }
                }
                if (target != 1 && !canDivide)
                {
                    divisorNum *= 2;
                }
                divisorNums[i] = divisorNum;
            }

            long sum = 0;
            for(var i = 1; i <= n; i++)
            {
                sum += i * divisorNums[i];
            }
            
            WriteLine(sum);
        }
    }
}


Measured memory_bytes: 111624