akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
const int MAXN=100005;
ll n,C,ans=0;
ll dist[MAXN],val[MAXN];
ll l[MAXN],r[MAXN];
ll lmax[MAXN],rmax[MAXN],lb[MAXN],rb[MAXN];
ll rplace,lplace;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	return x*f;
}
int main(){
	n=read();C=read();
	for(ll i=1;i<=n;++i) {dist[i]=read();val[i]=read();}
	dist[n+1]=C;
	for(int i=1;i<=n;++i){
		r[i]=r[i-1]+val[i]-(dist[i]-dist[i-1]);
		rb[i]=r[i]-dist[i];
	}
	for(int i=n;i>=1;--i) {
		l[i]=l[i+1]+val[i]-(dist[i+1]-dist[i]);
		lb[i]=l[i]-(C-dist[i]);
	}
	rplace=0;lplace=n+1;
	for(int i=1;i<=n;++i)
		if(r[i]>r[rplace]) rmax[i]=r[rplace=i];
		else rmax[i]=r[rplace];
	for(int i=n;i>=1;--i)
		if(l[i]>l[lplace]) lmax[i]=l[lplace=i];
		else lmax[i]=l[lplace];
	for(int i=1;i<=n;++i) ans=max(ans,rb[i]+lmax[i+1]);
	for(int i=n;i>=1;--i) ans=max(ans,lb[i]+rmax[i-1]);
	for(int i=1;i<=n;++i) ans=max(ans,max(l[i],r[i]));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define eps (1e-8)
#define PI (acos(-1.0))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9+7)
typedef pair<int, int> P;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    printf("%lld", max(a * c, max(a * d, max(b * c, b * d))));
    return 0;
}

Measured memory_bytes: 3820
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
    string a,b,c;
    cin>>a;
    b=a.at(0);
    c=a.at(a.size()-1);
    cout<<b+to_string(a.size()-2)+c<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	vint a(N);
	int sum = 0;
	rep(i,N)sum +=a[i] = in();
	sort(a.begin(), a.end());
	if (sum % 10) {
		cout << sum << endl;
		return 0;
	}
	rep(i,N) if (a[i]%10) {
		cout << sum - a[i] << endl;
		return 0;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as N
p=print
n=int(input())
c=int(N.sqrt(n*2))
if c**2+c-n*2:p('No')
else:a=N.zeros((c+1,c));t=N.triu_indices(c);a[t]=a[1:].T[t]=N.arange(n)+1;p('Yes');p(c+1);[p(c,*map(int,r))for r in a]

Measured memory_bytes: 18464
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int K,X;
  cin >> K >> X;
  for(int i = X - K + 1; i < X + K; i++){
    if(i - (X - K + 1)) cout << " ";
    cout << i;
  }
  cout << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a-b);
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}


int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	int count = 0;
	while(n != 0){
		n = n/k;
		count++;
	}
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
 
int main(){
 
    int i,j;
    for(i=0;i<9;i++)
        for(j=0;j<9;j++)
            cout<<(i+1)<<"x"<<(j+1)<<"="<<(i+1)*(j+1)<<endl;
 
 
    return 0;
}

Measured memory_bytes: 2892
N = int(input())
A = [int(hoge) for hoge in input().split()]
nodemax = []
cur = 0
for a in reversed(A):
    cur += a
    nodemax.append(cur)
nodemax = list(reversed(nodemax))#nodemax[d] d段目に存在できるノードのmax
ans = 1
curnode = 1
for n,a in enumerate(A):
    #n+1段目に生やすノード
    nothappa = curnode - A[n]#生やすリスト
    if n!=N:
        if nothappa <= 0:
            ans = -1
            break
        else:
            nextnode = min(nodemax[n+1],nothappa*2)
            ans += nextnode
            curnode = nextnode
    else:
        if nothappa !=0:
            ans = -1
print(ans)
        


Measured memory_bytes: 85876
N=int(input())
A=[int(input()) for i in range(N)]
count=0
count+=A[0]//2
A[0]%=2
for i in range(1,N):
    count+=(A[i-1]+A[i])//2
    if A[i]:
        A[i]=(A[i-1]+A[i])%2
    else:
        A[i]=0
print(count)


Measured memory_bytes: 50752
import java.io.*;
import java.util.*;
class   Main       {
	public static void main(String[] args) 
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = in.nextInt();
		System.out.println("ABC"+n);
		//w.println(n);
		w.close();
		sc.close();
	}
	static class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		public InputReader(InputStream st) {
			this.stream = st;
		}
		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
		
		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		
	}
	
}

Measured memory_bytes: 23892
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a>=b)
        {
            for(int i=1;i<=a;i++)
            {
                cout<<b;
            }
        }
        else
        {
            for(int i=1;i<=b;i++)
            {
                cout<<a;
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N=gets.to_i

h=Hash.new(0)
N.times do
    h[gets[0]] += 1
end

a = []
'MARCH'.each_char do |c|
    a<<h[c]
end

sum = 0
a.combination(3) do |x,y,z|
    sum += x*y*z
end

puts sum

Measured memory_bytes: 2044
n, c = map(int, input().split())
MAX_COLS = 10**5
table = [[0 for _ in range(MAX_COLS)] for _ in range(c)]

for _ in range(n):
    s, t, i = list(map(int, input().split()))
    for j in range(s - 1, t - 1):
        table[i - 1][j] = 1

for i in range(c):
    for j in range(MAX_COLS - 1):
        if table[i][j] == 0 and table[i][j + 1] == 1:
            table[i][j] = 1

res = 0
for j in range(MAX_COLS):
    count = 0
    for i in range(c):
        count += table[i][j]
    res = max(res, count)
print(res)

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

int main()
{
	string S;
	cin >> S;
	int N = S.length();
	vector<int> output(N);

	for (int i = 0; i < N;)
	{
		//R
		int start = i;
		while (S[i] == 'R')
		{
			i++;
		}
		int cut = i;
		int cut2 = i - 1;
		while (i < N && S[i] == 'L')
		{
			i++;
		}


		int childrennumber = i - start;
		int guusuuteam = 0;
		int kisuuteam = 0;
		if (start % 2 == 0)
		{
			kisuuteam = childrennumber / 2;
			guusuuteam = childrennumber - kisuuteam;
		}
		else
		{
			guusuuteam = childrennumber / 2;
			kisuuteam = childrennumber - guusuuteam;
		}
		if (cut2 % 2 == 0)
		{
			output[cut2] = guusuuteam;
			output[cut] = kisuuteam;

		}
		else
		{
			output[cut2] = kisuuteam;
			output[cut] = guusuuteam;
		}
	}
	for (int i = 0; i < N-1; i++)
	{
		cout << output[i];
		cout << " ";
	}
	cout << output[N - 1] << endl;
}



Measured memory_bytes: 1088
A,B,C=map(int,input().split())

D=abs(A-B)
E=abs(B-C)
F=abs(C-A)

if D>=E and D>=F:
  print(E+F)
elif E>=D and E>=F:
  print(D+F)
elif F>=D and F>=E:
  print(D+E)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#define M 100000
using namespace std;
  
int main(){
    int n;
    int m;
    int move;
    int dis;
    int pos = 0;
    int ans = 0;
    int x[M];
    scanf("%d %d",&n,&m);
    x[0] = 0;
    for (int i = 1; i < n; i++){
        scanf("%d", &dis);
        x[i] = x[i - 1] + dis;
    }
    while (m--){
        scanf("%d", &move);
        if(move > 0){
            ans += x[pos + move] - x[pos];
        }
        else{
            ans -= x[pos + move] - x[pos];
        }
        pos += move;
        ans %= M;
    }
    printf("%d\n", ans);
}

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

int main() {
    int N;
    cin >> N;
    int N1, N2, N3;
    N1 = N / 100;
    N2 = (N % 100) / 10;
    N3 = (N % 100) % 10;
    if((N1 != 0 && N1 % 7 == 0) || (N2 != 0 && N2 % 7 == 0) || (N3 != 0 && N3 % 7 == 0)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, M, R;
	
	cin >> N >> M >> R;

	int r[R];

	rep(i, R)
	{
		cin >> r[i];
		r[i]--;
	}

	int edge[N][N];
	//memset(edge, -1, sizeof(edge));
	rep(i, N)
	{
		rep(j, N)
		{
			edge[i][j] = MOD;
		}
	}

	rep(i, M)
	{
		int l, r, c;
		cin >> l >> r >> c;
		l--;
		r--;
		edge[l][r] = c;
		edge[r][l] = c;
	}
	


	rep(k, N)
	{
		rep(i, N)
		{
			rep(j, N)
			{
				if (edge[i][j] > (edge[i][k] + edge[k][j]))
				{
					edge[i][j] = edge[i][k] + edge[k][j];
				}
			}
		}
	}

	/*
	rep(i, N)
	{
		rep(j, N)
		{
			cout << "i = " << i << "; j = " << j << "; dist = " << edge[i][j] << endl;
		}
	}
	*/

	int res = 1e9;
	sort(r, r+R);
	do{
		int tmp = 0;
		rep(i, R-1)
		{
			tmp += edge[r[i]][r[i+1]];
		}
		res = min(res, tmp);
	}while(std::next_permutation(r, r+R));

	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100005
#define NIL -1

void print(int);
void setDepth(int,int);

typedef struct{
  int p;
  int l;
  int r;
}Node;

Node t[MAX];
int n,d[MAX];

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++) t[i].p =t[i].l = t[i].r= NIL;
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)t[v].l=c;
      else t[l].r=c;
      l=c;
      t[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(t[i].p==NIL)r=i;
  }
  setDepth(r,0);

  for(i=0;i<n;i++)print(i);

  return 0;
}
  
void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",t[u].p);
  printf("depth = %d, ",d[u]);

  if(t[u].p==NIL)printf("root, ");
  else if(t[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for( i=0,c=t[u].l ; c!=NIL ; i++, c=t[c].r ){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}


void setDepth(int u,int p){
  d[u]=p;
  if(t[u].r!=NIL)setDepth(t[u].r,p);
  if(t[u].l!=NIL)setDepth(t[u].l,p+1);
}



Measured memory_bytes: 6544
import java.util.Scanner;

public class Main {

    private static Scanner sc;

    public Main() {
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().solve();
    }

    private void solve() {
        String S = sc.next();
        if (S.startsWith("YAKI")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    set<string> s;
    string prev;
    cin >> prev;
    s.insert(prev);
    for (int i = 1; i < n; i++) {
        string next;
        cin >> next;
        if (prev[prev.size()-1] != next[0]) {
            cout << "No" << endl;
            return 0;
        }
        s.insert(next);
        prev = next;
    }
    if (n != s.size()) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

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

Measured memory_bytes: 3560
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
d=[]
ab=sorted(ab,key=lambda x: x[0])
ans=0
j=0
for i in range(m):
    for k in range(j,n):
        if ab[k][0]>i+1:
            j=k
            break
        heapq.heappush(d,(-1)*ab[k][1])
    else:
      j=n
    if not d:
        continue
    res=heapq.heappop(d)*(-1)
    ans+=res
    
print(ans)

Measured memory_bytes: 103072
#n = int(input())
n, k = map(int, input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
dic = {}
for i in range(n):
    a, b = map(int, input().split())
    dic[a] = dic.get(a, 0)+b

l = sorted(dic.items())

for a, b in l:
    if k <= b:
        ans = a
        break
    k -= b
print(ans)


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

ll a;
vector<ll> bcd(3);
vector<int> ar = {2, 3, 5};
map<ll, ll> m;
int cou = 0;

ll f(ll x){
	if(m[x] != 0) return m[x];
	if(x == 0) return 0;
	if(x == 1) return a;
	vector<ll> mi(3);
	rep(i, 3){
		if(x/ar[i] == 0){
			mi[i] = x*a;
		}else if(x%ar[i] == 0){
			ll k = f(x/ar[i]);
			if(x - x/ar[i] > 1000000000) mi[i] = k + bcd[i];
			else mi[i] = min(k + bcd[i], k + (x - x/ar[i])*a);
		}else{
			ll xn0 = x/ar[i];
			ll xn1 = x/ar[i]+1;
			ll sa0 = x%ar[i];
			ll sa1 = ar[i] - x%ar[i];
			ll k0 = f(xn0);
			ll k1 = f(xn1);
			ll mi0, mi1;
			if(x - xn0 > 1000000000) mi0 = k0 + bcd[i] + sa0 * a;
			else mi0 = min(k0 + bcd[i] + sa0 * a, k0 + (x - xn0)*a);
			if(x - xn1 > 1000000000) mi1 = k1 + bcd[i] + sa1 * a;
			else mi1 = min(k1 + bcd[i] + sa1 * a, k1 + (x - xn1)*a);
			mi[i] = min(mi0, mi1);
		}
	}
	ll ans = min(min(mi[0], mi[1]), mi[2]);
	m[x] = ans;
	return ans;
}

int main(){
	int t;
	cin >> t;
	vector<ll> ans(t);
	rep(i, t){
		ll n;
		cin >> n >> bcd[0] >> bcd[1]>> bcd[2] >> a;
		m.clear();
		ans[i] = f(n);
	}
	rep(i, t) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4420
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


signed main()
{
	speed
	int h,a;cin>>h>>a;
	cout<<((h/a)+((h%a)!=0))<<"\n";

}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: isize,
        d: isize,
        v: [(isize, isize); n]
    }

    let mut ans = 0;
    for (x, y) in v {
        if (x * x + y * y) <= d * d {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;

int dp[N];

int mul(int a , int b){
  return a*1ll*b%mod;
}
int sub(int a , int b){
  a -= b;
  if(a < 0) a += mod;
  return a;
}
int add(int a , int b){
  a += b;
  if(a >= mod) a -= mod;
  return a;
}
int power(int x , int y){
  int res = 1;
  while(y){
    if(y&1)
      res = mul(res , x);
    x = mul(x , x);
    y >>= 1;
  }
  return res;
}

int main(){
  int n , k; cin >> n >> k;
  for(int i = k ;i >= 1 ; --i){
    int no = k/i; 
    dp[i] = power(no , n);
    for(int j = 2*i; j <= k ; j += i)
      dp[i] = sub(dp[i] , dp[j]);
  }
  int ans = 0;
  for(int i = 1;i <=k ; ++i)
    ans = add(ans , mul(i, dp[i]));
  cout << ans << endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define pw(x) (1LL << (x))
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl

using namespace std;
typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

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

#ifdef HOME
    cerr << "time = " << (clock() * 1. / CLOCKS_PER_SEC) << "\n";
#endif
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int A,B; cin >> A >>B;
  int ans = 0;
  if (A==B) ans = A+B;
  else ans = max(A,B) * 2 -1;
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 5;
char mp[MAXN][MAXN];

int main() {
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 50; i++) {
        for (int j = 1; j < 100; j++, j++) {
            mp[i][j] = '.';
            if (b > 1) {
                mp[i][j + 1] = '#';
                b--;
            } else
                mp[i][j + 1] = '.';
        }
        i++;
        for (int j = 1; j <= 100; j++)
            mp[i][j] = '.';
    }
    for (int i = 51; i <= 100; i++) {
        for (int j = 1; j <= 100; j++)
            mp[i][j] = '#';
        i++;
        for (int j = 1; j < 100; j++, j++) {
            mp[i][j] = '#';
            if (a > 1) {
                mp[i][j + 1] = '.';
                a--;
            } else
                mp[i][j + 1] = '#';
        }
    }
    cout << 100 <<" "<< 100 << endl;
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++)
            cout << mp[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge{
	int dst;
	ll cost;
	edge(int dst, ll cost){
		this->dst=dst; this->cost=cost;
	}

};


 
int V,E;
typedef vector<edge> edges;
vector<edges> g;

ll num = 1000000000;//
char ans;

void print(ll num) {
	cout << "? " << num << endl;
}
void printout(ll num) {
	cout << "! " << num << endl;
}

void func1() {
	num = 2;
	while (1) {
		print(num);
		cin >> ans;
		if (ans == 'Y') {
			printout(num / 2);
			exit(1);
		}
		else {
			num *= 10;
		}
	}
}

void func3() {
	ll l = num;
	ll r = num * 10;
	ll m;
	while (r - l>1) {
		m = (l + r) / 2;
		print(m*10);
		cin >> ans;

		if (ans == 'Y') {
			r = m;
		}
		else {
			l = m;
		}
	}
	printout(r);//
	exit(1);
}

void func2() {
	num /= 10;//
	while (1) {
		print(num);
		cin >> ans;

		if (ans == 'Y') {
			func3();
		}
		else {
			num /= 10;
		}
	}
}


int main(){

	print(num);
	while (1) {
		scanf("%c", &ans);
		if (ans == 'Y') {
			func1();
		}
		else {
			func2();
		}
	}

	return 0;
}


Measured memory_bytes: 596
def read_inputs
  n, m = gets.split(" ").map(&:to_i)
  matrix_a = (1..n).map{gets.split(" ").map(&:to_i)}
  matrix_b = (1..m).map{gets.to_i}
  return matrix_a, matrix_b
end

matrix_a, matrix_b = read_inputs

puts matrix_a.map {|a|
  a.zip(matrix_b).map {|x| x.first * x.last}.inject(:+)
}.join("\n")

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
const ll inf = (ll)(1e18),mod = (ll)(1e9+7), MX= 100001; 
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

 

void solve(){
    int n,m;
  cin>>n;

  vector<int> a(n);
  vector<int> mp(1001);
    for(int i = 0; i<n; i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a.begin(),a.end());
    long long cnt=0;
    for(int i=n-1;i>=2;i--)
    {
        int l =0;int r =i-1;
        while(l<r)
        {
            if(a[l]+a[r]>a[i])
            {
                cnt=cnt+r-l;
                cnt=cnt;
                r--;
            }
            else l++;
        }
    }
    cout<<cnt<<endl;

    return;
}

int main()
{
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...i
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define mp make_pair
const int mx = 1000 * 100;
int n, a, b;
int h[mx];
bool f(int x){
	int i = 0, ans = 0;
	while(h[i] > x * b){
		ans += ((h[i] - x * b) + a - b - 1) / (a - b);
		i++;
	}
	return (ans <= x);
}
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	sort(h , h + n , greater < int >());
	int l = 1, r = (h[0] + b - 1) / b, mid;
	while(r - l > 1){
		mid = (r + l) / 2;
		if(f(mid))
			r = mid;
		else
			l = mid;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;

    if ((a == b || b == c || c == a) && !( a == b && b == c)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];

  vector<vector<int>> s(D);
  rep(d, D)
  {
    s[d].resize(26);
    rep(i, 26)
    {
      cin >> s[d][i];
    }
  }

  vector<int> t(D);
  rep(i, D)
  {
    cin >> t[i];
    t[i]--;
  }

  vector<int> last(26, 0);

  long long score = 0;
  rep(i, D)
  {
    score += s[i][t[i]];
    last[t[i]] = i + 1;
    rep(j, 26)
    {
      score -= c[j] * (i + 1 - last[j]);
    }

    cout << score << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200020
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
char s[N],t[N];
int n,ans;
int main(){
	scanf("%s",s+1);
	scanf("%s",t+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i){
		ans+=(s[i]!=t[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define mz 1000000007
#define pq priority_queue

int num[5][105];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&num[i][j]);
            num[i][j]+=max(num[i-1][j],num[i][j-1]);
        }
    printf("%d\n",num[2][n]);
	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=30;

typedef long long ll;

int N;

ll dp[MAX_N+1];

int main(){
	dp[1]=1;
	dp[2]=2;
	dp[3]=4;
	FOR(i,4,MAX_N+1){
		dp[i]=dp[i-3]+dp[i-2]+dp[i-1];
	}
	do{
		cin>>N;
		if (N){
			ll day=(dp[N]+9)/10;
			ll y=(day+364)/365;
			cout<<y<<endl;
		}
	}while (N);
	return 0;
}

Measured memory_bytes: 1156
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;  // check the limits, dummy

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
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;
}

template <class T>
void print(const vector<T> v) {
  cout << "[ ";
  F0R(i, v.size()) { cout << v[i] << ' '; }
  cout << "]" << '\n';
}

int mod(int i, int j) {
  return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int N, M, sum, d;
  vi A;
  cin >> N;
  cin >> M;
  // cin >> sum;
  // cout << sum << endl;
  sum = 0;
  d = 0;
  FOR(i, 0, M) {
    cin >> d;
    sum += d;
    // A.push_back(d);
    // cout << sum << endl;
  }

  if (N - sum >= 0) {
    cout << N - sum << endl;
  } else {
    cout << -1 << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		double h = double.Parse(IO.GetString());
		Console.WriteLine(Calc(h,0,0));
	}
	
	static double Calc(double h,double aC,double l){
	    l++; //1層目
	    aC += Math.Pow((double)2,(double)(l-1)); //攻撃
	    
	    //もしこの層の敵のHPが1ならここで終了
	    if(h==1)return aC;
	    
	    //HPが1より大きければ敵を分裂させて次の攻撃へ
	    h = Math.Floor((double)h/2);
	    return Calc(h,aC,l);
	    
	}

}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}

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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    int num = 1;
    while (cnt < n){
        num = a[num-1];
        cnt++;
        if (num==2){
            cout << cnt;
            return 0;
        }


    }
    cout << -1;

    return 0;
}

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

int main(){
    char s[51],t[51];
    int flug=0,lens,lent;
    scanf("%s",s);
    scanf("%s",t);
    lens=strlen(s);
    lent=strlen(t);
    for(int i=lens-1;i>=0;i--){
        for(int j=i;j>=0 && i-j+1<=lent && (s[j]=='?'||s[j]==t[lent-i+j-1] );j--){
            if(i-j+1==lent && flug==0)flug=1;
        }
        if(flug==1){
            for(int j=lent-1;j>=0;j--,i--){
                s[i]=t[j];
            }
            i++;
            flug=2;
        }else{
            if(s[i]=='?'){
                s[i]='a';
            }
        }
    }
    printf("%s\n",(flug==0)?"UNRESTORABLE":s);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;
//#pragma GCC optimize ("-O3")

int n;
vector<int> ar;
vector<vector<long long>> dp;

long long go(int l, int r)
{
    // base case
    if (l > r)
        return 0;
    if (dp[l][r]!= -1e18)
        return dp[l][r];
    // pick left
    long long ans;
    ans = max(ar[l] - go(l+1, r), ar[r] - go(l, r-1));
    return dp[l][r] = ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    ar.resize(n);
    dp = vector<vector<long long>> (n, vector<long long> (n, -1e18));
    for (int i = 0; i < n; i++)
        cin >> ar[i];
    cout << go(0, n-1);
    return 0;
}

Measured memory_bytes: 73816
N = int(input())
A = [int(x) for x in input().split()]

def op(x, y):
    print(x, y)
    A[y - 1] += A[x - 1]

mn, mx = min(A), max(A)
base = mx if abs(mn) < abs(mx) else mn
bi = A.index(base) + 1

print(N * 2 - 1)
for i in range(N):
    op(bi, i + 1)
if 0 < base:
    for i in range(1, N):
        op(i, i+1)
else:
    for i in range(N, 1, -1):
        op(i, i-1)

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

using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int>h(n); for (int i = 0; i < n; i++)cin >> h[i];
	vector<int>cost(n); for (int i = 1; i < n; i++)cost[i] = 1145141919;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= min(k, i); j++) {
			cost[i] = min(cost[i], cost[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << cost[n - 1] << endl;
	return 0;
}

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

int main()
{
	int n, maxm = -0x7fffffff;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; ++i)
    {
    	cin >> arr[i];
	}
    int mini = arr[0];
    for (int i = 1; i < n; ++i)
    {
		maxm = max(maxm, arr[i] - mini);
		mini = min(mini, arr[i]);
	}
	cout << maxm << endl;
	return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int n;
long long d;
int main () {
    int ans = 0;
    cin >> n >> d;

    while (n -- ) {
        long long x, y;
        scanf("%lld %lld", &x, &y);

        if (x * x + y * y <= d * d) {
            ++ ans;
        }
    }

    cout << ans << '\n';
}


Measured memory_bytes: 3576
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);
for ($i = 0; $i < strlen($s); $i++) {
	if (isset($q[$s[$i]])) {
		if ($q[$s[$i]] != $t[$i]) exit('No');
	} else {
		$q[$s[$i]] = $t[$i];
	}
	if (isset($r[$t[$i]])) {
		if ($r[$t[$i]] != $s[$i]) exit('No');
	} else {
		$r[$t[$i]] = $s[$i];
	}
}
echo 'Yes';

Measured memory_bytes: 4732
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int mod=1e9+7;
int n,f[3010][3010],sum[3010][3010];
char s[3010];
int main()
{
	scanf("%d",&n);getchar();
	scanf("%s",s+1);
	f[1][1]=sum[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			if(s[i-1]=='<') f[i][j]=sum[i-1][j-1];
			else f[i][j]=(sum[i-1][i-1]-sum[i-1][j-1])%mod;
		}
		for(int j=1;j<=i;j++) sum[i][j]=(sum[i][j-1]+f[i][j])%mod;//printf("%d ",f[i][j]);printf("\n");
	}
	printf("%d",(sum[n][n]+mod)%mod);
}

Measured memory_bytes: 69632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class BCardGameForTwo {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        int a[N];
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }

        sort(a, a + N, greater<int>());
        int alice_sum = 0;
        int bob_sum = 0;
        for (int i = 0; i < N; ++i) {
            if (i % 2 == 0) {
                alice_sum += a[i];
            } else {
                bob_sum += a[i];
            }
        }

        out << alice_sum - bob_sum;
    }
};


int main() {
	BCardGameForTwo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import heapq
import sys
sys.setrecursionlimit(20000)
N = int(input())
ab = [tuple(map(int, input().split())) for i in range(N-1)]
c = list(map(int, input().split()))

print(sum(c) - max(c))
c = list(map(lambda x: x*(-1), c))
heapq.heapify(c)
d = [[0, i] for i in range(N)]
g = [set() for i in range(N)]
for a, b in ab:
    d[a-1][0] += 1
    d[b-1][0] += 1
    g[a-1].add(b-1)
    g[b-1].add(a-1)
d.sort(reverse=True, key=lambda x: x[0])
for i in range(N):
    d[i][0] = -1


ans = ["-1"]*N
ans[d[0][1]] = str(-1 * heapq.heappop(c))


def dfs(start):
    for x in g[start]:
        if ans[x] == "-1":
            ans[x] = str(-1 * heapq.heappop(c))
            dfs(x)


dfs(d[0][1])
d.sort(key=lambda x: x[1])


print(" ".join(ans))


Measured memory_bytes: 15312
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

vector<int> G[1010];
int NG[1010];
pair<int, int> E[2019];
int arr[1010], sub[1010];
int d = 0;
set<int> cyc;

void dfs(int x) {
	sub[x] = 1;
	for (int i : G[x]) {
		if (sub[i]) {
			d = i;
			NG[x] = i;
			cyc.insert(i);
			sub[i] = 0;
			return;
		}
		dfs(i);
		if (d) {
			if (sub[i] == 0) {
				sub[x] = 0;return;
			}
			sub[i] = 0;
			NG[x] = i;
			cyc.insert(i);
			return;
		}
	}
	sub[x] = 0;
	return;
}

void dfs2(int x, int y) {
	cyc.erase(x);
	if (NG[x] == y) {
		NG[x] = 0;
		return;
	}
	dfs2(NG[x], y);
	NG[x] = 0;
}

signed main(){
	for (int i = 0;i < 1010;i++)arr[i] = INT32_MAX;
	arr[1] = 0;
	int N, M, a, b;
	cin >> N >> M;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		G[a].push_back(b);
		E[i] = { a,b };
	}
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < M;j++) {
			tie(a, b) = E[j];
			arr[b] = min(arr[b], arr[a] - 1);
		}
	}
	bool jud = 0;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < M;j++) {
			tie(a, b) = E[j];
			if (arr[b] > arr[a] - 1) {
				jud = 1;break;
			}
		}
		if (jud)break;
	}
	if (!jud) { cout << -1 << endl;return 0; }
	
	//ここまでで負閉路検出
	for (int i = 0;i < 1010;i++)sub[i] = 0;

	dfs(a);

	for (int i = 0;i < M;i++) {
		tie(a, b) = E[i];
		if (NG[a] == b)continue;
		if (cyc.count(a) > 0 && cyc.count(b) > 0) {
			dfs2(a, b);
			NG[a] = b;
			cyc.insert(a);
		}
	}

	vector<int> ans;
	for (int i = 1;i <= N;i++) {
		if (NG[i]) {
			ans.push_back(i);
		}
	}
	cout << ans.size() << endl;
	for (int i : ans)cout << i << endl;
}

Measured memory_bytes: 384
x = int(input())
l = [0]
for i in range(1, 121):
    l.append(i**5)
now = 0
for i in range(1, len(l)):
    if now == 1:
        break
    for j in range(i):
        if l[i]+l[j] == x:
            print(i, -j)
            now = 1
            break
        elif l[i]-l[j] == x:
            print(i, j)
            now = 1
            break

Measured memory_bytes: 9196
H, W = map(int, input().split())
grid = []

for _ in range(H):
  x = input()
  if x != "."*W:
    grid.append(x)

h = len(grid)
Flag = [True]*W

for j in range(W):
  if all([grid[i][j] == "." for i in range(h)]):
    Flag[j] = False

for i in range(h):
  print("".join([grid[i][j] for j in range(W) if Flag[j]]))

Measured memory_bytes: 9104
N, K = map(int, input().split())
p = list(map(int, input().split()))

a = 0
for i in range(N - K + 1):
  if i == 0:
    b = sum(p[0:K])
  else:
    b = b - p[i-1] + p[i + K - 1]
  
  if b > a:
    a = b
    f = i

ans = 0
for j in range(K):
  ans += (p[f + j] + 1) / 2

print(ans)

Measured memory_bytes: 24804
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	vector<vector<ll>> sum(n + 1, vector<ll>(60, 0));
	rep(i, n)rep(j, 60)
	{
		if ((a[i] >> j) & 1)++sum[i + 1][j];
		sum[i + 1][j] += sum[i][j];
	}
	ll MOD = 1e9 + 7;
	ll ans = 0;
	rep(i, n)rep(j, 60)
	{
		ll num = j;
		ll tmp = powl(2LL, num);
		tmp %= MOD;
		ll x;
		if ((a[i] >> j) & 1)x = n - i - 1 - (sum[n][j] - sum[i+1][j]);
		else x = sum[n][j] - sum[i+1][j];
		ans += x*tmp;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 155008
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, M;


signed main(){
    cin >> N >> M;
    cout << N*(N-1)/2+M*(M-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int>data(n);
	for (int i = 0; i < n; i++) {
		cin >> data[i];
	}
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		vector<int>v(3);
		v[0] = data[i];
		v[1] = data[i + 1];
		v[2] = data[i + 2];
		sort(v.begin(), v.end());
		if (data[i + 1] == v[1]) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main()
{
    int n;
    cin>>n;
    long long int s=0;
    for(long long int i=1;i<=n;i++)
    {
        if(!(i%3==0||i%5==0))
            s+=i;
    }
    cout<<s;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using BI = System.Numerics.BigInteger;

class Program
{
	public static void Main(String[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

		var N = input[0];
		var K = input[1];

		if (N >= (2 * K - 1))
			Console.WriteLine("YES");
		else
			Console.WriteLine("NO");
	}
}



Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    m1 = 60*h1+m1;
    m2 = 60*h2+m2;
    cout << m2-k-m1 << endl;
    return 0;
}

Measured memory_bytes: 3644