akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  char name[n][11], tmp[11];
  int p[n], id[n];
  int temp;
  for (i = 0; i < n; i++) {
    id[i] = i + 1;
  }

  for (i = 0; i < n; i++) {
    scanf("%s %d", name[i], &p[i]);
  }

  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      if (strcmp(name[j - 1], name[j]) > 0) {
        strcpy(tmp, name[j - 1]);
        strcpy(name[j - 1], name[j]);
        strcpy(name[j], tmp);
        temp = id[j - 1];
        id[j - 1] = id[j];
        id[j] = temp;
        temp = p[j - 1];
        p[j - 1] = p[j];
        p[j] = temp;
      }
    }
  }

  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      if (strcmp(name[j - 1], name[j]) == 0) {
        if (p[j - 1] < p[j]) {
          temp = id[j - 1];
          id[j - 1] = id[j];
          id[j] = temp;
          temp = p[j - 1];
          p[j - 1] = p[j];
          p[j] = temp;
        }
      }
    }
  }

  for (i = 0; i < n; i++) {
    printf("%d\n", id[i]);
  }

  return 0;
}


Measured memory_bytes: 128
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
typedef long long int lli;

void solve(){
    int h1,m1,h2,m2,k;
    int start,end;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    start=h1*60+m1;
    end=h2*60+m2;
    printf("%d\n",(end-k)-start);
    return;
}

int main(){
    int t;
    // scanf("%d",&t);
    // while(t--){
        solve();
    // }
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x,y;
	bool f=false;
	int c[100];
	int z[100];
	cin >>n>>m>>x>>y;
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	c[n]=x;
	for(int i=0;i<m;i++){
		cin>>z[i];
	}
	z[m]=y;
	sort(c,c+n+1);
	sort(z,z+m+1);
	if(c[n]<z[0]){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
}
		

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<random>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define endl "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) (x & (-x))
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }
template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const db PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)4e2 + 5;//remember to modify it, No RE or MLE
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int a[maxn];
ll dp[maxn][maxn], sum[maxn];
int n;

int main()
{
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", a + i), sum[i] = sum[i-1] + a[i];
	memset(dp, 0x3f, sizeof dp);
	rep(i, 1, n) dp[i][i] = 0;
	rep(len, 2, n){
		rep(l, 1, n - len + 1){
			int r = l + len - 1;
			rep(mid, l, r - 1){
				dp[l][r] = qmin(dp[l][r], dp[l][mid] + dp[mid+1][r] + sum[r] - sum[l-1]);
			}
		}
	}
	printf("%lld\n", dp[1][n]);
	return 0;
}

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

int main(void){
    int a,b;
   cin>>a>>b;
   if(a>=b){
       for(int i=0;i<a;i++){
           cout<<b;
       }
       cout<<endl;
   }else {
       for(int i=0;i<b;i++){
           cout<<a;
       }
       cout<<endl;
   }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (size_t i = 0; i < N; i++) {
    string s;
    cin >> s;
    switch (s[0]) {
      case 'A':
        ac++;
        break;
      case 'W':
        wa++;
        break;
      case 'T':
        tle++;
        break;
      case 'R':
        re++;
        break;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}


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

int N, Q;
string S;
vector<int> l, r;

void abc132c() {
  vector<ll> c(N + 1, 0);

  for (int i = 0; i < N - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      c[i] = 0;
      c[i + 1]++;
    }
  }

  for (int i = 1; i < N; i++) {
    c[i] += c[i - 1];
  }

  for (int i = 0; i < Q; i++) {
    cout << c[r[i] - 1] - c[l[i] - 1] << "\n";
  }

  return;
}

int main() {
  cin >> N >> Q >> S;
  l.resize(N);
  r.resize(N);
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }
  abc132c();
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    ll k,a,b; cin >> k >> a >> b;
    if(a>=k){
        cout << 1 << endl;
        return 0;
    }
    if(a<=b){
        cout << -1 << endl;
        return 0;
    }
    ll p=a-b;
    ll ans=1+(k-a+p-1)/p*2;
    cout << ans << endl;
}

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

int main() {
	long long a, b, v, w, t;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	if(v <= w) {cout<<"NO\n";return 0;}
	if(a < b){
		a += (v * t);
		b += (w * t);
		if(a >= b) cout<<"YES\n";
		else cout<<"NO\n";
	}else{
		a -= (v * t);
		b -= (w * t);
		if(a <= b) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}


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

using namespace std;

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

    if(s == "SUN")  cout << 7 << endl;
    else if(s == "MON")  cout << 6 << endl;
    else if(s == "TUE")  cout << 5 << endl;
    else if(s == "WED")  cout << 4 << endl;
    else if(s == "THU")  cout << 3 << endl;
    else if(s == "FRI")  cout << 2 << endl;
    else if(s == "SAT")  cout << 1 << endl;
    
    return 0;
}

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	vector<int> in(3);
	cin >> in[0] >> in[1] >> in[2];
	// cin >> in[0] >> in[1] >> in[2];
	cout << (in[0] + in[1] + in[2] < 22 ? "win": "bust") << endl;
	
	return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
int main()
{
  int i,j,n,a,b,aa,count=1;

  scanf("%d",&a);
  scanf("%d",&b);
  
  aa=a;

  if(b<=1)
    {
      count=0;
      
    }else
    {
      
  
  while(aa<b)
    {
      aa+=a-1;
      count++;
      
    }
    }
  
  
  printf("%d\n",count);

  return 0;
}


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

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  if(b>=0 && d>=0) cout << max(b*d,a*c) << endl;
  else if(b>=0 && d<=0) cout << max(a*d,a*c) << endl;
  else if(b<=0 && d>=0) cout << max(b*c,a*c) << endl;
  else if(b<0 && d<0) cout << a*c << endl;
  
  return 0;
}

Measured memory_bytes: 3580
import math

a,b,h,m = map(int,input().split())

ra = 360 / 60 * m
rb = 360 / 12 * h + 360 / 12 * m / 60
r = abs(ra-rb)

ans = math.sqrt(math.pow(a,2) + math.pow(b,2) 
                - 2 * a * b * math.cos(math.radians(r)))

print(ans)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans;


    return 0;
}



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

int main(){
	int n;
	bool f=0;
	cin >> n;
	for (int i=1,a;i<=n;i++){
		cin >> a;
		if (a%2==1) continue;
		if (a%3==0 || a%5==0) continue;
		f=1;
		break;
	}
	if (f==0) cout<<"APPROVED";
	else cout << "DENIED";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();
		
		System.out.println(String.format("%.6f %.6f",r*r*Math.PI,2*r*Math.PI));
	}
}


Measured memory_bytes: 28244
#include<iostream>
#include<string>

using namespace std;;

int main(){
    string s;
    int len,count = 0;
    cin >> s;
    len = s.length();
    if(len % 2 == 0){
        for(int i=0;i<len/2;i++){
            if(s[i] != s[len-1-i])count++;
        }
    }else{
        for(int i=0;i<(len-1)/2;i++){
            if(s[i] != s[len-1-i]) count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 888
#include <cstdio>
#include <vector>
#define NMAX 100005
#define MOD (int)(1e9+7)

using namespace std;

long long N,ans=1,dp[NMAX];
vector<int > p;

int main(){
	scanf("%lld",&N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%lld",&dp[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		int k = p.size()+1;
		if(dp[i] >= 2*k-1){
			p.push_back(dp[i]);
			ans *= (k);
		}else{
			ans = ans * (k);
		}
		ans = ans % MOD;
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1660
a=list(map(int, input().split()))
b=list(map(int, input().split()))
n=a[0]
x=a[1]
c=[0]*(n+1)

for i in range(1,n+1):
    c[i]=c[i-1]+b[i-1]
    
cnt=0

for i in range (n+1):
    if(c[i]<=x):
        cnt=cnt+1
        
print(cnt)
    


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.append(100)
C.append(0)

total = 0

for i in range(0,N):
    if(A[i + 1] - A[i] == 1):
        total += C[A[i] - 1]
    total += B[A[i] - 1]

print(total)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;


int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;
	
	ll x;
	cin >> x;

	ll ans = 0;
	ans += 1000 * (x / 500);
	x %= 500;
	ans += 5 * (x / 5);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  string target = "ATCG";
  string S;
  while (cin >> S) {
    int res = 0;
    int N = S.size();
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        bool ok = true;
        for (int k = i; k <= j; k++) ok &= target.find_first_of(S[k]) != string::npos;
        if (ok) chmax(res, j - i + 1);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def solve(x: int, a: int, b: int):
    return abs(a - x) < abs(b - x) and 'A' or 'B'

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    print(solve(x, a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>

using namespace std;

int w1,w2,h1,h2;

int main(){
	cin>>h1>>w1>>h2>>w2;
	cout<<abs(h1-h2)*abs(w1-w2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
    cout << "Yes\n";
  } else cout << "No\n";
  return 0;
}



Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int max = 0;
		int x = 0;
		for(int i = 0 ; i < N ; i++) {
			if(S.charAt(i) == 'I') {
				x++;
				max = Math.max(max, x);
			} else if(S.charAt(i) == 'D') {
				x--;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;

    int a[n];
    int most_max = 0, second_max = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (most_max < a[i]) {
            most_max = a[i];
        } else if (second_max < a[i]) {
            second_max = a[i];
        }
    }

    for (int i = 0; i < n; i++) {
        if (a[i] == most_max) {
            cout << second_max << endl;
        } else {
            cout << most_max << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>

int n, m, x, mini=1000000, sum=0;

int main(){
    scanf("%d %d", &n, &m);
    for(int i=0; i<n; i++){
        scanf("%d", &x);
        if(x < mini)
            mini = x;
        sum += x;
    }
    int res = m-sum;
    int dts = (res/mini) + n;
    printf("%d\n", dts);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;

vector<long long> dp, h;
const long long inf = 2 * 1e+18;

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

	dp.assign(n + 1, inf);
	h.resize(n + 1);

	dp[1] = 0;
	cin >> h[1];
	for (int i = 2; i <= n; i++)
	{
		cin >> h[i];
		if (i - 1 > 0)
		{
			dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		}

		if (i - 2 > 0)
		{
			dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}

	cout << dp[n];

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

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

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

using namespace std;

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

	long long int A,B;

	cin >> A >> B;

	if((A+B)%2==0)
	{
		cout << (A+B)/2 << '\n';
	}
	else
	{
		cout << "IMPOSSIBLE" << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 256
var
    n,i,j,tot,ans:longint;
begin
    readln(n);
    for i:=1 to n do
        if odd(i) then 
            begin
                tot:=0;
                for j:=1 to i do
                    if i mod j=0 then inc(tot);
                if tot=8 then inc(ans);
            end;
    writeln(ans);
end.

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

ll gcd(ll x, ll y){
	if(y == 0) return x;
	else gcd(y, x%y);
}

vector<pair<ll, int>> factorize(ll n){
	vector<pair<ll, int>> res;
	for(ll i=2; i*i <= n; ++i){
		if(n%i) continue;
		res.emplace_back(i,0);
		while(n%i == 0){
			n /= i;
			res.back().second++;
		}
	}
	if(n != 1) res.emplace_back(n, 1);
	return res;

}

int main(void){

	ll a, b; cin >> a >> b;
	ll g = gcd(a, b);
	
	auto f = factorize(g);
	int ans = f.size() + 1;
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[100000];
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }

    int count=0;
    
    for(int i=0;i<n;i++){
        if((double)a[i]<sum*1.0/(4*(double)m)){
           
        }else{
          count++;
        }
    }

    if(count>=m){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n[]={0,1,2,1,3,1,3,1,1,3,1,3,1};
main(){
	int a,b,c;
	cin>>a;
	cout<<"ABC"<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,h;
    cin >> n >> h;
    VI a(n), b(n);
    REP(i,0,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    reverse(all(a));
    reverse(all(b));
    int index = 0;
    int cnt = 0;
    while (h > 0 && b[index] > a[0]) {
        h -= b[index];
        ++index;
        ++cnt;
    }
    if (h > 0) {
        cnt += (h + a[0] - 1) / a[0];
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 1024
from collections import deque

N=int(input())

G=[[] for _ in range(N+1)]

for _ in range(N-1):
  a,b=map(int,input().split())
  G[a].append(b)
  G[b].append(a)

c=list(map(int,input().split()))
c.sort(reverse=True)

ans=0 
used=[0]*(N+1)
number=[0]*(N+1)
que=deque([1])

ccount=0
while que:
  v=que.popleft()
  if number[v]==0:
    number[v]=c[ccount]
    ccount+=1
  for e in G[v]:
    if used[e]:
      continue
    if number[e]==0:
      number[e]=c[ccount]
      ccount+=1
    ans+=min(number[v],number[e])
    que.append(e)
    used[v]=1
print(ans)
print(*number[1:])

Measured memory_bytes: 6296
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int n = scan.nextInt();
        int[] a = new int[n];
        int max = 0;
        int b = 0;
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        for(int i = 1; i < n; i++){
            if(a[i] - a[i - 1] > max){
                max = a[i] - a[i - 1];
                b = i;
            }
        }
        int out = Math.abs(k - a[b]) + a[b - 1];
        if(k - a[n - 1] + a[0] > max){
            out = a[n - 1] - a[0];
        }
        System.out.println(out);
    }
}

Measured memory_bytes: 66848
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    cout << (n - 1) / 2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> h(110000);
    rep(i,n) cin >> h[i];

    ll dp[110000];
    rep(i,n) dp[i] = INF;

    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= k; ++j){
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      int tmp = N - ((i * R) + (j * G));
      if (tmp < 0) continue;
      if (tmp % B == 0) {
	//cout << i << j << endl;
	ans++;
      }
    }
  }

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


Measured memory_bytes: 3616
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0); //cin.tie(0) bei schnellem Wechseln

	ll a, b, c;

	cin >> a >> b >> c;
	cout << max(c-(a-b), 0ll);
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();
        if (b - a <= 1) {
            System.out.println(k + 1);
        } else {
            long n = a;
            n += (long) (k + 1 - a) / 2 * (b - a);
            n += (long) (k + 1 - a) % 2;
            System.out.println(n);
        }
    }
}


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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 2e5 + 5;

class SegmentTree {
public:
	int N;
	vector<ll> minimum, delta;

	SegmentTree() {}

	SegmentTree(int N) {
		this->N = N;
		minimum = vector<ll>(4 * N + 1);
		delta = vector<ll>(4 * N + 1);
	}
	
	void update(int l, int r, ll val) {update(1, 0, N - 1, l, r, val);} //inclusive range
	
	ll query(int l, int r) {return query(1, 0, N - 1, l, r);} //inclusive range
	
	void push(int i) {
		delta[2 * i] += delta[i];
		delta[2 * i + 1] += delta[i];
		delta[i] = 0;
	}

	void pull(int i) {
		minimum[i] = min(minimum[2 * i] + delta[2 * i], minimum[2 * i + 1] + delta[2 * i + 1]);
	}
	
	void update(int i, int lo, int hi, int l, int r, ll val) {
		if (r < lo || hi < l) return;
		if (l <= lo && hi <= r) {
			delta[i] += val;
			return;
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		update(2 * i, lo, m, l, r, val);
		update(2 * i + 1, m + 1, hi, l, r, val);
		
		pull(i);
	}
	
	ll query(int i, int lo, int hi, int l, int r) {
		if (r < lo || hi < l) return (1 << 29);
		if (l <= lo && hi <= r) {
			return minimum[i] + delta[i];
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		ll minLeft = query(2 * i, lo, m, l, r);
		ll minRight = query(2 * i + 1, m + 1, hi, l, r);
		
		pull(i);
		
		return min(minLeft, minRight);
	}
};

int N, M;
vector<pi> intervals[MAX_N];
SegmentTree st(MAX_N);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> M;
	ll sum = 0;
	for (int i = 0; i < M; ++i) {
		int l, r, a; cin >> l >> r >> a;
		intervals[r].push_back({l, a});
		sum += a;
	}

	for (int i = 1; i <= N + 1; ++i) {
		for (pi seg: intervals[i - 1]) {
			st.update(0, seg.ff - 1, seg.ss);
		}
		st.update(i, i, st.query(0, i - 1));
	}

	cout << sum - st.query(0, N + 1) << '\n';

	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef pair<int,int>  pi;

struct Edge { int to, cost; };
vector<Edge> G[3000];
int d[3000];

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		fill(G, G+3000, vector<Edge>());
		int a, b, c;
		for (int i=0; i<m; ++i) {
			cin >> a >> b >> c;
			--a, --b;
			G[a].push_back((Edge){b, c});
			G[b].push_back((Edge){a, c});
			G[a].push_back((Edge){b+1000, 0});
			G[b].push_back((Edge){a+1000, 0});
			G[a+1000].push_back((Edge){b+2000, 0});
			G[b+1000].push_back((Edge){a+2000, 0});
			G[a+2000].push_back((Edge){b+2000, c});
			G[b+2000].push_back((Edge){a+2000, c});
		}
		fill(d, d+3000, INT_MAX);
		d[0] = 0;
		priority_queue<pi, vector<pi>, greater<pi> > q;
		q.push(make_pair(0, 0));
		while ( ! q.empty()) {
			int dist = q.top().first;
			int v = q.top().second;
			q.pop();
			for (int i=0; i<(int)G[v].size(); ++i) {
				Edge &e = G[v][i];
				if (dist + e.cost < d[e.to]) {
					d[e.to] = dist + e.cost;
					q.push(make_pair(d[e.to], e.to));
				}
			}
		}
		cout << min(d[n-1], d[n-1+2000]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
const int maxN = 2005;
int c[2 * maxN][2 * maxN];
int n, k;
int dp[maxN][maxN];
int pref[maxN][maxN];
int main() {
    srand(time(0));
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    c[0][0] = 1;
    for (int i = 1; i < 2 * maxN; i++) {
        c[i][0] = 1;
        for (int j = 1; j < 2 * maxN; j++) {
            c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]);
        }
    }
    cin >> k >> n;
    dp[0][0] = 1;
    for (int cnt = 0; cnt <= n; cnt++) {
        pref[0][cnt] = 1;
    }
    for (int parts = 1; parts <= k; parts++) {
        for (int cnt = 0; cnt <= n; cnt++) {
            dp[parts][cnt] = mult(2, pref[parts - 1][cnt]);
            dp[parts][cnt] = sub(dp[parts][cnt], dp[parts - 1][cnt]);
        }
        pref[parts][0] = dp[parts][0];
        for (int cnt = 1; cnt <= n; cnt++) {
            pref[parts][cnt] = sum(dp[parts][cnt], pref[parts][cnt - 1]);
        }
    }
    for (int i = 2; i <= 2 * k; i++) {
        int f = 0;
        if (i % 2 == 0) f = 1;
        int t = 0;
        for (int j = 1; 2 * j < i; j++) {
            if (i - j >= 1 && i - j <= k) t++;
        }
        int left = k - 2 * t - f;
        int ans = 0;
        //cout << f << " " << t << endl;
        for (int i1 = 0; i1 <= f; i1++) {
            for (int take = 0; take <= n - i1; take++) {
                int will = n - take - i1;
                if (left != 0) ans = sum(ans, mult(dp[t][take], c[will + left - 1][will]));
                else if (will == 0) ans = sum(ans, dp[t][take]);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 94464
#include<stdio.h>
int main(void){

	int x1,y1,x2,y2,x3,y3,x4,y4;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	
	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	
	x4 = x3 - (y3 - y2);
	y4 = y3 + (x3 - x2);
	
	printf("%d %d %d %d",x3,y3,x4,y4);
	
	return 0;

}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
cnt = [0]*int(1e5)
ans = 0
for i in range(n) :
  cnt[a[i]] += 1
for i in range(1, len(cnt)-1) :
  ans = max(ans, cnt[i-1] + cnt[i] + cnt[i+1])
print(ans)

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

int main() {
  string S;
  cin >> S;
  regex re("A[a-z]+C[a-z]+$");
  smatch m;

  if(regex_search(S, m, re)) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int n, m, k, rest;
vi a, b, a_sum, b_sum;
bool isOK(int index, int key){
	if(key >= b_sum[index]) return true;
	else return false;
}

int nibutan(int key){
	int ng = m+1;
	int ok = -1;
	while(abs(ok - ng) > 1){
		int mid = (ok + ng) / 2;
		if(isOK(mid, key)) ok = mid;
		else ng = mid;
	}
	return ok /*=条件を満たすギリギリを返す*/;
    /* 満たさないものを求めるときは1を加減算する */
}

signed main(){
    int ans = 0;
    cin >> n >> m >> k;
    a.resize(n);
    b.resize(m);
    a_sum.resize(n+1);
    b_sum.resize(m+1);
    rep(i, n){
        cin >> a[i];
        a_sum[i+1] = a[i] + a_sum[i];
    }
    /* rep(i, n) cin >> a[i]; */
    rep(i, m){
        cin >> b[i];
        b_sum[i+1] = b[i] + b_sum[i];
    }

    // aをi冊読む
    rep(i, n+1){
        if(a_sum[i] > k) continue;
        rest = k - a_sum[i];
        /* cout << i << " " << nibutan(rest) << endl; */
        chmax(ans, nibutan(rest) + i);
    }

    cout << ans << endl;
}

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

int N, M;
const int MAX_M = 1.0e5 + 100;
int x[MAX_M], y[MAX_M]; 

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
    }

    int ball[N+1];
    bool red[N+1];
    ball[1] = 1;
    red[1] = true;
    for (int i = 2; i <= N; i++) {
        ball[i] = 1.0;
        red[i] = false;
    }

    for (int i = 0; i < M; i++) {
        if (red[x[i]]) {
            red[y[i]] = true;
        }
        ball[y[i]]++;
        ball[x[i]]--;
        if (ball[x[i]] == 0) {
            red[x[i]] = false;
        }
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (red[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
const main = (input) => {
  let lines = input.split(/\n/);
  const N = lines.shift(); 
  const points = lines.slice(0,N).map(point => point.split(/\s/).map(v => +v));
  
  let min = Infinity;
  let max = -Infinity;
  let min_ = Infinity;
  let max_ = -Infinity;
  for (const point of points){
    min = Math.min(point[0] + point[1], min);
    max = Math.max(point[0] + point[1], max);
    min_ = Math.min(point[0] - point[1] , min_);
    max_ = Math.max(point[0] - point[1] , max_);
  }


  console.log(Math.max(max - min, max_ - min_));
  };
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 99292
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int a[100005];

int main(){
	int x, y;
	cin>>x>>y;
	cout<<(x+y)%24<<endl;
	return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w, m;
  cin >> h >> w >> m;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  } 
  int res = (int) 1e9;
  for (int i = 0; i < (1 << (h - 1)); i++) {
    int t = __builtin_popcount(i);
    vector<int> cnt(t + 1, 0);
    int cur = t;
    bool possible = true, split = false;
    for (int j = 0; j < w; j++) {
      int now = 0;
      for (int k = 0; k < h; k++) {
        cnt[now] += s[k][j] - '0';
        if ((1 << k) & i) {
          ++now;
        }
      }
      if (*max_element(cnt.begin(), cnt.end()) > m) {
        if (split) {
          possible = false;
          break;
        }
        --j;
        for (int& x : cnt) {
          x = 0;
        }
        ++cur;
        split = true;
        continue;
      }
      split = false;
    }
    if (possible) {
      res = min(res, cur);
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc151/tasks/abc151_c



N, M = gets.split.map(&:to_i)
hash = Hash.new { |h, key| h[key] = [] }
M.times do
  p, s = gets.split
  hash[p] << s
end

pass = 0
penalty = 0
hash.each do |q, answers|
  q_penalty = answers.index('AC')
  if q_penalty
    pass += 1
    penalty += q_penalty
  end
end
puts "#{pass} #{penalty}"


Measured memory_bytes: 27900
#include<iostream>
#include <cstdlib>

#include <algorithm>


using namespace std;

int main(){

  string s1,s2,s3;

  cin >> s1 >> s2 >> s3 ;

  cout << (char)toupper(s1[0])
          <<(char)toupper(s2[0])
            <<(char)toupper(s3[0])
              << endl;

}


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

#define pb push_back
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e6 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, p;
	cin >> n >> p;
	if(n == 1) return cout << p, 0;
	ll ans = 1;
	ll cnt;
	for(int i = 2; i <= 1000000; i++){
		cnt = 0;
		while(p % i == 0){
			p/=i;
			cnt ++;
		}
		for(int j = 0; j < cnt/n;j++) ans *= i;
	}
	cout << ans;
	return 0;
}


/*
4096 4096 4096
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int A, P;
        var input = Input.IntArray();
        A = input[0];
        P = input[1];

        Console.WriteLine(Math.Floor(((double)A * 3 + P)/2));
    }

    /** Input Class */
    internal static class Input
    {
        /** input int */
        public static int Int() => int.Parse(Console.ReadLine());

        /** input str */
        public static string Str() => Console.ReadLine();

        /** input array of int */
        public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        /** input array of char */
        public static char[] charArray() => Input.Str().ToCharArray();
    }

}

Measured memory_bytes: 13396
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(i64;;);

    let mut hfront = BinaryHeap::new();
    let mut hback = BinaryHeap::new();
    for i in 0..n {
        hfront.push(-vs[i]);
        hback.push(vs[i + 2 * n]);
    }
    let mut sfront = -hfront.iter().sum::<i64>();
    let mut sback = hback.iter().sum::<i64>();

    let mut ssfront = vec![sfront];
    let mut ssback = vec![sback];
    for i in n..2 * n {
        hfront.push(-vs[i]);
        let v = -hfront.pop().unwrap();
        sfront += vs[i] - v;
        ssfront.push(sfront);

        hback.push(vs[3 * n - i - 1]);
        let w = hback.pop().unwrap();
        sback += vs[3 * n - i - 1] - w;
        ssback.push(sback);
    }

    println!(
        "{}",
        ssfront
            .iter()
            .zip(ssback.iter().rev())
            .map(|(f, b)| f - b)
            .max()
            .unwrap()
    )
}


Measured memory_bytes: 14580
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**10
dp = [inf]*(n)
dp[0]=0
for i in range(n-1):
    for j in range(1, k+1):
        if i+j > n-1:
            break
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
        
print(dp[n-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

void dfs(const vector<vector<int>>& ki, vector<ll>& counter, const int& p, const int& pp) {
  for (auto& c : ki[p]) {
    if (c == pp) continue;
    counter[c] += counter[p];
    dfs(ki, counter, c, p);
  }
}

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

  int n, q;
  cin >> n >> q;
  vector<vector<int>> ki(n);
  rep(i, n-1) {
    int a, b; cin >> a >> b; a--; b--;
    ki[a].push_back(b);
    ki[b].push_back(a);
  }

  vector<ll> counter(n, 0);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    counter[p] += x;
  }

  dfs(ki, counter, 0, -1);

  for (auto& x : counter) cout << x << " "; cout << endl;

  return 0;
}


Measured memory_bytes: 28176
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,a[88][88],b[88][88];
bool dp[88][88][20005];

int main(){
	cin >> n >> m;
	repn(i,n)repn(j,m) cin>>a[i][j];
	repn(i,n)repn(j,m) cin>>b[i][j];
	dp[1][0][10000] = dp[0][1][10000] = 1;
	repn(i,n)repn(j,m)rep(k,20005){
		if(dp[i-1][j][k]&&k+a[i][j]-b[i][j]>=0&&k+a[i][j]-b[i][j]<20005)dp[i][j][k+a[i][j]-b[i][j]]=1;
		if(dp[i-1][j][k]&&k+b[i][j]-a[i][j]>=0&&k+b[i][j]-a[i][j]<20005)dp[i][j][k+b[i][j]-a[i][j]]=1;
		if(dp[i][j-1][k]&&k+a[i][j]-b[i][j]>=0&&k+a[i][j]-b[i][j]<20005)dp[i][j][k+a[i][j]-b[i][j]]=1;
		if(dp[i][j-1][k]&&k+b[i][j]-a[i][j]>=0&&k+b[i][j]-a[i][j]<20005)dp[i][j][k+b[i][j]-a[i][j]]=1;
	}
	int ans = INF;
	rep(j,20005) if(dp[n][m][j]) ans = min(ans,abs(j-10000)); cout<<ans<<endl;}

Measured memory_bytes: 137728
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll H, W;
    int r1, c1, r2, c2;

    cin >> H >> W;

    if (H ==1 || W == 1) {
        cout << 1;
    } else {
        cout << (H*W+1)/2;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
int h[N];
vi g[N];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	REP(i, n) scanf("%d", h+i+1);
	REP(i, m){
		int a, b; scanf("%d%d", &a, &b);
		g[a].EB(b);
		g[b].EB(a);
	}
	int ans = 0;
	FOR(i, 1, n+1){
		bool ok = true;
		for(int j : g[i]) if(h[i] <= h[j]) ok = false;
		ans += ok;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 9632
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
A, B, C = map(int, input().split())
# 文字列の入力
K = int(input())
# 出力
#print("{} {}".format(a+b+c, s))

print("{}".format(A + B + C + max(A, B, C) * ( 2 ** K - 1)))



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M,X;
    cin >> N >>M>>X;
    vector<int>vec(M);
    for(int i=0;i<M;i++){
        cin >>vec.at(i);
    }
    int B=0,Y=0;
    for(int i=0;i<M;i++){
        if(vec.at(i)<X){
            B++;
        }
        else if(vec.at(i)>X){
            Y++;
        }
    }
    cout <<min(B,Y)<<endl;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  int a[n], res = 1e9;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n - k + 1; i++){
    int l = i, r = i + k - 1;
    res = min(res, min(abs(a[l]) + abs(a[r] - a[l]), abs(a[r]) + abs(a[r] - a[l])));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <climits>
#include <cstring>
using namespace std;
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; }
vector<int> a;
vector<bool> isok;
int mod = 1000000007;
int main(void){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    vector<int> dp(101000);
    for(int i = 0;i < 101000;i++) dp[i] = INT_MAX;
    
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 0;i < n;i++){
        for(int j = 1;j <= k;j++){
            chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  ll K; scanf("%lld", &K);
  vector<ll> freqs(1e5 + 5, 0);
  ll a, b;
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &a, &b);
    freqs[a] += b;
  }
  ll cnt = 0;
  int ans = -1;
  for (int i = 0; i <= (int)1e5; ++i) {
    if (cnt + freqs[i] >= K) {
      ans = i;
      break;
    }
    cnt += freqs[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024