akhauriyash/Code-Regression huggingface dataset:
/* author   : mpily :-()
title : Competing.cpp
time :Sat May 30 13:38:34 2020

*/
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int64_t a;
	string b;
	cin >> a >> b;
	int64_t b_100 = 0;
	int i = 0;
	while(b[i] != '.'){
		int t = b[i]-'0';
		b_100*=10;
		b_100+=t;
		++i;
	}
	++i;
	while(i < b.size()){
		int t = b[i]-'0';
		b_100*=10;
		b_100+=t;
		++i;
	}
	a*=b_100;
	a/=100;
	cout << a;
	
	
}
int main(){
	int t;
	t = 1;
	while(t--){
		solve();
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#ifdef JLOCAL
#include "stress.h"
#endif
using namespace std;

#define rep(i, z, n) for (int i = (z); i < int(n); ++i)
#define repr(i, n, z) for (int i = int(n) - 1; i >= (z); --i)
#define shl(n) (1 << (n))
#define hbit(n, i) (((n) >> (i)) & 1)

#define STRESS 0
using lint = long long;

void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) {
        cin >> a[i];
        --a[i];
    }
    a.push_back(n);
    int ans = 0;
    rep(i, 0, n) {
        if (a[i] == i) {
            swap(a[i], a[i + 1]);
            ans++;
        }
    }
    cout << ans;
}

int main() {
#if !defined(JLOCAL) || !STRESS
#ifdef JLOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve(cin, cout);
#else
    srand();
    for (int ti = 0; ti < 100; ti++) {
        stress::gen();
        stress::stupid();
        ifstream in("input.txt");
        ofstream out("output.txt");
        solve(in, out);
        out.flush();
        stress::check();
    }
    cout << "ok" << endl;
#endif
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[1005][1005],H,W,cnt;
vector<pair<ll,ll> >v,vv;

void check(ll x,ll y)
{
	if(x>=0&&x<H&&y<W&&y>=0&&arr[x][y]==0)
	{
		cnt++;
		arr[x][y]=1;
		vv.pb(mp(x,y));
	}
}

int main()
{
	ll k=0,i,j;
	char c;
	cin>>H>>W;
	ll x[]={1,-1,0,0};
	ll y[]={0,0,1,-1};
	for(i=0;i<H;i++)
	{
		for(j=0;j<W;j++)
		{
			cin>>c;
			if(c=='#')
			{
				cnt++;
				arr[i][j]=1;
				v.pb(mp(i,j));
			}
			else
				arr[i][j]=0;
		}
	}
	while(cnt!=H*W)
	{
		k++;
		for(i=0;i<v.size();i++)
		{
			for(j=0;j<=3;j++)
				check(v[i].fi+x[j],v[i].se+y[j]);
		}
		v.clear();
		v=vv;
		vv.clear();
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 31716
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;


int main() {

  int n ; cin >> n;
  int t,a ; cin >> t >> a ;
  
  vector<int> v1(n) ; 
  for ( int i = 0 ; i < n ; i++ ) 
    cin >> v1.at(i) ; 
  
  // compute
  
  float ideal = 100000 ; 
  int point = 0 ; 
  
  for ( int i = 0 ; i < n ; i++){
  	if ( ideal > abs(a - (t - v1.at(i)*0.006)) ) {
    	ideal = abs(a - (t - v1.at(i)*0.006)) ;
        point = i+1 ;
    }
  }
  
  cout << point ;


}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int a,b,t,cookie;
  	scanf("%d %d %d",&a,&b,&t);
  	if(a>t){
      cookie=0;
      printf("%d\n",cookie);
    }
  	else {
   		cookie=t/a;
    	printf("%d\n",cookie * b);
    }
    return 0;
}

Measured memory_bytes: 128
#読み込み
N, K = map(int, input().split())
A = list(map(int, input().split()))
#処理回数
reduce_type = len(set(A)) - K
#削除する数の選定
A_dict = {str(i):0 for i in set(A)}
for a in A:
  A_dict[str(a)] += 1
del A
list_del_num = sorted(list(A_dict.values()))[:reduce_type]
#計算
ans = sum(list_del_num)
print(ans)

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

int a[103];
bool cmp(int s, int f){
    return s>f;
}

int main(){

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; ++i){
        scanf("%d", a+i);
    }

    sort(a, a+n, cmp);
    int sum1=0, sum2=0;
    bool alice=1;
    for(int i=0; i<n; ++i){
        if(alice){
            //puts("Hi1");
            sum1+=a[i];
            alice = !alice;
            //cout<<sum<<" "<<alice<<"\n";
        }
        else{
            //puts("Hi2");
            sum2+=a[i];
            alice = !alice;
            //cout<<sum<<" "<<alice<<"\n";
        }
    }

    printf("%d", sum1-sum2);




    return 0;
}


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

}

#define sz 10000007

vector<long long> arr(sz);

int main()
{

    textIO();
    fastIO();

    for(int i=1;i<sz;i++){
        for(int j=i;j<sz;j+=i){
            arr[j]++;
        }
    }

    for(int i=1;i<sz;i++){
        arr[i] = arr[i-1]+(arr[i]*i);
    }

    long long n;
    cin >> n;

    cout << arr[n] << '\n';

    return 0;
}


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

signed main(void)
{
	int x, y;
	cin >> x >> y;
	for(int turu = 0; turu <= x; turu++)
	{
		int kame = x - turu;
		if (kame * 2 + turu * 4 == y)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

vector<pair<string,int>> rec(int n) {
    vector<pair<string,int>> res;
    if (n==1) {
        res.push_back(make_pair("a",1));
    } else {
        vector<pair<string,int>> s=rec(n-1);
        rep(i,s.size()) {
            string t=s[i].first;
            int k=s[i].second;
            rep(i,k) {
                string tt=t;
                tt.push_back('a'+i);
                res.push_back(make_pair(tt,k));
            }
            t.push_back('a'+k);
            res.push_back(make_pair(t,k+1));
        }
    }
    return res;
}


int main() {
    int n;
    cin >> n;
    vector<pair<string,int>> s=rec(n);
    rep(i,s.size()) cout << s[i].first << endl;
}

Measured memory_bytes: 10080
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());

		List<Integer> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			list.add(Integer.parseInt(sc.nextLine()));
		}

		 System.out.println(list.stream().distinct().count());

	}

}

Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    vector<long long> A(n);
    for(auto& x : A) cin >> x;
    long long money = 1000;
    for(int i = 0; i < n; ++i)
    {
        int cur_topo = i;
        for(int j = i + 1; j < n; ++j)
        {
            if(A[j] < A[cur_topo]) break; 
            else if(A[j] == A[cur_topo]) break;
            else {
                if(A[j] > A[cur_topo]) {
                    cur_topo = j; 
                }
            }
        }
        if(cur_topo == i) continue; 
        else {
            long long buy = money / A[i];
            money -= (buy * A[i]);
            long long sell = buy * A[cur_topo];
            money += sell;
        }
        i = cur_topo;
    }
    cout << money << '\n'; 
    return 0;
}





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

int main() {
    ll n; cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    n *= 2;

    vector<ll> check;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            check.emplace_back(i);
            if (n / i != i) check.emplace_back(n / i);
        }
    }

    ll ans = n - 1;
    for (int i = 0; i < (int)check.size(); i++) {
        ll x = check[i], y = n / x;
        auto change = crt({0ll, y - 1}, {x, y});
        if (change.second != 0 && change.first < ans) ans = change.first;
    }

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


Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int n;
        static List<int> a;
        
        static void Main(string[] args)
        {
            //[summary]C - Sequence
            n = int.Parse(Console.ReadLine());
            a = ReadLine();

            //偶数のインデックスを1にするケース
            long count1 = CountOperations(0);

            //奇数のインデックスを1にするケース
            long count2 = CountOperations(1);

            if (count1 < count2)
            {
                Console.WriteLine(count1);
            }
            else
            {
                Console.WriteLine(count2);
            }
        }

        static long CountOperations(int mod)
        {
            var b = GetNewNumbers(mod);
            long count = 0;

            for (int i = 0; i < n; i++)
            {
                count += Math.Abs(a[i] - b[i]);
            }

            return count;
        }

        static List<int> GetNewNumbers(int mod)
        {
            var b = new List<int>(a);
            long sum = 0;

            for (int i = 0; i < n; i++)
            {
                if (i % 2 == mod)
                {
                    //i項までの和をプラスに
                    if (sum + b[i] <= 0)
                    {
                        //i項までの和を1にする
                        b[i] += (int)Math.Abs(sum + b[i]) + 1;
                    }
                }
                else
                {
                    //i項までの和をマイナスに
                    if (sum + b[i] >= 0)
                    {
                        //i項までの和を-1にする
                        b[i] -= (int)(Math.Abs(sum + b[i]) + 1);
                    }
                }

                sum += b[i];
            }

            return b;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 30300
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll a[30];

int main(void){
	          ll i;

	          cin.tie(0);  ios_base::sync_with_stdio(false);

	          ll N;
	          string S;
	          cin >> N >> S;

	          for(i=0;i<N;i++){
	        	  a[S[i]-'a']++;
	          }

	          ll ans=1,m=1e9+7;
	          for(i=0;i<26;i++){
	        	  ans*=a[i]+1LL;
	        	  ans%=m;
	          }

	          cout << ans-1LL << endl;

	          return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S, T; cin >> S >> T;
	int ans = 0;
	REP(i, S.size()) {
		if (S[i] != T[i])ans++;

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



Measured memory_bytes: 3784
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

x = ip()
print(x.index(0)+1)

Measured memory_bytes: 61628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void test_case()
{
	ll n ;
	cin >> n;
	vector<ll>v;
	ll ans=0,max=INT_MIN,tmp;
	for(ll i = 0;i<n;++i) 
	{
		cin >> tmp;
		if(tmp >= max)
			max = tmp;
		else
			ans+= (max - tmp);
	}

	cout<<ans;


}

int main(){
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	int T = 1;
	// cin>>T;
	while(T--)
		test_case();

}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
vector <ll> g[10];
ll visited[10];
int main(){
    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    ll dx=tx-sx,dy=ty-sy;
    ll i;
    for(i=0;i<dx;i++){
        cout <<'R';
    }
    for(i=0;i<dy;i++){
        cout <<'U';
    }
    for(i=0;i<dx;i++){
        cout <<'L';
    }
    for(i=0;i<dy+1;i++){
        cout << 'D';
    }
    for(i=0;i<dx+1;i++){
        cout <<'R';
    }
    for(i=0;i<dy+1;i++){
        cout <<'U';
    }
    cout << 'L';
    cout << 'U';
    for(i=0;i<dx+1;i++){
        cout <<'L';
    }
    for(i=0;i<dy+1;i++){
        cout << 'D';
    }
    cout <<'R';
    return 0;
}


Measured memory_bytes: 256
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }
fun main(args:Array<String>){
  var (d,n) = listOfInt()
  var cnt = 0
  var i = 1
  while(true){
    var tmp = i
    var t = 0
    while(tmp%100==0){
      t++
      tmp/=100
    }
    if(t==d)cnt++
    if(cnt==n){
      println(i)
      break
    }
    i++
  }
}


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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n; cin>>n;
    vector<int> v(n);

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

    int mx = *max_element(v.begin(), v.end());
    int mn = *min_element(v.begin(), v.end());

    cout<<mx-mn<<endl;
    
    return 0;
}

Measured memory_bytes: 3644
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
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")
}


//main function
fn main() {
    let c: String = read();
    match &*c{
	"a" => println!("vowel"),
	"i" => println!("vowel"),
	"u" => println!("vowel"),
	"e" => println!("vowel"),
	"o" => println!("vowel"),
	_=> println!("consonant"),
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int solve(int n, const vecint &cnt, int i) {
  if (i == 15) {
    if (n == 1) return 1;
    else return 0;
  }
  int a[6] = {1, 3, 5, 15, 25, 75};
  int sum = 0;
  REP(j,6) {
    if (a[j] > cnt[i]+1) break;
    if ((n % a[j]) != 0) continue;
    sum += solve(n / a[j], cnt, i+1);
  }
  return sum;
}

int main()
{
  int n;
  cin>>n;
  vecint cnt(15, 0);
  FOR(i,2,n+1) {
    int a[15] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    REP(k,15) {
      int j = i;
      while ((j % a[k]) == 0) {
        j /= a[k];
        ++cnt[k];
      }
    }
  }
  cout << solve(75, cnt, 0) << endl;
  return 0;
}


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

int main(){
  int n;
  int a[210];

  cin >> n;

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

  int count = 0;

  while(true)
  {
    bool exsist_odd = false;
    for(int i = 0;i < n;++i)
      if(a[i]%2 != 0) exsist_odd = true;

     if(exsist_odd) break;

    for(int i = 0;i < n;i++) a[i] /= 2;

    ++count;
  }
  cout << count << endl;
}

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

long long digit(long long x) {
  long long count=0;
  while (x>0) {
    x = x/10;
    count++;
  }
  return count;
}

long long dig_sum(long long x) {
  long long sum=0;
  while (x>0) {
    sum += x%10;
    x = x/10;
  }
  return sum;
}

int main() {
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if (K%2==0) {
    cout << A-B << endl;
  }
  else {
    cout << B-A << endl;
  }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
ls = []
l = 1
ans = 0
count = 0
pcount = 0
flag = False
for i in range(N):
  if S[i]=='L':
    if i!=0 and S[i]==S[i-1]:
      ans += 1
  else:
    if i!=N-1 and S[i]==S[i+1]:
      ans += 1
  
  if i!=N-1 and S[i]!=S[i+1]:
    count += 1
#print(ans, count, pcount)
for i in range(K):
  if count>1:
    ans += 2
    count -= 2
    continue
  elif count==1:
    ans += 1
    break
print(ans)

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  bool p[110], q[110];
  for (int i = 0; i <= a; i++) p[i] = false;
  for (int i = 0; i <= b; i++) q[i] = false;
  for (int i = 1; i <= a; i++) {
    if (a%i == 0) p[i] = true;
  }
  for (int i = 1; i <= b; i++) {
    if (b%i == 0) q[i] = true;
  }
  int c = min(a, b), d = 1, ans = 0;
  for (int i = c; i >= 0; i--) {
    if (p[i] && q[i]) {
      if (d == k) {
        ans = i;
        break;
      }
      d++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  int n,m;
  cin>>n>>m;
  vector<string> t(n);
  REP(i,n) cin>>t[i];
  vector<vector<bool>> th(n, vector<bool>(m, false));
  vector<vector<bool>> tv(n, vector<bool>(m, false));
  REP(i,n)REP(j,m) {
    if (i+2 < n) {
      if (t[i][j] == 'R' && t[i+1][j] == 'G' && t[i+2][j] == 'W') {
        tv[i][j] = true;
      }
    }
    if (j+2 < m) {
      if (t[i][j] == 'R' && t[i][j+1] == 'G' && t[i][j+2] == 'W') {
        th[i][j] = true;
      }
    }
  }
  ll sum = 0;
  REP(d,n+m) {
    vector<vector<ll>> dp(max(n, m)+1, vector<ll>(4, 0));
    REP(i,n) {
      int j = d - i;
      if (j >= m || j < 0) continue;
      REP(k,2)REP(l,2) {
        int index = k + 2*l;
        if (tv[i][j]) {
          int index2 = 1 + 2*k;
          dp[i+1][index2] = max(dp[i+1][index2], dp[i][index] + 1);
        }
        if (th[i][j]) {
          int index2 = 0 + 2*k;
          if (!k && !l) {
            dp[i+1][index2] = max(dp[i+1][index2], dp[i][index] + 1);
          }
        }
        int index2 = 0 + 2*k;
        dp[i+1][index2] = max(dp[i+1][index2], dp[i][index] + 0);
      }
    }
    ll mx = 0;
    for(auto&& v : dp)
      for (ll e : v)
        mx = max(mx, e);
    sum += mx;
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 26516
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]


ans = False
for a in A:
    ans |= set(a) <= set(B)
    
for i in range(3):
    ans |= set([A[0][i], A[1][i], A[2][i]]) <= set(B)
    
ans |= set([A[0][0], A[1][1], A[2][2]]) <= set(B)
ans |= set([A[0][2], A[1][1], A[2][0]]) <= set(B)
    
print("Yes" if ans else "No")


Measured memory_bytes: 38516
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
long N,H,D,mod=1e9+7;
main()
{
	cin>>N>>H>>D;
	lazysegtree<long>P(H,0,
	[](long a,long b){return (a+b)%mod;},
	[](long a,long b){return (a+b)%mod;},
	[](long a,long b,unsigned int w){return (a+b*w)%mod;});
	long s=0,p=1;
	for(int i=1;i<=N;i++)
	{
		p=p*i%mod;
		s=(s+p)%mod;
	}
	P.update(0,D,p);
	for(int i=0;i<H;i++)
	{
		P.update(i+1,i+D+1,P.query(i,i+1)*s%mod);
	}
	cout<<P.query(H-1,H)<<endl;
}


Measured memory_bytes: 35328
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int A = sc.nextInt();

        PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->a.x-b.x);
        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int h = sc.nextInt();
            pq.offer(new Pair(x, h));
        }

        long totalDamage = 0;
        long ans = 0;
        LinkedList<Pair> q = new LinkedList<>();
        while (!pq.isEmpty()) {
            Pair m = pq.poll();
            int x = m.x;
            long h = m.v;
            while (q.size() > 0 && q.peek().x < x) {
                totalDamage -= q.poll().v;
            }
            
            if (h >= totalDamage) {
                h -= totalDamage;
                long atackNum = Math.max((h+A-1)/A, 0);
                ans += atackNum;
                totalDamage += atackNum*A;
                q.offer(new Pair(x+2*D, atackNum*A));
            }
        }

        System.out.println(ans);
    }

    private static class Pair {
        private final int x;
        private final long v;
        Pair(int x, long v) {
            this.x = x;
            this.v = v;
        }
    }
}


Measured memory_bytes: 126036
#include<iostream>
#include<algorithm>

using namespace std;
int main(){

  int n;
  long long int a[100000], x=0, y=0;
  bool flag = false;
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  sort(a, a+n);

  for(int i=n-2; 0<=i; i--){
    if(a[i+1]==a[i] && x==0){
      x = a[i];
      for(int j=i-2; 0<=j; j--){
        if(a[j+1]==a[j] && y==0){
          y=a[j];
          cout << x * y << endl;
          flag = true;
          break;
        }
      }
    }
  }

if(!flag){
  cout << 0 << endl;
}

  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d %d %d", &a,&b,&c);
  if((b+c)<=a)
  {
    printf("0\n");
  }
  else
  {
    int t=a-b;
    int s=c-t;
    printf("%d\n", s);
  }
  return 0;
}

Measured memory_bytes: 128
import numpy as np
#from numba import jit
import sys

input = sys.stdin.readline

N = int(input())
H = np.array(input().split(), dtype=np.int64)

#@jit(nopython=True)
def main():
    Hdiff = np.diff(H)
    cnt = 0; ans = 0
    for h in Hdiff:
        if h <= 0:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 24624
#include <stdio.h>

int main(void)
{
	int n;
	int money = 100000;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		money = money + (money * 0.05);
		if (money % 1000){
			money = (money + 1000) / 1000 * 1000;
		}
	}
	
	printf("%d\n", money);
	
	return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;
bool use[30];
string str;

int main(){
	cin >> str;
	n = str.size();
	
	memset(use, 0, sizeof(use));
	if(n < 26){
		for(ll i = 0; i < n; i++){
			use[str[i]-'a'] = true;
		}
		
		for(ll ab = 0; ab < 26; ab++){
			if(!use[ab]){
				str += char('a'+ab);
				break;
			}
		}
		cout << str << endl;
	}
	else{
		if(str == "zyxwvutsrqponmlkjihgfedcba"){cout << -1 << endl;}
		else{
			int itr = 25;
			use[str[itr]-'a'] = true;
			while(str[itr] < str[itr-1]){
				itr--;
				use[str[itr]-'a'] = true;
			}
			
			string ans = str.substr(0, itr-1);
			//cout << ans << endl;
			//cout << str[itr-1] << endl;
			for(ll ab = 0; ab < 26; ab++){
				if(use[ab] && 'a'+ab > str[itr-1]){
					ans += char('a'+ab);
					break;
				}
			}
			
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
// Stack
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 200

void initialize();
int isEmpty();
int isFull();
void push(int);
int pop();


int top, S[1000]; // 一番最後に追加された要素を指す
int S[1000]; // データを格納する配列

int main(){
  int i, n, a, b;
  char str[100];
  initialize();
  top = 0;

  while(scanf("%s", str) != EOF){
    if(str[0] == '+'){ // 演算子"+"が代入されたとき
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(str[0] == '-'){ // 演算子"-"が代入されたとき
      b = pop();
      a = pop();
      push(a - b);
    }
    else if(str[0] == '*'){ // 演算子"*"が代入されたとき
      a = pop();
      b = pop();
      push(a * b);
    }
    else{ // 数値が代入されたとき
      push(atoi(str));
    }
  }
  printf("%d\n", pop()); // 計算結果の表示
  
  return 0;
}

// スタックを空にする
void initialize(){
  top = 0;
}

// スタックが空かどうか確認
int isEmpty(){
  if(top == 0)return 1;
  else return 0;
}

// スタックが満杯かどうか確認
int isFull(){
  if(top >= MAX - 1)return 1;
  else return 0;
}

// スタックに要素xを追加する
void push(int x){
  if(isFull() == 1) exit(8);
  top++;
  S[top] = x;
}

// スタックのトップから要素を取り出す
int pop(){
  if(isEmpty() == 1) exit(8);
  else {
    top--;
    return S[top + 1];
  }
}



Measured memory_bytes: 2108
using System;
using System.IO;
namespace aoj{
    class program{
     
    static void Main() {
        string find=Console.ReadLine();
        string str=Console.In.ReadToEnd();
        FindStr fs=new FindStr(find,str);
        Console.WriteLine("{0}",fs.find());
     
    }
}
 
class FindStr{
    string src;
    string[] dst;
    public FindStr(string s, string d){
        src=s;
        d=d.Substring(0,
        d.LastIndexOf("END_OF_TEXT",StringComparison.OrdinalIgnoreCase));
        //Console.WriteLine(d);
        char[] sep = new char[] {' ','\n'};
        dst = d.Split(sep,
        StringSplitOptions.RemoveEmptyEntries);
	
    }
    public int find(){
        int count =0;
        for(int i=0;i<dst.Length;i++){
		//	Console.Write(dst[i]+" ");
        if(src.Equals(dst[i],StringComparison.OrdinalIgnoreCase)){          
            count++;
        //	Console.Write("true");
        }
       // Console.WriteLine("");
        }
        return count;
    }
 
}
}

Measured memory_bytes: 5648
/*input
1
11 11
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	lld	x,y,k;
	cin >>k >> x >> y ;
	lld ans=(y/k)-(x-1)/k;
	cout << (ans?"OK":"NG") << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    rep(i,n){
        vector<int> dist(n, -1);
        queue<int> q;

        dist[i] = 0;
        q.push(i);
        while(!q.empty()){
            int v = q.front(); q.pop();
            ans[dist[v]]++;
            if (v+1 < n && dist[v+1] == -1){
                q.push(v+1);
                dist[v+1] = dist[v] + 1;
            }
            if (v-1 >= 0 && dist[v-1] == -1){
                q.push(v-1);
                dist[v-1] = dist[v] + 1;
            }
            if (v == x && dist[y] == -1){
                q.push(y);
                dist[y] = dist[v] + 1;
            }
            if (v == y && dist[x] == -1){
                q.push(x);
                dist[x] = dist[v] + 1;
            }
        }
    }
    for(int i = 1; i < n; i++){
        cout << ans[i] / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
const ll N=1000005;
ll fact[N];

const ll MOD=1000000007;
ll pow(ll a, ll b, ll m)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}

ll modinv(ll k)
{
    ll ans=pow(k, MOD-2, MOD);
    ans=(ans)%MOD;
    return ans;
}

void precompute()
{
    fact[0]=fact[1]=1;
    for(ll i=2;i<N;i++)
    {
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    
}

ll nCr(ll x, ll y)
{
    
    if(y>x)
        return 0;
    ll num=fact[x];
    num*=modinv(fact[y]);
    num%=MOD;
    num*=modinv(fact[x-y]);
    num%=MOD;
    return (num)%MOD;
}


int main(){
    precompute();
    ll x,y;
    cin>>x>>y;
    ll n,m;
    //dbg(x+y);
    if((x+y)%3!=0){cout<<0<<endl; return 0;}
    if(x<0||y<0){
        cout<<0<<endl;
        return 0;
    }
    if ((2 * x - y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll a = (2 * x - y) / 3;
  ll b = (2 * y - x) / 3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
    m=(2*x-y)/3;
    n=(2*y-x)/3;
    m=m%MOD;
    n=n%MOD;
    
    ll ans=nCr((n+m)%MOD,n);
    ans=(ans)%MOD;
    //dbg(invfact[1]);
    
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 8064
#include<iostream>

using namespace std;

int main() {
	int N;

	cin >> N;

	if (N < 3) {
		cout << 2;
	}
	else if (N > 2) {
		if (N % 2 == 0) {
			cout << N;
		}
		else { cout << N * 2; }
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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, K;

long long inp[100010][3];
long long dp[100010][3];
int main(){
    cin >> N;
    
    for (int i=0; i< N; ++i) cin >> inp[i][0] >> inp[i][1] >> inp[i][2];
    
    
    for(int i=0; i< N; ++i){
        for(int j=0; j< 3; ++j){
            for(int k=0; k< 3; ++k){
                if(j==k) continue;
                chmax(dp[i+1][j], inp[i][j] + dp[i][k]);
            }
        }
    }
    
    long long max=0;
    for(int j=0; j< 3; ++j) {
      chmax(max, dp[N][j]);
    }
    
    cout << max << endl;
    
    return 0;
}

Measured memory_bytes: 4992
var
 a,b:array[1..100,1..100] of longint;
 i,j,x,y,n,m,k,t,z:longInt;
begin
 read(n,m);
 fillchar(a,sizeof(a),$3f);
 for i:=1 to m do
  begin
   read(x,y,z);
   a[x,y]:=z;
   a[y,x]:=z;
   b[x,y]:=z;
   b[y,x]:=z;
  end;
 for k:=1 to n do
  for i:=1 to n do
   for j:=1 to n do
    if (a[i,j]>a[i,k]+a[k,j]) then a[i,j]:=a[i,k]+a[k,j];
  for i:=1 to n do
   for j:=i+1 to n do
    if (a[i,j]<b[i,j]) then t:=t+1;
 writeln(t);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int a,b,c,d;
  string s;
  cin >> s;
  
  a = s[0] - '0'; b = s[1] - '0';
  c = s[2] - '0'; d = s[3] - '0';

  if(a+b+c+d == 7) 
    cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
  else if(a+b+c-d == 7)
    cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
  else if(a+b-c+d == 7)
    cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
  else if(a+b-c-d == 7)
    cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
  else if(a-b+c+d == 7)
    cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
  else if(a-b-c+d == 7)
    cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
  else if(a-b+c-d == 7)
    cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
  else if(a-b-c-d == 7)
    cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
}

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

using namespace std;

const int MAX = 2000000 + 5;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x, y;
    cin >> x >> y;
    long long a = (2 * y - x) / 3, b = (2 * x - y) / 3;
    if ((x + y) % 3 != 0 || 2 * y - x < 0 || 2 * x - y < 0) {
        cout << 0 << endl;
        return 0;
    }

    COMinit();
    cout << COM(a + b, a) << endl;
    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::set<int64_t>> e(n);

  for (int64_t i = 0; i < n - 1; i++) {
    int64_t a, b;
    std::cin >> a >> b;
    a--;
    b--;
    e[a].insert(b);
    e[b].insert(a);
  }

  std::vector<std::pair<int64_t, int64_t>> len(n, std::make_pair(-1, -1));
  len[0] = std::make_pair(0, 0);

  std::set<std::pair<int64_t, int64_t>> q;
  for (const auto i : e[0]) {
    if (len[i].first == -1) {
      q.insert(std::make_pair(0, i));
    }
  }

  while (!q.empty()) {
    auto itr = q.begin();
    const auto cost = itr->first + 1;
    const auto num = itr->second;
    if (len[num].first == -1 || cost < len[num].first) {
      len[num] = std::make_pair(cost, num);
    }
    for (const auto i : e[num]) {
      if (len[i].first == -1) {
        q.insert(std::make_pair(cost, i));
      }
    }
    q.erase(itr);
  }
  std::sort(len.begin(), len.end());
  std::reverse(len.begin(), len.end());

  std::vector<int64_t> c(n);
  std::cin >> c;
  std::sort(c.begin(), c.end());

  std::vector<int64_t> ans(n);

  for (int64_t i = 0; i < n; i++) {
    ans[len[i].second] = c[i];
  }

  std::cout << summation(c.begin(), c.end()) - c.back() << std::endl;

  for (int64_t i = 0; i < n; i++) {
    std::cout << ans[i] << (i == n - 1 ? "" : " ");
  }
  std::cout << std::endl;

  return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector< vector<int> > a(n, vector<int>(n)), b;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			cin >> a[i][j];
	b = a;
	
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			if(a[i][j] != a[j][i])
			{
				cout << "-1\n";
				return 0;
			}
	for(int j=0; j<n; ++j)
		if(a[j][j] != 0)
		{
			cout << "-1\n";
			return 0;
		}
	
	for(int k=0; k<n; ++k)
		for(int i=0; i<n; ++i)
			for(int j=0; j<n; ++j)
				b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
	
	if(a != b)
	{
		cout << "-1\n";
		return 0;
	}
	
	for(int i=0; i<n; ++i)
		for(int j=i+1; j<n; ++j)
		{
			bool removable = false;
			for(int k=0; k<n && !removable; ++k) if(k != i && k != j)
			{
				if(a[i][k]+a[k][j] == a[i][j])
					removable = true;
			}
			if(removable)
				b[i][j] = b[j][i] = 0;
		}
	
	ll ans = 0;
	for(int i=0; i<n; ++i)
		for(int j=i+1; j<n; ++j)
			ans += b[i][j];
	
	cout << ans << "\n";

	return 0;
}


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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)
    
    
     
int main() {
     
    int n, x, sum=0;
    vector<int> V;
    cin >> n;
    FOR(i, 0, n) {
     	cin >> x;
     	V.push_back(x);
     	sum += x;
    }
     
    sort(V.begin(), V.end());
     
    while(sum%10 == 0 && V.size()){
    	if(V[0]%10 != 0) sum -= V[0];
    	V.erase(V.begin());
    }
    
    if(!(sum%10)){
    	cout << 0 << endl;
    } else {
    	cout << sum << endl;
    }
    
          return 0;
     }

Measured memory_bytes: 256
import heapq
ceruleans, skills = map(int, input().split())
HP = list(map(lambda x: int(x) * (-1), input().split())) # OK! 次に進もうぜ
heapq.heapify(HP)

for i in range(skills):
  heapq.heappop(HP)

  if HP == []:
    break

print(-sum(HP))

Measured memory_bytes: 25896
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <list>
#include <forward_list>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

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

  int n;
  cin >> n;
  
  int l = n % 10;
  switch(l) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9: cout << "hon" << endl; return 0;
  case 0:
  case 1:
  case 6:
  case 8: cout << "pon" << endl; return 0;
  default: cout << "bon" << endl;
  }
}

Measured memory_bytes: 3688
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

long long num[50],e[50];

void getans()
{
    num[0]=1;e[0]=1;
    for(int i=1;i<=40;i++)
    {
        e[i]=e[i-1]*2;
        num[i]=num[i-1]*2+1;
    }
}

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    getans();
    long long n;
    scanf("%lld",&n);
    if(n==1)printf("1\n");
    else
    {
        for(int i=1;i<=40;i++)
        {
            if(n>e[i-1]&&n<=e[i])
            {
                if(n==e[i])printf("%lld\n",num[i]);
                else printf("%lld\n",num[i-1]);
                break;
            }
        }
    }

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 256