akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    vector<ll> AA(2*N);
    rep(i,N){
        cin>>A.at(i);
        AA.at(i)=A.at(i);
        AA.at(i+N)=A.at(i);
    }
    vector<ll> base(N);
    rep(i,N){
        for(int j=i+1; j<N; j++){
            if(A.at(i)>A.at(j)){
                base.at(i)++;
            }
        }
    }
    vector<ll> inc(N);
    rep(i,N){
        for(int j=N; j<2*N; j++){
            if(AA.at(i)>AA.at(j)){
                inc.at(i)++;
            }
        }
    }
    ll ans=0;
    ll mod=1000000007;
    ll minv = modinv(2,mod);
    rep(i,N){
        //初項base.at(i)
        //公差inc.at(i)
        //項数K
        ll tmp=((2*base.at(i))+((K-1)*inc.at(i)))%mod *K %mod *minv %mod;
        ans+=tmp;
        ans%=mod;
    }
    cout<<ans<<endl;
}


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

using namespace std;
const int maxn=1e5+5;
int n;
char s[maxn];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]!=s[i-1])
            ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int x;
	cin>>x;
	cout<<(x?0:1);
	re 0;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main() {
    int H, N;

    cin >> H >> N;

    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        H -= A;
        if(H <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int n;
	cin>>n;
	map<int,int> mpp;
	ll sum=0;
	for(int i=0;i<n;i++) {
		int a; cin>>a;
		mpp[a]++;
		sum+=a;
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++) {
		ll b,c;
		cin>>b>>c;
		sum+=mpp[b]*(c-b);
		mpp[c]+=mpp[b];
		mpp[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 7976
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] xArray = new int[n];
		int[] yArray = new int[m];
		for(int i = 0; i < n; i++)
			xArray[i] = sc.nextInt();
		for(int i = 0; i < m; i++)
			yArray[i] = sc.nextInt();
		int low = Arrays.stream(xArray).max().getAsInt();
		int high = Arrays.stream(yArray).min().getAsInt();
		boolean b = false;
		for(int i = low+1; i <= high && !b; i++)
			b |= x < i && i <= y;
		System.out.println(b ?"No War" :"War" );
	}
}


Measured memory_bytes: 28364
#include <iostream>

using namespace std;

int main(){
    int a,b;
    while(cin >> a >> b){
        if(a+b == 0) break;
        int change = b - a;

        int x,y,z;
        z = change / 1000;
        change -= z * 1000;
        y = change / 500;
        change -= y * 500;
        x = change / 100;

        cout << x << " " << y << " " << z << endl;
    }
}

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

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	UL A[3000];
	ULL dp[3001] = {};
	ULL dp2[3001] = {};

	static const ULL M = 998244353;

	void Solve() {
		UL N, S; cin >> N >> S;
		rep(i, N) cin >> A[i];
		dp[0] = dp2[0] = 1;
		ULL ans = 0;
		rep(i, N) {
			for (UL s = A[i]; s <= S; s++) {
				dp2[s] += dp[s - A[i]];
			}
			dp2[0]++;
			rep(i, S + 1) dp2[i] %= M;
			rep(i, S + 1) dp[i] = dp2[i];
			ans += dp[S]; ans %= M;
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){

    ll h,w;
    cin >> h >> w;
    ll ans = h*w;

    if(w==1||h==1){
        cout << 1 << endl;
        return 0;
    }
    if(ans%2==1){
        cout << (ans+1)/2 << endl;
    }else{
        cout << ans/2 << endl;
    }
    


    return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a,b,c) for(b=(c);b<(a);b++)
#define zettaiti(a) ((a) > 0 ? (a) : (-a))
int kakuinowa(long x);
int main() {
	int n;
	vector<int> a;
	int i, num, ans;
	cin >> n;
	FOR(n, i, 0) {
		cin >> num;
		a.push_back(num);
	}
	sort(a.begin(), a.end());
	ans = a[n - 1] - a[0];
	cout << ans;
	cin >> ans;
	return 0;
}
int kakuinowa(long x) {
	int y = 0;
	while (x>10)
	{
		y += x % 10;
		x /= 10;
	}
	y += x;
	return y;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> y[i];
  }
  ll xs = 0, ys = 0;
  for (int i = 1; i < n; i++) {
    xs += ((x[i] - x[i-1]) * (1ll * i * (n - i) % MOD)) % MOD;
    xs %= MOD;
  }
  for (int i = 1; i < m; i++) {
    ys += ((y[i] - y[i-1]) * (1ll * i * (m - i) % MOD)) % MOD;
    ys %= MOD;
  }
  ll res = (xs * ys) % MOD;
  cout << res << endl;
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	long long ans = 0, before;
	cin >> before;
	bool HasNoAns = (before > 0);
	for (int i = 1; i < N; i++) {
		int now;
		cin >> now;
		if (now == 0) {
			before = now;
			continue;
		}
		if (now == before + 1) ans++;
		else {
			if (now <= before) ans += now;
			else HasNoAns = true;
		}
		before = now;
	}
	cout << (HasNoAns ? -1 : ans) << endl;
}

Measured memory_bytes: 256
//Created by Aminul on 7/5/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        HashMap<String, Integer> map = new HashMap<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String s = in.next();
            map.put(s, map.getOrDefault(s, 0) + 1);
        }

        pw.println("AC x " + map.getOrDefault("AC", 0));
        pw.println("WA x " + map.getOrDefault("WA", 0));
        pw.println("TLE x " + map.getOrDefault("TLE", 0));
        pw.println("RE x " + map.getOrDefault("RE", 0));


        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 48948
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        _k: usize,
        ss: [Chars; h],
    }

    let mut ans = vec![vec![0; w]; h];
    let mut berries = vec![];

    let mut id = 1;
    for i in 0..h {
        for j in 0..w {
            if ss[i][j] == '#' {
                berries.push(((i, j), id));
                ans[i][j] = id;
                id += 1;
            }
        }
    }

    for ((i, j), id) in berries.into_iter() {
        let mut left = j;
        if left > 0 {
            left -= 1;
            loop {
                if ans[i][left] != 0 {
                    left += 1;
                    break;
                }

                ans[i][left] = id;
                if left == 0 {
                    break;
                }
                left -= 1;
            }
        }

        let mut top = i;
        if top > 0 {
            top -= 1;
            'top: loop {
                for j in left..=j {
                    if ans[top][j] != 0 {
                        top += 1;
                        break 'top;
                    }
                }
                for j in left..=j {
                    ans[top][j] = id;
                }
                if top == 0 {
                    break;
                }
                top -= 1;
            }
        }

        let mut right = j + 1;
        'right: while right < w {
            for i in top..=i {
                if ans[i][right] != 0 {
                    break 'right;
                }
            }
            for i in top..=i {
                ans[i][right] = id;
            }
            right += 1;
        }

        let mut bottom = i + 1;
        'bottom: while bottom < h {
            for j in left..right {
                if ans[bottom][j] != 0 {
                    break 'bottom;
                }
            }
            for j in left..right {
                ans[bottom][j] = id;
            }
            bottom += 1;
        }
    }

    for line in ans.iter() {
        let line = line
            .into_iter()
            .map(|e| e.to_string())
            .collect::<Vec<_>>()
            .join(" ");
        println!("{}", line);
    }
}


Measured memory_bytes: 5040
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, a, b;
vector<int> vec[100009];
multiset<int> st;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		int tmp = m - a;
		if (tmp < 0) continue;
		vec[tmp].pb(b);
	}
	long long ans = 0;
	int cnt = 0;
	for (int i = m - 1; i >= 0; i--) {
		for (int j = 0; j < (int)vec[i].size(); j++) {
			st.insert(-vec[i][j]);
		}
		if (st.empty()) continue;
		auto x = st.begin();
		ans -= *x;
		st.erase(x);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 7808
N = int(input())
S = input()

cd = []
q = []
for s in S:
    if q and q[-1]=="(":
        if s==")":
            q.pop()
        else:
            q.append(s)
    else:
        q.append(s)
sl = []
sr = []
for s in q:
    if s==")":
        sl.append("(")
    else:
        sr.append(")")
print("".join(sl)+S+"".join(sr))


Measured memory_bytes: 8968
# -*- coding: utf-8 -*-

mod = 10 ** 9 + 7


def mod_pow(a: int, p: int):
    '''a ** p % mod.'''

    if p == 0:
        return 1

    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return (half ** 2) % mod
    else:
        return (a * mod_pow(a, p - 1)) % mod


def calc_combination(a: int, b: int):
    '''aCb % mod.'''

    if b > (a - b):
        return calc_combination(a, a - b)

    multiple = 1
    division = 1

    for i in range(b):
        multiple *= a - i
        division *= i + 1
        multiple %= mod
        division %= mod

    return multiple * mod_pow(division, mod - 2) % mod


def solve(n: int, m: int):
    from math import sqrt

    ans = 1
    remain = m

    for j in range(2, int(sqrt(m)) + 1):
        if remain % j == 0:
            count = 0

            while remain % j == 0:
                count += 1
                remain //= j

            ans *= calc_combination(n + count - 1, n - 1)
            ans %= mod

    if remain != 1:
        ans *= calc_combination(n, 1)
        ans %= mod

    return ans


def main():
    n, m = map(int, input().split())

    # See:
    # https://www.youtube.com/watch?v=gdQxKESnXKs
    print(solve(n, m))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	cout << (1000 - (n % 1000)) % 1000 << endl;
}

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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=2e5+10;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

const i32 MOD=2019;
i32 N;
ar Hash;
i32 Cnt[2019];
char s[MAXN];

inline void pre(){
    scanf("%s",s);
    N=strlen(s);
    i32 Bas=1;
    Cnt[0]=1;
    g(i,N-1,I,0){
        Hash[i]=(Bas*(s[i]-48)+Hash[i+1])%MOD;
        Cnt[ Hash[i] ]++;
        Bas=Bas*10%MOD;
    }
}

int main(){
    pre();
    i32 Ans=0;
    f(i,0,I,2018) Ans+=Cnt[i]*(Cnt[i]-1)>>1;
    print(Ans);
    output();
    return 0;
}

Measured memory_bytes: 4620
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int max_price = 12.5*100 + 100;
    int a, b; cin >> a >> b;

    for (int price=0; price<max_price; price++) {
        if ((int)(price*0.08) == a && (int)(price*0.1) == b) {
            cout << price << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 2147483647;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

template <typename T>
class SegmentTree {
    public:
        int n;
        vector<T> data;
        T e;
        function<T(T, T)> operation;
        function<T(T, T)> process;

        SegmentTree() {}
        SegmentTree(int n_, T e_, function<T(T, T)> operation_, 
            function<T(T, T)> process_) : e(e_), operation(operation_), process(process_) {
            n = 1;
            while (n < n_) n <<= 1;
            data.assign(2 * n, e);
        }

        T query(int a, int b) {
            return query(a, b + 1, 1, 0, n);
        }

        T query(int a, int b, int k, int l, int r) {
            if (a >= r || b <= l) return e;
            if (a <= l && b >= r) return data[k];
            T c = query(a, b, 2 * k + 0, l, (l + r) / 2);
            T d = query(a, b, 2 * k + 1, (l + r) / 2, r);
            return operation(c, d);
        }

        void update(int idx, T v) {
            idx += n;
            data[idx] = process(data[idx], v);
            while (idx >>= 1) {
                data[idx] = operation(data[2 * idx + 0], data[2 * idx + 1]);
            }
        }

        T operator[](int idx) {
            return data[idx + n];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    SegmentTree<int> seg = SegmentTree<int>(n, 0, 
        [](int a, int b) { return a + b; }, [](int a, int b) { return a + b; });
    rep (i, q) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x - 1, y);
        } else {
            cout << seg.query(x - 1, y - 1) << endl;
        }
    } 

    return 0;
}




Measured memory_bytes: 3812
#include<stdio.h>
int main (void)
{
  int a,b,c,d;
  scanf("%d%d%d",&a,&b,&c);
  d = a+b+c;
  if(d>21) {
    printf("bust");
  }
  else if(d<=21){
     printf("win");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b&&a >= c)cout << a * 10 + b + c;
	else if (b >= a&&b >= c)cout << b * 10 + c + a;
	else cout << c * 10 + a + b;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Numeric


keta :: Double -> String
keta d = do
    let dd = read (showFFloat (Just 3) d "") :: Double
    if dd == 0.0 then "0.000" else  (showFFloat (Just 3) d "")

calc (a:b:c:d:e:f:g) = do
    putStr $ keta  ((e*c-b*f)/(a*e-b*d))
    putStr " "
    putStrLn $ keta  ((a*f-c*d)/(a*e-b*d))


main = do
    ss <- lines <$> getContents
    let ll = map (\x->map (\y->read y::Double) $ words x)  ss
    mapM_ calc ll

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

int main(){
  long long H,W;
  cin >>H>>W;
  if(H==1||W==1){
    cout<<1<<endl;
    return 0;
  }
  cout<<setprecision(20)<<(W/2)*(H/2)+(W/2+W%2)*(H/2+H%2)<<endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np


n = int(input())
l = [[0] * (ord('z') - ord('a') + 1) for _ in range(n)]
for i in range(n):
    S = input()
    for s in S:
        idx = ord(s) - ord('a')
        l[i][idx] += 1
l = np.array(l)
l = np.rot90(l, -1)
ans = ''
for j in range(len(l)):
    num = min(l[j])
    ans += chr(ord('a') + j) * num
print(ans)

Measured memory_bytes: 18736
import fractions as fra
n,x=list(map(int,input().split()))
location=list(map(int,input().split()))
diff=[]
for i in location:
    diff.append(abs(x-i))
if len(diff)==1:
    print(diff[0])
else:
    ans=fra.gcd(diff[0],diff[1])
    for i in diff:
        ans=fra.gcd(ans,i)
    print(ans)

Measured memory_bytes: 16276
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  long long N;
  cin >> N;
  string s[N];
  for(long long i = 0; i < N; ++i)cin >> s[i];

  long long a[5]={0};
  for(int i = 0; i < N; ++i){
    if(s[i][0]=='M')a[0]++;
    if(s[i][0]=='A')a[1]++;
    if(s[i][0]=='R')a[2]++;
    if(s[i][0]=='C')a[3]++;
    if(s[i][0]=='H')a[4]++;
  }

  long long res=0;
  res+=a[0]*a[1]*a[2];
  res+=a[0]*a[1]*a[3];
  res+=a[0]*a[1]*a[4];
  res+=a[0]*a[2]*a[3];
  res+=a[0]*a[2]*a[4];
  res+=a[0]*a[3]*a[4];
  res+=a[1]*a[2]*a[3];
  res+=a[1]*a[2]*a[4];
  res+=a[1]*a[3]*a[4];
  res+=a[2]*a[3]*a[4];

  cout << res << endl;
  
}

// # include < cstdio >
// # include < iostream >
// using namespace std ;
// typedef long long ll ;
// string s ;
// int N ;
// ll m ,a ,r ,c , h ;
// ll D [5];
// int P [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
// int Q [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
// int R [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
// int main ()
// {
// scanf ("% d " ,& N );
// for ( int i =0; i < N ; i ++)
// {
// cin > > s ;
// if ( s [0]== ’ M ’) m ++;
// if ( s [0]== ’ A ’) a ++;
// if ( s [0]== ’ R ’) r ++;
// if ( s [0]== ’ C ’) c ++;
// if ( s [0]== ’ H ’) h ++;
// }
// D [0]= m , D [1]= a , D [2]= r , D [3]= c , D [4]= h ;
// ll res =0;
// for ( int d =0; d <10; d ++)
// res += D [ P [ d ]]* D [ Q [ d ]]* D [ R [ d ]];
// printf ("% lld \ n " , res );
// }



Measured memory_bytes: 6672
def f():
 from heapq import heappop, heappush
 N=int(input())
 r=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  r[a-1]+=3*(c>d)+(c==d)
  r[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[r[i]]+=[i]
 pq = []
 for i, s in enumerate(r):heappush(pq,[-s,i])
 rank=1
 display_rank=1
 prev_score=float('inf')
 while pq:
  s,i=heappop(pq)
  if s!=prev_score:rank=display_rank
  r[i]=rank
  display_rank+=1
  prev_score=s
 print(*r,sep='\n')
f()


Measured memory_bytes: 5720
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	n := oneInt()
	as := scanNums(n)
	ans := calc(n, as)
	fmt.Println(ans)

}

func calc(n int, as []int) int {
	L := make([]int, n+1)
	for i := 0; i < n; i++ {
		L[i+1] = gcd(L[i], as[i])
	}

	R := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		R[i] = gcd(R[i+1], as[i])
	}

	ans := 0

	for i := 0; i < n; i++ {
		ans = max(ans, gcd(L[i], R[i+1]))
	}
	return ans
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func scanNums(n int) (nums []int) {
	str := readLine()
	s := strings.Split(str, " ")
	for i := 0; i < n; i++ {
		num, _ := strconv.Atoi(s[i])
		nums = append(nums, num)
	}
	return nums
}

func scanStrings() (nums []string) {
	str := readLine()
	s := strings.Split(str, " ")

	return s
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


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

void selectionSort(int *A, int N){
	int cnt=0;
	for(int i=0; i<N; i++){
		bool flag = false;
		int minj = i;
		for(int j=i; j<N; j++){
			if(A[j]<A[minj]){
				minj = j;
				flag=true;
			}
		}
		if(flag==true){
			swap(A[i],A[minj]);
			cnt ++;
		}
	}
	for(int i=0; i<N; i++)
		cout << A[i] << (i<N-1?" ":"");
	cout << endl << cnt << endl;
}
int main(){
	int N; cin >> N;
	int array[N];
	for(int i=0; i<N; i++)
		cin >> array[i];
	selectionSort(array,N);
	return 0;
}

Measured memory_bytes: 3076
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int p1 = 0, p0 = 0, n = scanner.nextInt(), p = scanner.nextInt();
		for (int i = 1; i <= n; i++) {
			int tmp = scanner.nextInt();
			if ((tmp & 1) == 1)
				p1++;
			else
				p0++;
		}
		BigInteger[] c1 = new BigInteger[p1 + 1];
		c1[0] = BigInteger.ONE;
		for (int i = 1; i <= p1; i++)
			c1[i] = c1[i - 1].multiply(BigInteger.valueOf(p1 + 1 - i)).divide(BigInteger.valueOf(i));
		BigInteger ans = BigInteger.ZERO;
		for (int i = p; i <= p1; i += 2)
			ans=ans.add(c1[i].multiply(BigInteger.valueOf(2).pow(p0)));
		System.out.println(ans);
	}
}


Measured memory_bytes: 22228
//ΔAGC030B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
int l,n,a[N],b[N];
LL sa[N],sb[N],ans;
int main()
{
	int i,o;
	scanf("%d%d",&l,&n);
	for(i=1;i<=n;i=i+1)
		scanf("%d",a+i),b[i]=l-a[i];
	for(i=1;i<=n;i=i+1)
		sa[i]=sa[i-1]+a[i],sb[i]=sb[i-1]+b[i];
	ans=max(a[n],b[1]);
	for(i=1;i<n;i=i+1){
		if(i==n-i){
			ans=max(ans,(sa[i]+sb[n]-sb[i])*2-min(a[i],b[i+1]));
			continue;
		}
		if(i<n-i){
			o=i+i;
			ans=max(ans,(sa[i]+sb[o]-sb[i])*2+b[o+1]-min(a[o+1]-a[i+1],b[o+1]+a[i]));
		}
		else{
			o=i+i-n;
			ans=max(ans,(sa[i]-sa[o]+sb[n]-sb[i])*2+a[o]-min(a[i]-a[o],b[i+1]+a[o]));
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5120
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

void pakuripair_sort(int N, int A[], int B[]) {
	const int b = 8;
	int tmp[200001], tmp2[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
		}
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];
		}
	}
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	int A[100000], B[100000];
	rep(i, N) {
		A[i] = getint();
		B[i] = i;
	}
	pakuripair_sort(N, A, B);

	int kotae = 0;
	rep(i, N) {
		if ((i + B[i]) & 1) kotae++;
	}
	printf("%d", kotae / 2);

	Would you please return 0;
}

Measured memory_bytes: 1920
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

ll n,m,q;
vector<ll>a(55),b(55),c(55),d(55);
ll mx;
ll ans;
void dfs(vector<ll>A){
    if(A.size()==n+1){
        mx=0;
        rep(k,q){
            if(A[b[k]]-A[a[k]]==c[k])mx+=d[k];
        }
        ans=max(ans,mx);
        return;
    }
    else{
        A.push_back(A.back());
        while(A.back()<=m){
            dfs(A);
            A.back()++;
        }
    }
}
int main(){
    cin>>n>>m>>q;
    rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
    vector<ll>A(1,1);
    dfs(A);
    cout<<ans<<endl;
}





Measured memory_bytes: 3556
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Cs = list(map(int, input().split()))
max_list = list()
for i in range(N):
    next = Ps[i] - 1
    scores = [Cs[next]]
    while next != i:
        next = Ps[next] - 1
        scores.append(scores[-1] + Cs[next])
    l = len(scores)
    if K <= l:
        max_list.append(max(scores[:K]))
    else:
        if scores[-1] < 0:
            max_list.append(max(scores))
        else:
            a, b = divmod(K, l)
            cand1 = 0
            if b!=0:
                cand1 = a*scores[-1] + max(scores[:b])
            cand2 = (a-1)*scores[-1] + max(scores)
            max_list.append(max(cand1, cand2))
    #print(scores)
print(max(max_list))


Measured memory_bytes: 81644
#include <iostream>

using namespace std;

int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if((a+b) > (c+d)) cout << "Left" << endl;
  else if((a+b) == (c+d)) cout << "Balanced" << endl;
  else cout << "Right" << endl;
  
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int tmp = a.at(i);
		while (tmp % 2 == 0) {
			tmp /= 2;
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
    ll n;
    cin>>n;
    ll aa[n];
    map<ll,ll>mp;
    ll s=0;
    for(int i=0; i<n; i++){
        cin>>aa[i];
        mp[aa[i]]++;
        s+=aa[i];
    }
    int q; cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        ll x=mp[a];
        mp[a]-=x;
        mp[b]+=x;
        if(x)
            s=s-(x*a)+(x*b);
        cout<<s<<endl;
    }
}
int main()
{
    io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 10280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

ll mod = 1000000007;

int main()
{
	// 入力
	ll N;
	cin>>N;

	vec x(N),y(N);
	REP(i,N){
		cin>>x[i]>>y[i];
	}

	vector<Pii> difcount(100*N+N,make_pair(0,0));
	REP(i,N){
		REP(j,N){
			difcount[100*i+j].f=x[j]-x[i];
			difcount[100*i+j].s=y[j]-y[i];
		}
	}

	SORT(difcount);
	REVERSE(difcount);

	ll tempans=0;
	ll maxdifnum=1;
	REP(i,difcount.size()-1){
		// debug(maxdifnum);
		if(difcount[i].f==0 && difcount[i].s==0) continue;
		if(difcount[i].f==difcount[i+1].f && difcount[i].s==difcount[i+1].s) tempans++;
		else {
			Max(maxdifnum,tempans);
			tempans=1;
		}
	}
	Max(maxdifnum,tempans);

	if(N==1) {
		cout<<1<<endl;
		return 0;
	}
	ll ans=N-maxdifnum;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
ll A[100010];
ll B[100010];

void solve() {

	ll ans = 0;
	cin >> N;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] < 0) cnt++;
		B[i] += abs(A[i]);
		ans += B[i];
	}

	if (cnt % 2 != 0) {
		ans -= 2 * *min_element(B, B + N);
	}

	cout << ans << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)
        cin>>a[i];
    long long int x=0;
    for(long long int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            x+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<x<<endl;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
int n,k,arr,mn,mx=0;
int gcd(int a, int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&arr);
		if(arr>mx)mx=arr;
		if(i==1){
			mn=arr;
		}else{
			mn=gcd(mn,arr);
		}
	}
	if(k>mx){
		printf("IMPOSSIBLE");
	}else{
		if(k%mn==0){
			printf("POSSIBLE");
		}else printf("IMPOSSIBLE");
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cassert>
#include<climits>
#include<cstring>
#include<cassert>
#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

#define MAX 51
int N,M;
string c[MAX];
bool visited[MAX][MAX][4];
bool path[MAX][MAX][4];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y) { return 0 <= x && x < M && 0 <= y && y < N; }

inline bool check(int x,int y) { rep(i,4) if( path[y][x][i] ) return true; return false; }

bool dfs(int x,int y,int dir) {
  if( x == 1 && y == 0 ) {
    if( !check(M-1,0) || !check(0,N-1) || !check(M-1,N-1) ) return false;
    return true;
  }
  rep(i,4) {
    int xdir = ( dir + i ) % 4;
    int nx = x + dx[xdir], ny = y + dy[xdir], ndir = xdir;
    if( !isValid(nx,ny) ) {
      nx = x, ny = y;
      ( ndir += 1 ) %= 4;
    } else {
      if( c[ny][nx] == '#' ) {
	( ndir += 1 ) %= 4;
	nx = x, ny = y;
      } else {
	int lx = nx + dx[(ndir+3)%4], ly = ny + dy[(ndir+3)%4];
	if( isValid(lx,ly) && c[ly][lx] != '#' ) ( ndir += 3 ) %= 4;
      }
    }
    if( !( x == nx && y == ny ) && check(nx,ny) ) continue;
    if( visited[ny][nx][ndir] ) continue;
    visited[ny][nx][ndir] = true;
    path[ny][nx][ndir] = true;
    if( dfs(nx,ny,ndir) ) return true;
    path[ny][nx][ndir] = false;
  }  
  return false;
}

bool compute() {
  memset(visited, false, sizeof visited);
  memset(path, false, sizeof path);
  visited[0][0][0] = true;
  path[0][0][0] = true;
  return dfs(0,0,0);
}

int main() {
  while( cin >> N >> M, N|M ) {
    rep(i,N) cin >> c[i];
    puts(compute()?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

vector<int> g[100005];
int ch[100005];

int dfs(int v, int from){
  int ret = 1;
  for(auto to : g[v]) if(to != from){
    ret += dfs(to, v);
  }
  return ch[v] = ret;
}

vector<pair<int,long>> f[100005];
pair<long,int> dfs2(int v, int from){
  pair<long,int> ret = {0,1};
  for(auto to : f[v]) if(to.first != from){
    auto p = dfs2(to.first, v);
    ret.first += p.first + to.second*p.second;
    ret.second += p.second;
  }
  return ret;
}

int main(){
  int n;
  cin>>n;
  vector<int> a(n-1), b(n-1);
  rep(i,n-1){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    g[a[i]].pb(b[i]);
    g[b[i]].pb(a[i]);
  }

  vector<long> s(n);
  rep(i,n) cin>>s[i];

  dfs(0,-1);

  vector<long> ans(n-1);

  int center = -1;
  rep(i,n-1){
    int cd = (n-2*min(ch[a[i]], ch[b[i]]));
    if(cd!=0){
      ans[i] = abs((s[a[i]] - s[b[i]])/cd);
      f[a[i]].pb(mp(b[i], ans[i]));
      f[b[i]].pb(mp(a[i], ans[i]));
    }
    else {
      center = i;
    }
  }

  if(center>=0){
    int i = center;
    auto p1 = dfs2(a[i], b[i]);
    auto p2 = dfs2(b[i], a[i]);
    ans[i] = (s[a[i]] - (p1.first+p2.first)) / p2.second;
  }

  rep(i,n-1) cout << ans[i] << "\n";

  return 0;
}


Measured memory_bytes: 22272
#include <stdio.h>
 
int main(void) {
    int h,w;
    while(scanf("%d%d", &h,&w)){
        if(h == 0 && w == 0)
            break;
        int i,c;
        for(i =0; h > i; i++){
            for(c = 0; w > c; c++){
                if(i == 0 || c == 0 || c == w-1 || i == h-1)
                   printf("#");
                else 
                   printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2060
#include<stdio.h> 
int rectangle(int tate,int yoko); int main(void){ int H[1000],W[1000],a,j; j=0; while(1){ scanf("%d %d",&H[j] ,&W[j]); if((H[j]==0)&&(W[j]==0)){ break; } j++; } for(a=0;a<j;a++){ rectangle(H[a],W[a]); printf("\n"); } return 0; } int rectangle(int tate,int yoko){ int h,i; for(h=0;h<tate;h++){ for(i=0;i<yoko;i++){ printf("#"); } printf("\n"); } return 0; } 


Measured memory_bytes: 2032
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int p[3111];
int dp[3111][3111];
vector<char> ans;
int main() {
	string s1, s;
	cin >> s >> s1;
	s = " " + s;
	s1 = " " + s1;
	for (int i = 1; i < s.size(); i++) {
		for (int j = 1; j < s1.size(); j++) {
			if (s[i] == s1[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			}
		}
	}
	int i = s.size()-1, j = s1.size()-1;
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) {
			i--;
		}
		else {
			if (dp[i][j] == dp[i][j-1]) {
				j--;
			}
			else {
				if (dp[i][j] = dp[i - 1][j - 1] + 1) {
					ans.push_back(s[i]);
					i--;
					j--;
				}
			}
		}
	}
	for (int i = ans.size() -1; i >=0 ; i--) {
		cout << ans[i];
	}
}

Measured memory_bytes: 40032
import sys
import time
import math
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

A, B = map(int, input().split())
print(A*B // math.gcd(A,B))

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9108
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int x1 = sc.nextInt();
      int y1 = sc.nextInt();
      int x2 = sc.nextInt();
      int y2 = sc.nextInt();
      int x3 = x2+y1-y2;
      int y3 = x2-x1+y2;
      int x4 = x1+y1-y2;
      int y4 = x2-x1+y1;
      System.out.println(x3+" "+y3+" "+x4+" "+y4);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define ll long long
using namespace std;

vector <char> m;
int main() {
  string n;
  cin >> n;

  ll f = n.length();
  ll res = f;
  for (ll i=0; i< f; i++){
    if (n[i] == 'S'){
      m.push_back(n[i]);
    }
    else{
      if (!m.empty() && m.back() == 'S'){
        m.pop_back();
      }
      else{
        m.push_back(n[i]);
      }
    }
  }

  cout << m.size() << endl;
  return 0;
}

Measured memory_bytes: 772
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,i,j,tmp,r=0,t=1;
	int arr[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(arr[i]<arr[j])
			{
				tmp=arr[i];
				arr[i]=arr[j];
				arr[j]=tmp;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		r+=t*arr[i];
		t=-t;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

const int C = 998244353;

int pow1(int x, int y){
    if (y == 0){
        return 1;
    }
    if (y % 2 == 0){
        return pow1(x*x % C, y/2);
    }
    return pow1(x, y-1)*x % C;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> deg = {1}, c = {1};
    for (int q = 0; q < n-1; q++){
        deg.push_back(deg.back()*(m-1) % C);
        c.push_back(c.back()*(n-1-q) % C*pow1(q+1, C-2) % C);
    }
    int ans = 0;
    for (int q = 0; q < k+1; q++){
        ans = (ans+deg[n-1-q]*c[q]) % C;
    }
    cout << ans*m % C << endl;
    return 0;
}


Measured memory_bytes: 6580
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
#define SEGMAX 131072
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s1, s2;

	cin>>s1>>s2;

	if(s1.size()<s2.size()){
		cout<<"LESS"<<endl;
	}else if(s1.size()>s2.size()){
		cout<<"GREATER"<<endl;
	}else{
		bool flag=true;
		rep(i, s1.size()){
			if((int)(s1[0])>(int)(s2[0])){
				cout<<"GREATER"<<endl;
				flag=false;
				break;
			}else if((int)(s1[0])<(int)(s2[0])){
				cout<<"LESS"<<endl;
				flag=false;
				break;
			}
		}
		if(flag) cout<<"EQUAL"<<endl;
	}
}

Measured memory_bytes: 256