akhauriyash/Code-Regression huggingface dataset:
module DLinkedList = struct
  type 'a element =
    { value : 'a;
      mutable next : int;
      mutable prev : int
    }
  type 'a t = {
    mutable first : int;
    mutable last  : int;
    mutable index : int;
    elts : 'a element array
  }

  let create n = {first = -1; last = -1; index = 0;
                  elts = Array.make n {value="";next=0;prev=0}}
                 
  let insert_first t value =
    let new_elt = {prev = -1; next = t.first; value} in
    let i = t.index in
    begin match t.first with
      | -1 -> ()
      |  old_first -> t.elts.(old_first).prev <- i
    end;
    t.first <- i; t.elts.(i) <- new_elt; t.index <- i + 1;
    begin match t.last with
      | -1 -> t.last <- t.first
      | _ -> ()
    end

  let remove t elt =
    let {prev; next; _} = elt in
    begin match prev with
      | -1 -> t.first <- next
      | pi -> t.elts.(pi).next <- next
    end;
    begin match next with
      | -1 -> t.last <- prev
      | ni -> t.elts.(ni).prev <- prev
    end
      
  let find t v =
    let eq (a:string) (b:string) = (=) a b in
    let rec loop = function
      | -1 -> ()
      |  i ->
        let elt = t.elts.(i) in
        if eq v elt.value then remove t elt
        else loop elt.next
    in
    loop t.first

  let remove_first t =
    begin match t.first with
      | -1 -> ()
      |  i ->
        let first = t.elts.(i) in
        begin match first.next with
          | -1 -> t.first <- -1; t.last <- -1
          | j -> t.elts.(j).prev <- -1; t.first <- j
        end
    end

  let remove_last t =
    begin match t.last with
      | -1 -> ()
      | i ->
        let last = t.elts.(i) in
        begin match last.prev with
          | -1 -> t.first <- -1; t.last <- -1
          |  j -> t.elts.(j).next <- -1; t.last <- j
        end
    end

  let print t =
    let rec loop e = match e.next with
      | -1 -> Printf.printf "%s\n" e.value
      |  i -> Printf.printf "%s " e.value; loop t.elts.(i)
    in
    loop t.elts.(t.first)
end

let () =
  let open DLinkedList in
  let (n: int) = read_int () in
  let (dll: string t) = create n in
  for i=1 to n do
    begin match read_line () with
      | "deleteFirst" -> remove_first dll
      | "deleteLast" -> remove_last dll
      | s ->
        begin match String.sub s 0 6,
                    (String.sub s 7 (String.length s - 7)) with
        | "insert", n -> insert_first dll n
        | "delete", n -> find dll n
        | _ -> ()
        end
    end
  done;
  print dll

Measured memory_bytes: 76472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> S;
    string s;
    for (int i=0; i<N; i++) {
        cin >> s;
        S.push_back(s);
    }
    
    ll cnt[5];
    for (int i=0; i<5; i++){
        cnt[i] = 0;
    }

    for (int i=0; i<N; i++) {
        if (S[i][0] == 'M') cnt[0]++;
        else if (S[i][0] == 'A') cnt[1]++;
        else if (S[i][0] == 'R') cnt[2]++;
        else if (S[i][0] == 'C') cnt[3]++;
        else if (S[i][0] == 'H') cnt[4]++;
    }

    ll res=0;
    for (int i=0; i<3; i++){
        for (int j=i+1; j<4; j++){
            for (int k=j+1; k<5; k++){
                res += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << res << endl; 
}


Measured memory_bytes: 6132
#include <cstdio>
#include <algorithm>
using std::min;
 
int m_abs(int z)
{
    if (z<0)
        return -z;
    else
        return z;
}
 
int main(void)
{
    int *a,*dp,N,i,j,K;
    scanf("%d%d",&N,&K);
    a=new int [N];
    dp=new int [N];
    for (i=0;i<N;i++)
    {
        scanf("%d",a+i);
    }
    dp[N-1]=0;
    if(K>N)
        K=N;
    for(i=0;i<K;i++)
        dp[N-1-i]=abs(a[N-1]-a[N-1-i]);
 
    for(i=N-1-K;i>=0;i--)
    {
        dp[i]=dp[i+1]+abs(a[i]-a[i+1]);
        for(j=2;j<=K;j++)
        {
            dp[i]=min(dp[i+j]+abs(a[i]-a[i+j]),dp[i]);
        }
        //printf("dp[%d]= %d\n",i,dp[i]);
 
    }
 
    printf("%d\n",dp[0]);
    delete [] dp;
    delete [] a;
 
    return 0;
}

Measured memory_bytes: 1024
from collections import deque

H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

Q = deque((i, j, 0) for i in range(H) for j in range(W) if A[i][j] == "#")

ans = 0
while Q:
    i, j, dist = Q.popleft()
    ans = max(ans, dist)
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))

print(ans)


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

typedef long long ll;
int main()
{
    ll n,t;
    cin>>n>>t;
    bool flag=true;
    ll mn=INT_MAX;
    for(int i=0; i<n; i++)
    {
        ll c,tim;
        cin>>c>>tim;
        if(tim<=t)
        {
            mn=min(mn,c);
            flag=false;
        }
    }
    if(flag)
    {
        cout<<"TLE"<<endl;
    }
    else
    {
        cout<<mn<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
total = 0
for name_len in range(1,12+1):
    if total+26**name_len >= n:
        n -= total
        break
    else:
        total += 26**name_len
n -= 1
digits = []
for i in range(name_len):
    digits.append(chr(ord('a')+n%26))
    n //= 26
digits.reverse()
print(''.join(digits))

Measured memory_bytes: 61836
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int digit = 10;
    int nine = 999999999;
    while (1) {
        cout << "? " << nine << endl;
        char ans; cin >> ans;
        if (ans == 'N') {
            if (digit == 10) {
                cout << "! 1000000000" << endl;
                return 0;
            }
            break;
        } else {
            digit--;
            int c = 1;
            nine /= 10;
        }
        if (digit == 1) break;
    }
    if (digit == 1) {
        ll ten = 10;
        while (1) {
            cout << "? " << ten << endl;
            char ans; cin >> ans;
            if (ans == 'Y') {
                digit++;
                ten *= 10LL;
                if (digit == 10) {
                    cout << "! 1" << endl;
                    return 0;
                }
            } else break;
        }
    }
    ll res = 0;
    rep(_,digit) {
        if (_ == digit-1) {
            ll left = -1;
            ll right = 9;
            while (right - left > 1) {
                ll mid = (left+right)/2;
                cout << "? " << (res*10LL+mid)*10LL+1LL << endl;
                char ans; cin >> ans;
                if (ans == 'Y') right = mid;
                else left = mid;
            }
            res = res*10LL + right;
            continue;
        }
        ll left = 0;
        ll right = 10;
        while (right - left > 1) {
            ll mid = (left+right)/2;
            cout << "? " << res*10LL+mid << endl;
            char ans; cin >> ans;
            if (ans == 'Y') left = mid;
            else right = mid;
        }
        res = res*10LL+left;
    }
    cout << "! " << res << endl;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48&&c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
//\n 0   //r
int ans,a[105],n;

int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=2;i<=n;++i){
		if(a[i] == a[i-1]){
			++ans;
			++i;
		}
	} 
	cout<<ans;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))


def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)


def m():
    left, right = A.copy(), A.copy()
    for i in range(1, N):
        left[i] = gcd(A[i], left[i-1])

    for i in reversed(range(0, N-1)):
        right[i] = gcd(A[i], right[i+1])

    res = max(left[N-2], right[1])
    for i in range(1, N-1):
        res = max(gcd(left[i-1],right[i+1]), res)
    return res


print(m())


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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
    if (l >= r) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m+1, r);
    post.push_back(root);
}

void solve(){
    pos = 0;
    rec(0, pre.size());
    for (int i = 0; i < n; i++)
    {
        if(i) cout << " ";
        cout << post[i]; 
    }
    cout << endl;
}
int main(){
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        pre.emplace_back(x);
    }
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        in.emplace_back(x);
    }
    
    solve();
}


Measured memory_bytes: 3160
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
const int MR=100010;


deque<int> q;
int d_min[MR];
int parent[MR];
int type[MR];
int main(){
	memset(d_min,-1,sizeof(d_min));
	d_min[1]=1;
	int K;
	cin>>K;
	q.push_back(1);
	while(1){
		int now=q.front();
		//printf("%d\n",now);
		if(now==0){
			printf("%d\n",d_min[now]);
			break;
		}
		q.pop_front();
		if(d_min[(now*10)%K]==-1 || d_min[(now*10)%K]>d_min[now]){
			q.push_front((now*10)%K);
			d_min[(now*10)%K]=d_min[now];
			parent[(now*10)%K]=now;
			type[(now*10)%K]=0;
		}
		if(d_min[(now+1)%K]==-1){
			q.push_back((now+1)%K);
			d_min[(now+1)%K]=d_min[now]+1;
			parent[(now+1)%K]=now;
			type[(now+1)%K]=1;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    ll n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }
}


Measured memory_bytes: 256
q=int(input())
lr=[list(map(int, input().split())) for _ in range(q)]

import math
def is_prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True

n=10**5+1
prime_list=[0]*n
for i in range(3,n,1):
    if is_prime(i) and is_prime((i+1)//2):
        prime_list[i]=1

from itertools import accumulate
acc=list(accumulate(prime_list))

for lr_i in lr:
    print(acc[lr_i[1]]-acc[lr_i[0]-1])



Measured memory_bytes: 32056
n, m = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()
diff_list = [x_list[i] - x_list[i-1] for i in range(1, m)]
diff_list.sort()
if m-n < 0:
    nokori = 0
else:
    nokori = m - n
print(sum(diff_list[:nokori]))

Measured memory_bytes: 13960
#include "bits/stdc++.h"
using namespace std;
 
long long n,sum=0;
int cnt=0;
string s;
map<int, long long> m;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='M'){
			m[1]++;
		}
		else if(s[0]=='A'){
			m[2]++;
		}
		else if(s[0]=='R'){
			m[3]++;
		}
		else if(s[0]=='C'){
			m[4]++;
		}
		else if(s[0]=='H'){
			m[5]++;
		}
	}

	for(int i=1;i<=m.size();i++){
		for(int j=i+1;j<=m.size();j++){
			for(int k=j+1;k<=m.size();k++){
				sum+=(m[i]*m[j]*m[k]);
			}
		}
	}

	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec[i];
    }
    int Min=1e9;
    for(int i=-100;i<=100;i++){
        int c=0;
        for(int j=0;j<n;j++){
            c+=pow(abs(vec[j]-i),2);
        }
        Min=min(Min,c);
    }
    cout<<Min<<endl;
}


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

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

	if ((abs(a-c)<=d) || (abs(a-b)<=d && abs(b-c)<=d))
	{
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc156/tasks/abc156_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll n, r;
    cin >> n >> r;

    if(n>=10) {
        print(r);
    } else {
        print(r+100*(10-n));
    }
    return 0;
}


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

const int INF = 1001001001;

vector<int> to[2505];
vector<int> ot[2505];
bool reach[2505];
bool reach1[2505];
bool ok[2505];

void dfs(int i){
  if(reach[i]) return;
  reach[i] = true;
  for(int j : to[i]){
    dfs(j);
  }
}

void dfs1(int i){
  if(reach1[i]) return;
  reach1[i] = true;
  for(int j : ot[i]){
    dfs1(j);
  }
}

int main(){
  int n,m,p;
  cin >> n >> m >> p;
  vector<tuple<int,int,int>> edges;
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    c -= p;
    c = -c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    ot[b].push_back(a);
  }
  dfs(0);
  dfs1(n-1);
  rep(i,n){
    ok[i] = reach[i] & reach1[i];
  }
  int step = 0;
  bool flg = true;
  vector<int> d(n,INF);
  d[0] = 0;
  while(flg){
    flg = false;
    rep(i,m){
      int a,b,c;
      tie(a,b,c) = edges[i];
      if(!ok[a])continue;
      if(!ok[b])continue;
      int newD = d[a] + c;
      if(newD<d[b]){
        d[b] = newD;
        flg = true;
      }
    }
    step++;
    if(step>n){
      puts("-1");
      return 0;
    }
  }
  int ans = -d[n-1];
  ans = max(0,ans);
  cout << ans << endl;
}


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


int main(){

    int n;
    int R[200010];


    cin >> n;

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

    //Rmin,Vmaxの初期値を設定
    int Rmin = R[0];
    int Vmax = R[1]-R[0];

    for (int i =1; i < n; i++){
        if (Vmax < R[i] - Rmin){
            Vmax = R[i] - Rmin;
        }
        if (Rmin > R[i]){
            Rmin = R[i];
        }
    }

    cout << Vmax <<endl;



}


Measured memory_bytes: 3880
import math

EPS = 1e-10

class Segment():
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, point):
        # + 演算子での挙動を指定
        return Point(self.x+point.x, self.y+point.y)

    def __sub__(self, point):
        # - 演算子での挙動を指定
        return Point(self.x-point.x, self.y-point.y)

    def __mul__(self, a):
        # * 演算子での挙動を指定
        return Point(a*self.x, a*self.y)

    def __truediv__(self, a):
        # / 演算子での挙動を指定
        return Point(self.x/a, self.y/a)

    def __abs__(self):
        # abs関数での挙動を指定
        return math.sqrt(self.norm())

    def norm(self):
        return self.x**2+self.y**2

    def __eq__(self, point):
        # == 演算子での挙動を指定
        return abs(self.x-point.x) < EPS and abs(self.y-point.y) <EPS

def dot(a, b):
    return a.x*b.x+a.y*b.y

def cross(a, b):
    return a.x*b.y - a.y*b.x

def isOrthogonal(a, b):
    return dot(a, b) == 0

def isParallel(a, b):
    return cross(a, b) == 0

def project(s, p):
    #s: Segment(), p: Point()
    base = s.p2 - s.p1
    r = dot(p-s.p1, base)/base.norm()
    return s.p1+base*r

if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    x1, y1, x2, y2 = map(int, input().split())
    s = Segment(Point(x1, y1), Point(x2, y2))

    q = int(input())
    for _ in range(q):
        x0, y0 = map(int, input().split())
        p = Point(x0, y0)
        projection = project(s, p)
        print(projection.x, projection.y)



Measured memory_bytes: 5812
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int main() {
	vector <char> str;
	int N, K;
	cin >> N >> K;
	char s;
	for (int i = 0; i < N; i++) {
		cin >> s;
		str.emplace_back(s);
	}
	str[K - 1] += 32;
	for (int j = 0; j < str.size(); j++) {
		cout << str[j];
	}
	
}

Measured memory_bytes: 256
def main
  s_ary = gets.chomp.chars
  # puts s

  # 左から
  # Bの数を数えながら
  # Wが出たら、そこまでのBの数だけ ans に加算
  b_num = 0
  ans = 0
  s_ary.each do |c|
    if c == "B"
      b_num += 1
    else
      ans += b_num
    end
  end

  puts ans
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 16764
# -*- coding: utf-8 -*-
"""
http://abc069.contest.atcoder.jp/tasks/arc080_b

"""
from itertools import repeat

def walk_grid(H, W):
    # 左上(0, 0)からスタートして、下方向へ移動する。
    # 一番下まできたら一列右に移動して、今度は上方向へ一歩ずつ移動する。
    # 一番上まできたら一列右に移動して、今度は下方向へ一歩ずつ移動する。
    x, y = 0, 0
    step = 1
    while True:
        yield (x, y)
        y += step
        if y >= H or y < 0:
            step *= -1
            y += step
            x += 1


def solve(repeats, H, W, N):
    grid = [['.']*W for _ in range(H)]
    pos = walk_grid(H, W)
    for c, r in enumerate(repeats, start=1):
        for _ in range(r):
            x, y = pos.__next__()
            grid[y][x] = c
    return grid


def main():
    H, W = map(int, input().split())
    N = int(input())
    repeats = [int(x) for x in input().split()]
    result = solve(repeats, H, W, N)
    for r in result:
        print(*r)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3948
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var res = 0;
        for (var i = 0; n - 2 > i; i++)
        {
            if (nums[i] < nums[i + 1] && nums[i + 1] < nums[i + 2] ||
                nums[i + 2] < nums[i + 1] && nums[i + 1] < nums[i])
                res++;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  set<char> st;

  rep(i, 3){
    char c; cin >> c;
    st.insert(c);
  }

  cout << (st.size() == 2 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, p;
    cin >> n >> p;
    vector<lint> a(n);
    lint even = 1;
    lint odd = 0;
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    for (int i=0; i<n; ++i){
        if(a[i] % 2 == 0){
            even *= 2;
            odd *= 2;
        }
        else {
            lint tmp = even;
            even += odd;
            odd += tmp;
        }
    }
    lint ans = (p == 1) ? odd : even;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i, n) for (int i=0;i<n;i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  double a,b=2*n;
  if (n%2==0) a=0.5000000000;
  else a=(n+1)/b;
  cout << a << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

typedef long long ll;

const int MAX_N = 100000;

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

    string s;

    cin >> s;

    ll ans = 0;
    bool reversed = false;

    while (true) {
        int oldsiz = s.size();
        string new_s = "";
        new_s += s[0];
        unordered_set<char> st;
        for (int i = 0; i < s.size(); i++) {
            if (st.count(s[i]) || i == s.size() - 1) {
                if (new_s[new_s.size() - 1] == s[i]) {
                    new_s += s[i - 1];
                    ans += st.size() - 2;
                } else {
                    ans += st.size() - 1;
                }
                new_s += s[i];
                st.clear();
            }
            st.insert(s[i]);
        }

        s = new_s;
        if (oldsiz == s.size()) {
            if (!reversed) {
                reversed = true;
                reverse(s.begin(), s.end());
            } else {
                break;
            }
        }
    }

    if (ans % 2) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }

    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
 
int main(){
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;

	ll ans=(h2-h1)*60+(m2-m1)-k;

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

Measured memory_bytes: 3596
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

#define bs(n) (1ull<<(ull)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)

pair<ll, ll> extgcd(ll a, ll b) {
    if (b == 0)return make_pair(a, 0);
    auto t = extgcd(b, a % b);
    return make_pair(t.second, t.first - t.second * (a / b));
}

ll modinv(ll n) {
    return (extgcd(n, mod).first + mod) % mod;
}

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

ll lcm(ll a, ll b) {
    return (((a * b) % mod) * modinv(gcd(a, b))) % mod;
}

ll p[1000000], q[1000000], c;

int main() {
    for (ll i = 2; i <= 1000; i++) {
        bool f = true;
        rep(j, c) {
            if (i % p[j] == 0) {
                f = false;
                break;
            }
        }
        if (f) {
            p[c] = i;
            c++;
        }
    }
    ll n;
    cin >> n;
    ll *a = new ll[n];
    rep(i, n)cin >> a[i];
    ll g = 1;
    rep(i, n) {
        ll t = a[i];
        rep(j, c) {
            ll v = 0;
            while (t % p[j] == 0) {
                v++;
                t /= p[j];
            }
            q[j] = max(q[j], v);
        }
        if (t != 1) {
            p[c] = t;
            q[c] = 1;
            c++;
        }
    }
    rep(i, c) {
        while (q[i] > 0) {
            g = (g * p[i]) % mod;
            q[i]--;
        }
    }
    ll r = 0;
    rep(i, n) {
        r = (r + ((g * modinv(a[i])) % mod)) % mod;
    }
    cout << r << endl;
}


Measured memory_bytes: 2432
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

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

    map<ll,ll> P;
    for (int i=0;i<N;i++) {
        P[i+1+A[i]]++;
        // M.insert(i+1-A[i]);a
    }
    ll res = 0;
    for (int i=0;i<N;i++) {
        res += P[i+1-A[i]];
        // res += M.count(i+1+A[i]);
        // cout << res << endl;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 27296
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();

    let mut sum = 0;
    let mut ans = 0;
    for i in 0..n {
        if i % 2 == 0 {
            if sum + a[i] <= 0 {
                ans += 1 - sum - a[i];
                sum = 1;
            } else {
                sum += a[i];
            }
        } else {
            if sum + a[i] >= 0 {
                ans += 1 + sum + a[i];
                sum = -1;
            } else {
                sum += a[i];
            }
        }
    }
    let ans1 = ans;

    let mut sum = 0;
    let mut ans = 0;
    for i in 0..n {
        if i % 2 == 1 {
            if sum + a[i] <= 0 {
                ans += 1 - sum - a[i];
                sum = 1;
            } else {
                sum += a[i];
            }
        } else {
            if sum + a[i] >= 0 {
                ans += 1 + sum + a[i];
                sum = -1;
            } else {
                sum += a[i];
            }
        }
    }

    println!("{}", min(ans1, ans));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
  int N = 0, M = 0, max = 0;
  
  cin >> N;
  
  vector<int> count(N);
  
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  
  cin >> M;
  
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = i; j < N; j++) {
      if (s.at(i) == s.at(j)) {
        count.at(i)++;
      }
    }
    
    for (int j = 0; j < M; j++) {
      if (s.at(i) == t.at(j)) {
        count.at(i)--;
      }
    }
    
    if (count.at(i) < 0) {
      count.at(i) = 0;
    }
  }
  
  for (int i = 0; i < N; i++) {
    if (max < count.at(i)) {
      max = count.at(i);
    }
  }
  
  cout << max << endl;
}


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

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b, x;
	cin >> a >> b >> x;
	cout << b / x - (a == 0 ? -1 : (a-1) / x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	VE sume(n + 1), sumw(n + 1);
	rep(i, n) {
		int nowe = 0; int noww = 0;
		if (s[i] == 'W')noww++;
		else nowe++;
		sume[i + 1] = sume[i] + nowe;
		sumw[i + 1] = sumw[i] + noww;
	}
	int ans = INF;
	rep(i, n) {
		chmin(ans, sumw[i] + (sume[n]-sume[i + 1]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int x, y;
	cin >> x >> y;
	if (y % 2) {cout << "No" << endl; return 0;}
	y /= 2;
	int a, b;
	b = y - x;
	a = x - b;
	if (a < 0 || b < 0) {cout << "No" << endl; return 0;}
	if (a + 2*b != y) {cout << "No" << endl; return 0;}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;scanf("%lld%lld",&n,&m);
	if(m>=2*n)m=m-2*n,printf("%lld\n",n+m/4);
	else printf("%lld\n",m/2);
	return 0;
 } 

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<set>
#include<vector>
#include<random>
#include<chrono>
#include<algorithm>

int main() {
	std::string s, t, ans;
	std::cin >> s >> t;

	for (int i = 0; i < s.size() - t.size() + 1; i++) {
		std::string temp;
		bool flag = true;
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] == '?' || s[i + j] == t[j])continue;
			flag = false;
			break;
		}

		if (flag) {
			temp= std::string(s.size(), 'a');
			for (int j = 0; j < s.size(); j++) {
				if (s[j] == '?')continue;
				temp[j] = s[j];
			}
			for (int j = 0; j < t.size(); j++) {
				temp[i + j] = t[j];
			}
		}

		if (!flag)continue;
		if (ans.empty())ans = temp;
		else {
			for (int i = 0; i < s.size(); i++) {
				if (ans[i] > temp[i]) {
					ans = temp;
					break;
				}
			}
		}
	}

	if (ans.empty())printf("UNRESTORABLE\n");
	else std::cout << ans << std::endl;
}

Measured memory_bytes: 256
N = input()

if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
    print("hon")
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
    print("pon")
elif N[-1] == '3':
    print("bon")

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

int main() {
	long long a,b,k;
	cin>>a>>b>>k;
	if(a>k){
		cout<<a-k<<" "<<b<<endl;
	}
	else if(k<a+b){
		cout<<0<<" "<<a+b-k<<endl;
	}
	else{
		cout<<"0 0"<<endl;
	}
}


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

int main(){

    string a, b, c;
    cin >> a >> b >> c;

    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;cin>>N;
  if(N%2==1){puts("0");return 0;}
  long long ans=0;
  for(int i=1;i<26;i++){
    long long count=2ll*(pow(5,i));
    ans+=N/count;
  }
  cout<<ans<<endl;
}

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

int main(){
    int n,nm[100];
    
    while(true){
        string first = "0000000";
        
        cin >> n;
        if(n == -1) break;
        
        for(int i = 0 ; i < n ; i++){
            cin >> nm[i];
            
            string str;
            switch(nm[i]){
                case 0:
                    str = "0111111";
                    break;
                case 1:
                    str = "0000110";
                    break;
                case 2:
                    str = "1011011";
                    break;
                case 3:
                    str = "1001111";
                    break;
                case 4:
                    str = "1100110";
                    break;
                case 5:
                    str = "1101101";
                    break;
                case 6:
                    str = "1111101";
                    break;
                case 7:
                    str = "0100111";
                    break;
                case 8:
                    str = "1111111";
                    break;
                case 9:
                    str = "1101111";
                    break;
            }
            string ans = "";
            for(int j = 0 ; j < 7 ; j++){
                if(first[j]!= str[j]) ans += '1';
                else ans += '0';
            }
            cout << ans << endl;
            first = str;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1204
import sys
input = sys.stdin.readline

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

ab_array = sorted(ab_array, key=lambda x: -x[1])

# print(ab_array)
time = ab_array[0][1]

for ab in ab_array:
    time = min(ab[1],time)
    time -= ab[0]
    if time < 0:
        print("No")
        exit()
else:
    print("Yes")

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

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

    int minP = MAX;
    int ans = 0;
    while (N--)
    {
        int P;
        cin >> P;
        if (P <= minP)
        {
            ans++;
            minP = P;
        }
        
    }
    cerr << minP << endl;
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,x;
	int ans=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=a;i++)
	{
		scanf("%d",&x);
		if(x<b||x>=c)
		{
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

int main(){
  int A, B;
  cin >> A >> B;
  int p = A + B;
  int m = A - B;
  int z = A * B;
  
  if (p >= m && p >= z){
    cout << p << endl;
  }
  else if (m >= p && m >= z){
    cout << m << endl;
  }
  else{
	cout << z << endl;  
  }
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int N;
int length[10];

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

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &length[i]);
	}

	int maxLength = 0;

	for (int i = 0; i < N; i++)
	{
		if (maxLength < length[i]) maxLength = length[i];
	}

	int sum = 0;

	for (int i = 0; i < N; i++)
	{
		sum = sum + length[i];
	}

	int others = sum - maxLength;

	if (maxLength  < others) printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 128
package main

import (
	"container/heap"
	"sort"
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	n := scanInt()

	t := make([][]int, n)

	for i := 0; i < n-1; i++ {
		a := scanInt()-1
		b := scanInt()-1
		t[a] = append(t[a], b)
		t[b] = append(t[b], a)
	}

	c := scanInts(n)
	sort.Ints(c)

	cnt := &verts{}
	heap.Init(cnt)
	ec := make([]int, n)

	for i := 0; i < n; i++ {
		ec[i] = len(t[i])
		heap.Push(cnt, vert{i,ec[i]})
	}

	done := make([]bool, n)
	d := make([]int, n)
	m := 0

	for i := 0; i < n; i++ {
		next := -1
		for cnt.Len() != 0 {
			v := heap.Pop(cnt).(vert)
			if !done[v.num] {
				next = v.num
				break
			}
		}

		d[next] = c[i]
		done[next] = true
		m += c[i]*ec[next]

		for _, e := range t[next] {
			ec[e]--
			heap.Push(cnt, vert{e, ec[e]})
		}
	}

	fmt.Println(m)

	for i, e := range d {
		fmt.Fprint(wr, e)
		if i != len(d)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

type vert struct {
	num int
	cnt int
}

type verts []vert

func (a verts) Len() int           { return len(a) }
func (a verts) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a verts) Less(i, j int) bool { return a[i].cnt < a[j].cnt }

func (a *verts) Push(x interface{}) {
	*a = append(*a, x.(vert))
}

func (a *verts) Pop() interface{} {
	old := *a
	n := len(old)
	x := old[n-1]
	*a = old[0:n-1]

	return x
}

Measured memory_bytes: 4480
def euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)
a, b, c, d=map(int,input().split())
if a%c==0:
  ac = a//c
else:
  ac = (a//c)+1
bc=b//c
n=bc-ac+1
if a%d == 0:
  ad = a//d
else:
  ad = (a//d)+1
bd = b//d
m = bd-ad+1
new = (c*d)//euclid(c, d)
if a%(c*d)==0:
  cnew=a//new
else:
  cnew=(a//new)+1
dnew=(b//new)
r=dnew-cnew+1
s=n+m-r
print(b-a+1-s)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    int t;
    for(cin >> t; t--; ){
        int n, x, y, a = 0, b = 0;
        cin >> n;
        for(int i = 0; i < n; ++i){
            cin >> x;
            if(i != 0){
                int d = x - y;
                a = max(a, d);
                b = max(b, -d);
            }
            y = x;
        }
        cout << a << ' ' << b << '\n';
    }
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long multiple = 1;
		while(h > 0) {
			h = h / 2;
			multiple *= 2;
		}
		System.out.println(multiple - 1);

	}


}



Measured memory_bytes: 35588
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
//Auther: Arin Roday
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
 
int test_case_number = 1;

void print_case(){
    #ifdef LOCAL
    cout << "Case #" << test_case_number++ << ": ";
    #endif
}
#define int long long
void solve(){
    int n, d;
    int ans = 0;
    cin >> n >> d;
    d *= d;
    int u , v;
    for(int i = 0; i < n; ++i){
        cin >> u >> v;
        if(u*u + v*v <= d){
            ans ++;
        }
    }
    cout << ans << endl;
}
 
int32_t main(){
    solve();
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_set>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define derr if(1) cerr
typedef vector<int> vi;
// END NO SAD

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

ll choose(int n, int k) {
  if(k < 0) return 0;
  ll ret = 1;
  for(int i = 0; i < k; i++) {
    ret *= n-i;
    ret /= i+1;
  }
  return ret;
}

ll solve(string s, int k) {
  if(k == 0) return 1;
  if(sz(s) == 0) return 0;
  ll ret = 0;
  for(char c = '0'; c <= '9'; c++) {
    int nonzero = k - (c != '0');
    if(s[0] == c) {
      ret += solve(s.substr(1), nonzero);
      break;
    }
    ll cand = choose(sz(s)-1, nonzero);
    for(int a = 0; a < nonzero; a++) cand *= 9;
    ret += cand;
  }
  return ret;
}

void solve() {
  string s;
  int k;
  cin >> s >> k;
  cout << solve(s, k) << "\n";
}
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases

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


Measured memory_bytes: 256