akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define N 100000

long long n;
int a[N];

int a_sort[N];
int b[N];
int s[N];

class BIT {
	int m;
	vector<int> bit;

public:
	BIT( int n )
	{
		m = n;
		bit.resize(m + 1);
		fill( bit.begin(), bit.end(), 0 );
	}

	int sum( int i )
	{
		int s = 0;
		while( i > 0 ) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add( int i, int x )
	{
		while( i <= m ) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

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

	sort( a_sort, a_sort + n );
	int lb = 0, ub = n;
	while( ub - lb > 1 ) {
		int x = ( lb + ub ) / 2;
		for( int i = 0; i < n; i++ ) {
			b[i] = ( a[i] < a_sort[x] ) ? -1 : 1;
		}
		for( int i = 0; i < n; i++ ) {
			s[i] = ( i == 0 ) ? b[i] : s[i - 1] + b[i];
		}
		long long cnt = 0;
		BIT bit( 2 * n + 1 );
		bit.add( n, 1 );
		for(int i = 0; i < n; i++ ) {
			cnt += bit.sum( s[i] + n );
			bit.add( s[i] + n, 1 );
		}
		if( cnt * 2 * 2 >= n * (n + 1) ) {
			lb = x;
		}
		else {
			ub = x;
		}
	}
	int ans = a_sort[ lb ];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2572
package main

import (
	"fmt"
	"math"
)

func max(a, b int) int {
	m := float64(a + b)
	n := float64(a - b)
	l := float64(a * b)

	res := math.Max(m, n)
	res = math.Max(res, l)

	return int(res)
}

func main() {
	var a, b int
	fmt.Scanln(&a, &b)

	fmt.Println(max(a, b))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax=200010;
//ll a[Nmax];

int main() {
	int A,B,C,K,flag=0;
	cin >> A >> B >> C >> K;
	int max = A;
	if(max < B){max = B;flag=1;}
	if(max < C){max = C;flag=2;}
	max *= pow(2,K);
	if(flag==0) cout << max+B+C << endl;
	if(flag==1) cout << A+max+C << endl;
	if(flag==2) cout << A+B+max << endl;
	return 0;
}

Measured memory_bytes: 256
/*
Look at the star
Look at the shine for U
*/ 

#include<bits/stdc++.h>
#define sl(x) scanf("%lld",&x)
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
ll s[N];

int main()
{
	int i,j,k;
	for(i = 0;i < 3;i++)
	sl(s[i]);
	
	sort(s,s+3);
	ll sum = 0;
	for(i = 1;i < 3;i++)
	sum += (s[i]-s[i-1]);
	
	cout<<sum<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	dic := map[int]int{}
	for range make([]struct{}, n) {
		var a, b int
		fmt.Scan(&a, &b)
		dic[a] += b
	}

	seq := []int{}
	for key := range dic {
		seq = append(seq, key)
	}
	sort.Ints(seq)

	var ans int
	for k > 0 {
		ans = seq[0]
		k -= dic[seq[0]]
		seq = seq[1:]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#define XOX
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define int long long

signed main()
{
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d > k) {
        cout << x - d * k << "\n";
        return 0;
    }
    int pos = x - (x / d) * d;
    int neg = abs(x - (x / d + 1) * d);
    k -= x / d;
    if (k%2 == 0) cout << pos << "\n";
    else cout << neg << "\n";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> H;
  vector<int> W;
  int cnt = 0, tmpH, tmpW;
  REP(i, 1e6){
    cin >> tmpH >> tmpW;
    if(tmpH == 0 && tmpW == 0){
      cnt = i;
      break;
    }
    H.push_back(tmpH);
    W.push_back(tmpW);
  }

  REP(i, cnt){
    REP(j, H.at(i)){
      REP(k, W.at(i)){
        if((j+k)%2 == 0){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3172
<?php
    $min = 10;
    for ($i=0; $i < 5; $i++) { 
        fscanf(STDIN, "%d", $N[$i]);
        $nowmin = $N[$i]%10;
        if ($min > $nowmin && $nowmin != 0) {
            $min = $nowmin;
        }
        if ($nowmin == 0) {
            $result += $N[$i];
        }else{
            $result += $N[$i] + 10 - $nowmin;
        }
    }
    $result = $result - 10 + $min;


    echo $result;


Measured memory_bytes: 4728
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
w=list(input())
w.sort()
w=groupby(w)
for i in w:
    if i[1]%2==1:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 9040
n = int(input())

arr = map(int,raw_input().split())

sums = [0 for i in range(n)]

for i in range(n):
	sums[arr[i]] += 1


isprinted = False
mod = 1000000007
if n%2 == 1:
	if sums[0] == 1:
		for i in range(2,n,2):
			if sums[i] != 2:
				print 0
				isprinted = True
				break

		if not isprinted :
			print 2**((n-1)/2)%mod
	else :
		print 0

else :
	for i in range(1,n,2):
		if sums[i] != 2:
			print 0
			isprinted = True
			break

	if not isprinted:
		print 2**(n/2)%mod

Measured memory_bytes: 11328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
const ll mod = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int s; cin>>s;
    int mae=s/100;
    int ato=s%100;
    if(1<=mae&&mae<=12&&1<=ato&&ato<=12){
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    if(1<=mae&&mae<=12&&(ato==0||ato>=13)){
        cout<<"MMYY"<<endl;
        return 0;
    }
    if(1<=ato&&ato<=12&&(mae==0||mae>=13)){
        cout<<"YYMM"<<endl;
        return 0;
    }
    if((ato==0||ato>=13)&&(mae==0||mae>=13)){
        cout<<"NA"<<endl;
        return 0;
    }
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cout<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define f(x,y) g[(x)][(y)+52]
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=105,mod=1e9+7;
int g[N][N],C[N][N],n;

int fix(int x){
	return x>=mod?x-mod:x;
}

int main(){
	read(n);
	C[0][0]=1;
	rep(i,1,n){
		C[i][0]=1;
		rep(j,1,i)
			C[i][j]=fix(C[i-1][j-1]+C[i-1][j]);
	}
	f(1,0)=f(1,-1)=1;
	rep(i,1,n-1)rep(j,-i,i)
		if(f(i,j)){
			rep(a,0,n-i)rep(b,!a,n-i-a)
				if(a+b>=abs(j)&&(a+b+j)%2==0)
					f(i+a+b,(a-b+j)/2)=(f(i+a+b,(a-b+j)/2)
						+(ll)C[i+a+b][a+b]*C[a+b][b]%mod*f(i,j))%mod;
		}
	cout<<f(n,0)<<endl;
	return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    if (l >= 0) {
        cout << l * (n-1) + n * (n-1) / 2 << endl;
    }
    else if (l + n - 1 < 0) {
        cout << l * (n-1) + (n-1) * (n-2) / 2 << endl;
    }
    else {
        cout << l * n + n * (n-1) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	long int i, j;
	long int a;
	long int max;
	long int count;
	long int work;
	char str[100];
	
	scanf("%ld%s", &a, str);
	
	
	if(a >= 3200) {
		printf("%s\n", str);
	} else {
		printf("red\n");
	}
	
	return 0;
}


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

int main ()
{
    int a, b;
    char c;
    do
    {
        cin >> a >> c >> b;
        switch(c)
        {
            case '+': cout << a+b << endl; break;
            case '-': cout << a-b << endl; break;
            case '*': cout << a*b << endl; break;
            case '/': cout << a/b << endl; break;
            case '?': break;
        }
    }while(c != '?');
    
    
    return 0;
}


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

int main(){
    int n, tt; cin >> n >> tt;
    vector<int> c(n), t(n);
    rep(i,n) cin >> c[i] >> t[i];

    int index = -1, minc = 1e9;
    for(int i = 0; i < n; i++){
        if(c[i] <= minc && t[i] <= tt){
            minc = c[i];
            index = i;
        }
    }
    if(index < 0) put("TLE");
    else put(c[index]);
}

Measured memory_bytes: 256
N = int(input())
N_List = list(map(int,input().split()))
S = sum(N_List)
a = S
b = 0
sa = S
for i in range(N):
    if abs((a - N_List[i]) - (b + N_List[i])) < sa:
        a -= N_List[i]
        b += N_List[i]
        sa = abs(a-b)
    else:
        break

print(sa)
    

Measured memory_bytes: 9112
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int top = 0;
int A[1000];
void push(int);
int pop(void);

int main(){
  int x,y,p;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if(*s < 48 || *s > 57){
      s[0] = *s;
    }
    if ( s[0] == '+' ){
      x = pop();
      y = pop();
      push(x + y);
    } else if ( s[0] == '-' ){
      y = pop();
      x = pop();
      push  (x - y);
    } else if ( s[0] == '*' ){

      x = pop();
      y = pop();
      push  (x * y);
    } else {
      push(atoi(s));
    }

    
  }

  printf("%d\n",pop());
    
  return 0;
}




void push(int h){
  A[++top] = h;
}

int pop(){
  top--;
  return A[top+1];
}



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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (auto &e: d) cin >> e;
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        
        int i, j;
        for(i=0; i<=n; i++){
            for(j=0; j<=n-i; j++){
                if(i*1000 + j*5000 + (n-i-j)*10000 == y){
                    System.out.print(n-i-j + " " + j + " " + i);
                    return;
                }
            }
        }
        
        System.out.print("-1 -1 -1");
	}
}

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

typedef long long ll;

typedef struct{
    ll value;
    ll idi;
    ll idj;
    ll idk;
}cake;

bool operator< (const cake ck1, const cake ck2){
    return ck1.value < ck2.value;
}
bool operator> (const cake ck1, const cake ck2){
    return ck1.value > ck2.value;
}

int main(){
    ll X,Y,Z,K; cin >> X >> Y >> Z >> K;

    ll a[X],b[Y],c[Z];
    for(int i=0;i<X;i++) cin >> a[i];
    for(int i=0;i<Y;i++) cin >> b[i];
    for(int i=0;i<Z;i++) cin >> c[i];

    sort(a,a+X,greater<ll>());
    sort(b,b+Y,greater<ll>());
    sort(c,c+Z,greater<ll>());

    priority_queue<cake> que;
    set<tuple<int,int,int>> s;

    que.push(cake{a[0]+b[0]+c[0],0,0,0});
    s.insert(make_tuple(0,0,0));
    for(int i=0;i<K;i++){
        cake tmp=que.top(); que.pop();
        cout << tmp.value << endl;
        int x=tmp.idi; int y=tmp.idj; int z=tmp.idk;
        if(x+1<X&&!s.count(make_tuple(x+1,y,z))){
            que.push(cake{a[x+1]+b[y]+c[z],x+1,y,z});
            s.insert(make_tuple(x+1,y,z));
        }
        if(y+1<Y&&!s.count(make_tuple(x,y+1,z))){
            que.push(cake{a[x]+b[y+1]+c[z],x,y+1,z});
            s.insert(make_tuple(x,y+1,z));
        }
        if(z+1<Z&&!s.count(make_tuple(x,y,z+1))){
            que.push(cake{a[x]+b[y]+c[z+1],x,y,z+1});
            s.insert(make_tuple(x,y,z+1));
        } 
    }
}

Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


int main()
{
	string s;
	cin >> s;
	Vi c(26, 0);

	REP(i, 4)
		c[s[i] - 'A']++;

	REP(i, 26)
		if (c[i] && c[i] != 2)
		{
			No(); return 0;
		}
	Yes();
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  string s, t;
  long A, B;
  string u;
  scanln(s, t);
  scanln(A, B);
  scanln(u);
  if (u == s) {
    writeln(A-1, " ", B);
  } else {
    writeln(A, " ", B-1);
  }
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep);

  string line = readln.chomp;
  static if (__VERSION__ >= 2074) {
    line.formattedRead!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "line.formattedRead(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	
	int n,l;
	string s[111];
	cin>>n>>l;
	for(int i=0;i<n;i++)cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++)cout<<s[i];
	cout<<endl;
	
}

Measured memory_bytes: 256
import re
S = input()
if 'B' in S:
	A = re.split("01BB|10BB|11BB|00BB|0B|1B",S)
	A = "".join(A)
	if 'B' in A:
		C = re.split("01BB|10BB|11BB|00BB|0B|1B",A)
		C = "".join(C)
		C = C.split("B")
		print("".join(C))
	else:
		print(A)
else:
	print(S)

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] color = new int[N];
        for (int i = 0; i < N; i++) {
            color[i] = scan.nextInt();
        }
        System.out.println(solve(N, color));
    }
    public static int solve(int N, int[] color) {
        int answer = 0;
        for (int i = 1; i < N; i++) {
            if (color[i-1] == color[i]) {
                answer++;
                if (i + 1 < N) {
                    color[i] = color[i+1]+1;
                }
            }
        }
        return answer;
    }
}


Measured memory_bytes: 23892
#include <stdio.h>
#include <math.h>

int main()
{
long long N;
long long A;
long long even;
long long odd;
long long i;
  scanf("%d",&N);
  even=0;
  for(i=0; i<N; i++)
  {
    scanf("%d",&A);
    if ( (A%2)==0 ) even++;
  }
  odd=N-even;
  if( (odd%2)==0)                                                       
  {
       printf("YES");
  }else{
       printf("NO");
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
 
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        if(n<1200){
            System.out.print("ABC");
        }
        else{
            System.out.print("ARC");
        }
 
        
        sc.close();
    }
 
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> out;
  if(n > m){
    for(int i = 0;i < n; i++) out.push_back(m);
  }else{
    for(int i = 0; i < m; i++) out.push_back(n);
  }
  for(int i =0; i < out.size(); i++) cout << out.at(i);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long ans=1010101010101010ll;
long long n,s;
void jud(long long b)
{
	if(b<=1)
		return;
	long long nn=n,ss=0;
	while(nn)
	{
		ss+=(nn%b);
		nn/=b;
	}
	if(ss==s)
		ans=min(ans,b);
}
int main()
{
	scanf("%lld%lld",&n,&s);
	for(long long i=1;i*i<=n;i++)
	{
		jud(i);
		jud((n-s+i)/i);
	}
	jud(n+1);
	if(ans==1010101010101010ll)
		ans=-1;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
arr=list(map(int,input().split()))
imos1=[0]*(m*2+2)
imos2=[0]*(m*2+2)
imos3=[0]*(m*2+2)
for i in range(n-1):
  cost=(m+arr[i+1]-arr[i])%m
  if arr[i]<arr[i+1]:
    imos1[arr[i]]+=cost
    imos1[arr[i]+m]-=cost
    imos2[arr[i]+2]+=-1
    imos2[arr[i+1]+1]+=1
    imos3[arr[i+1]+1]+=cost-1
  else:
    imos1[arr[i]]+=cost
    imos1[arr[i]+m]-=cost
    imos2[arr[i]+2]+=-1
    imos2[arr[i+1]+m+1]+=1
    imos3[arr[i+1]+m+1]+=cost-1
for i in range(1,m*2+2):
  imos2[i]+=imos2[i-1]
for i in range(m*2+2):
  imos1[i]+=imos2[i]
  imos1[i]+=imos3[i]
for i in range(1,m*2+2):
  imos1[i]+=imos1[i-1]
xs=[0]*(m+1)
xs[0]=10**18
for i in range(1,m+1):
  xs[i]=imos1[i]+imos1[m+i]
print(min(xs))

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

using namespace std;

int N;
vector<int> G[100005];

int dfs(int v)
{
	if(G[v].size() == 0) return 0;
	vector<int> dep;
	for(int i = 0; i < G[v].size(); i++){
		dep.push_back(dfs(G[v][i]));
	}
	sort(dep.begin(), dep.end());
	reverse(dep.begin(), dep.end());
	
	int ret = 0;
	for(int i = 0; i < dep.size(); i++){
		ret = max(ret, dep[i]+i);
	}
	return ret + 1;
}

int main(void)
{
	cin >> N;
	int a;
	for(int i = 2; i <= N; i++){
		cin >> a;
		G[a].push_back(i);
	}
	
	cout << dfs(1) << endl;
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
static const int INF = 2147483647;
static const int NIL = -1;
static const int MOD = 1000000007;
typedef long long ll;
typedef pair<int,int> P;
//#define int ll 

static const int MAX_N = 114514;
P info[MAX_N];

signed main(){
    int n;
    scanf("%d",&n);
    
    int tmp1,tmp2;
    for(int i=1;i<n+1;i++){
        scanf("%d %d",&tmp1,&tmp2);
        info[i].first = tmp1;
        info[i].second = tmp2;
    }
    
    sort(info+1,info+n+1);
    info[0].first = 0;
    info[0].second = INF;
    info[n+1].first = INF;
    info[n+1].second = -1;

    /*for(int i=0;i<=n+1;i++){
        printf("%d %d\n",info[i].first,info[i].second);
    }*/
    
    int ans=n;
    for(int i=0;i<=n;i++){
        ans += min(info[i+1].first-info[i].first,info[i].second-info[i+1].second)-1;
    }

    printf("%d\n",ans);

    return 0;
}

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

int main() {
	
	string s, t; cin >> s >> t;
	if (t.substr(0, t.size() - 1) == s) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3624
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


// ========== main() ==========================================================

fn main() {
    input!{
        x: usize, y: usize,
    }

    let mut count = 0;
    let mut s = x;
    while s <= y {
        count += 1;
        s *= 2;
    }
    println!("{}", count);
}

// ========== 以下使い捨て関数 ===================================================

// ========== 以下作り置き関数 ===================================================

pub use std::io::*;
pub use std::process;
pub use std::str::FromStr;

// 10^9 + 7 で割ったあまりを出力してください
pub const MOD: i64 = 1_000_000_007;

/// 標準入力から
/// 空白文字で囲まれた1つのトークンを
/// 指定の型に変換する
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

/// 標準入力から1行読み取り
/// 空白文字で区切って
/// 指定の型のVecに格納する
pub fn read_vec<T: FromStr>() -> Vec<T> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

/// プログラムを終了
pub fn exit() {
    process::exit(0)
}

// Rustの言語アップデートありがたいです
// 頑張ってください！


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	string ans="";
	ll n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	for(ll i=0;i<n;i++)
	{
		ans+=s[i];
		ans+=t[i];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import heapq
def resolve():
    N,=pin()
    A=[*pin()]
    A.sort(reverse=True)

    ans=0
    h=[]
    heapq.heappush(h,0)
    for i in range(1,N):
        temp=heapq.heappop(h)
    #    print(temp)
        ans+=A[temp]
        heapq.heappush(h,i)
        heapq.heappush(h,i)
    print(ans)

#%%submit!
resolve()

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

string s,t;

int main() {
	cin >> s >> t;
	for (int i = 0; i < s.size() - 1; i++) {
		for (int j = i + 1; j < s.size(); j++) {
			if (s[i] > s[j]) swap(s[i], s[j]);
		}
	}

	for (int i = 0; i < t.size() - 1; i++) {
		for (int j = i + 1; j < t.size(); j++) {
			if (t[i] < t[j]) swap(t[i], t[j]);
		}
	}

	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define lp( i, L, U ) for(int i=(int)L ; i<=(int)U ; i++ )
#define rlp( i, U, L ) for(int i=(int)U ; i>=(int)L ; i-- )
#define SQR(x) ((x)*(x))
#define nl "\n"
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Max3(a,b,c)           max(a,max(b,c))
#define Min3(a,b,c)           min(a,min(b,c))
#define pb push_back
#define mkp make_pair

#define INF INT_MAX


#define READ(filename)  freopen(filename, "r", stdin);
#define WRITE(filename)  freopen(filename, "w", stdout);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<vector<int> > vvc;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;
typedef map<string, char> msc;

int main()
{
    string s; cin >> s;
    bool ok = false;
    for(int i=0; s[i]; ++i) if(s[i]=='7') {ok = true; break;}
    if(ok) cout << "Yes" << nl;
    else cout << "No" << nl;
    return 0;
}



Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
	int n, i, a[1001];
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n; i++)
	{
		if (a[i] % 2 == 0)
		{
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				printf("DENIED");
				return 0;
			}
		}
	}
	printf("APPROVED");
	return 0;
}

Measured memory_bytes: 128
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test int t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b) {
	return (a.second < b.second) ;
}

ll binpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b&1) res = res * a;
		a = a*a;
		b = b >> 1;
	}

	return res;
}


/*
BHAI EFFORT DAAL
*/


int main(){
	ItsFUN;

	ll n; cin >> n;
	ll ans = 0;


	for(ll i = 1 ; i < n; ++i) {
		for(ll j = 1; i*j < n; ++j) ++ans;
	}


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




Measured memory_bytes: 3512
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;
ll a[N];
ll sum;
ll ans[N];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    ll n;
    cin >>n;
    a[0]=a[n+1]=0;
    for(int i=1;i<=n;i++)   cin >> a[i];
    for(int i=1;i<=n+1;i++)   sum+=abs(a[i]-a[i-1]);
//    cout << sum<<endl;
    for(int i=1;i<=n;i++){
        ans[i]=sum;
        ans[i]-=abs(a[i]-a[i+1]);
        ans[i]-=abs(a[i]-a[i-1]);
        ans[i]+=abs(a[i+1]-a[i-1]);
    }
    for(int i=1;i<=n;i++)   cout <<ans[i]<<endl;

    return 0;
}


Measured memory_bytes: 2816
def solve(n, m, A, BC):
    # https://atcoder.jp/contests/abc127/tasks/abc127_d
    A.sort()
    BC.sort(key=lambda bc: -bc[1])
    i = 0
    finished = False
    for b, c in BC:
        for j in range(b):
            if i + j >= n:
                finished = True
                break
            if A[i + j] < c:
                A[i + j] = c
            else:
                finished = True
                break
        if finished:
            break
        i += b
    return sum(A)

_n, _m = map(int, input().split())
_A = list(map(int, input().split()))
_BC = [list(map(int, input().split())) for _ in range(_m)]
print(solve(_n, _m, _A, _BC))

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

int X, Y, Z, K;
long int A[1000], B[1000], C[1000];

int main(){
    cin >> X >> Y >> Z >> K;

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

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

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

    vector<long int> sum_ab;
    sum_ab.reserve(X * Y);

    for(int i = 0; i < X; i++){
        long int a = A[i];
        for(int j = 0; j < Y; j++){
            sum_ab.emplace_back(a + B[j]);
        }
    }

    sort(sum_ab.begin(), sum_ab.end(), greater<long int>());
    vector<long int> sum_abc;
  	sum_abc.reserve(K * Z);

    for(int i = 0; i < min(K, X * Y); i++){
        long int ab = sum_ab[i];
        for(int j = 0; j < Z; j++){
            sum_abc.emplace_back(ab + C[j]);
        }
    }

    sort(sum_abc.begin(), sum_abc.end(), greater<long int>());

    for(int i = 0; i < K; i++){
        cout << sum_abc[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	string S;
	cin >> S;
	int cou = 0;
	int ans = 0;
	rep(i,S.size()){
		if(S[i] == 'B') cou++;
		else ans += cou;
	}
	cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int dice[6];
int dir = 0;

class Dice{
public:
	//(front,back,up,down,right,left) = (1,3,5,0,2,4)
	int dat[6];

	void front(){
		int tmp = dat[0];
		dat[0] = dat[1];
		dat[1] = dat[5];
		dat[5] = dat[3];
		dat[3] = tmp;
	}
	void back(){
		int tmp = dat[0];
		dat[0] = dat[3];
		dat[3] = dat[5];
		dat[5] = dat[1];
		dat[1] = tmp;
	}
	void right(){
		int tmp = dat[0];
		dat[0] = dat[2];
		dat[2] = dat[5];
		dat[5] = dat[4];
		dat[4] = tmp;
	}
	void left(){
		int tmp = dat[0];
		dat[0] = dat[4];
		dat[4] = dat[5];
		dat[5] = dat[2];
		dat[2] = tmp;
	}
};

Dice d;

int main(){
	std::cin >> d.dat[5] >> d.dat[1] >> d.dat[2] >> d.dat[4] >> d.dat[3] >> d.dat[0];
	std::string s;
	std::cin >> s;
	rep(i, s.size()){
		if (s[i] == 'S')d.front();
		if (s[i] == 'N')d.back();
		if (s[i] == 'E')d.right();
		if (s[i] == 'W')d.left();
	}
	std::cout << d.dat[5] << std::endl;
	return 0;
}

Measured memory_bytes: 1204
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

a, b, k = il()
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a//2
        a -= a//2
    else:
        if b % 2 == 1:
            b -= 1
        a += b//2
        b -= b//2
print(a, b)

Measured memory_bytes: 3316
#include<cstdio>
#include<cctype>
const int N=2007,P=1000000007;
int inc(int a,int b){return a+=b,a>=P? a-P:a;}
int dec(int a,int b){return a-=b,a<0? a+P:a;}
int read(){int x;scanf("%d",&x);return x;}
int f[N<<1][N][2],s[N];
int main()
{
    int n=read(),m=read(),k=read(),i,j,ans=0;
    f[0][0][0]=1;
    for(i=1;i<=(n+m-1)/(k-1);++i)
    {
    s[0]=inc(f[i-1][0][1],f[i-1][0][0]);
    for(j=1;j<=m;++j) s[j]=inc(s[j-1],inc(f[i-1][j][0],f[i-1][j][1]));
    for(j=0;j<=m;++j)
    {
        f[i][j][0]=inc(f[i-1][j][0],f[i-1][j][1]);
        if(j) f[i][j][1]=dec(s[j-1],(j>=k? s[j-k]:0));
    }
    for(j=0;j<=m;++j) if(j%(k-1)==m%(k-1)&&(i*(k-1)+1-j)%(k-1)==n%(k-1)&&i*(k-1)+1-j<=n) ans=inc(ans,f[i][j][1]);
    }
    printf("%d",ans);
}

Measured memory_bytes: 62848
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	h=int(input())
	w=int(input())
	n=int(input())
	a=max(h,w)
	
	print((n-1)//a+1)












if __name__ == "__main__":
	main()


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long A = GetLong();
		long V = GetLong();
		long B = GetLong();
		long W = GetLong();
		long T = GetLong();
		if(V <= W)
		{
			WriteLine("NO");
			return;
		}
		long D = V - W;
		WriteLine((Abs(A - B) + D - 1) / D <= T ? "YES" : "NO");
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int n;

int main(){
  cin>>n;
  if(n%2==0){
    cout<<n*(n-1)/2-n/2<<endl;
    REP(i,n){
      FOR(j,i+1,n){
	if(i+j!=n-1)
	  cout<<i+1<<" "<<j+1<<endl;
      }
    }
  }else{
    cout<<(n-1)*(n-2)/2-(n-1)/2+n-1<<endl;
    REP(i,n-1){
      FOR(j,i+1,n-1){
	if(i+j!=n-2)
	  cout<<i+1<<" "<<j+1<<endl;
      }
    }
    REP(i,n-1)cout<<i+1<<" "<<n<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <vector<int>> g(n+10,vector <int>());
    rep(i,n-1){
        int a,b; cin>>a>>b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector <bool>  v(n) ;
    priority_queue <int> pq;
    rep(i,n) {int a; cin>>a; pq.push(a);} 
    int ans = 0;
    vector <int> score(n);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int now = q.front(); int cost = pq.top(); 
        q.pop(); pq.pop();
        v[now] = true;
        if(now != 0) ans += cost;
        score[now] = cost;
        int sz = g[now].size();
        for(int i=0;i<sz;i++){
            if(v[g[now][i]]) continue;
            else {
                q.push(g[now][i]);
                //ans += cost;
            }
        }
    }
    cout<<ans<<endl;
    rep(i,n) cout<<score[i]<<' ';
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

string s, t;
ll dp[3100][3100] = {0};

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

int main(){

    cin >> s >> t;

    for(ll  i=0; i<s.size(); ++i){
        for(ll j=0; j<t.size(); ++j){

            if(s[i]==t[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);

        }
    }

    string ans="";

    ll i = s.size();
    ll j = t.size();

    while(i>0 && j>0){

        if(dp[i][j] == dp[i-1][j]) --i;

        else if(dp[i][j] == dp[i][j-1]) --j;

        else{
        ans = s[i-1] + ans;
        --i;
        --j;
        }

    }

    cout << ans << endl;

}

Measured memory_bytes: 73984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        int[] dp = new int[3];
        for (int i = 0; i <N ; i++) {
            String[] lo  = reader.readLine().split(" ");
            int a = Integer.parseInt(lo[0]);
            int b = Integer.parseInt(lo[1]);
            int c = Integer.parseInt(lo[2]);
            int[] list = {a,b,c};
            int[] temp = new int[3];
            for (int j = 0; j <3 ; j++) {
                int max = Integer.MIN_VALUE;
                for (int k = 0; k <3 ; k++) {
                    if(k!=j) max = Math.max(max,list[j]+dp[k]);
                }
                temp[j] =max;
            }
            dp =temp;
        }
        int res = Integer.MIN_VALUE;
        for (int i = 0; i <3; i++) {
            res=Math.max(res,dp[i]);
        }
        //System.out.println(Arrays.toString(dp));
        System.out.println(res);
    }
}


Measured memory_bytes: 44604
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	double p[12];p[0]=1;
	for(int i=1;i<11;i++) p[i]=p[i-1]*0.5;
	double c[12],d;int n;
	while(cin>>n&&n)
	{
		c[0]=0;c[1]=1;
		double sum=1;
		if(n==1){printf("1.00000000\n");continue;}
		int i;
		for(int t=2;t<=n;t++)
		{
			i=t;
			if(t>11) i=11;
			d=0;
			for(int j=i;j>0;j--)
			{
				c[j]=c[j-1]*p[j-1];
				d+=c[j-1]*(1-p[j-1]);
				sum+=c[j];
			}
			c[0]=d;
		}
		printf("%.8lf\n",sum);
	}
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

int main()
{
    boost
    int n, k, s;
    cin >> n >> k >> s;

    for(int i = 0; i < k; i++) cout << s << " ";
    if(s < 1000000000)
    {
        for(int i = k; i < n; i++) cout << s + 1 << " ";
    }
    else
    {
        for(int i = k; i < n; i++) cout << s - 1 << " ";
    }

    cout << nl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
#define MAX 100000

int main() {
	int N;
	cin >> N;
	int p[MAX];
	for(int i = 1; i <= N;i++){
		cin >> p[i];
	}
	int i = 1;
	int count = 0;
	while (i <= N) {
		if (i == p[i]) {
			i = i + 2;
			count += 1;
		}
		else {
			i += 1;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    if(n%(a+b)==0) cout<<(n/(a+b))*a<<endl;
    else cout<<(n/(a+b))*a+min(a,n%(a+b))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

int main() {
    IN(int, n);
    IN(int, k);
    vector<bool> a(n,false);
    REP(i, k){
        IN(int, d);
        REP(i, d){
            IN(int, hoge);
            a[hoge-1] = true;
        }
    }
    int ans = 0;
    REP(i, n){
        if (!a[i]) {
            ans++;
        }
    }
    COUT(ans);
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
N, price = list(map(int, input().split()))

li = map(str, [-1] * 3)

if N * 10000 >= price and N * 1000 <= price:
    x = price // 10000
    for i in range(x + 1):
        y = (price - i * 10000) // 5000
        for j in range(y + 1):
            if N >= i + j and price == i * 10000 + j * 5000 + (N - i - j) * 1000:
                li = map(str, [i, j, N - i - j])

print(" ".join(li))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  ll n,k; cin >> n >> k;
  ll ans = 0;
  vector<ll> h(n);

  rep(i,n){
    cin >> h.at(i);
    ans += h.at(i);
  }

  sort(all(h));
  reverse(all(h));

  rep(i,min(k,n)){
    ans -=h.at(i);
  }

  cout << ans << endl;
}


Measured memory_bytes: 4796
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  i64 a[105];

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

  i64 ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      chmax(ans, abs(a[i] - a[j]));
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,f,r,i=0;
  char a[50] = {};
  while(1){
    cin >> m >> f >> r;
    if(m==-1&&f==-1&&r==-1){
      break;
    }
    if(m==-1||f==-1){
      a[i] = 'F';
      i++;
    }else{
      if(f+m<30){
        a[i] = 'F';
      }
      if(30<=f+m&&f+m<50){
        if(r>=50){
          a[i] = 'C';
        }
        else{
          a[i] = 'D';
        }
      }
      if(50<=f+m&&f+m<65) a[i] = 'C';
      if(65<=f+m&&f+m<80) a[i] = 'B';
      if(80<=f+m) a[i] = 'A';
      i++;
    }
}
  for(int j=0;j<i;j++){
    cout << a[j] << endl;
  }
  return 0;
}



Measured memory_bytes: 3104