akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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 N;
    cin >> N;

    vector<ll> values(N, 0);
    REP(i, N) {
        cin >> values[i];
    }
    sort(values.begin(), values.end());

    ll diffMax = abs(values[N - 1] - values[0]);
    cout << diffMax << endl;
    return 0;
}

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

#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0(i, n) for (i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

//* utility function
inline bool compare(ll i, ll j)
{
    return i < j;
}
//*/

//* function prototypes
template< typename T>
T gcd(T a, T b);
template< typename T>
T modpow(T number, T power, T mod_value);
//*/

//int row, column;
//int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
//int dx[4] = {1,  0, -1, 0};
//int dy[4] = {0, -1,  0, 1};
//ll p2[63] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904};
#ifdef DEBUG
#endif // DEBUG

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll number_of_test_case = 1, test_case;
    //cin >> number_of_test_case;
    for (test_case = 1; test_case <= number_of_test_case; test_case++)
    {
        ll a, b;
        cin >> a >> b;

        cout << max(0ll, a-2*b) << endl;
    	//cout << "Test #" << test_case << ": ";
    	//cout << "Case " << test_case << ": ";
    }
    return 0;
}


template< typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
template< typename T>
T modpow(T number, T power, T mod_value)
{
    if (power == 0)
        return 1%mod_value;
    ll u = modpow(number,power/2,mod_value);
    u = (u*u)%mod_value;
    if (power%2 == 1)
        u = (u*number)%mod_value;
    return u;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
bool is_prime[1000000];

int main(){
	fill(is_prime, is_prime + 1000000, 1);
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= 2 * 123456; i++){
		if (is_prime[i]){
			for (int j = i * 2; j <= 2 * 123456; j += i){
				is_prime[j] = 0;
			}
		}
	}

	while (cin >> n&&n){
		int co = 0;
		FOR(i, n + 1, 2 * n + 1){
			if (is_prime[i])co++;
		}
		cout << co << endl;
	}
}

Measured memory_bytes: 2136
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

struct Vec2d
{
  double x;
  double y;
};

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

  vector<Vec2d> pos(N);
  vector<int> v(N);
  for (int i = 0; i < N; ++i)
  {
    cin >> pos[i].x >> pos[i].y;
    v[i] = i;
  }

  double sum_distance = 0.0;
  int count = 0;
  do{
    ++count;
    for (int i = 0; i < v.size() - 1; ++i)
    {
      double dis = pow(pos[v[i]].x - pos[v[i + 1]].x, 2) + pow(pos[v[i]].y - pos[v[i + 1]].y, 2);
      sum_distance += sqrt(dis);
    }
  } while (next_permutation(v.begin(), v.end()));

  cout << setprecision(10) << sum_distance / count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> operator * (const vector<int> & a, const vector<int> & b)
{
	vector<int> ret(n + 1);
	for(int i = 1; i <= n; ++i) ret[i] = a[b[i]];
	return ret;
}
vector<int> inv(const vector<int> & a)
{
	vector<int> ret(n + 1);
	for(int i = 1; i <= n; ++i) ret[a[i]] = i;
	return ret;
}
vector<int> Pow(const vector<int> & a, int k)
{
	vector<bool> vis(n + 1, 0);
	vector<int> ret(n + 1);
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
		{
			vector<int> cycle;
			int cur = i;
			while(!vis[cur])
			{
				vis[cur] = 1;
				cycle.push_back(cur);
				cur = a[cur];
			}
			for(int j = 0; j < cycle.size(); ++j)
				ret[cycle[j]] = cycle[(j + k) % cycle.size()];
		}
	return ret;
}
int main()
{
	scanf("%d%d", &n, &k);
	vector<int> a[6]; for(int i = 0; i < 6; ++i) a[i] = vector<int>(n + 1);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[0][i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[1][i]);
	for(int i = 2; i < 6; ++i) a[i] = a[i - 1] * inv(a[i - 2]);
	auto A = a[1] * inv(a[0]) * inv(a[1]) * a[0], P = Pow(A, (k - 1) / 6);
	auto ans = P * a[(k - 1) % 6] * inv(P);
	for(int i = 1; i <= n; ++i) printf("%d ", ans[i]);
	return 0;
}

Measured memory_bytes: 7864
use std::io::*; //Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: i32 = read();
    let mut a: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut ans: i32 = 0;
    for i in 0..n {
        ans ^= a[i as usize];
    }
    for i in 0..n {
        if i < n - 1 {
            print!("{} ", a[i as usize] ^ ans);
        } else {
            print!("{}\n", ans ^ a[i as usize]);
        }
    }
}


Measured memory_bytes: 3364
a, c = map(int, input().split())

table = [[0 for j in range(c+1)] for i in range(a+1)]

for col in range(a):
    Col = list(map(int, input().split()))
    for row in range(c):
        table[col][row] = Col[row]

for row in range(c):
    for col in range(a):
        table[a][row] += table[col][row]
        table[col][c] += table[col][row]
        table[a][c] += table[col][row]

for i in range(a+1):
    for j in range(c+1):
        if j == c:
            print(table[i][j], end = "")
        else:
            print(table[i][j], end = " ")

    print()



    



Measured memory_bytes: 6216
#include <stdio.h>

#define min(a,b)  ((a<b)?(a):(b))

int main(int argc, char const *argv[])
{
	long long n,k;
	scanf("%lld %lld",&n,&k);

	long long count = 0;
	if(k == 0 ){
		printf("%lld\n",n*n);
		return 0;
	}

 	for(int b = k+1;b<=n;b++){
 		count += n + 1  - k * (n/b );
 		if((n%b) == 0){
 			count--;
 		} else if(n%b+1 > k){
 			count -= k;
 		}else{
 			count -= (n%b)+1;
 		}
 	}

 	printf("%lld\n",count);


	return 0;
}

Measured memory_bytes: 128
program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,c,k
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,k
    a=(n-1)/(k-1)
    if(mod(n-1,k-1)/=0)then
        a=a+1
    end if
  	write(*,*)a
    stop
end program sample
  



Measured memory_bytes: 2828
n,k = map(int,input().split())
ans = [0]*n
for _ in range(k):
    n=int(input())
    t = list(map(int,input().split()))
    for i in t:
        ans[i-1] = 1
memo = 0

for i in ans:
    if i == 0:
        memo += 1
print(memo)

Measured memory_bytes: 67624
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int x;
    cin >> x;
    int ans = 8 - (x - 400) / 200;
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

typedef struct{
    std::vector<int> nextnode;
} node;

typedef struct {
    int pl;
    int link;
} ink;



signed main()
{
int n,m;
std::cin >> n >> m;
std::vector<node> nodelist(n);
for(int i = 0; i < m; i++){
    int a,b;
    std::cin >> a >> b;
    nodelist[a - 1].nextnode.pb(b - 1);
    nodelist[b - 1].nextnode.pb(a - 1);
}
int q;
std::cin >> q;

std::vector<std::vector<int>> mv;
rep(i,q){
    std::vector<int> temp;
    int o,tw,th;
    std::cin >> o >> tw >> th;
    o--;
    temp.pb(o);
    temp.pb(tw);
    temp.pb(th);
    mv.pb(temp);
}
int it = q - 1;
std::vector<std::vector<int>> check(n,std::vector<int>(10,0));

for(int i = it; i >= 0; i--){
    ink start;
    int color = mv[i][2];
    start.link =  mv[i][1];
    start.pl = mv[i][0];
    std::queue<ink> spl;
    spl.push(start);
    while(!spl.empty()){
        ink now = spl.front();
        spl.pop();
        if(check[now.pl][now.link] != 0){
            continue;
        }
        for(int d = now.link; d >= 0; d--){
            if(check[now.pl][d] == 0){
                check[now.pl][d] = color;
            }
        }
        if(now.link == 0){
            continue;
        }
        for(int j = 0; j < nodelist[now.pl].nextnode.size(); j++){
            ink next = {nodelist[now.pl].nextnode[j], now.link - 1};
            spl.push(next);
        }
    }   
}

for(int i = 0; i < n; i++){
    std::cout << check[i][0] << std::endl;
}

return 0;
}

Measured memory_bytes: 26476
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<ctime>
#include<deque>
#include<set>
#include<string.h>
#include<algorithm>
#include<map>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ls rt<<1
#define rs rt<<1|1
#define mmm(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e17;
const double pi = acos(-1.0);
const int maxn = 1e5+5;
int kase;
ll n,m,p,k,cnt;
ll a,b,c,d;
void run(){
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)))<<'\n';
}
int main(){
#ifdef haosao
freopen("main.h", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
//    cin>>kase;
//    while(kase--)
        run();
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
//#define INF 1<<31-1
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int INF=INT_MAX;

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
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string s1 = "aiueo";
  string s2 = "kstnhmyrw";
  string s;
  while(cin >> s) {
    REP(i, s.size()) {
      int a = s[i]-'0';
      if (a == 0) a = 10;
      int b = string("TLURD").find(s[i+1]);
      if (a == 10 && b == 2) {
        cout << "nn";
      } else {
        if (a!=1) cout << s2[a-2];
        cout << s1[b];
      }
      i++;
    }
    puts("");
  }
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	char a;
	int b, n;
	int S[13] = {0};
	int H[13] = {0};
	int C[13] = {0};
	int D[13] = {0};

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a == 'S') S[b - 1] = 1;
		if (a == 'H') H[b - 1] = 1;
		if (a == 'C') C[b - 1] = 1;
		if (a == 'D') D[b - 1] = 1;
	}

	for (int i = 0; i < 13; i++) {
		if (S[i] == 0)  cout << "S " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++) {
		if (H[i] == 0)  cout << "H " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++) {
		if (C[i] == 0)  cout << "C " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++) {
		if (D[i] == 0)  cout << "D " << i + 1 << endl;
	}
	

	return (0);
}

Measured memory_bytes: 1160
### constant

MAX_STEP = 10
DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### subroutines

def count_rec(k, x, y)
  return k if k > MAX_STEP

  min_count = MAX_STEP + 1

  DXYS.each do |dx, dy|
    x0 = x + dx
    y0 = y + dy
    next if x0 >= 0 && x0 < $w && y0 >= 0 && y0 < $h && $flds[y0][x0] == 1
    while x0 >= 0 && x0 < $w && y0 >= 0 && y0 < $h
      return k if x0 == $gx && y0 == $gy
      if $flds[y0][x0] == 1
        $flds[y0][x0] = 0
        c = count_rec(k + 1, x0 - dx, y0 - dy)
        min_count = c if min_count > c
        $flds[y0][x0] = 1
        break
      end
      x0 += dx
      y0 += dy
    end
  end
  min_count
end

### main

loop do
  $w, $h = gets.split.map(&:to_i)
  break if ($w | $h) == 0

  $flds = $h.times.map{$w.times.map{0}}
  sx = sy = $gx = $gy = 0

  for y in (0...$h)
    line = gets.split.map(&:to_i)
    for x in (0...$w)
      case line[x]
      when 1
        $flds[y][x] = 1
      when 2
        sx = x
        sy = y
      when 3
        $gx = x
        $gy = y
      end
    end
  end
  #p $flds
  #p [sx, sy, $gx, $gy]

  c = count_rec(1, sx, sy)
  puts (c > MAX_STEP ? -1 : c)
end

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

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
    int n,v,m1=0,m2=0,ix1,ix2,sm1=0,sm2=0;
    cin >> n;
    map<int,int> p1,p2;

    rep(i,n) {
        cin >> v;
        if(!(i%2)) {
            if(!p1.count(v))
                p1[v] = 1;
            else
                p1.at(v)++;
        } else {
            if(!p2.count(v))
                p2[v] = 1;
            else
                p2.at(v)++;
        }
    }

    for(auto p : p1) {
        if(p.second > m1) {
            m1 = p.second;
            ix1 = p.first;
        }
    }
    p1.erase(ix1);
    for(auto p : p2) {
        if(p.second > m2) {
            m2 = p.second;
            ix2 = p.first;
        }
    }
    p2.erase(ix2);

    if(ix1 == ix2) {
        for(auto p : p1)
            sm1 = max(sm1, p.second);
        for(auto p : p2)
            sm2 = max(sm2, p.second);
        cout << min(n-m1-sm2, n-m2-sm1);
    } else
        cout << n-m1-m2;
    cout << endl;
}

Measured memory_bytes: 4992
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    H = il()
    AB = [il() for _ in range(M)]

    ret = [True] * N
    for a, b in AB:
        if H[a - 1] <= H[b - 1]:
            ret[a - 1] = False
        if H[b - 1] <= H[a - 1]:
            ret[b - 1] = False

    print(sum(1 for r in ret if r))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32672
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long A, long B, long C, long D, long E) {
    auto limit = [A, B, C, D, E].reduce!min;
    return 4 + (N + limit - 1) / limit;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    long C;
    C = input.front.to!long;
    input.popFront;

    long D;
    D = input.front.to!long;
    input.popFront;

    long E;
    E = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, A, B, C, D, E);
    else
        solve(N, A, B, C, D, E).writeln;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
LA=[0]*N
LB=[0]*N
LA[0]=A[0]
LB[-1]=B[-1]

for i in range(N-1):
    LA[i+1]=LA[i]+A[i+1]
    LB[-i-2]=LB[-i-1]+B[-i-2]
c=0
for i in range(N):
    c=max(c,LA[i]+LB[i])
print(c)

Measured memory_bytes: 38384
#include <stdio.h>

int main(){
	
	int n, total = 0;
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		total += b-a+1;
	}
	
	printf("%d\n", total);
	
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
	FastReader sc = new FastReader();
	int n = sc.nextInt();
	Map<Long, Long> map = new TreeMap<>(Collections.reverseOrder());
	
	for (int i = 0; i < n; i++) {
		long l = sc.nextLong();
		map.put(l, map.getOrDefault(l, 0L) + 1L);
	}

	long firstEdge = 0;
	long secondEdge = 0;
	int k = 2;
	for (long key: map.keySet()) {
		long cnt = map.get(key);
		
		// 如果有邊已經被取到，即使遇到正方形也不能取
		if (cnt >= 4 && k == 2) {
			System.out.println(key * key);
			System.exit(0);
		}
		
		if (cnt >= 2) {
			if (k == 2) {
				firstEdge = key;
				k--;
			} else if (k == 1) {
				secondEdge = key;
				k--;
			}
		}
		
		if (k == 0) {
			System.out.println(firstEdge * secondEdge);
			System.exit(0);
		}
	}
	System.out.println(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 45700
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const ll inf = 1e18;
const ll mod = 1e9+7;
int main(){
    ld x,y;
    cin>>x>>y;
    cout<<ceil(x/y)<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
     
    static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = "";
        while(stdIn.hasNext()) {
        s += stdIn.nextLine();
        }
        s = s.toLowerCase();
        int[] ans = new int[k.length];
        for(int i = 0; i < s.length(); i++) {
            for(int j = 0; j < k.length; j++) {
                if(s.charAt(i) == k[j]) {
                    ans[j]++;
                }
            }
        }
         
        for(int i = 0; i < 26; i++) {
            System.out.println(k[i]+" : " + ans[i]);
        }
    }
}

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

int main() {
    string S;
    cin >> S;

    if (S == "Sunny") {
        cout << "Cloudy"s << "\n"s;
    } else if (S == "Cloudy") {
        cout << "Rainy" << "\n"s;
    } else if (S == "Rainy") {
        cout << "Sunny" << "\n"s;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    string s;
    cin >> s;
    if (s == "Sunny")cout << "Cloudy\n";
    else if (s == "Cloudy")cout << "Rainy\n";
    else cout << "Sunny\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl    '\n'
using namespace std;

typedef long long ll;

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

    int ans = 0;

    for (int i = 0; i < 10; i++) {
        int a; cin >> a;
        ans += a;
    }

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3204
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
 
typedef long long ll;
using namespace std;
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int Tk_cnt=0,Ak_cnt=0;
    while(A > 0){
        Tk_cnt++;
        A -= D;
    }
    while(C > 0){
        Ak_cnt++;
        C -= B;
    }
    if(Tk_cnt >= Ak_cnt){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

int main()
{
  while (1)
  {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0)
    {
      break;
    }
    if (x < y)
    {
      cout << x << " " << y << endl;
    }
    else
    {
      cout << y << " " << x << endl;
    }
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
    {
		std::ios::sync_with_stdio(false);
		// cin.ignore(); must be there when using getline(cin, s)
		long long int n,lt[6],m,temp,ans;
		m=inf;
		cin>>n;
		for (int i = 1; i < 6; ++i)
		{
			cin>>temp;
			m=min(m,temp);
		}
		ans = (n/m)+(n%m>0);
		cout<<5+(ans-1);
	}

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

using namespace std;
typedef long long ll;

const ll MX = 1e18;

int main(){
    int N;
    cin >> N;
    int long long ans, A[100010];
    ans = 1;
    bool stop = false;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if(A[i] == 0){
            ans = 0;
            stop = true;
            break;
        }
    }

    if(!stop)
    {
        for (int i = 0; i < N; i++)
        {
            if(A == 0){
                ans = 0;
                break;
            }

            if(ans > MX/A[i]){
                ans = -1;
                break;
            }else{
                ans *= A[i];
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4452
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;

    int count = 700;
    REP(i, 3){
        if(S[i] == 'o'){
            count += 100;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import math

n, d = map(int, input().split())

x = [0] * n
y = [0] * n

count = 0

for i in range(n):
  x[i], y[i] = map(int, input().split())
  
for i in range(n):
  l = math.sqrt(x[i]**2 + y[i]**2)
  #print(l)
  if l <= d:
    count = count + 1
    
print(count)
    

Measured memory_bytes: 24700
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	vl a(n+1),b(n);
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n){
		ll tab=min(b[i],a[i]);
		ans+=tab;
		b[i]-=tab;
		tab=min(a[i+1],b[i]);
		ans+=tab;
		a[i+1]-=tab;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc161/tasks/abc161_f
def make_divisors(n: int, sort=False):
    # 約数列挙
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    if sort:
        divisors.sort()
    return divisors


N = int(input())

# 重要な考察
# 1. N%K!=0のものは、ずっと引き続けられる。その結果1になりたいんだからN%K==1の条件を満たすKは答えの候補である(しかも必ず条件を満たす)。
# 2. N%K==0のものも操作ができるので答えの候補である。(ただし条件を満たさない可能性はある)
# 1の候補は(N-1)の約数、2の候補はNの約数なので、O(√N)で探索が可能

# 具体的にはすべての候補のkに対して、割り切れなくなるまでN//=k。N%k==1ならば、答えに加算する。


# 確実にカウントできる1から
ans = len(make_divisors(N - 1)) - 1  # 1は答えに入らない

# 2の方をカウント
candi = make_divisors(N)[1:]  # 1は考えないでおく
for k in candi:
    n = N
    while n % k == 0:
        n //= k
    if n % k == 1:
        ans += 1
print(ans)


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

int dp[2001];

void solve_test()
{
    int s;
    cin >> s;
    int sum = 0;
    dp[0] = 1;
    for(int i=0; i<=s; i++)
    {
        for(int j=3; j<=s; j++)
        {
            if(i+j <= s)
            {
                dp[i+j] = (dp[i+j] + dp[i]) % MOD;
            }
        }
    }
    cout << dp[s];

}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 3572
def main():
    l, r = map(int, input().split())
    ans = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            ans = min(ans, i * j % 2019)
            if ans == 0:
                break
        if ans == 0:
            break
    print(ans)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	ff 				first
#define 	ss				second
#define 	pb				push_back
#define 	mp				make_pair
#define 	bb 				begin()
#define     rb              rbegin()
#define 	ee 				end()
#define     ub              upper_bound
#define     lb              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define     sorta(v)         sort(all(a))
#define     sortd(v)        sort(all(a), greater<ll >())
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(11);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 11)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    for(auto &i : a)cin >> i;

    ll ans = 0;
    for(ll i = 1 ; i < n ; i++) {
        if(a[i] < a[i-1]) {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << nl;
}

 
int main(){
    // boost;
    // cal(1);

    // // For getting input from input.txt file 
    // freopen("timber_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);


    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll ans,p[105],n;
int main(void){
    scanf("%lld",&n);
    for(ll i=2;i<=n;i++){
        ll a=i;
        for(ll j=2;j*j<=a;j++){
            if(a%j==0){
                while(a%j==0){
                    p[j]++;
                    a/=j;
                }
            }
        }
        if(a!=1)p[a]++;
    }
    for(ll i=2;i<=100;i++){
        if(p[i]>=74)ans++;
        for(ll j=i+1;j<=100;j++){
            if(p[i]>=2&&p[j]>=24)ans++;
            if(p[i]>=4&&p[j]>=14)ans++;
            if(p[j]>=2&&p[i]>=24)ans++;
            if(p[j]>=4&&p[i]>=14)ans++;
            for(ll k=j+1;k<=100;k++){
                if(p[i]>=2&&p[j]>=4&&p[k]>=4)ans++;
                if(p[j]>=2&&p[i]>=4&&p[k]>=4)ans++;
                if(p[k]>=2&&p[j]>=4&&p[i]>=4)ans++;
            }
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n= int(input())

sum = 0

i = 0
while True:
    min = 10 ** i
    max = 10 ** (i+1) - 1

    if n < min:
        break
    elif n < max:
        max = n

    sum += max - min + 1
    i += 2

print(sum)



Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll f(ll b, ll n){
  if(n < b) return n;
  else {
    return f(b,n/b) + n % b;
  }
}

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

  if(s == n){
    cout << n + 1 << endl;
    return 0;
  }

  // 2<=b<=√n
  for(ll b=2;b*b<=n;b++){
    if(f(b,n) == s){
      cout << b << endl;
      return 0;
    }
  }

  ll ans = 10000000000000LL;
  //√n<b
  for(ll p=1;p*p<n;p++){
    if((n-s+p)%p!=0) continue;
    ll b = (n - s + p) / p;
    if(b < 2) continue;
    if(f(b,n) == s){
      ans = min(ans,b);
    }
  }

  if(ans != 10000000000000LL) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
using System;


public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var r = new int[n];
        var maxv = 0;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var v = int.Parse(line[1]);
            r[a - 1] = v;
            maxv = Math.Max(maxv, v);
        }
        for (int i = 0; i < n; i++)
            if (r[i] == maxv) { Console.WriteLine("{0} {1}", i + 1, maxv);  break; }
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

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

    int N;
    cin >> N;
    vector<vector<int>> g(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> c(N);
    REP(i, N) {
        cin >> c[i];
    }
    sort(all(c), greater<int>());

    int count = 0;
    vector<bool> used(N, false);
    vector<int> assign(N);
    queue<int> q;

    q.push(0);
    used[0] = true;
    assign[0] = c[count++];

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int w: g[v]) {
            if (!used[w]) {
                q.push(w);
                used[w] = true;
                assign[w] = c[count++];
            }
        }
    }
    int M = accumulate(c.begin() + 1, c.end(), 0);
    cout << M << '\n';
    REP(i, N) {
        cout << assign[i] << (i == N - 1 ? '\n' : ' ');
    }
    cout << flush;
    return 0;
}



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

int main(void)
{
  int n,m,i,j,door=0;
  char u[256][11],ID[256][11];

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s", u[i]);
  }
  scanf("%d", &m);
  for(i=0;i<m;i++){
    scanf("%s", ID[i]);
  }
  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(strcmp(ID[i],u[j])==0){
	if(door==0){
	  printf("Opened by %s\n", ID[i]);
	  door=1;
	} else {
	  printf("Closed by %s\n", ID[i]);
	  door=0;
	}
	break;
      }
      if(j==n-1) printf("Unknown %s\n", ID[i]);
    }
  }

  return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
// Problem Specific Parameter:
const int inf=1<<28;

// Description: グラフの型定義(これは最小費用流)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to;};
using G=vector<vector<edge>>;

//Appropriately Changed
inline void add_edge(G &graph,int from,int to){ 
	graph[from].push_back({to});
	graph[to].push_back({from});
}

vector<int> node;

bool check(const auto &graph,int v,int p,int d){
	if(node[v]!=-1 and node[v]%2!=d) return false;
	bool ret=true;
	for(auto &e:graph[v]){
		if(e.to==p) continue;
		ret&=check(graph,e.to,v,d^1);
	}
	return ret;
}

using pii=pair<int,int>;
vector<pii> ret;

pii dfs(const auto &graph,int v,int p){
	if(node[v]!=-1){
		chmax(ret[v].first,node[v]);
		chmin(ret[v].second,node[v]);
	}

	for(auto &e:graph[v]){
		if(e.to==p) continue;
		pii tmp=dfs(graph,e.to,v);
		chmax(ret[v].first,tmp.first-1);
		chmin(ret[v].second,tmp.second+1);
	}

	return ret[v];
}

void rest(const auto &graph,int v,int p,int d){
	if(node[v]==-1){		
		if(p==-1){
			node[v]=ret[v].first;
			if(node[v]%2!=d) node[v]++;
		}else{
			if(ret[v].first<= node[p]-1 and node[p]-1<= ret[v].second) node[v]=node[p]-1;
			if(ret[v].first<= node[p]+1 and node[p]+1<= ret[v].second) node[v]=node[p]+1;
		}
	}

	for(auto &e:graph[v]){
		if(e.to==p) continue;
		rest(graph,e.to,v,d^1);
	}
	return;
}



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

	G graph(n);
	rep(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		add_edge(graph,a-1,b-1);
	}

	node.assign(n,-1);
	ret.assign(n,pii(-inf,inf));
	int k;
	scanf("%d",&k);
	rep(i,k){
		int v,p;
		scanf("%d%d",&v,&p);
		node[v-1]=p;
	}

	int ok=-1;
	rep(d,2) if(check(graph,0,-1,d)) ok=d;

	dfs(graph,0,-1);
	//rep(v,n) cout << ret[v].first << " " << ret[v].second << endl;
	rep(v,n) if(ret[v].first>ret[v].second) ok=-1;
	
	if(ok==-1){
		puts("No");
	}else{
		puts("Yes");
		rest(graph,0,-1,ok);
		rep(v,n) printf("%d\n",node[v]);
	}
	return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  ll ans=0;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin >> s;
    sort(all(s));
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
N=int(input().strip())
A=list(map(int, input().strip().split()))
A_posi=[]
A_nega=[]
for i in range(N):
    A[i]=A[i]-(i+1)
    if A[i]<0:
        A_nega.append(A[i]*(-1))
    elif A[i]>0:
        A_posi.append(A[i])
sm=sum(abs(i) for i in A)

A_tgt=A_nega if len(A_nega)>len(A_posi) else A_posi
A_tgt=sorted(A_tgt)

diff=0
old=0
mindiff=0
for i,a in enumerate(A_tgt):
    if old<a:
        diffdiff=(-i+(len(A_tgt)-i))*(a-old)
    else:
        continue
    if diffdiff<0:
        break
    old=a
    diff = diff+diffdiff
    total_diff=-diff+a*(N-len(A_tgt))
    if total_diff<mindiff:
        mindiff=total_diff
print(sm+mindiff)

Measured memory_bytes: 25200
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m,a,b,c,t,i;
V M(const V &x,const V &y){
	V z(n*n);
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(x[slice(i*n,n,1)]*y[slice(j,n,n)]).sum()%m;
	return z;
}
V E(const V &x,const int &n){
	if(n==1)return x;
	if(n&1)return M(E(x,n-1),x);
	V y=E(x,n>>1);
	return M(y,y);
}
V s,x;
void O(const V &r){
    for(i=0;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		s.resize(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		x.resize(0);
		x.resize(n*n);
		if(t){
			x[0]=b;
			x[1]=c;
			for(i=1;i<n-1;i++){
				x[i*n+i-1]=a;
				x[i*n+i]=b;
				x[i*n+i+1]=c;
			}
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			O(E(x,t));
		}else{
			for(i=0;i<n;i++)x[i*n+i]=1;
			O(x);
		}
	}
}

Measured memory_bytes: 1084
program main
	implicit none
    character(3)::s,t
    integer::i,ans=0
    read(*,*)s
    read(*,*)t
    do i=1,3
    	if(s(i:i)==t(i:i))then
        	ans=ans+1
        end if
    end do
    write(*,*)ans
    stop
end program main


Measured memory_bytes: 2764
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n;
long long  f[100011];
long long  ans,cnt,tot;
char a[101];
int b[101];
int prime;
unsigned long long mod;
int read()
{
	int _=1,__=0;char ___;___=getchar();
	while(___>'9'||___<'0'){if(___=='-')_=-1;___=getchar();}
	while(___<='9'&&___>='0'){__=__*10+___-'0';___=getchar();}
	return _*__;
}
int main()
{
	n=read();
	prime=233317;
	mod=212370440130137957ll;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		for(int j=0;j<10;j++)
		b[j+1]=a[j]-'a'+1;
		sort(b+1,b+10+1);
		for(int j=1;j<=10;j++)
		{
			f[i]=(f[i]*prime+b[j])%mod;
		}
	}
	sort(f+1,f+n+1);
	cnt=f[1];tot=1;
	for(int i=2;i<=n;i++)
	{
		if(f[i]==cnt)
		tot++;
		else
		{
			cnt=f[i];
			ans+=tot*(tot-1)/2;
			tot=1;
		}
	}
	ans+=tot*(tot-1)/2;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 1024