akhauriyash/Code-Regression huggingface dataset:
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
int A, B, C;
void solve(){
	if(B / A >= C)
		cout << C << endl;
	else
		cout << B / A << endl;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> A >> B >> C;
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            ArrayList<Integer> scores = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                scores.add(sc.nextInt());
            }
            scores.sort(Comparator.naturalOrder());
            double average = 0;
            for (int i = 1; i < scores.size() - 1; i++) {
                average += scores.get(i);
            }
            average /= (scores.size() - 2);
            System.out.println((int)Math.floor(average));
        }
        sc.close();
    }
}



Measured memory_bytes: 29488
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


priority_queue<pair<ll,int> > pque;
ll A[200000], B[200000];
int main(){
    int N;
    cin >> N;
    

    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    for(int i=0; i<N; i++){
        cin >> B[i];
        pque.push(make_pair(B[i], i));
    }
    
    
    ll ans=0;
    while(!pque.empty()){
        int i = pque.top().second;
        pque.pop();
        
        if(B[i]==A[i]){
            continue;
        }
        
        if(B[i]<A[i]){
            cout<<-1<<endl;
            return 0;
        }
        
        
   //     cout<<"i="<< i<<endl;
        
        
        if(B[i]>=A[i] && (B[i]-A[i])%(B[(i+1)%N]+B[(i+N-1)%N])==0){
            int next = A[i];
            //     cout<<"next:"<<next<<endl;
            ll times = (B[i]-next) / (B[(i+1)%N]+B[(i+N-1)%N]);

       //     cout<<"times:"<<times<<endl;
            
            ans+=times;
            B[i] = B[i] - (B[(i+1)%N] + B[(i+N-1)%N])*times;
        }else{
            int next = max(B[(i+1)%N], B[(i+N-1)%N]);
            //     cout<<"next:"<<next<<endl;
            ll times = (B[i]-next) / (B[(i+1)%N]+B[(i+N-1)%N]);
            if( (B[i]-next) % (B[(i+1)%N]+B[(i+N-1)%N]) != 0){
                times++;
            }
        //    cout<<"times:"<<times<<endl;
            
            ans+=times;
            B[i] = B[i] - (B[(i+1)%N] + B[(i+N-1)%N])*times;
        }
 /*
        cout<<B[i] << " " << A[i] << endl;
        for(int i=0; i<N; i++){
            cout << B[i]<<" ";
        }cout<<endl;
  */
        if(B[i]<A[i]){
            cout<<-1<<endl;
            return 0;
        }else if(B[i]>=A[i]){
            pque.push(make_pair(B[i],i));
        }
        
        

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


Measured memory_bytes: 9072
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int _=1e5+5;
inline int read()
{
	char ch='!';int z=1,num=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')z=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=(num<<3)+(num<<1)+ch-'0',ch=getchar();
	return z*num;
}
int n,a[_];
const int N=1e5;
int t[N+5];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	int c1=0,c2=0;
	for(int i=1;i<=n;i+=2)t[a[i]]++,c1++;
	int s1=0,s2=0,k;
	for(int i=1;i<=N;++i)
	{
		if(!s1||s1<t[i])s2=s1,s1=t[i],k=i;
		else if(s2<t[i])s2=t[i];
		t[i]=0;
	}
	for(int i=2;i<=n;i+=2)t[a[i]]++,c2++;
	int s3=0,s4=0,g;
	for(int i=1;i<=N;++i)
	{
		if(!s3||s3<t[i])s4=s3,s3=t[i],g=i;
		else if(s4<t[i])s4=t[i];
	}
//	cout<<s1<<' '<<s2<<' '<<k<<' '<<c1<<endl;
//	cout<<s3<<' '<<s4<<' '<<g<<' '<<c2<<endl;
	if(k==g)
	{
		int ans=c1-s1+c2-s4;
		ans=min(ans,c1-s2+c2-s3);
		printf("%d\n",ans);
	}
	else printf("%d\n",c1-s1+c2-s3);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
            int a,b;
            cin>>a>>b;
            
            
            if(a < b) {
            cout << "a < b" << endl;
    }
            else if(a > b) {
            cout << "a > b" << endl;
    }
            else {
            cout << "a == b" << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3068
(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nm (input-to-list (read-line)))
(defvar sc (loop for i from 1 to (cadr nm)
                 collect (input-to-list (read-line))))

(defun setnumlst (num-l index num)
  (if (and (zerop num)
           (eq 1 index)
           (not (eq 1 (length num-l))))
      nil
      (if (nth (1- index) num-l)
          (if (eq num (nth (1- index) num-l))
              num-l
              nil)
          (concatenate 'list (subseq num-l 0 (1- index))
                       `(,num)
                       (subseq num-l (1+ (1- index)))))))


(defun fill-first (num-l)
  (if (car num-l)
      num-l
      (concatenate 'list `(,(if (eq 1 (length num-l)) 0 1)) (subseq num-l 1))))

(defun fill-rest (num-l)
  (loop for num in num-l
        collect (if num
                    num
                    0)))

(defun setup (num-l set-l)
  (if set-l
      (let ((next-num-l (setnumlst num-l (caar set-l) (cadar set-l))))
        (if next-num-l
            (setup next-num-l (cdr set-l))
            nil))
      num-l))

(princ (let ((set-num-l (setup (loop for i from 1 to (car nm) collect nil) sc)))
         (if set-num-l
             (parse-integer (apply #'concatenate (cons 'string (loop for num in (fill-rest (fill-first set-num-l))
                                                                     collect (princ-to-string num)))))
             -1)))

Measured memory_bytes: 15456
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll a(n), b(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    ll cnt_a = 0, cnt_b = 0;
    rep(i, 0, n) {
        if (a[i] < b[i]) cnt_a += ceil((b[i] - a[i])/2);
        else cnt_b += a[i] - b[i];
    }
    if (cnt_a < cnt_b) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

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

    int input;
    for (int i = 0; i < n-1; i++)
    {
        cin >> input;
        v.push_back(input);
    }
    vector<int> ans(n);
    for (size_t i = 0; i < n-1; i++)
    {
        ans[v[i]-1]++;
    }

    for (size_t i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll n; cin>>n;
	ml m;
	lp(i,0,n) {
		ll p; cin>>p;
		m[p] = i+1;
	}
	lp(i,1,n+1)
	cout<<m[i]<<" ";
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

Measured memory_bytes: 7040
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main()
{
    ll A, B, C, K;
    std::cin >> A >> B >> C >> K;

    ll result = 0;

    // A が 引ける数よりおおい -> Aから全部引く
    if (K <= A)
        result = K;
    else
    {
        // Aまい先に引く
        result = A;
        ll rest = K - A;

        // 残り引ける数が B より少ない -> 残りは全部Bを引く
        if (rest <= B)
            result = A;
        else
        {
            // Bまい先に引く
            rest -= B;

            // 残った数だけCを引く
            result -= rest;
        }
    }

    std::cout << result << std::endl;
}


Measured memory_bytes: 3636
def main():
    N,K = map(int,input().split())
    
    if N==K:
        ans = 0
    elif N<K:
        ans = min(-N+K,N)
    else:
        ans = N%K
        ans = min(ans, K-ans)

    print(ans)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  int n;
  std::cin >> n;

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

  double mean = std::accumulate(a.begin(), a.end(), 0) / (double)a.size();
  int x = (int)std::floor(mean);
  int y = (int)std::ceil(mean);

  int x_sum = 0, y_sum = 0;
  for (auto ai : a) {
    x_sum += (ai - x) * (ai - x);
    y_sum += (ai - y) * (ai - y);
  }
  std::cout << std::min(x_sum, y_sum) << std::endl;
  /* */

  return EXIT_SUCCESS;
}


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

int mod_pow(int n, int e, int mod){
    int ans = 1;
    n = n % mod;
    while(e != 0){
        if(e % 2 == 1){
            ans = (ans * n) % mod;
        }
        e /= 2;
        n = (n * n) % mod;
    }
    return ans;
}

int mod_inv(int n, int mod){
    return mod_pow(n, mod-2, mod);
}

int mod_combination(int n, int k, int mod){
    if(n < k || k < 0) return 0;
    if(n-k < k) k = n-k;
    int ans = 1;
    for(int i=1; i<=k; i++){
        ans = (((ans * (n+1-i)) % mod) * mod_inv(i, mod)) % mod;
    }
    return ans;
}

template<int MOD> struct modint{
    int val;
    constexpr modint(int v): val(v % MOD){
        if(val < 0) val += MOD;
    }
    constexpr int getmod(){
        return MOD;
    }
    constexpr modint operator-(){
        return val? MOD - val : 0; 
    }

    constexpr modint operator+(const modint& r){
        return modint(*this) += r;
    }
    constexpr modint operator-(const modint& r){
        return modint(*this) -= r;
    }
    constexpr modint operator*(const modint& r){
        return modint(*this) *= r;
    }
    constexpr modint operator/(const modint& r){
        return modint(*this) /= r;
    }


    constexpr modint& operator+=(const modint &r){
        val += r.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    constexpr modint& operator-=(const modint& r){
        val -= r.val;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr modint& operator*=(const modint& r){
        val = (val * r.val) % MOD;
        return *this;
    }
    constexpr modint& operator/=(const modint& r){
        // ax + bz = a, ay + bw = b からスタートして
        // 右辺について互除法して係数を変えていく
        // (x, y) -> (y, x-y*(a/b)), (z, w) -> (w, z-w*(a/b))
        // 最終的に ax + bz = gcd(a, b) となるので a, b が互いに素なら x が逆元
        // z と w を覚えておく必要はない
        int a = r.val, b = MOD, x = 1, y = 0;
        while(b){
            x -= y * (a/b); swap(x, y);
            a -= b * (a/b); swap(a, b);
        }
        val = (val * x) % MOD;
        if(val < 0) val += MOD;
        return *this;
    }

    constexpr bool operator==(const modint& r){
        return val == r.val;
    }
    constexpr bool operator!=(const modint& r){
        return val != r.val;
    }

    constexpr modint modpow(int e){
        modint ans = 1, n = *this;
        while(e){
            if(e & 1) ans *= n;
            n *= n;
            e /= 2;
        }
        return ans;
    }

    friend constexpr ostream& operator<<(ostream &os, const modint<MOD>& x){
        return os << x.val;
    }
};

const int MOD = 1000000007;
using mint = modint<MOD>;

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int s;
    cin >> s;
    mint ans = 0;
    for(int i=0; 3*i<=s; i++){
        ans += mod_combination(s-3*i+i-1, i-1, MOD);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int n;

map<string, int> mp; 

int main() {
	cin >> n;
	string str;
	for (int i = 1; i <= n; i++) {
		cin >> str;
		mp[str]++;
	}
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int a,b,c,m;
    scanf("%d%d%d",&a,&b,&c);
    m=max(c,max(a,b));
    if((3*m-a-b-c)%2) printf("%d\n",(3*m-a-b-c+3)/2);
    else printf("%d\n",(3*m-a-b-c)/2);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for(long long i = a; i < b; i++)
#define ll long long
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, 0, n) {
    cin >> a[i];
    sum += a[i];
  }
  long long q;
  cin >> q;
  vector<ll> b(100001, 0), c(100001, 0);
  rep(i, 0, q) cin >> b[i] >> c[i];
  vector<ll> s(100000, 0);
  rep(i, 0, n) {
    s[a[i]]++;
  }
  rep(i, 0, q) {
    sum -= s[b[i]] * b[i];
    sum += s[b[i]] * c[i];
    s[c[i]] += s[b[i]];
    s[b[i]] = 0ll;
    cout << sum << "\n";
  }
}

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

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (int i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<int,int> ii;

/****************************************************/
void printArr(int a[], int l, int r)
{
    up(i,l,r) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void printMtx(int a[][1010],int n, int m)
{
    up(i,1,n) {
        up(j,1,m) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}
/****************************************************/

ll n,cnt4,cnt, temp,cnt2;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n;
    up(i,1,n) {
        cin >> temp;
        if (temp%4 == 0) cnt4++;
        else if (temp%2==0) cnt2++;
        else if ((temp%4!=0) && (temp%2!=0)) cnt++;
    }
    if (cnt2 > 0) {
        if (cnt4 >= cnt) cout << "Yes\n";
        else cout << "No\n";
    }
    else {
        if (cnt4 >= cnt-1) cout << "Yes\n";
        else cout << "No\n";
    }
}


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

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

  lint ans = 0;
  for(lint i=1; i<=N; i++) {
    lint a;
    cin >> a;
    ans += (i%2 && a%2);
  }
  cout << ans << endl;
}

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

typedef long long ll;

/*
MARCHの個数をcntに入れておく
添え字はMARCHの順
組み合わせは、
{0,1,2},{0,1,3},{0,1,4},{1,2,3},{1,3,4},{2,3,4},
{1,2,4},{0,3,4},{0,2,4},{0,2,3}
*/

int fir[] = {0,0,0,1,1,2,1,0,0,0};
int sec[] = {1,1,1,2,3,3,2,3,2,2};
int thi[] = {2,3,4,3,4,4,4,4,4,3};

int main(){
    ll N;
    cin>>N;
    vector<ll> cnt(5,0);

    for(int i=0; i<N; i++){
        string s;
        cin>>s;
        if(s[0] == 'M') cnt[0]++;
        else if(s[0] == 'A') cnt[1]++;
        else if(s[0] =='R') cnt[2]++;
        else if(s[0] == 'C') cnt[3]++;
        else if(s[0] == 'H') cnt[4]++;
    }

    long long ans = 0;

    for(int i=0; i<10; i++){
        ans += cnt[fir[i]]*cnt[sec[i]]*cnt[thi[i]];
    }

    cout<<ans<<endl;

    return 0;

}

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

#define rep(i,s,t) for(int i=s,i##end=t;i<=i##end;++i)
#define per(i,s,t) for(int i=t,i##end=s;i>=i##end;--i)
#define repo(i,s,t) for(int i=s,i##end=t;i<i##end;++i)
#define debug(x) cerr<<#x<<" : "<<x<<" "<<__FUNCTION__<<__LINE__<<endl

const int MAXN = 2005;

int n;
int A[MAXN], all;

bitset <MAXN * MAXN> dp;

int main() {
	cin >> n;
	rep (i, 1, n) scanf("%d", &A[i]), all += A[i];
	
	int hf = (all + 1) / 2;
	
	dp[0] = 1;
	rep (i, 1, n) {
		dp |= dp << A[i];
	}
	
	rep (i, hf, all) if (dp[i]) {
		cout << i << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1664
import numpy as np
import sys
sys.setrecursionlimit(10**6)

n=int(input())

m=int(np.sqrt(n))+1

if n==1 or n==0:
    print(0)
    exit()

ans=0
for i in range(2,m):
    cnt=0
    for j in range(44):
        if n%i==0:
            n=n/i
#            print("i=",i,"n=",n)
            cnt+=1
        else:
            break
    if 1<=cnt<3:
        ans+=1
    if 3<=cnt<6:
        ans+=2
    if 6<=cnt<10:
        ans+=3
    if 10<=cnt<15:
        ans+=4
    if 15<=cnt<21:
        ans+=5
    if 21<=cnt<28:
        ans+=6
    if 28<=cnt<36:
        ans+=7
    if 36<=cnt<45:
        ans+=8

if int(n)!=1:
    ans+=1

if ans==0:
    print(1)
    exit()

print(ans)        


Measured memory_bytes: 27172
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint solve (int n, vector<vector<lint>> &a){
    lint ret = 0;
    lint sum = 0;
    for (int i=0; i<n; ++i){
        sum = 0;
        for (int j=0; j<n; ++j){
            if(j < i){
                sum += a[0][j];
            }
            else if(j == i){
                sum += a[0][j] + a[1][j];
            }
            else if(j > i){
                sum += a[1][j];
            }
        }
        ret = max(ret, sum);
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<lint>> a(2);
    for (int i=0; i<2; ++i){
        a[i].resize(n);
        for (int j=0; j<n; ++j){
            cin >> a[i][j];
        }
    }
    cout << solve(n, a) << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
const string alp = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ll N;
    cin >> N;
    map<ll, ll> aMap;
    ll sum = 0;
    rep(i, N) {
        ll a;
        cin >> a;
        if (aMap[a]) {
            aMap[a]++;
        } else {
            aMap[a] = 1;
        }

        sum += a;
    }

    map<ll, ll>::iterator it;
    ll Q;
    cin >> Q;
    ll sumAll[Q];
    
    rep(i, Q) {
        ll B;
        ll C;
        cin >> B >> C;

        if (aMap[B]) {
            ll cnt = aMap[B];
            if (aMap[C]) {
                aMap[C] = aMap[C] + cnt;
            } else {
                aMap[C] = cnt;
            }
            sum = sum + cnt * (C - B);
            aMap.erase(B);
        }

        sumAll[i] = sum;
    }

    rep(i, Q){
        cout << sumAll[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 8500
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(All(v));
  int ans = 0;
  for(int i = 0; i < n-2; i++){
    for(int j = i+1; j < n-1; j++){
      ans += lower_bound(All(v), v[i]+v[j]) - (v.begin()+j+1);
    }
  }
  cout << ans << endl;
  system("pause");
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll N,K; cin >> N >> K;
	V<V<ll>> a(11);
	REP(i,N) {
		ll C;
		int idx;
		cin >> C >> idx;
		a[idx].push_back(C);
	}
	REP(i,11) sort(ALL(a[i]),greater<ll>());
	for(int i = 1; i < 11; ++i) 
	for(int j = 1; j < a[i].size(); ++j) a[i][j] += a[i][j-1];

	V<V<ll>> dp(11,V<ll>(K+1,-1));
	dp[0][0] = 0;
	for(int i = 1; i < 11; ++i){
		for(int j = 0; j < a[i].size(); ++j){
			for(int k = 0; k <= K; ++k){
				if(k+j+1<=K)chmax(dp[i][k+j+1],dp[i-1][k]+a[i][j]+j*(j+1) );
			}
		}
		for(int k = 0; k <= K; ++k){
			chmax(dp[i][k],dp[i-1][k]);
		}
	}
	cout << dp[10][K] << endl;


	return 0;
}



Measured memory_bytes: 3288
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printl(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}

signed main (){
    char c;cin>>c;
    if(c=='A')cout<<'T'<<endl;
    else if(c=='T')cout<<'A'<<endl;
    else if(c=='C')cout<<"G"<<endl;
    else if(c=='G')cout<<"C"<<endl;
}

/*
*/


Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut a = a.iter().zip(0..n).collect::<Vec<_>>();
    a.sort();
    a.reverse();

    let mut dp = vec![vec![0; n + 1]; n + 1];

    for l in 0..n {
        for r in 0..n {
            if l + r >= n {
                break;
            }

            let (v, i) = a[l + r];

            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + v * (l as i64 - i as i64).abs());
            dp[l][r + 1] = max(
                dp[l][r + 1],
                dp[l][r] + v * (n as i64 - 1 - r as i64 - i as i64).abs(),
            );
        }
    }

    let mut ans = 0;

    for i in 0..n {
        ans = max(ans, dp[i][n - i]);
    }

    println!("{}", ans);
}


Measured memory_bytes: 33404
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;
 
typedef ostringstream OSS;
typedef istringstream ISS;
 
typedef vector<int> VI;
typedef vector< VI > VVI;
 
typedef long long LL;
 
typedef pair<int, int> PII;
typedef vector<PII> VPII;
 
#define X first
#define Y second
 
int main(void) {
	int dataset_index = 1;

	int W, N;
	while (cin >> W >> N, W) {
		VI ps(N), ws(N);

		char dummy;
		for (int i = 0; i < N; i++) {
			cin >> ps[i] >> dummy >> ws[i];
		}

		VVI dp(N + 1, VI(W + 1, -1));
		dp[0][0] = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < W + 1; j++) {
				if (dp[i][j] == -1) continue;
				
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

				int w = j + ws[i];
				int p = dp[i][j] + ps[i];
				if (w <= W) {
					dp[i + 1][w] = max(dp[i + 1][w], p);
				}
			}
		}

		int ans_p = 0, ans_w = 0;

		for (int i = 0; i < W + 1; i++) {
			if (dp[N][i] > ans_p) {
				ans_p = dp[N][i];
				ans_w = i;
			}
		}

		cout << "Case " << dataset_index << ":" << endl;
		cout << ans_p << endl << ans_w << endl;

		++dataset_index;
	}
}

Measured memory_bytes: 5028
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで
using namespace std;
typedef pair<string, int> P;
typedef pair<P,int> PP;



int n;
vector<PP> v;

signed main(){
  cin >> n;
  FOR(i,n){
    string s;
    int k;
    cin >> s >> k;
    P p1 = P(s,-k);
    PP p2 = PP(p1,i);
    v.pb(p2);
  }
  sort(v.begin(),v.end());
  REP(i,n){
    cout << v[i].second << endl;
  }
  return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    string ans = "Balanced";
    if (A + B > C + D)
    {
        ans = "Left";
    }
    else if (A + B < C + D)
    {
        ans = "Right";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
bets = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

n = gets.chomp.to_i
text_b = gets.chomp.split("")
text_a = ""

text_b.each do |t|
  tmp_n = bets.index(t) + n
  if tmp_n >= 26 then
    tmp_n -= 26
  end
  tmp_s = bets[tmp_n]
  text_a += tmp_s
end

puts text_a


Measured memory_bytes: 19836
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, d, e, f = map(int, readline().split())
A = 100 * a
B = 100 * b
E = e / (100 + e)
ans = [0, 0]
check = 0
for i in range(f // A + 2):
    for j in range(f // B + 2):
        w = A * i + B * j
        for k in range(int((w * E) // c) + 2):
            for l in range(int((w * E) // d) + 2):
                if k == 0 and l == 0:
                    continue
                s = c * k + d * l
                n = s / (w + s)
                if w + s > f or n > E:
                    break
                if n > check:
                    ans = w + s, s
                    check = n
                    if check == E:
                        print(*ans)
                        exit()
if ans[0] == 0:
    print(100 * a, ans[1])
else:
    print(*ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9;


int main()
{
    int n;
    ll k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    vector<int> s;
    vector<int> order(n+1,-1);
    int point=1;
    while(order[point]==-1)
    {
        order[point]=s.size();
        s.push_back(point);
        point=a[point-1];

    }

    if(k<order[point])
    {
        cout<<s[k];
    }
    else
    {
        k-=order[point];
        int c=s.size()-order[point];
        k%=c;
        cout<<s[k+order[point]];
    }
    
    
    

}

Measured memory_bytes: 5824
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>


typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll DEF_VAL = (1LL << 31) - 1;
constexpr ll SEG_LEN = (1LL << 18);
pair<ll,ll> segTree[SEG_LEN * 2]; // segTree[i] = {times, val}

void initialize() {
	for (ll i = 0; i < SEG_LEN * 2; i++) {
		segTree[i] = make_pair(0, DEF_VAL);
	}
}

void add(ll l, ll r, ll val, ll times) {
	l += SEG_LEN;
	r += SEG_LEN;
	while (l < r) {
		if (l % 2 == 1) {
			segTree[l++] = make_pair(times, val);
		}
		l /= 2;
		if (r % 2 == 1) {
			segTree[--r] = make_pair(times, val);
		}
		r /= 2;
	}
}

ll get(ll idx) {
	idx += SEG_LEN;
	pair<ll,ll> ans = make_pair(0, DEF_VAL);
	while (idx > 0) {
		if (ans.first < segTree[idx].first) {
			ans = segTree[idx];
		}
		idx /= 2;
	}
	return ans.second;
}

int main() {
	ll aLen, Q;
	cin >> aLen >> Q;
	ll times = 0;
	for (ll i = 0; i < Q; i++) {
		ll com;
		cin >> com;
		if (com == 0) {
			ll l, r, val;
			cin >> l >> r >> val;
			add(l, r+1, val, ++times);
		}
		else {
			ll idx;
			cin >> idx;
			cout << get(idx) << endl;
		}
	}
}



Measured memory_bytes: 6204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
char d[] = {'E', 'S', 'W', 'N'};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, w, l;
	while(cin >> h >> w >> l)
	{
		if(h == 0 && w == 0 && l == 0)
			break;
		int y, x, dir;
		char table[h + 1][w + 1];
		for(int i = 0; i < h; i++)
			for(int j = 0; j < w; j++)
			{
				cin >> table[i][j];
				if(table[i][j] == 'E')
				{
					y = i; x = j; dir = 0;
				}
				if(table[i][j] == 'S')
				{
					y = i; x = j; dir = 1;
				}
				if(table[i][j] == 'W')
				{
					y = i, x = j; dir = 2;
				}
				if(table[i][j] == 'N')
				{
					y = i; x = j; dir = 3;
				}
			}
		ll flag[h + 1][w + 1][4];
		memset(flag, -1, sizeof(flag));
		while(l > 0)
		{
			if(flag[y][x][dir] != -1)
			{
				ll tmp = (flag[y][x][dir] - l);
				l %= tmp;
				if(l == 0) l += tmp;

			}
			else 
				flag[y][x][dir] = l;
			int ny = y + dy[dir];
			int nx = x + dx[dir];
			if(ny < 0 || nx < 0 || ny >= h || nx >= w || table[ny][nx] == '#')
			{
				dir = (dir + 1) % 4;
			}
			else
			{
				y += dy[dir];
				x += dx[dir];
				l--;
			}
		}
		cout << y + 1 << " " << x + 1 << " " << d[dir] << endl;	
	}
	return 0;
}


Measured memory_bytes: 3424
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct Ver {
	int i;
	int c;
	int64_t v;
};

tuple<int, int, int> count_hight(int i, multimap<int, int>& es, int n)
{
	vector<bool> check(n + 1);
	vector<int> hs(n + 1);
	vector<int> prevs(n + 1);

	hs[i] = 0;
	check[i] = true;

	queue<int> search;
	search.push(i);

	int cur_max = 0;
	int max_i = 0;
	while (!search.empty()) {
		int j = search.front();
		search.pop();

		cur_max = hs[j];
		max_i = j;

		auto it = es.find(j);
		while (it != es.end() && it->first == j) {
			if (check[it->second]) {
				it++;
				continue;
			}

			hs[it->second] = cur_max + 1;
			check[it->second] = true;
			prevs[it->second] = it->first;
			search.push(it->second);

			it++;
		}
	}

	int j = max_i;
	for (int c = 0; c < cur_max / 2; c++) {
		j = prevs[j];
	}

	return make_tuple( cur_max, max_i, j);
}

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

	int n; cin >> n;
	vector<Ver> counts(n + 1);
	FOR_LE(i, 1, n) {
		counts[i].i = i;
	}
	vector<int64_t> vals(n);
	vector < pair<int, int>> es(n - 1);
	multimap<int, int> es_m;

	FOR_LT(i, 1, n) {
		int a, b; cin >> a >> b;
		counts[a].c++;
		counts[b].c++;
		es[i - 1] = { a, b };

		es_m.insert({ a, b });
		es_m.insert({ b, a });
	}

	FOR_LT(i, 0, n) {
		int c; cin >> c;
		vals[i] = c;
	}
	std::sort(vals.begin(), vals.end(), greater<int64_t>());

	int hj = 0;
	{
		auto m = count_hight(1, es_m, n);
		hj = get<2> (count_hight(get<1>(m), es_m, n));
	}

	{
		vector<bool> check(n + 1);

		check[hj] = true;
		int c = 0;
		counts[hj].v = vals[c];
		c++;

		queue<int> search;
		search.push(hj);

		while (!search.empty()) {
			int j = search.front();
			search.pop();

			auto it = es_m.find(j);
			while (it != es_m.end() && it->first == j) {
				if (check[it->second]) {
					it++;
					continue;
				}

				counts[it->second].v = vals[c];
				c++;

				check[it->second] = true;
				search.push(it->second);
				it++;
			}
		}
	}

	int64_t sum = 0;
	for(auto e : es) {
		sum += min(counts[e.first].v, counts[e.second].v);
	}

	cout << sum << endl;

	FOR_LE(i, 1, n) {
		cout << counts[i].v << " ";
	}
	cout << endl;


	return 0;
}

Measured memory_bytes: 1664
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String A = sc.next();
      if("SAT".equals(A)){
      System.out.println("1");
      }else if("FRI".equals(A)){
      System.out.println("2");
      }else if("THU".equals(A)){
      System.out.println("3");
      }else if("WED".equals(A)){
      System.out.println("4");
      }else if("TUE".equals(A)){
      System.out.println("5");
      }else if("MON".equals(A)){
      System.out.println("6");
      }else if("SUN".equals(A)){
      System.out.println("7");
      }
        
      

 
      
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 23636
#include <cstdio>

int main() {
    int N;
    scanf(" %d", &N);

    bool flg = false;
    for (int i = 0; i < N; i++) {
        char S;
        scanf(" %c", &S);
        if (S == 'Y') {
            flg = true;
        }
    }

    if (flg) {
        printf("Four\n");
    } else {
        printf("Three\n");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll dpa[101], dpc[101], dpg[101], dpt[101];
  cin >> N;
  dpa[0] = dpc[0] = dpg[0] = dpt[0] = 0;
  dpa[1] = dpc[1] = dpg[1] = dpt[1] = 1;
  dpa[2] = dpc[2] = dpg[2] = dpt[2] = 4;
  for(int i = 3; i <= N; i++){
    dpa[i] = (dpa[i-1] + dpc[i-1] + dpg[i-1] + dpt[i-1]) % MOD;
    dpc[i] = (dpa[i-1] + dpc[i-1] + dpg[i-1] + dpt[i-1] - dpa[i-2] - dpg[i-2] - dpa[i-3]*3) % MOD;
    dpg[i] = (dpa[i-1] + dpc[i-1] + dpg[i-1] + dpt[i-1] - dpa[i-2] + dpg[i-3]) % MOD;
    dpt[i] = (dpa[i-1] + dpc[i-1] + dpg[i-1] + dpt[i-1]) % MOD;
  }
  int ans = (dpa[N] + dpc[N] + dpg[N] + dpt[N]) % MOD;
  if (ans < 0) ans += MOD * (abs(ans) / MOD + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    H, W = NMI()
    grid = [SI() for _ in range(H)]
    step = [[-1]*W for _ in range(H)]
    que = deque()
    for h in range(H):
        for w in range(W):
            p = grid[h][w]
            if p == "#":
                que.append((h, w))
                step[h][w] = 0
    DIR = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    while que:
        x, y = que.popleft()

        for dx, dy in DIR:
            if not(0 <= x+dx < H and 0 <= y+dy < W):
                continue
            if step[x+dx][y+dy] >= 0:
                continue
            que.append((x+dx, y+dy))
            step[x+dx][y+dy] = step[x][y] + 1

    print(max([max(s) for s in step]))



if __name__ == "__main__":
    main()

Measured memory_bytes: 110316
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=50+10;

int N,A;
int X[maxm];
long long DP[maxm][maxm*maxm];

int main(){
	register int i,j,k;
	register long long Ans=0;
	scanf("%d%d",&N,&A);
	DP[0][0]=1;
	for(i=1;i<=N;i++) scanf("%d",X+i);
	for(i=1;i<=N;i++){
		for(j=i;j;j--){
			for(k=X[i];k<=2500;k++){
				DP[j][k]+=DP[j-1][k-X[i]];
			}
		}
	}
	for(i=1;i<=N;i++){
		Ans+=DP[i][i*A];
	}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
 
int main(void){
  int n,i;
  long int a[10] = {0,0,0,0,0,0,0,0,0,0};
  long long int b = 0;
  scanf("%d", &n);
  for (i = 0; i<n; i++){
  	scanf("%d",&a[i]);  //ここまで配列の準備
  	b = b + a[i];
  }
  
  int tmp,j;
  for (i = 1; i<n; i++) {
    tmp = a[i];
    if (a[i - 1] > tmp) {
        j = i;
        do {
            a[j] = a[j - 1];
            j--;
        } while (j > 0 && a[j - 1] > tmp);
        a[j] = tmp;
    }
  }
  b = b - a[n-1];
  //printf("%d",b);
  if(b>a[n-1]){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
  
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
G = dict([[i, []] for i in range(N)])
for _ in range(M):
    x, y = map(int, input().split())
    G[x-1].append(y-1)

dp = [-1] * N


def rec(v):
    if dp[v] >= 0:
        return dp[v]
    if len(G[v]) == 0:
        return 0

    ret = -1
    for nv in G[v]:
        ret = max(ret, rec(nv) + 1)

    dp[v] = ret
    return ret


print(max([rec(v) for v in range(N)]))


Measured memory_bytes: 73936