akhauriyash/Code-Regression huggingface dataset:
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}


int main()
{
    fast();
    int l,r,d,ans=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >

int32_t main()
{
    fast;
    int H,W,h,w,ans;
    cin>>H>>W>>h>>w;
    ans=H*W;
    ans-=((h*W)+(H*w));
    ans+=(h*w);
    cout<<ans<<endl;
    return 0;
}



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

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

    if(N / 100 == 7 || (N % 100) / 10 == 7 || N % 10 == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final String str = s.next();

			if(str.chars().sorted().distinct().count() != 2) {
				System.out.println("No");
				return;
			}

			if(str.chars().filter(c -> c == str.charAt(0)).count() != 2) {
				System.out.println("No");
				return;
			}

			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 28500
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 700;
    int tmp;
    string s;
    cin >> s;
    REP(i, 3) if(s[i]=='o') ans += 100;
    cout << ans << endl;
}

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

int main()
{
    int a, b;
    char op;
    while(true)
    {
        int c;
        cin >> a >> op >> b;
        if(op=='?') break;
        if (op == '+')
            c = a + b;
        if(op=='-')
            c = a - b;
        if(op=='*')
            c = a * b;
        if(op=='/')
            c=a/b;
        cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
# include "cstdio"
# include "iostream"
# include "algorithm"

using namespace std;

const int maxm=1e5+10;

int N,L[maxm];

inline bool Check(){
	register int i,Sum=0;
	for(i=1;i<N;i++) Sum+=L[i];
	return Sum<=L[N];
}

int main(){
	register int i;
	scanf("%d",&N);
	for(i=1;i<=N;i++) scanf("%d",L+i);
	sort(L+1,L+1+N);
	puts(Check()?"No":"Yes");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
const int MAX_V = 100000;
int main() {
    int i, k,v[20000],y,s=0;
    int prime[MAX_V+1];
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;
            }
        }
    }
    for(;;){
        scanf("%d",&v[s]);
        if(v[s]==0)break;
        s++;
    }
    int j=s;
    for(s=0;s<j;s++){
        for(y=v[s];y>0;y--){
            int isprime = prime[y];
            if(isprime){
                isprime=prime[y-2];
                if(isprime) {
                    printf("%d %d\n",y-2,y);
                    break;
                }
            }
        }
    }
    return 0;
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FILEIO                          \
    freopen("./input.txt", "r", stdin); \
    freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                               \
    for (                                                                       \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                                       \
        debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }

int main()
{
    FASTIO
#ifdef LOCAL
    FILEIO
#endif
    ll a;
    cin >> a;
    long double b;
    cin >> b;
    ll y = round(b * 100);
    cout << a * y / 100 << endl;
}

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

int		main(void)
{
	ios::sync_with_stdio(false);
	int		n;
	cin >> n;
	string	arr[n + 1];
	int		i = 0;
	int		j = 0;
	int		max = 0;
	string	winner[n + 1];
	int		count = 1;
	while (i < n)
		cin >> arr[i++];
	sort(arr, arr + n);
	arr[n] = "";
	i = 1;
	while (i <= n)
	{
		if (arr[i - 1] == arr[i])
			count++;
		else
			count = 1;
		if (count >= max)
		{
			if (count > max)
				j = 0;
			max = count;
			winner[j] = arr[i - 1];
			winner[++j] = "";
		}
		i++;
	}
	i = 0;
	while (winner[i] != "")
		cout << winner[i++] << '\n';
}


Measured memory_bytes: 14464
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, k;
double x;
double pre[SIZE];
int main() {
	cin >> n >> k;
	rep(i, 1, n) {
		cin >> x;
		x = 0.5 * (x + 1);
		pre[i] = pre[i - 1] + x;
	}
	double maxx = 0;
	rep(i, k, n) maxx = max(maxx, pre[i] - pre[i - k]);
	printf("%.12lf", maxx);
}

Measured memory_bytes: 1792
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()
{
    fastio;
    ll n,i,c=0;
    cin>>n;
    vector<ll>v(n);
    for(i=0;i<n;i++)cin>>v[i];
    ll curmax=v[0];
    for(i=1;i<n;i++)
    {
        if(v[i]>=curmax)
        {
            curmax=v[i];
        }
        else
        {
           c+=curmax-v[i];
        }

    }
    cout<<c<<endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    string s;
    ll K;
    cin >> s >> K;
    ll N = s.size();
    string t = "";
    REP(i, N){
    	if(i==N-1){
    		char p = char('a' + (s[i] - 'a' + K)%26);
    		t += p;
    	}else{
    		ll d = (26 - (s[i]-'a'))%26;
	    	if(d<=K){
	    		t += 'a';
	    		K -= d;
	    	}else{
	    		t += s[i];
	    	}
	    }
    }
    cout << t << endl;
    return 0;
}

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

int main(){
	char str[1005], ans[1005];
	int store = 0;
	int value = 0, x = 0;
	int flag = 0;
	scanf("%s", str);
	getchar();
	scanf("%s", ans);
	getchar();
	for(int i = 0; i <= strlen(str) - strlen(ans);i++){
		value = 0;
		x = 0;
		for(int j = 0;j < strlen(ans);j++){
			if(ans[j] != str[x + i]){
				value++;
			}
			x++;
		}
		if(value < store || flag == 0){
			store = value;
			flag = 1;
		}
	}
	printf("%d", store);
	return 0;
}

Measured memory_bytes: 1740
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Debug.Trace (trace)

main :: IO ()
main = do
  x <- readLn
  print $ solve x

solve :: Int -> Int
solve x = head $ filter isExpNumber [x, x-1 ..]

isExpNumber :: Int -> Bool
isExpNumber 1 = True
isExpNumber x = any f [2 .. x] where
  f b = go b 2
  go b p
   | x == y    = True
   | x < y     = False
   | otherwise = go b (p + 1) where
       y = b ^ p


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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for (int i = A; i <= B; i++) {
        int s = i % 10;
        int t = (i / 10000) % 10;
        int v = (i / 10) % 10;
        int u = (i / 1000) % 10;
        if (s == t && v == u) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
// template version 1.11
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings {{{
#define infile "../test/sample-1.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int a,p;cin>>a>>p;
  cout << (a*3 + p)/2 << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[5], k;
	int i, j;

	for (i = 0; i < 5; i++){
		scanf("%d", &a[i]);
	}
	scanf("%d", &k);

	if (a[4] - a[0] <= k){
		printf("Yay!\n");
	}
	else{
		printf(":(\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;

char s[310][310];

void solve(){

    ll n;
    cin >> n;
    rep(i,n){
        string st;
        cin >> st;
        rep(j,n){
            s[i][j]=st[j];
        }
    }

    ll ans = 0;
    rep(i,n){
        //移動水平距離i
        bool b=true;
        rep(p,n){
            for(ll q=0;q<p;q++){
                if(s[(p-i+n)%n][q]!=s[(q-i+n)%n][p]) b=false;
            }
        }
        if(b) ans += n;
    }

    cout << ans << endl;
    
}

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


Measured memory_bytes: 384
/*
AOJ - ITP1_10_a
Date: 20181010
Author: Mikoron * ♡mikoiwate_351♡
*/

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void) {

        double result, x1, y1, x2, y2, x, y;

        scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

        x = fabs(x2-x1);
        y = fabs(y2-y1);

        result = sqrt(x*x+y*y);

        printf("%.7lf\n", result);

        return 0;
}



Measured memory_bytes: 2136
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<std::pair<int,int>> result;
  int skip_black=1;
  int skip_red=(n%2==0)?n:n-1;
  for(int r=1;r<=n;r++){
    for(int c=r;c<=n;c++){
      if(c==skip_black||c==skip_red) continue;
      result.push_back(std::make_pair(r,c));
      
    }
    skip_black++;
    skip_red--;
  }

  cout<<result.size()<<endl;
  for(auto p:result){
    cout<<p.first<<" "<<p.second<<endl;
  }


  return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
N, K, Q = map(int, input().split())
A = []
A = [int(input()) for i in range(Q)]
scores = [K-Q] * N
for i, A_ in enumerate(A):
    scores[A_-1] = scores[A_-1] + 1
outputs = ['Yes' if score > 0 else 'No' for i, score in enumerate(scores) ]
for i, output in enumerate(outputs):
    print(output)

Measured memory_bytes: 11292
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n"; 

signed main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	
	string s; cin >> s;
	int n = s.length();
	bool ok = true;
	
	
	for(int i = 0; i < n; i++)
		if(s[i] != s[n-1-i]) ok = false;
	int k = (n-1)/2;
	for(int i = 0; i < k; i++)
		if(s[i] != s[k-1-i]) ok = false;
	string tt = "";
	for(int i = (n+3)/2 - 1; i < n; i++)
		tt += s[i];
	s = tt;
	n = s.length();
	for(int i = 0; i < n; i++)
		if(s[i] != s[n-1-i]) ok = false;
	if(ok) cout << "Yes\n";
	else cout << "No\n";
	
	
} 


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

int main() {

	int n;
	cin >> n;

	vector<int> a(n);
	map<int,int> count;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		count[a[i]]++ ;
	}

	int res = 0;
	for(int i = 0; i < n; i++) {
		count[a[i]]--;
		bool flag = true;
		for(int j = 1 ; j*j <= a[i]; j++) {
			if((a[i]%j == 0)) {
				if((count[j] > 0) or (count[a[i]/j] > 0)) {
					flag = false;
					break;
				}
			}
		}
		if(flag) {
			res++;
		}
		count[a[i]]++;
	}

	cout << res <<"\n";
}



Measured memory_bytes: 32680
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=2000002;
int n,k,num,res,p[maxn],in[maxn],to[maxn],ans[maxn],from[maxn],head[maxn],tree[maxn];
priority_queue < int , vector < int > , greater < int > > Q;
inline void add (int u,int v) {
	from[++num]=head[u];
	++in[v]; to[num]=v;
	head[u]=num;
}
inline void Update (int x,int l,int r,int pos,int val) {
	if(l==pos&&r==pos) { tree[x]=val; return ; }
	register int mid=(l+r)>>1;
	if(pos<=mid) Update(x<<1,l,mid,pos,val);
	else Update(x<<1|1,mid+1,r,pos,val);
	tree[x]=min(tree[x<<1],tree[x<<1|1]);
}
inline void Query (int x,int l,int r,int L,int R) {
	if(L<=l&&r<=R) { res=min(res,tree[x]); return ; }
	register int mid=(l+r)>>1;
	if(L<=mid) Query(x<<1,l,mid,L,R);
	if(R>mid) Query(x<<1|1,mid+1,r,L,R);
}
inline void Topo () {
	register int now=0;
	for(register int i=1;i<=n;++i)
	    if(!in[i]) Q.push(i);
	while(!Q.empty()) {
		register int u=Q.top(); Q.pop();
		ans[u]=++now;
		for(register int i=head[u];i;i=from[i])
		    if(!--in[to[i]]) Q.push(to[i]);
	}
	for(register int i=1;i<=n;++i) printf("%d\n",ans[i]);
}
inline int read () {
    char ch=getchar(); register int num=0;
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) num=(num<<3)+(num<<1)+(ch^'0'),ch=getchar();
    return num;
}
int main () {
    n=read(),k=read(); register int l,r;
    for(register int i=1;i<=n;++i) p[read()]=i;
    memset(tree,INF,sizeof(tree));
    for(register int i=n;i;--i) {
    	l=p[i]+1,r=min(p[i]+k-1,n); res=INF;
		if(l<=r) Query(1,1,n,l,r);
    	if(res!=INF) add(p[i],p[res]);
    	l=max(1,p[i]-k+1),r=p[i]-1; res=INF;
    	if(l<=r) Query(1,1,n,l,r);
    	if(res!=INF) add(p[i],p[res]);
    	Update(1,1,n,p[i],i);
	}
	Topo();
    return 0;
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    int n = 0;
    cin >> n;

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

    int count = 0;
    for(int i = 1; i < n - 1; i++) {
        int p_left   = ps[i-1];
        int p_center = ps[i];
        int p_right  = ps[i+1];
        if(p_center < p_left) {
            if(p_center < p_right) {
                ;
            } else {
                count++;
            }
        } else if(p_center < p_right) {
            if(p_center < p_left) {
                ;
            } else {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
const LL maxn = 111;
LL v[maxn], t[maxn];
LL c[maxn][maxn];

double p[maxn];
double lv[maxn];
LL n, m, l;

double ff (LL u, LL state, LL v) {
	double ret = 0;
	for (LL i = 0; i <= m; ++i) {
		if (lv[v] + i * t[v] > lv[u] + state * t[u]) {
			ret += 1.0 * c[i][m] * pow (1.0 * p[v], 1.0*i) * pow (1.0 - p[v], 1.0*m - i);
		}
	}
	return ret;
}
double f (LL u, LL state) {
	double ret = 1.0 * c[state][m] * pow (1.0 * p[u], 1.0 * state) * pow (1.0 - p[u], 1.0 * m - state);
	for (LL i = 0; i < n; ++i) {
		if (i == u) continue;
		ret *= ff (u, state, i);
	}
	return ret;
}
double solve (LL u) {
	double ret = 0;
	for (LL i = 0; i <= m; ++i) {
		ret += f (u, i);
	}
	return ret;
}

//快速求&#32452;合数 c(m, n)
LL combination(LL m, LL n) {
	LL i, a, b, p;
	if (n < m) n ^= m ^= n ^= m;
	p = 1;
	a = n - m < m ? n-m : m;
	b = n - m > m ? n-m : m;
	for (i = 1; i <= a; ++i) p += p * b / i;
	return p;
}

int main () {
	LL i;
	while (~scanf ("%lld%lld%lld", &n, &m, &l)) {
		//生成所有c[i][m]的&#32452;合数
		for (i = 0; i <= (m >> 1); ++i) {
			c[i][m] = c[m-i][m] = combination (i, m);
		}
		/*for (i = 0; i <= m; ++i) {
			printf ("c[%lld][%lld] = %lld\n", i, m, c[i][m]);
		}*/
		for (i = 0; i < n; ++i) {
			scanf ("%lf%lld%lld", &p[i], &t[i], &v[i]);
			lv[i] = 1.0 * l / v[i];
			p[i] /= 100;
		}
		for (i = 0; i < n; ++i) {
			double ans = solve (i);
			printf ("%.8lf\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 1012
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int n,m,q;
	cin>>m>>n>>q;
	int x,y;
	cin>>y>>x;
	int sum=0;
	rep(i,q-1){
		int a,b;
		cin>>b>>a;
		int c=a-x,d=b-y;
		if(c<0){c*=-1;d*=-1;}
		if(c==0)sum+=abs(d);
		else if(d<0)sum+=c-d;
		else sum+=max(c,d);
		x=a;
		y=b;
	}
	cout<<sum<<endl;
}

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

int main(){
  string S;
  cin >> S;
  int zero=0; int one=0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='0') zero++;
    else one++;
  }
  int ansa=2* min(zero, one);
  cout << ansa << endl;
}

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

int main(){
 double a,b,c;
  cin >> a>>b;
  c=b*10;
  for(int i = 0; i < 10; i++){
    int temp = (c+i)*0.08;
    if(temp==a){
     cout << c+i << endl; 
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main(void){
    string S,T;
    cin>>S>>T;
    bool flag=false;
    for(int i=0;i<S.size();i++){
        if(S==T){
            flag=true;
            break;
        }
        S=S.back()+S.substr(0,S.size()-1);
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N, M;
  cin >> N >> M;
  vector<bool> like(M, true);
  for (int32_t i = 0; i < N; ++i) {
    int32_t K;
    cin >> K;
    vector<bool> temp_like(M, false);
    for (int32_t j = 0; j < K; ++j) {
      int32_t a;
      cin >> a;
      const int32_t food_index = a - 1;
      temp_like[food_index] = true;
    }
    for (int32_t j = 0; j < M; ++j) {
      like[j] = like[j] && temp_like[j];
    }
  }
  int32_t count = 0;
  for (int32_t j = 0; j < M; ++j) {
    if (like[j]) {
      ++count;
    }
  }
  cout << count << endl;

  return 0;
}


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

#define sc scanf
#define pf printf
#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull unsigned long long int
#define ll  long long int
#define db double
#define fl float
#define vi vector<int>
#define vl vector<ll>
#define qin queue<int>
#define pb push_back
#define pob pop_back
#define ft front
#define bk back
#define mp make_pair
#define pii pair<int,int>
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define pll __builtin_popcountll
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())



int main()
{
    CIN;

    ll n,m,x;
    cin>>n>>m>>x;

    vl u(n),v(m),su(n+1),sv(m+1);


    for(ll i=0;i<n;i++)
        cin>>u[i];

    for(ll i=0;i<m;i++)
        cin>>v[i];


    for(ll i=0;i<n;i++)
        su[i+1]=su[i]+u[i];

    for(ll i=0;i<m;i++)
        sv[i+1]=sv[i]+v[i];

    //for(ll i=0;i<sv.size();i++) cout<<sv[i]<<endl;

    ll cnt=0;

    for(ll i=0;i<=n;i++)
    {
        ll p=x-su[i];

        if(p<0)
            break;


        //cout<<"hey"<<endl;

        ll l=lower_bound(sv.begin(),sv.end(),p)-sv.begin();


        if(l>m || sv[l]>p)
            l--;

        cnt=max(i+l,cnt);
    }

    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 9500
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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 main(){
	ll X, Y, Z;
	cin >> X >> Y >> Z;
	ll cnt = 0;
	while (true){
		ll temp = (Y + Z) * cnt + Z;
		if (X < temp){
			cnt--;
			break;
		}
		cnt++;
	}
	cout << cnt << endl;
 	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int x,N,X,m[100],t=0,i,min;
scanf("%d%d",&N,&X);
for(i=0;i<N;i++)
scanf("%d",&m[i]);
for(i=0;i<N;i++)
t=t+m[i];
min=m[0];
for(i=1;i<N;i++)
  {
     if(m[i]<min)
       min=m[i];
  }
x=N;
while(t<=X)
{
   if((min+t)<=X)
      {
        t=t+min;
        x++; 
      }
   else
      {
         break;
      }
}  
printf("%d",x);
return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main implements Runnable{
	int N;
	int[] S;
	public void solve() {
		N = nextInt();
		S = new int[N];
		for(int i = 0;i < N;i++){
			S[i] = nextInt();
		}

		ArrayList<Integer> ts = new ArrayList<Integer>();
		for(int i = 1;i <= N;i++){
			if(N%i==0){
				ts.add(i);
			}
		}
		int ans = 0;
		for(int t : ts){

			int k = N / t;
			boolean flag = false;
			for(int i = 0;i < t;i++){
				for(int j = 0;j < k;j++){
					if(S[j * t + i]==S[i])continue;
					flag = true;
					break;
				}
				if(flag)break;
			}

			if(!flag){
				ans = Math.max(ans, k);
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

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

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VI card(n);
    VPI op(m);
    REP(i, n) { cin >> card[i]; }
    REP(i, m) {
        int b, c;
        cin >> b >> c;
        op[i] = make_pair(b, c);
    }
    sort(ALL(card));
    sort(ALL(op), [](const auto &a, const auto &b) {
        if (a.second == b.second)
            return a.first > b.first;
        else
            return a.second > b.second;
    });

    int i = 0;
    bool stop = false;
    for (auto &o : op) {
        if (stop) break;
        REP(r, o.first) {
            if (card[i] < o.second) {
                card[i] = o.second;
            } else {
                stop = true;
                break;
            }
            i++;
            if (i >= n) {
                stop = true;
                break;
            }
        }
    }
    ll ans = 0;
    REP(i, n)
    ans += card[i];
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 1408
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
w = inpl()
res = mod
for i in range(n):
    res = min(res,abs(sum(w[:i])- sum(w[i:])))
print(res)


Measured memory_bytes: 39148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	d := nextInt()
	n := nextInt()

	a := 1
	if d == 1 {
		a = 100
	} else if d == 2 {
		a = 10000
	}

	if n == 100 {
		fmt.Println(n*a + a)
	} else {
		fmt.Println(n * a)
	}

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World"<<endl;
	}else{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define INF 1050000000
 
using namespace std;

int n;
int w[101];
int v[101];
int dp[101][10001];

int rec(int i, int j) 
{
	int res;
	if (dp[i][j] >= 0) return dp[i][j];

	if (i == n) res = 0;
	else if (w[i] > j)
		res = rec(i + 1, j);
	else
		res = max(rec(i + 1, j), max(rec(i, j - w[i]) + v[i], rec(i + 1, j - w[i]) + v[i]));
	dp[i][j] = res;
	return (res);
}

int main(void)
{
	int W;

	cin >> n >> W;
	memset(dp, -1, sizeof(dp));

	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	cout << rec(0, W) << endl;

	return (0);
}

Measured memory_bytes: 5732
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int a, b, c, d;
    cin>>a>>b>>c>>d;
  //  cout<<min(b,d)<<" "<<max(a,b)<<endl;
    cout<<max(0, (min(b,d) - max(a, c)) );






    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int ans;
    if(n&1)
        ans = n/2+1;
    else ans=n/2;  
    if(ans>=k){
        cout<<"YES";
    }  
    else{
        cout<<"NO";
    }
}


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

int main() {
  ll n, x = 0, t = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    x += (a - 1) / t;
    if (t == 1 || t == a) t++;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
function MainC(input) {
	input = input.split("\n");
	var n = input.shift();
	var min = Infinity;	
　for(var i = 0; i < 5; i++){
		if( parseInt(input[i]) < min){
			min = parseInt(input[i]);
		}
	}
  var totalTime = Math.ceil(n / min) + 4;

	console.log('%d',totalTime);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
MainC(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int k, q;
    cin >> k >> q;
    vector<int> d(k);
    for(int i=0; i<k; ++i)
        cin >> d[i];

    while(--q >= 0){
        int n, x, m;
        cin >> n >> x >> m;
        -- n;

        long long sum = x % m;
        for(int i=0; i<k; ++i){
            int a = (n - i + k - 1) / k;
            int b = (d[i] + m - 1) % m + 1;
            sum += a * (long long)b;
        }
        long long ans = n - sum / m;
        cout << ans << endl;
    }

    return 0;
}


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

int bubbleSort(int A[],int n){
    bool flag(true);
    int ans(0);
    while(flag){
        flag = false;
        for(int i=n-1;i>=1;i--){
            if(A[i]<A[i-1]){
                swap(A[i],A[i-1]);
                ans++;
                flag = true;
            }
        }
    }
    return ans;
}

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

    int x = bubbleSort(A,n);
    for(int i=0;i<n;i++){
        if(i+1==n){
            cout << A[i] << endl;
        }else
            cout << A[i] << " ";
    }
    cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 3100
n=int(input())
for i in range(int((2*n)**0.5-3),n+2):
  if i*(i+1)//2==n:
    for j in range(1,i+1):
      print(j)
    break
  elif i*(i+1)//2>n:
    k=i*(i+1)//2-n
    for j in range(1,i+1):
      if j!=k:
        print(j)
    break

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans;
    if (2 * c >= a + b)
    {
        ans = a * x + b * y;
    }
    else
    {
        ans = 2 * c * min(x, y);
        if (x > y)
        {
            ans += min(2 * c, a) * (x - y);
        }
        else
        {
            ans += min(2 * c, b) * (y - x);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

int n;
vector<int> g[N];
int deg[N];
vector<int> order,leaves;
int ans[N];
long long answ;
int used[N];
vector<pair<int,int> > edges;

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);

	cin>>n;
	for (int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
		edges.push_back(make_pair(a,b));
		deg[a]++;
		deg[b]++;
	}

	for (int i=1;i<=n;i++){
		int val;
		cin>>val;
		order.push_back(val);
	}

	sort(order.begin(),order.end());
	reverse(order.begin(),order.end());

	for (int i=1;i<=n;i++){
		if (deg[i]<=1)
			leaves.push_back(i),
			used[i]=1;
	}

	while (leaves.size()>=1){
		int v=leaves.back();
		leaves.pop_back();
		ans[v]=order.back();
		order.pop_back();
		for (int i=0;i<g[v].size();i++){
			int to=g[v][i];
			if (used[to])
				continue;
			deg[to]--;
			if (deg[to]<=1){
				leaves.push_back(to);
				used[to]=1;
			}
		}
	}

	for (int i=0;i<edges.size();i++){
		int a=edges[i].first;
		int b=edges[i].second;
		answ+=min(ans[a],ans[b]);
	}

	cout<<answ<<endl;
	for (int i=1;i<=n;i++){
		if (i>1)
			cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;

//    cin.get(); cin.get();
    return 0;
}


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

  
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
  	long A[N];
  	int idx = 0;
  	while(cin >> A[idx])
    {
      idx++;
    }
  	
  	std::vector<long> dp_p(N+1);
  	std::vector<long> dp_n(N+1);
  
	dp_n[0] = -1e10;
 
  	for (int i=0; i<N; i++) {
    	dp_p[i+1] = std::max(dp_p[i]+A[i], dp_n[i]-A[i]);
    	dp_n[i+1] = std::max(dp_p[i]-A[i], dp_n[i]+A[i]);
      	cerr << dp_p[i+1] << ":" << dp_n[i+1] << endl;
  	}
  	cout << dp_p[N] << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll c[200000];
ll beki2[400001];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>c[i];
	sort(c,c+n);
	beki2[0]=1;
	for(int i=1;i<400001;i++)
	{
		beki2[i]=beki2[i-1]*2LL;
		beki2[i]%=MOD;
	}
	for(int i=0;i<n;i++)
	{
		ll tmp=beki2[2*n-2]*(ll)(n-i+1);
		tmp%=MOD;
		//cerr<<tmp<<endl;
		tmp*=c[i];
		tmp%=MOD;
		ans+=tmp;
		ans%=MOD;
	}
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  long long int N,M,i,j,k;
  string s = "";
  cin>>N>>M;
  if(N<=M) k=N,j=M;
  else k=M,j=N;
  for(i=0;i<j;i++) s+=('0' + k);
  cout<<s<<endl;
  return (0);
}

Measured memory_bytes: 256
def somesum(n):
    sum = 0
    x = n
    while int(x / 10) > 0:
        sum += x % 10
        x = int(x / 10)
    sum += x % 10
    return sum
    
n,a,b = map(int,input().split())
sum = 0
for val in range(1,n+1):
    if somesum(val) >= a and somesum(val) <= b:
        sum += val
print(sum)

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i] = A[i];
    }

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

    for (int i = 0; i < N; i++)
    {
        if (A[i] == B[0])
        {
            cout << B[1] << endl;
        }

        else
        {
            cout << B[0] << endl;
        }
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1LL<<60;

int main(){
  string s; cin >> s;
  ll k; cin >> k;
  for(int i = 0; i < k; i++){
    if('1' != s[i]){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if h[i] >= K:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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


int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  for(int i=A; i<B+1; i++) {
    if(abs(i-A)<K || abs(i-B)<K) cout << i << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <climits>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <stack>
#include <iomanip>
#include <set>
#include <map>

using namespace std ;

int main()
{
	int n,m;
	cin >> n >> m;
	if (m>=n)
	{
		cout<<"unsafe";
	}
	else 
	{
		cout<<"safe";
	}

return 0 ;

}

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

int main(void){
    ll n;
    cin >> n;

    ll march[5] = {0, 0, 0, 0, 0};
    rep(i, n){
        string s;
        cin >> s;

        if(s[0] == 'M')
            march[0]++;
        if(s[0] == 'A')
            march[1]++;
        if(s[0] == 'R')
            march[2]++;
        if(s[0] == 'C')
            march[3]++;
        if(s[0] == 'H')
            march[4]++;
    }

    ll a [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
    ll b [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
    ll c [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};

    ll count = 0;
    rep(i, 10){
        count += march[a[i]] * march[b[i]] * march[c[i]];
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAX_N = 1, MAX_W = 1010;

const int MOD = 1000000007;

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

// mod 1000000007 の世界で a += b する関数
void add(long long &a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

long long SSS[100];

int main() {
	// 入力
	long long N;
	string SS; cin >> N >> SS;
	string S;
	
	for (int i = 0; i < N; i++)
	{
		SSS[SS[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++)
	{
		for (int j = 0; j < SSS[i]; j++)
		{
			S += i + 'a';
		}
	}

	int n = N;

	// 前処理配列
	vector<vector<int> > next = calcNext(S);

	// DP
	vector<long long> dp(n + 1, 0);
	dp[0] = 1; // 初期化、空文字列 "" に対応
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 26; ++j) {
			if (next[i][j] >= n) continue; // 次の文字 j がもうない場合はスルー
			add(dp[next[i][j] + 1], dp[i]);
		}
	}

	// 集計
	long long res = 0;
	for (int i = 0; i <= n; ++i) add(res, dp[i]);

	cout << res - 1 << endl;
}

Measured memory_bytes: 14464
integer N
integer A,B
integer,allocatable,dimension(:)::P
integer Q1,Q2,Q3
read*,N
read*,A,B
allocate(P(N))
read*,P

Q1=0;Q2=0;Q3=0
do i=1,N
  if(P(i)<=A)then
    Q1=Q1+1
  else if(P(i)<=B)then
    Q2=Q2+1
  else
    Q3=Q3+1
  endif
end do
print"(I0)",min(Q1,Q2,Q3)
end

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;


int main(){
    int N,Q;
    int ans=0;
    string s;
    int l[100010],r[100010];
    cin >>N>>Q>>s;
    rep(i,Q)  cin >>l[i] >>r[i];
    rep(i,N-1){
        if(s[i] =='A' &&s[i+1] =='C') s[i] ='a';
    }
    int t[100010];
    t[0]=0;
    rep(i,N){
        if(s[i]=='a'){
            t[i+1] =t[i]+1;
        }
        else t[i+1] =t[i];
    }
    rep(i,Q){
        cout <<t[r[i]-1]-t[l[i]-1] <<endl;
    }
    return 0;
}

Measured memory_bytes: 2176