akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;


#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull testcase;cin>>testcase;while(testcase--)
#define pb push_back
#define mkp make_pair
#define nl cout<<"\n"
#define prime 1000000007
#define debug(x) cout<<(#x)<<" : "<<x,nl
#define debug2(x,y) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y,nl
#define debug3(x,y,z) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y<<" "<<(#z)<<" : "<<z,nl
#define f first
#define s second
#define oa(a,n) loop(i,0,n)cout<<a[i]<<" ";nl;
#define ov(a) loop(i,0,a.size()) cout<<a[i]<<" ";nl;
#define MOD(a) (((a%prime)+prime)%prime)



int main()
{

    ll n,k,i;

    cin >> n >> k;

    string s;
    cin >> s;

    if(islower(s[k-1])==0)
    {
    	s[k-1] = s[k-1] + 32;
    }

    cout << s;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int m = cin.nextInt();
		long[] x = new long[n];
		long[] y = new long[m];
		for (int i=0;i<n;i++){
			x[i] = cin.nextLong();
		}
		for (int i=0;i<m;i++){
			y[i] = cin.nextLong();
		}
		long segmax = 0;
		long segmay = 0;
		for (int i=0;i<n;i++){
			segmax -= (n-i-1)*x[i];
			segmax += i*x[i];
		}
		segmax %= 1000000007;
		for (int i=0;i<m;i++){
			segmay -= (m-i-1)*y[i];
			segmay += i*y[i];
		}
		segmay %= 1000000007;
		System.out.println(segmax * segmay % 1000000007);
	} 
	
}


Measured memory_bytes: 89452
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
//#define LOCAL
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 10000+10;
const LL mod = 1000000000+7;

int main()
{
    #ifdef LOCAL
        freopen("input.txt" , "r", stdin);
    #endif // LOCAL
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a==c-b)    cout << "YES" << endl;
    else    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of bool
    """

    is_prime = [True] * (x + 1)
    is_prime[0] = is_prime[1] = False

    for i in range(2, x + 1):
        if is_prime[i]:
            for j in range(i * 2, x + 1, i):
                is_prime[j] = False

    return is_prime


n = int(input())

is_prime = sieve(10 ** 6)
primes = [i for i, e in enumerate(is_prime) if e]

ans = 0
for e in primes:
    div = e
    while n % div == 0:
        n //= div
        ans += 1
        div *= e

    while n % e == 0:
        n //= e

ans += n != 1

print(ans)


Measured memory_bytes: 19948
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

typedef std::complex<double> Com;
Com ver[25];

double cross_product(Com x, Com y){
    return (conj(x)*y).imag();
}

int main(){
    double x, y;
    long n = 0;
    while(EOF != scanf("%lf,%lf", &x, &y)){
        ver[n] = Com(x, y);
        n++;
        //printf("pass\n");
    }
    /*
    for(int i = 0; i < n; i++){
        std::cout << ver[i] << std::endl;
    }
    //*/
    long ans = 0;
    for(int i = 1; i < n-1; i++){
        ans += cross_product(ver[i+1]-ver[0], ver[i]-ver[0]);
    }
    printf("%lf\n", std::abs(ans)/2.0);
}



Measured memory_bytes: 3152
from collections import Counter
n = int(input())
a = [int(n) for n in input().split()]
q = int(input())

bs = []
cs = []
for i in range(q):
  b,c = map(int, input().split())
  bs.append(b)
  cs.append(c)

total = sum(a)
a = Counter(a)  

for i in range(q):
  dif = cs[i] - bs[i]
  total += dif * a[bs[i]]
  a[cs[i]] += a[bs[i]]
  a[bs[i]] = 0
  print(total)

Measured memory_bytes: 29716
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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



int main() {
	ll x;
	cin >> x;

	for (ll a = -1000; a <= 1000; a++) {
		for (ll b = -1000; b <= 1000; b++) {
			ll a5 = 1;
			ll b5 = 1;
			for (int i = 0; i < 5; i++) {
				a5 *= a;
				b5 *= b;
			}

			

			if (a5 - b5 == x) {
				cout << a << " " << b << endl;
				return 0;
			}

			
		}
	}

}

Measured memory_bytes: 3604
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

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

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (a, p) = read!(i32, i32);

    let parts: i32 = a * 3 + p;
    println!("{}", parts / 2);
}


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

int gcd(int a, int b){
  int ma=max(a, b);
  int mb=min(a, b);
  if(ma%mb==0){
    return mb;
  }
  else{
    return gcd(ma%mb, mb);
  }
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  int Ans=0;
  vector<int> gcdf(N), gcds(N);
  gcdf.at(0)=A.at(0);
  gcds.at(N-1)=A.at(N-1);
  for(int i=1; i<N; i++){
    gcdf.at(i)=gcd(gcdf.at(i-1), A.at(i-1));
    gcds.at(N-i-1)=gcd(gcds.at(N-i), A.at(N-i));
  }
  Ans=max(gcds.at(0), gcdf.at(N-1));
  for(int i=1; i<N-1; i++){
    Ans=max(Ans, gcd(gcds.at(i), gcdf.at(i)));
  }
  cout << Ans << endl;
}

Measured memory_bytes: 1408
package main

import (
	"fmt"
	"math"
)

const (
	MAX_INF = math.MaxInt64 / 2
)

func main() {
	var N int
	fmt.Scan(&N)
	count := make([]int, N+1)
	count[0] = 0
	count[1] = 1
	for i := 2; i <= N; i++ {
		min := MAX_INF
		c := count[i-1] + 1
		if c < min {
			min = c
		}
		pay := 6
		for i-pay >= 0 {
			c = count[i-pay] + 1
			if c < min {
				min = c
			}
			pay *= 6
		}
		pay = 9
		for i-pay >= 0 {
			c = count[i-pay] + 1
			if c < min {
				min = c
			}
			pay *= 9
		}
		count[i] = min
	}
	fmt.Println(count[N])
}


Measured memory_bytes: 1280
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
dp=[[0 for _ in range(H+1)] for _ in range(N)]
A, B=AB[0]
for j in range(1, H+1):
  dp[0][j]=((j-1)//A+1)*B
for i in range(1, N):
  A, B=AB[i]
  for j in range(H+1):
    if j>=A:
      dp[i][j]=min(dp[i-1][j], dp[i-1][j-A]+B, dp[i][j-A]+B)
    else:
      dp[i][j]=min(dp[i-1][j], B)
print(dp[N-1][H])

Measured memory_bytes: 125560
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};
use std::convert::TryInto;
const MOD: u64 = 1e9 as u64 + 7;
const MAX: usize = 11e5 as usize;

fn com_init() -> (Vec<u64>, Vec<u64>) {
    let mut fac = vec![0u64; MAX];
    let mut finv = vec![0u64; MAX];
    let mut inv = vec![0u64; MAX];
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for i in 2..MAX {
        fac[i] = fac[i - 1] * i as u64 % MOD;
        inv[i] = MOD - inv[MOD as usize % i] * (MOD / i as u64) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
    return (fac, finv);
}

fn com(n: u64, k: u64, fac: &Vec<u64>, finv: &Vec<u64>) -> u64 {
    if n < k {
        return 0;
    }
    // if n < 0 || k < 0 {
    //     return 0;
    // }
    return fac[n as usize] * (finv[k as usize] * finv[(n - k) as usize] % MOD) % MOD;
}

#[fastout]
fn main() {
    input! {
        n: u64,
        k: u64,
        mut a: [i64; n]
    }

    let (fac, finv) = com_init();

    a.sort_by(|a, b| b.cmp(a));
    let mut ans = 0i64;
    let mut cnt = 0;
    for i in 0..n {
        cnt += 1;
        if i == n - 1 || a.get(i as usize).unwrap() != a.get(i as usize + 1).unwrap() {
            if k > n - 1 - i + cnt {
                cnt = 0;
                continue;
            }
            if k > n - 1 - i {
                ans += com(n - 1 - i + cnt, k, &fac, &finv) as i64 * a[i as usize];
            } else {
                ans += (com(n - 1 - i + cnt, k, &fac, &finv) - com(n - 1 - i, k, &fac, &finv))
                    as i64
                    * a[i as usize];
            }
            cnt = 0;
            if ans > 0 {
                let tmp: u64 = (ans as u64).try_into().unwrap();
                ans = (tmp % MOD) as i64;
            } else {
                while ans < 0 {
                    ans += MOD as i64;
                }
            }
        }
    }
    a.sort();
    cnt = 0;
    for i in 0..n {
        cnt += 1;
        if i == n - 1 || a.get(i as usize).unwrap() != a.get(i as usize + 1).unwrap() {
            if k > n - 1 - i + cnt {
                cnt = 0;
                continue;
            }
            if k > n - 1 - i {
                ans -= com(n - 1 - i + cnt, k, &fac, &finv) as i64 * a[i as usize];
            } else {
                ans -= (com(n - 1 - i + cnt, k, &fac, &finv) - com(n - 1 - i, k, &fac, &finv))
                    as i64
                    * a[i as usize];
            }
            cnt = 0;
            if ans > 0 {
                let tmp: u64 = (ans as u64).try_into().unwrap();
                ans = (tmp % MOD) as i64;
            } else {
                while ans < 0 {
                    ans += MOD as i64;
                }
            }
        }
    }
    let ans: u64 = ans.abs() as u64 % MOD;
    println!("{}", ans);
}


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

#define ll long long int

int main()
{
    int n;
    cin>>n;
    int x = n%1000;
    if(x!=0)
    {
        cout<<1000-x;
    }
    else
    cout<<0;
    return 0;
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long  n, k;
	pair<int, int> p[200000];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);
	long long kk = k;
	for (int i = 0; i < n; i++) {
		kk -= p[i].second;
		if (kk <= 0) {
			cout << p[i].first << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int n,m,i,j;
    scanf("%d%d",&n,&m);
    int a[n][m];
    int b[m];
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            scanf("%d",&a[i][j]);
        }
    }



    for(j=0; j<m; j++)
    {
        scanf("%d",&b[j]);
    }

    int sum=0;
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            sum= sum+(a[i][j]*b[j]);
        }

        printf("%d\n",sum);
        sum=0;
    }

    return 0;
}



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

int a[2000005],c[10005],b[2000005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		++c[a[i]];
	}
		
	for(int i=0;i<=10000;++i)
		c[i]=c[i-1]+c[i];
		
	for(int i=1;i<=n;++i){
		b[c[a[i]]]=a[i];
		c[a[i]]--;
	}
	
	for(int i=1;i<=n;++i){
		if(i>1)printf(" ");
		printf("%d",b[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 18864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    BufferedReader rd;

    Main() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int n = pint();
        long[] cnt = new long[200];
        for(int i=0;i<n;i++) {
            String s = rd.readLine();
            cnt[s.charAt(0)]++;
        }
        char[] d = "MARCH".toCharArray();
        long res = 0;
        for(int i=0;i<32;i++) {
            if(Integer.bitCount(i) == 3) {
                int u = 1;
                char[] chosen = new char[3];
                int ic = 0;
                for(int k=0;k<5;k++) {
                    if((i&u)>=1) {
                        chosen[ic] = d[k];
                        ic++;
                    }
                    u <<= 1;
                }
                res += cnt[chosen[0]] * cnt[chosen[1]] * cnt[chosen[2]];
            }
        }
        out(res);
    }

    private int pint() throws IOException {
        return pint(rd.readLine());
    }

    private int pint(String s) {
        return Integer.parseInt(s);
    }

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

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


Measured memory_bytes: 29140
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
	int n,k;
	int sum=1;
	int i=0;
	cin>>n>>k;
	
	while (i<n){

		if (sum<k) {

			sum=sum*2;

		}else
		{

			sum+=k;


		}
		i++;
	}
	cout<<sum<<endl;


}



Measured memory_bytes: 256
//
// Created on 2020/02/09.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>
#include <functional>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;


int main() {

    string s;
    int k;
    cin>>s;
    cin>>k;

     vector<vector<vector<int >>>dp(105,vector<vector<int >>(4,vector<int >(2,0)));

    dp[0][0][0] = 1;

    for (int i = 0; i <= s.size(); ++i) {
        for (int j = 0; j <= k; ++j) {
            for (int l = 0; l <= 1; ++l) {
                for (int m = 0; m < 10; ++m) {
                    int ns = s[i] - '0';
                    int nl = l;
                    int nj = j;
                    if (m!=0) nj ++;
                    if (nj > k) continue;
                    if (m > ns && nl == 0) continue;
                    if (m < ns) nl = 1;
                    dp[i+1][nj][nl] += dp[i][j][l];
                }

            }
        }
    }
    int ans = 0;
    ans = dp[s.size()][k][0]+dp[s.size()][k][1];
    cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   string n;
 
   cin >> n;
   for(int i=0;i<n.size();i++){
     
     if(i!=n.size()-1){
     cout << "x";
     }else{
       cout << "x" << endl;
     }
     
   }
   

   
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==b) cout<<"0"<<endl;
    else if((a+b)%2==0) cout<<(a+b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = []
for _ in range(N):
    A.append(input().strip())
B = []
for _ in range(M):
    B.append(input().strip())
flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        ind = 0
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    ind = 1
                    break
            if ind==1:break
        if ind==0:
            flag = 1
    if flag==1:break
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63580
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }
const double PI = 3.14159265359;

double get_h(double x, double t, double theta_d) {
    double theta_r = PI*theta_d / 180;
    double h = t * tan(theta_r);
    return h;
}

double get_y(double x, double a, double b, double theta_d) {
    double h = get_h(x, a, theta_d);
    double t = x / (a*a) - h / 2.0;
    if (t >= 0)
        return h + t;
    return -1;
}

double get_y2(double x, double a, double b, double theta_d) {
    double theta_r = PI*theta_d / 180;
    double t = sqrt(2 * x / (a * tan(theta_r)));
    return t * tan(theta_r);
}

bool in_cond(double x, double a, double b, double theta_d) {
    double y = get_y(x, a, b, theta_d);
    if (y < 0) {
        y = get_y2(x, a, b, theta_d);
    }
    if (y <= b) return true;
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double a, b, x;
    cin >> a >> b >> x;
    //double L = 0.0, R = 89.9999999;
    //rep(i, 100000) {
    //    double M = (L + R) / 2;
    //    if (in_cond(x, a, b, M) == true) {
    //        L = M;
    //    }
    //    else {
    //        R = M;
    //    }

    //}
    //printf("%20.15f\n", L);

    double b1 = atan(2 / a * (b - x / (a*a)) ) * 180/PI;
    double b2 = atan((b * b * a) /(2 * x) ) * 180 / PI;
    if (x / (a*a) - (a * tan(b1 * PI/180) / 2) >= 0) {
        printf("%20.15f\n", b1);
    }
    else {
        printf("%20.15f\n", b2);
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()

	max := -1000005
	min := 1000005
	sum := 0
	for i := 0; i < n; i++ {
		a := nextInt()
		if max < a {
			max = a
		}
		if min > a {
			min = a
		}
		sum += a
	}
	fmt.Println(min, max, sum)
}



Measured memory_bytes: 1172
#include<stdio.h>
#include<string.h>

int main(void){
  char a[100000];
  scanf("%s", a);
  int i;
  int len = strlen(a);
  char b[len];
  char c[len];
  //for(i=0; i<len; i++){
    //printf("%c", a[i]);
  //}
  if(len == 1){
    printf("0");
    return 0;
  }
  for(i=0; i<len; i++){
    if(i%2 == 0){
      b[i] = '1';
      c[i] = '0';
    }else{
      b[i] = '0';
      c[i] = '1';
    }
  }
  int bcount = 0;
  int ccount = 0;
  for(i=0; i<len; i++){
    if(a[i]!=b[i]){
      bcount++;
    }
    if(a[i]!=c[i]){
      ccount++;
    }
  }
  if(bcount>ccount){
    printf("%d", ccount);
  }else{
    printf("%d", bcount);
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll c[2500001];
ll b[501][501];
struct A {
	ll ko, level;
};
A a[2][250001];
ll u[501][501];
struct P {
	ll x, y, level;
};
ll d[2];
bool operator<(P a, P b) { return a.level < b.level; }
bool operator>(P a, P b) { return a.level > b.level; }
const ll inf = 800000000000000000;
int main() {
	ll r;
	int lp[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
	while (cin >> r&&r != 0) {
		for (int z = 0; z < 2; z++) {
			ll h, w, x, y;
			cin >> w >> h >> y >> x;
			x--;
			y--;
			queue<P>p;
			for (ll i = 0; i < h; i++) {
				for (ll j = 0; j < w; j++) {
					cin >> u[i][j];
					b[i][j] = inf;
				}
			}
			p.push(P{ x,y,1 });
			b[x][y] = 1;
			while (!p.empty()) {
				P t = p.front(); p.pop();
				ll x = t.x, y = t.y;
				if (t.level == b[x][y]) {
					for (int i = 0; i < 4; i++) {
						ll x2 = x + lp[i][0], y2 = y + lp[i][1];
						if (b[x2][y2] > t.level) {
							if (u[x2][y2] <= t.level) {
								b[x2][y2] = t.level;
								p.push(P{ x2,y2,t.level });
							}
							else {
								if (u[x2][y2] < b[x2][y2]) {
									b[x2][y2] = u[x2][y2];
									p.push(P{ x2,y2,u[x2][y2] });
								}
							}
						}
					}
				}
			}
			ll o = 0;
			for (ll i = 0; i < h; i++) {
				for (ll j = 0; j < w; j++) {
					c[o] = b[i][j];
					o++;
				}
			}
			sort(c, c + o);
			ll sum = 0, g = 1;
			a[z][0] = A{ 0,0 };
			for (ll i = 0; i < (h*w);) {
				ll k = c[i], sum2 = 0;
				while (i < (h*w) && c[i] == k) {
					sum2++;
					i++;
				}
				a[z][g] = A{ sum2 + sum,k };
				g++;
				sum += sum2;
			}
			d[z] = g;
		}
		ll sum = inf;
		for (ll i = 0; i < d[0]; i++) {
			ll s = 0, e = d[1] - 1, t, m = r - a[0][i].ko;
			while (e - s > 1) {
				t = (e + s) / 2;
				if (a[1][t].ko <= m)
					s = t;
				if (a[1][t].ko >= m)
					e = t;
			}
			if (a[0][i].ko + a[1][s].ko >= r)
				sum = min(sum, a[0][i].level + a[1][s].level);
			if (a[0][i].ko + a[1][e].ko >= r)
				sum = min(sum, a[0][i].level + a[1][e].level);
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 12424
#include <iostream>
#include <cstdio>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
#include <queue>

#define rep(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
#define repn(i,a,b) for(int i=(a),_b=(b);i<=_b;i++)
#define pern(i,b,a) for(int i=(b),_a=(a);i>=_a;i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

template <typename T> inline void read(T &x){
	x = 0; char c; int positive = 1;
	while (!isdigit(c = getchar())) if (c == '-') positive = 0;
	do x = x * 10 + c - '0'; while (isdigit(c = getchar()));
	if (!positive) x = -x;
}

template <typename T> inline void write(T x){
	if (x > 9) write(x / 10);
	putchar(x % 10 + 48);
}

struct node{
	int down[26];
	int sum;
} Node[400010];

const int maxn = 100010;

string s[maxn];
int n, q;
int sum[maxn][26][26];
int pre[maxn];

void input(){
	scanf("%d\n",&n);
	repn(i,1,n) getline(cin, s[i]);
}

void init(){
	int totnode = 0;
	repn(x,1,n){
		int cur = 0;
		rep(j,0,sz(s[x])){
			int c = s[x][j] - 'a';
			if (Node[cur].down[c] == 0)
				Node[cur].down[c] = ++totnode;
			cur = Node[cur].down[c];
		}
		Node[cur].sum++;
	}
	
	repn(x,1,n){
		int cur = 0;
		rep(j,0,sz(s[x])){
			int c = s[x][j] - 'a';
			cur = Node[cur].down[c];
			pre[x] += Node[cur].sum;
		}
	}
	
	repn(x,1,n){
		int cur = 0;
		rep(j,0,sz(s[x])){
			int c = s[x][j] - 'a';
			if (j) Node[cur].sum++;
			cur = Node[cur].down[c];
		}
	}
	
	repn(x,1,n){
		int cur = 0;
		rep(j,0,sz(s[x])){
			int c = s[x][j] - 'a';
			rep(k,0,26) if (k != c)
				sum[x][k][c] += Node[Node[cur].down[k]].sum;
			cur = Node[cur].down[c];
		}
	}
}

void solve(){
	read(q);
	int d[26];
	repn(Q,1,q){
		int id; scanf("%d ",&id);
		string tmp; getline(cin, tmp);
		rep(i,0,26) d[i] = tmp[i] - 'a';
		int ans = 0;
		rep(i,0,26) rep(j,i+1,26) 
			ans += sum[id][d[i]][d[j]];
		write(ans + pre[id]);
		putchar('\n');
	}
}

void output(){
}

int main(){
	clock_t timestart, timeend;
	timestart = clock();
//	freopen("input.inp","r",stdin);
//	freopen("output.out","w",stdout);
	input();
	init();
	solve();
	output();
	timeend = clock();
	//system("pause");
	//printf("\nRun time : %lf",(timeend-timestart)*1.0/CLK_TCK);
	return 0;
}

Measured memory_bytes: 283264
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  set<int> number;
  int N;
  cin >> N;
  rep(i,N){
    int A;
    cin >> A;
    if(*number.lower_bound(A)==A) number.erase(A);
    else number.insert(A);
  }
  cout << number.size() << endl;
}

Measured memory_bytes: 4992
def main():
    N = int(input())
    S = input()
    ans = 0
    for v in range(1000):
        cur = 0
        v_s = str(v)
        if len(v_s) == 1:
            v_s = "00" + v_s
        elif len(v_s) == 2:
            v_s = "0" + v_s
        for s in S:
            if v_s[cur] == s:
                cur += 1
            if 2 < cur:
                ans += 1
                break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41900
n,a,b,c,d = map(int,input().split())
s = input()

# bをさきに
if c > d:
        a,b = b,a
        c,d = d,c

# c < d
if a < b:
        # bだけ考える
        # aはうごかさない
        t = s[b:d]
        if t.count('##'):
                print('No')
                exit()
        t = s[a:c]
        if t.count('##'):
                print('No')
                exit()
        print('Yes')
        exit()
else:
        t = s[b:d]
        if t.count('##'):
                print('No')
                exit()
        t = s[a-2:c+1]
        if t.count('...') == 0:
                print('No')
                exit()
        print('Yes')
        exit()


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

// → ↑ ← ↓
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> graph(H);
    for(auto &e : graph) cin >> e;

    auto bfs = [&](int sy, int sx) {
        queue<pair<int, int>> que;
        vector<vector<int>> dist(H, vector<int>(W, -1));
        auto push = [&](int y, int x, int cost) {
            if(dist[y][x] != -1) return;
            que.emplace(y, x);
            dist[y][x] = cost;
        };
        push(sy, sx, 0);
        while(!que.empty()) {
            auto[y, x] = que.front(); que.pop();
            for(int i = 0; i < 4; ++i) {
                int ny = y + dy[i], nx = x + dx[i];
                if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
                if(graph[ny][nx] == '.') push(ny, nx, dist[y][x] + 1);
            }
        }
        int res = -1;
        rep(i, H) rep(j, W) res = max(res, dist[i][j]);
        return res;
    };

    int ans = 0;
    rep(i, H) rep(j, W) {
        if(graph[i][j] == '.') ans = max(ans, bfs(i, j));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    deque<long> a;
    for(int i = 0; i < n; i++){
        long t;
        cin>>t;
        if(n%2==0){
            if(i%2==1)
                a.push_front(t);
            else
                a.push_back(t);
        }
        else{
            if(i%2==0)
                a.push_front(t);
            else
                a.push_back(t);
        }
    }
    for(auto x:a)
        cout<<x<<" ";
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define RSort(a) reverse(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

signed main(){
    int n;
    cin >> n;
    double ans = 0;
    REP(i,n){
        double x;
        string u;
        cin >> x >> u;
        if(u=="JPY"){
            ans += x;
        }
        else{
            ans += x*380000;
        }
    }
    cout << setprecision(10) << ans << endl; 

    return 0;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

ll v,e,r;
vector<vector<pair<int,ll>>> vec(100000+1);

vll dijkstra(int s){
    vll d(v+1,1e10);
    d[s]=0;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
    q.push({0,s});
    while(q.size()!=0){
        auto q1=q.top();
        q.pop();
        ll c=q1.fi;
        int num=q1.se;
        for (auto p:vec[num]){
            int n1=p.fi;
            ll c1=p.se;
            if (c1+c<d[n1]){
                q.push({c1+c,n1});
                d[n1]=c1+c;
            }
        }

    } 
    return d;

}

int main() {
    cin>>v>>e>>r;
    rep(i,e){
        int s,t;
        ll d;
        cin>>s>>t>>d;
        vec[s].push_back({t,d});
        //vec[t].push_back({s,d});
    }
    auto d=dijkstra(r);
    rep(i,v){
        if (d[i]!=1e10)cout<<d[i]<<endl;
        else cout<<"INF"<<endl;
    }
    


    return 0;
}


Measured memory_bytes: 19412
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,0,n) cin >> a[i];
  rep(i,0,m) cin >> b[i];
  bool ok = false;
  repr(i,y,x) {
    if(i > *max_element(ALL(a)) && i <= *min_element(ALL(b))) ok = true;
  }
  
  if(ok) cout << "No War" << endl;
  else cout << "War" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int result = 0;
        String steps = sc.nextLine();

        for (int i = 0; i < 4; i++) {
            char ch = steps.charAt(i);
            if (ch == '+')
                result++;
            else if (ch == '-')
                result--;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#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 all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int>v;

	rep(n, 1, 3501)rep(h, 1, 3501) {
		int a = -N*h*n;
		int b = N*(n + h) - 4 * h*n;
		if (b == 0)continue;
		if (a%b == 0 && a / b > 0) {
			v.push_back(h);
			v.push_back(n);
			v.push_back(a / b);
			goto here;
		}
	}
	dump(v);
	here:
	rep(i, 0, v.size()) {
		cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
	}
	return 0;
}

Measured memory_bytes: 256
import java.lang.Math.*
import java.util.*

fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val semi = readLine()!!.trim().split(' ').map(String::toInt)
    val nodes = Array(n){ Stack<Edge>() }
    repeat(n - 1){
        val (u, v, p) = readLine()!!.trim().split(' ').map(String::toInt)
        nodes[u].add(Edge(v, p))
        nodes[v].add(Edge(u, p))
    }
    fun dfs(current: Int, prev: Int = -1, minEdge: Int = Int.MAX_VALUE): Int {
        return if (current != 0 && semi[current - 1] > 0) minEdge
        else min(minEdge, nodes[current].filterNot{ it.to == prev }.sumBy{ dfs(it.to, current, min(minEdge, it.cost)) })
    }
    println(dfs(0))
}

data class Edge(val to: Int, val cost: Int)


Measured memory_bytes: 35380
N,M,Q=map(int, input().split())
X=[list(map(int, input().split())) for i in range(Q)]
import itertools
a=[]
for i in range(1,M+1):
  a.append(i)
A=list(itertools.combinations_with_replacement(a,N))
ans=0
for i in range(len(A)):
  K=A[i]
  p=0
  for a,b,c,d in X:
    if K[b-1]-K[a-1]==c:
      p+=d
  ans=max(p,ans)
print(ans)

Measured memory_bytes: 21536
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\0';
  char *p,*c1,*c2;
  c1 = com+1;
  c2 = com+2;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (*c1=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      puts(buf+i+1);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (*c2!='d');
  return 0;
}


Measured memory_bytes: 5524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
int n,m,per[N],a[N];
ll sum,cnt,f[N][35];
ll solve() {
	for (int i=0; i<=n*m; i++)
		for (int j=0; j<(1<<(n-1)); j++)
			f[i][j]=0;
	f[n*a[n-1]][0]=1;
	for (int i=0; i<n*m; i++)
		for (int j=i; j<=n*m; j++)
			for (int k=0; k<(1<<(n-1)); k++)
				if (i%n && !(k>>per[i%n-1]&1))
					f[min(n*m,max(j,i+n*a[per[i%n-1]]))][k|(1<<per[i%n-1])]+=f[j][k];
	return f[n*m][(1<<(n-1))-1];
}
int main() {
	scanf("%d%d",&n,&m);
	for (int i=0; i<n; i++) scanf("%d",&a[i]);
	sort(a,a+n);
	for (int i=0; i<n-1; i++) per[i]=i;
	do {
		sum+=solve(); cnt++;
	} while (next_permutation(per,per+n-1));
	for (int i=0; i<n-1; i++) cnt*=m;
	printf("%.15lf\n",(double)sum/cnt);
	return 0;
} 
	

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535 
 
 
int32_t main() {
    fastio;
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) {
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    ll sum = 0;
    for(ll i=0;i<k;i++) {
        sum += a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
int main()
{
	int i,j,k,n,m;
	string s;
	cin>>s;
	if(s.size()==3)
	{
		reverse(s.begin(),s.end());
	}
	cout<<s;
}


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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll r, d, xi;
  cin >> r >> d >> xi;

  ll x = xi;
  for(ll i=0; i<10; i++) {
    x = r * x - d;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
text = input()
i = 0
ans = "keyence"
for ob_n in range(len(ans)):
    if text[i] != ans[ob_n]:
        if text.endswith(ans[ob_n:]):
            flag = 1
            break
        else:
            flag = 0
            break
    i+=1
    if i == len(text):
        flag = 1
        break
if flag == 1:
    print("YES")
else :
    print("NO")
        

Measured memory_bytes: 3060
# N = int(input())
# edge = []
# for _ in range(N - 1):
#     a, b = map(int, input().split())
#     edge.append((a - 1, b - 1))
#
# c = sorted(map(int, input().split()))
# M = sum(c[:-1])
# use = [0 for _ in range(N)]
#
# for e in edge:
#     a, b = e
#     if use[a] == 0:
#         use[a] = c.pop()
#     if use[b] == 0:
#         use[b] = c.pop()
#
# print(M)
# print(*use)



from collections import deque

N = int(input())

neighbors = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    neighbors[a].append(b)
    neighbors[b].append(a)
c = list(map(int, input().split()))
sorted_c = sorted(c)

closed = [0 for _ in range(N)]
use = [0 for _ in range(N)]
q = deque()
q.append(0)
use[0] = sorted_c.pop()
M = 0


while len(q) > 0:
    parent = q.pop()
    closed[parent] = use[parent]
    for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor)

print(M)
print(*use)


Measured memory_bytes: 6292
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define track  1;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

const int N=1e5+1738;
int n;
vector<int>dp(N,-1),a;
int sol(int ind)
{
	if(ind==n)
	{
		return 0;   // because we have to calculate minimum cost so 0 has no impact..
	}
	if(ind>n)
	{
		return INT_MAX;
	}

	if(dp[ind]!=-1)
	{
		return dp[ind];
	}

	int left = abs(a[ind+1]-a[ind])+sol(ind+1);

	int right = abs(a[ind+2]-a[ind])+sol(ind+2);

	return dp[ind]=min(left,right);
}


int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j,cnt=0;
	bool flag=0;

	cin>>n;
	a.resize(n+1);

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

	int ans = sol(1);
	cout<<ans<<endl;
}

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

int main()
{
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  a *= 100;
  b *= 100;

  int ans1 = 0;
  int ans2 = 0;
  for (int i=0; i<=30 && i*a<=f; i++) {
    for (int j=0; j<=30 && i*a+j*b<=f; j++) {
      if (i+j > 0) {
        int water = a*i + b*j;
        int maxsugar = min(water*e/100, f-water);
        int sugar = 0;

        for (int k=0; k<=100 && c*k<=maxsugar; k++) {
          for (int l=0; l<=100 && c*k+d*l<=maxsugar; l++) {
            sugar = max(sugar, c*k + d*l);
          }
        }
        if (ans1==0 || sugar*(ans1+ans2) > ans2*(water+sugar)) {
          ans1 = water;
          ans2 = sugar;
        }
      }
    }
  }
  printf("%d %d\n", ans1+ans2, ans2);

  return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

PL operator-(const PL& v1, const PL& v2) {
    return P(v1.first - v2.first, v1.second - v2.second);
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VPL xy(n);
    REP(i, n) cin >> xy[i].first >> xy[i].second;

    map<PL, int> pq_map;
    REP(i, n)REP(j, n)if(i != j) pq_map[xy[i] - xy[j]]++;

    int max_pq_cnt = 0;
    for(auto pq : pq_map) max_pq_cnt = max(max_pq_cnt, pq.second);

    cout << n - max_pq_cnt << ln;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main (){
	int n, m ;
	cin >> n >> m ;
	multiset<int> s ; 
	ll tot = 0 ;
	rep(i, n) {
		int a ;
		cin >> a ;
		tot += a ;
		s.insert(a) ;
	}
	rep(i, m){
		if(*s.rbegin() == 0) break ;
		else {
			int k = *s.rbegin() ;
			s.erase(s.find(k)) ;
			tot -= k - k/2 ;
			k /= 2 ;
			s.insert(k) ;
		}
	}
	if(tot <= 0){
		cout << 0 << endl ;
	}
	else {
		cout << tot << endl ;
	}
}

Measured memory_bytes: 8264
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[202020]={},b[202020]={};
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n)b[i]=a[i];
	sort(a,a+n);
	int p=a[n/2-1],q=a[n/2];
	//cout<<p<<q<<endl;
	FOR(i,0,n){
		if(q>b[i])cout<<q<<endl;
		else if(q<=b[i])cout<<p<<endl;
	}
	  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>exist(13);
    bool f=0;
    rep(i,n){
        ll d;cin>>d;
        exist[d]++;
        if(d==0||exist[d]==3||exist[12]==2)f=1;
    }
    if(f){
        cout<<0<<endl;
        return 0;
    }
    ll mi=0;
    rep(i,1<<13){
        vector<ll>a(0);
        a.pb(0);
        rep(j,13){
            if(exist[j]==2){
                a.pb(j);
                a.pb(24-j);
            }else if(exist[j]==1){
                if((1<<j)&i)a.pb(j);
                else a.pb(24-j);
            }
        }
        ll cnt=inf;
        rep(j,a.size()){
            REP(k,j+1,a.size()){
                ll D=max(a[j],a[k])-min(a[j],a[k]);
                D=min(D,24-D);
                cnt=min(cnt,D);
            }
        }
        mi=max(cnt,mi);
    }
    cout<<mi<<endl;
}

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

using namespace std;

int main() {
  string s;
  long long int k;
  cin >> s >> k;
  
  bool flag = false;
  
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[0] == s[i])
      count++;
  }
  if (count == s.size()) {
    cout << count * k / 2 << endl;
    return 0;
  }
  
  int sl = 0, sr = 0;
  if (s.front() == s.back()) {
    flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[0] == s[i])
        sl++;
      else
        break;
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[0] == s[i])
        sr++;
      else
        break;
    }
    s = s.substr(sl, s.size() - sl - sr);
  }
  
  long long int d = 1, total = 0;

  char c = s[0];
  for (int i = 1; i < s.size() + 1; i++) {
    if (i < s.size() && c == s[i]) {
      d++;
    }
    else {
      total += d/2;
      d = 1;
      c = s[i];
    }
  }
  total *= k;
  
  if (flag) {
    total += sl/2 + sr/2 + (sl+sr)/2*(k-1);
  }
  
  cout << total << endl;
  
  return 0;
}

Measured memory_bytes: 256