akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


def dfs(v):
    dist = [-1] * (N + 1)
    stack = [v]
    dist[v] = 0
    while stack:
        v = stack.pop()
        dw = dist[v] + 1
        for w in graph[v]:
            if dist[w] >= 0:
                continue
            dist[w] = dw
            stack.append(w)
    return dist


DU, DV = dfs(u), dfs(v)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Measured memory_bytes: 31584
import heapq
def main():
    T = int(input())
    ans = [None]*T
    ipt = [list(map(int, input().split())) for _ in range(T)]
    for i in range(T):
        n, a, b, c, d = ipt[i]
        dic = {}
        dic[n] = 0
        hq = [-n]
        heapq.heapify(hq)
        while len(hq) > 0:
            p = heapq.heappop(hq)
            p *= -1
            for x in range(p-5, p+6):
                if x <= 1:
                    continue
                if x%2 == 0:
                    if not x//2 in dic:
                        dic[x//2] = float("inf")
                        heapq.heappush(hq, -1*(x//2))
                    if dic[p]+d*abs(x-p)+a < dic[x//2]:
                        dic[x//2] = dic[p]+d*abs(x-p)+a
                    if dic[p]+d*abs(p-x//2) < dic[x//2]:
                        dic[x//2] = dic[p]+d*abs(p-x//2)
                if x%3 == 0:
                    if not x//3 in dic:
                        dic[x//3] = float("inf")
                        heapq.heappush(hq, -1*(x//3))
                    if dic[p]+d*abs(x-p)+b < dic[x//3]:
                        dic[x//3] = dic[p]+d*abs(x-p)+b
                    if dic[p]+d*abs(p-x//3) < dic[x//3]:
                        dic[x//3] = dic[p]+d*abs(p-x//3)
                if x%5 == 0:
                    if not x//5 in dic:
                        dic[x//5] = float("inf")
                        heapq.heappush(hq, -1*(x//5))
                    if dic[p]+d*abs(x-p)+c < dic[x//5]:
                        dic[x//5] = dic[p]+d*abs(x-p)+c
                    if dic[p]+d*abs(p-x//5) < dic[x//5]:
                        dic[x//5] = dic[p]+d*abs(p-x//5)
        ans[i] = min(n*d, dic[1]+d)
    for v in ans:
        print(v)

if __name__ == "__main__":
    main()

Measured memory_bytes: 160868
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

bool number(char a){
	if(0<=a-'0'&&a-'0'<=9){
		return true;
	}
	return false;
}

string bigger(string a, string b){
	if(a.size() > b.size()){
		return a;
	} else{
		if(a.size() == b.size()){
			return max(a,b);
		} else{
			return b;
		}
	}
}

int main(){
	int w, h;
	while(scanf("%d%d", &w,&h),w||h){
		char deta[70][70];
		string num[70][70];
		rep(i,h) rep(j,w) scanf(" %c", &deta[i][j]);
		rep(i,h){
			rep(j,w){
				if(!number(deta[i][j])) continue;
				if(i == 0 && j == 0){
					if(deta[i][j] != '0'){
						num[i][j].pb(deta[i][j]);
					}
					continue;
				}
				if(i == 0){
					num[i][j] += num[i][j-1];
					if(deta[i][j] != '0' || num[i][j].size() != 0){
						num[i][j].pb(deta[i][j]);
					}
					continue;
				}
				if(j == 0){
					num[i][j] += num[i-1][j];
					if(deta[i][j] != '0' || num[i][j].size() != 0){
						num[i][j].pb(deta[i][j]);
					}
					continue;
				}
				num[i][j] += bigger(num[i-1][j],num[i][j-1]);
				if(deta[i][j] != '0' || num[i][j].size() != 0){
					num[i][j].pb(deta[i][j]);
				}
			}
		}
		string ans;
		rep(i,h) rep(j,w){
			ans = bigger(ans,num[i][j]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1396
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(i%3 != 0 && i%5 != 0) ans += i;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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 = 1e9+7;
int dp[100005][13] = {};

int main(){

    string s;
    cin >> s;
    int n = sz(s);

    dp[0][0] = 1;
    rep(i,n) {
        rep(j,13) {
            if(s[i] >= '0' && s[i] <= '9') {
                int c = s[i] - '0';
                dp[i+1][(j*10+c)%13] += dp[i][j];
                dp[i+1][(j*10+c)%13] %= mod;
            }
            else {
                rep(c,10) {
                    dp[i+1][(j*10+c)%13] += dp[i][j];
                    dp[i+1][(j*10+c)%13] %= mod;
                }
            }
        }
    }

    int ans = dp[n][5];
    cout << ans << endl;
}

Measured memory_bytes: 8800
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>

using namespace std;

#define N 2010
#define ll long long
#define RG register

inline int read(){
    RG int x=0,o=1; RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=((x<<3)+(x<<1))+ch-'0',ch=getchar();
    return x*o;
}

int main(){
	ll K=read(),A=read(),B=read();
	if(K<A-1) { cout<<K+1<<endl; return 0; }
	ll ans=A; K-=A-1;
	if(A<=B-2){
		ans+=K/2*(B-A)+(K&1);
		cout<<ans<<endl;
	}   else cout<<ans+K<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vector<ll> sum(n+1); rep(i,n) sum[i+1] += sum[i] + a[i];

  ll ans = 1e18;
  rep(i,n-1){
    ll x = sum[i+1];
    ll y = sum[n]-sum[i+1];
    chmin(ans,abs(x-y));
  }

  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 5652
n, m = gets.strip.split.map(&:to_i)
xx = gets.strip.split.map(&:to_i)
yy = gets.strip.split.map(&:to_i)
MOD = 10**9+7

x_len = 0
xx.each_with_index do |x, i|
  x_len += ((n-1-i)*x + -1*i*x)
end

y_len = 0
yy.each_with_index do |y, i|
  y_len += ((m-1-i)*y + -1*i*y)
end

p x_len*y_len%MOD


Measured memory_bytes: 17548
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  deque<char>d;
  string s;
  int q;
  cin>>s>>q;
  rep(i,s.size()){
    d.push_back(s[i]);
  }
  bool kai = 0;
  rep(i,q){
    int a;
    cin>>a;
    if(a == 1){
      if(kai)kai = false;
      else kai = true;
    }
    else{
      int b;
      char c;
      cin >> b >> c;
      if(b == 1){
        if(kai)d.push_back(c);
        else d.push_front(c);
      }
      else{
        if(kai)d.push_front(c);
        else d.push_back(c);
      }
    }
  }
  string ans = "";
  for(auto i : d){
    ans.push_back(i);
  }
  if(kai)reverse(all(ans));
  cout << ans << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 1368
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 200 + 10;
LL a[maxn];

int main()
{
    int n;
    while(cin >> n)
    {
        int ok = 1;
        int ans = INF;
        LL x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(!ok) continue;

            if(x & 1) ok = 0;
            int count = 0;
            while(1)
            {
                if(x & 1) break;
                x /= 2;
                count++;
            }
            ans = min(ans, count);
        }

        if(!ok) cout << 0 << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

	ll a, b, k;
	cin >> a >> b >> k;
	if(k >= a)
	{
		k -= a;
		a = 0;
		if(k >= b)
		{
			k -= b;
			b = 0;
		}
		else b -= k;
	}    
	else a -= k;
	cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    int x, y;
    cin >> x >> y;
    bool a = false;

    for(int i = 0; i <=x; i++) {
        if(i*2 + (x-i)*4 == y) {
            a = true;
            break;
        }
    }
    if(a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

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

#define int long long
#define mod 1000000007

int max(int a,int b){
    return (a>b?a:b);
}

int dp[105][100005];int arr[105];

int32_t main(){
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }
    sort(arr+1,arr+n+1);
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j == 0){
                dp[i][j] = 1;
                continue;
            }
            if(i == 1 && j <= arr[i]){
                dp[i][j] = 1;
                continue;
            }
            dp[i][j] = dp[i-1][max(0,j-arr[i])]-dp[i-1][j+1];
            dp[i][j] %= mod;
            if(dp[i][j] < 0){
                dp[i][j] += mod;
            }
        }
        for(int j=k;j>=0;j--){
            dp[i][j] += dp[i][j+1];
            dp[i][j] %= mod;
        }
    }
    // for(int i=1;i<=n;i++){
    //     for(int j=0;j<=k;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 81664
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

	int a, b;
	cin >> a >> b;
	
	if(a + b == 15){
		cout << "+" << endl;
	}
	else if(a * b == 15){
		cout << "*" << endl;
	}
	else{
		cout << "x" << endl;
	}

    return 0;
}


Measured memory_bytes: 256
use proconio::fastout;

#[fastout]
fn main(){
    use proconio::input;

    input!{
        n: i32,
        x: i32,
        t: i32,
    }

    let ans = if n%x == 0 {
       n/x * t
    }else{
         (n / x + 1) * t 
    };

    println!("{}",ans);


}

Measured memory_bytes: 2136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int prime_check(int x) {
    if(x == 1) return 0;
    int i;
    for(i=2; i<x; i++) {
        if(x % i == 0) {
            return 0;
        }
    }
    return 1;
}
int main() {
    int X;
    scanf("%d", &X);

    int prime = X;
    while(1) {
        if(prime_check(prime) == 1) {
            break;
        }
        prime++;
    }
    printf("%d\n", prime);
    return 0;
}

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

using namespace std;

void solve() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((10 * g + b)%4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

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

int main(void) {
    stack<int> unforwardable;
    vector<int> output;
    int car;
    while(cin >> car) {
        if(car == 0) {
            output.push_back(unforwardable.top());
            unforwardable.pop();
        } else {
            unforwardable.push(car);
        }
    }
    vector<int>::iterator ite;
    for(ite = output.begin(); ite != output.end(); ite++) {
        cout << *ite << endl;
    }
    return(0);
}

Measured memory_bytes: 1220
#!/usr/bin/perl
use POSIX qw(floor);

my ($a,$b,$c) = map { $_ - 0 } split(/\s+/,<STDIN>);
my ($k) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $cnt = 0;

while( $b <= $a ){
  $b *= 2;
  $cnt++;
}
while( $c <= $b ){
  $c *= 2;
  $cnt++;
}

my $r = 'No';
$r = 'Yes' if $cnt <= $k;


print "$r\n";



Measured memory_bytes: 6648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[60005]={0};
int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=sqrt(n);i++){
        for(int j=1;j<=sqrt(n);j++){
            for(int k=1;k<=sqrt(n);k++){
                int x=i*i+j*j+k*k+i*j+i*k+j*k;
                a[x]++;
            }
        }
    }

    for(int i=1;i<=n;i++){
        cout<<a[i]<<endl;
    }
	return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int k;
    cin >> k;
    long long ret = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                ret += __gcd(__gcd(i, j), l);
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str;

int main(void){
    scanf("%d",&n);
    cin >> str;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(str[i]=='R')cnt++;
        else cnt--;
    }
    printf("%s\n",cnt>0?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
import sys


def main():
    S = sys.stdin.readline().rstrip()
    T = sys.stdin.readline().rstrip()

    ans = len(T)

    for i in range(len(S) - len(T) + 1):
        cnt = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)

    print(ans)


main()

Measured memory_bytes: 9116
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	vector<int> nums(n,0);
	for(int i=0;i<n;i++) cin>>nums[i];
	// sort(nums.begin(),nums.end());
	LL sn = accumulate(nums.begin(),nums.end(),0ll);
	LL tx = sn/n;
	LL res = MOD;
	for(int i=0;i<2;i++){
		LL temptx = tx+i;
		LL tempre = 0ll;
		for(int j=0;j<n;j++){
			tempre+=1ll * (nums[j]-temptx)*(nums[j]-temptx);
		}
		res = min(res,tempre);
	}
	cout<<res<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;]
    
    vector<vector<bool>> edges(4,vector<bool>(4));
    rep(i,0,3){
        i64 a,b;
        cin >> a >> b;
        --a;
        --b;
        edges[a][b]=edges[b][a]=true;
    }
    
    vector<i64> p(4);
    rep(i,0,4) p[i]=i;
    do{
        i64 u=p[0];
        bool ok=true;
        rep(i,1,4){
            i64 v=p[i];
            if(!edges[u][v]){
                ok=false;
                break;
            }
            u=v;
        }
        if(ok){
            cout << "YES" << endl;
            return;
        }
    }while(next_permutation(begin(p),end(p)));
    
    cout << "NO" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

int main(void)
{
    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>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(w);
    VVL dp(110, VL(100100));
    VVL item(110, VL(2));
    rep(i, n){
        cin >> item[i][0] >> item[i][1];
    }
    rep(i, w+1)
        dp[0][i]=0;
    rep(i, n){
        rep(j, w+1){
            if (j < item[i][0])
                chmax(dp[i+1][j], dp[i][j]);
            else
                chmax(dp[i+1][j], max(dp[i][j], dp[i][j-item[i][0]] + item[i][1]));
        }
    }
    LL ans = dp[n][w];
    co(ans);
    return 0;
}

Measured memory_bytes: 87296
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s[50001],t[50001],e[50001];
  cin>>n>>m;
  int i=0;
  while(cin>>s[i]>>t[i]>>e[i],s[i])s[i]--,t[i]--,i++;
  int l;
  cin>>l;
  for(int j=0;j<l;j++){
    int b[10000];
    for(int k=0;k<m;k++){
      cin>>b[k];
    }
    int ans[10000]={};
    for(int k=0;k<i;k++)
      ans[s[k]]+=e[k]*b[t[k]];
    for(int k=0;k<n;k++){
      if(k)cout<<" ";
      cout<<ans[k];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3700
#include<iostream>

using namespace std;

int n,A,B;

int main(){
	while(true){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			if(a>b)A=A+a+b;
			else if(a<b)B=B+a+b;
			else A=A+a,B=B+b;
		}
		cout<<A<<" "<<B<<endl;
		A=0,B=0;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
typedef long long ll;
typedef pair<int,int> P;

int gcd(int a, int b){ //最大公約数 O(log(min(a,b)))
    if(b==0) return a;
    return gcd(b,a%b);
}


int main(){
    int N;
    cin >> N;
    int A[N+1];
    ll sum=0;
    ll sum_e=0;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        sum+=A[i];
        if(i%2==0) sum_e+=A[i];
    }
    ll x=sum-2*sum_e;
    cout << x << " ";
    x/=2;
    for(int i=1;i<N;i++){
        cout << (A[i]-x)*2 << " ";
        x=(A[i]-x);
    }
}


Measured memory_bytes: 1664
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B,C,D = MI()


from math import gcd


def f(n):
    return n-n//C-n//D+n//((C*D)//gcd(C,D))


print(f(B)-f(A-1))


Measured memory_bytes: 62284
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    
    cout << c << " " << a << " " << b << endl;
    


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

Measured memory_bytes: 3624
#include <stdio.h>

#define ARRAY_INIT 0
#define DIV_INIT 0
#define LOOP_INIT 0
#define G_MAX 12

int main( void )
{
	unsigned long ulW_Dtc_cnt;
	int *aulW_Dtestcase;
	unsigned long ulW_Cloop_cnt;
	unsigned long ulW_Cloop_sub_cnt;
	unsigned long ulW_Csort_cnt = DIV_INIT;
	unsigned long ulW_Dm;
	unsigned long aulW_DG[ G_MAX ];
	unsigned long ulW_Dv;
	signed long slW_Dk;

	scanf( "%d", &ulW_Dtc_cnt );
	aulW_Dtestcase = ( int * ) malloc ( sizeof ( int ) * ulW_Dtc_cnt );
	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Dtc_cnt; ulW_Cloop_cnt++ ){
		scanf( "%d", &aulW_Dtestcase[ ulW_Cloop_cnt ] );
	}

	ulW_Dm = 1;
	aulW_DG[ 0 ] = 1;
	while( 3 * aulW_DG[ ulW_Dm - 1 ] + 1 < ulW_Dtc_cnt ){
		aulW_DG[ ulW_Dm ] = 3 * aulW_DG[ ulW_Dm - 1 ] + 1;
		ulW_Dm++;
	}

	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Dm / 2; ulW_Cloop_cnt++ ){
		ulW_Dv = aulW_DG[ ulW_Cloop_cnt ];
		aulW_DG[ ulW_Cloop_cnt ] = aulW_DG[ ulW_Dm - 1 - ulW_Cloop_cnt ];
		aulW_DG[ ulW_Dm - 1 - ulW_Cloop_cnt ] = ulW_Dv;
	}

	printf( "%d\n", ulW_Dm );
	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Dm; ulW_Cloop_cnt++ ){
		if( ulW_Cloop_cnt == ulW_Dm - 1 ){
			printf( "%d\n", aulW_DG[ ulW_Cloop_cnt ] );
		}
		else{
			printf( "%d ", aulW_DG[ ulW_Cloop_cnt ] );
		}
	}

	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Dm; ulW_Cloop_cnt++){
		for( ulW_Cloop_sub_cnt = aulW_DG[ ulW_Cloop_cnt ]; ulW_Cloop_sub_cnt < ulW_Dtc_cnt; ulW_Cloop_sub_cnt++ ){
			ulW_Dv = aulW_Dtestcase[ ulW_Cloop_sub_cnt ];
			slW_Dk = ulW_Cloop_sub_cnt - aulW_DG[ ulW_Cloop_cnt ];
			while( ( slW_Dk >= 0 ) && ( aulW_Dtestcase[ slW_Dk ] > ulW_Dv ) ){
				aulW_Dtestcase[ slW_Dk + aulW_DG[ ulW_Cloop_cnt ] ] = aulW_Dtestcase[ slW_Dk ];
				slW_Dk -= aulW_DG[ ulW_Cloop_cnt ];
				ulW_Csort_cnt++;
			}
			aulW_Dtestcase[ slW_Dk + aulW_DG[ ulW_Cloop_cnt ] ] = ulW_Dv;
		}
	}

	printf( "%d\n", ulW_Csort_cnt );
	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Dtc_cnt; ulW_Cloop_cnt++ ){
		printf( "%d\n", aulW_Dtestcase[ ulW_Cloop_cnt ] );
	}

	return 0;
}

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

#define INF int(1e9+5)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=105;
const int mod=1e9+7;
int n;
int h[maxn],dp[maxn][maxn][3];

int quickpow(int x,int pow){
	int res=1;
	for(;pow;pow>>=1){
		if(pow&1)res=1LL*res*x%mod;
		x=1LL*x*x%mod;
	}
	return res;
}

void solve(int l,int r,int last){
	dp[l][r][0]=dp[l][r][1]=dp[l][r][2]=1;
	int mn=INF;
	for(int i=l;i<=r;i++)mn=min(mn,h[i]);
	int cnt=0;
	for(int i=l;i<=r;i++){
		if(h[i]==mn)cnt++;
		else{
			int j=i;
			while(j<=r&&h[j]>mn)j++;
			solve(i,j-1,mn-1);
			dp[l][r][0]=1LL*dp[l][r][0]*dp[i][j-1][(i-l)&1]%mod;
			dp[l][r][1]=1LL*dp[l][r][1]*dp[i][j-1][1^((i-l)&1)]%mod;
			dp[l][r][2]=1LL*dp[l][r][2]*dp[i][j-1][2]%mod;
			i=j-1; 
		}
	}
	int cur=dp[l][r][0]+dp[l][r][1];
	if(cur>=mod)cur-=mod;
	dp[l][r][2]=1LL*dp[l][r][2]*quickpow(2,cnt)%mod;
	dp[l][r][2]-=cur;
	if(dp[l][r][2]<0)dp[l][r][2]+=mod;
	if(mn-last>1)dp[l][r][0]=dp[l][r][1]=1LL*cur*quickpow(2,mn-last-2)%mod;
	rep(i,2){
		dp[l][r][2]+=dp[l][r][i];
		if(dp[l][r][2]>=mod)dp[l][r][2]-=mod;
	}
} 

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",&h[i]);
	solve(1,n,0);
	printf("%d\n",dp[1][n][2]);
	return 0;
}

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

const int maxn = 1e5, maxm = 4e5, inf = 1e9;
int n, m, d[maxn + 3], tot, ter[maxm + 3], nxt[maxm + 3], wei[maxm + 3], lnk[maxn + 3], to[maxn + 3], id[maxn + 3];
vector<int> S[maxn + 3];
bool vis[maxn + 3];
char s[maxn + 3];

void add(int u, int v) {
	ter[++tot] = v, wei[tot] = inf, nxt[tot] = lnk[u], lnk[u] = tot;
}

void dfs(int u) {
	vis[u] = true;
	for (int i = 0, e, v; i < S[u].size(); i++) {
		e = S[u][i], v = ter[e];
		if (!vis[v]) {
			wei[e] = wei[e & 1 ? e + 1 : e - 1] = d[v];
			s[v] = s[u] ^ 'W' ^ 'B', dfs(v);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d %d", &u, &v), add(u, v), add(v, u);
	}
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		pair<int, int> p = make_pair(inf, inf);
		int e = 0;
		for (int j = lnk[i], v; j; j = nxt[j]) {
			v = ter[j];
			if (make_pair(d[v], v) < p) {
				p = make_pair(d[v], v), e = j;
			}
		}
		if (p.first > d[i]) { flag = false; break; }
		to[i] = p.second, id[i] = e, S[to[i]].push_back(e & 1 ? e + 1 : e - 1);
	}
	if (!flag) puts("-1"), exit(0);
	for (int i = 1; i <= n; i++) if (!vis[i] && to[to[i]] == i) s[i] = 'W', dfs(i);
	puts(s + 1);
	for (int i = 1; i <= m; i++) printf("%d\n", wei[i * 2]);
	return 0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<list>
using namespace std;
int main() { 
	long long  n;
	cin >> n;
	vector<long long >a(n);
	vector<long long >a2(n);
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
		a2[i] = a[i];
	}
	sort(a2.begin(), a2.end());
	for (long long i = 0; i < n; i++) {
		if (a[i] == a2[n-1]) {
			cout << a2[n-2] << endl;
		}
		else {
			cout << a2[n-1] << endl;
		}
		
	}
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int main(){
	int n, x, y, px, py;
	scanf("%d%d%d%d%d", &x, &y, &n, &px, &py);
	int ans = 0, tx, ty;n--;
	while(n--){
		scanf("%d%d", &x, &y);
		tx = x-px;ty = y-py;
		px = x;py = y;
		if((tx > 0 && ty > 0) || (tx < 0 && ty < 0))
		ans += max(abs(tx), abs(ty));
		else ans += abs(tx)+abs(ty);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3200
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=2e6+10;
	
	struct Nod{ int pos,val,id;
		friend bool operator < (Nod a,Nod b){ return (a.pos<b.pos) or (a.pos==b.pos and a.val<b.val); }
	}a[N];
	
	vc<pii> to[N];vc<int> ans;
	bool err;int n;bool vis[N];
	void solve(int x,int fa)
	{
		vis[x]=1;
		for(auto t:to[x])
		{
			int y=t.FR,id=t.SE;if(y==fa or vis[y])continue;solve(y,x);
			if(a[y].val) a[y].val^=1,a[x].val^=1,ans.PB(id);
		}
	}
	void main()
	{
		n=qread();int m=qread();fo(i,1,n) a[i].pos=qread(),a[i].val=qread();
		sort(a+1,a+n+1);fd(i,n+1,2) a[i].val^=a[i-1].val;
		 fo(i,1,m)
		 {
			 int l=qread(),r=qread();l=lower_bound(a+1,a+n+1,(Nod){l,0,0})-a;r=upper_bound(a+1,a+n+1,(Nod){r,INF,0})-a-1;if(l>r) continue;
			 to[l].PB({r+1,i}),to[r+1].PB({l,i});
			 debug("i=%d %d,%d\n",i,l,r);
		 }
		 bool err=0;fd(i,n+1,1) if(!vis[i]) { solve(i,0);if(i!=n+1 and a[i].val) err=1; }
		 if(err) write(-1); else{ sort(all(ans));write2(sz(ans));for(auto in:ans) write1(in); }
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("b.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"Time: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 61948
"""
map(int,input().split())

"""
N = int(input())
h = map(int,input().split())

hls =  []

for i in h:
    hls.append(i)

mx = hls[0]
cnt = 1
for i in range(1,N):
    if mx <= hls[i]:
        cnt += 1
        mx = hls[i]

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
//typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define SIZE 100005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD)  % MOD * fac[b] % MOD;
}

int N, K; 
vei to[100005];
ll ans;


void dfs(int v, int p = -1) {
    for(int u: to[v]) {
        if(u == p) continue;
        dfs(u,v);
    }
    int nk;
    if(p == -1) nk = K;
    else nk = K - 2;
    int c;
    if(p == -1) c = to[v].size() + 1;
    else c = to[v].size() - 1;
    ans *= comb(nk, c);
    ans %= MOD;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    
	cin >> N >> K;
	rep(i,N-1) {
		int a, b; cin >> a >> b; a--; b--;
		to[a].pub(b); to[b].pub(a);
	}
    make();
    ans = 1;
    dfs(0);
    cout << ans << endl;
}



Measured memory_bytes: 11648
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

using namespace std;

int h, w;
int g[10][10];
int cnt;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
const char *toS = "URDL";

char ans[50];
int ansp;

void solve(int x, int y, int d){
  if(ansp == cnt){
    ans[ansp] = '\0';
    throw 0;
  }else{
    REP(i,4) if((d - i + 4) % 4 != 2){
      int xx = x + _dx[i];
      int yy = y + _dy[i];

      while(ISIN(xx, yy, w, h)){
        if(g[yy][xx] == 1){
          ans[ansp++] = toS[i];
          g[yy][xx] = 0;
          solve(xx, yy, i);
          g[yy][xx] = 1;
          ansp--;
          break;
        }
        xx += _dx[i];
        yy += _dy[i];
      }
    }
  }
}

int main(){
  int sx, sy;
  int sd;

  scanf("%d%d", &h, &w);

  REP(i,h){
    char buff[20];
    scanf("%s", buff);
    REP(j,w){
      if(buff[j] == '.' || buff[j] == 'o'){
        g[i][j] = (buff[j] == '.' ? 0 : 1);
        if(g[i][j] == 1) cnt++;
      }else{
        g[i][j] = 0;
        sx = j; sy = i;
        switch(buff[j]){
        case 'U': sd = 0; break;
        case 'D': sd = 2; break;
        case 'R': sd = 1; break;
        case 'L': sd = 3; break;
        }
      }
    }
  }

  try{
    solve(sx, sy, sd);
  }catch(int e){
    puts(ans);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
//#pragma GCC optimize ("-O3")
//#pragma GCC target ("sse4")
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int k;
    cin >> k;
    int n;
    n = 1 << k;
    multiset<int> ms;
    for (int i = 0; i < n; i ++)
    {
        int a;
        cin >> a;
        ms.insert(a*-1);
    }
    bool np = false;
    vector<int> res;
    res.push_back(*ms.begin());
    ms.erase(ms.begin());

    for (int xx = 0; xx < k; xx++)
    {
        vector<int> nv;
        for (int x: res)
        {
            auto it = ms.upper_bound(x);
            if (it == ms.end())
            {
                np = true;
                break;
            }
            else
            {
                nv.push_back(*it);
                ms.erase(it);
            }
        }
        for (int x: nv)
            res.push_back(x);
        sort(res.begin(), res.end());
    }
    if (np)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 16832
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::max;
fn main(){
    input!{
        n:i64,
        k:i64
    }
    let mut ans = 0.;
    for j in  1..n+1 {
        let mut tmp = 1./n as f64;
        let mut now = j.clone();
        while now < k {
            now *= 2;
            tmp /= 2.;
        }
        ans +=tmp;
    }
    println!("{:.14}",ans);
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
def factorial(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret
def combination(n, k):
    return factorial(n)//factorial(k)//factorial(n-k)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
abc = LIR(N)

#dpb[i] = max(dpa[i-1], dpc[i-1])

dpa = [0]*(N+1)
dpb = [0]*(N+1)
dpc = [0]*(N+1)

for i in range(1, N+1):
    dpa[i] = max(dpb[i-1], dpc[i-1]) + abc[i-1][0]
    dpb[i] = max(dpa[i-1], dpc[i-1]) + abc[i-1][1]
    dpc[i] = max(dpa[i-1], dpb[i-1]) + abc[i-1][2]

print(max(dpa[N], dpb[N], dpc[N]))

Measured memory_bytes: 57648
s = input()
k = int(input())
n = 0
j = s[0]
l = 1
p = 0
fi,la = 0,0
c = 1
if len(set(list(s))) == 1:
  print(len(s)*k//2)
else:
  for i in range(1,len(s)):
    if s[i] == j:
      l += 1
    else:
      n += l//2
      if s[i-1] == s[0] and c == 1:
        fi = l
        c = 0
      l = 1
      j = s[i]
  n += l//2
  la = l
  if s[0] == s[-1] and fi%2 == 1 and la%2 == 1:
    p = k-1
  print(n*k+p)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	vector<int>a;
	int n, k, t;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	while(true) {
		a.clear();
		scanf("%d", &n);
      if(n==0)return 0;
		f(i, n) {
			scanf("%d", &x);
			a.push_back(x);
		}
		sort(a.begin(), a.end());
      s=0;
		f(i, n-2) {
			s += a[i + 1];
		}
		ans = s / (n - 2);
		printf("%d\n", ans);
	}



	return 0;
}


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

int main(int argc, char **argv)
{
	ll N; cin >> N;
	string str; cin >> str;

	ll r{0}, g{0}, b{0};
	for (ll i = 0; i < N; ++i)
	{
		if (str[i] == 'R') ++r;
		else if (str[i] == 'G') ++g;
		else ++b;
	}

	ll all = r * g * b;
	for (ll i = 0; i < N-1; ++i)
	{
		for (ll j = i + 1; j < N; ++j)
		{
			ll k = 2 * j - i;
			if (k < 0 || k >= N) continue;

			if (str[i] == str[j] || str[i] == str[k] || str[j] == str[k]) continue;
			--all;
		}
	}
	std::cout << all << std::endl;
}


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

const int Maxn = 200005;

int best[2];
int n;
int a[Maxn];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] > best[0]) best[1] = best[0], best[0] = a[i];
        else if (a[i] > best[1]) best[1] = a[i];
    }
    for (int i = 0; i < n; i++)
        if (a[i] == best[0]) printf("%d\n", best[1]);
        else printf("%d\n", best[0]);
    return 0;
}


Measured memory_bytes: 2432