Problem:
仲良しスライム
問題
スライムが $N$ 匹います。 $i$ 番目のスライムの強さは $X_i$ です。
ふるやん君は、$1$ 番目から $k$ 番目までのスライムを仲間にします。
ここで、仲間にしたスライム同士がケンカしないように、ふるやん君は以下の $2$ 種類の魔法を好きなだけ使って、スライムたちの強さを等しくしたいです。
強化魔法：コスト $A$ を消費し、スライム $1$ 匹の強さを $1$ 大きくする
弱化魔法：コスト $B$ を消費し、スライム $1$ 匹の強さを $1$ 小さくする
各 $k$ ($1 \leq k \leq N$) について、スライム $k$ までを仲間にしたときに、仲間のスライムの強さを等しくするために必要なコストの最小値を出力してください。
なお、必要なコストを計算する際に、実際にスライムの強さを変更することはありません。
制約
$1 \leq N \leq 10^5$
$1 \leq A, B \leq 10^4$
$1 \leq X_i \leq 10^9$ ($1 \leq i \leq N$)
入力
$N$ $A$ $B$
$X_1$ $X_2$ $\cdots$ $X_N$
出力
$N$ 行出力してください。 $k$ 行目 ($1 \leq k \leq N$) には、スライム $k$ までを仲間にしたときに、仲間のスライムの強さを等しくするために必要なコストの最小値を出力してください。
入力例 1
5 3 2
5 1 4 2 3
出力例 1
0
8
11
13
15
スライム $k$ までを仲間にしたときに、仲間のスライムの強さを $Y$ にするためのコストを $C$ とすると
$k=1$ のとき、強さを $Y=5$ にすることでコスト $C=0$ となります
$k=2$ のとき、強さを $Y=1$ にすることでコスト $C=8$ となります
$k=3$ のとき、強さを $Y=4$ にすることでコスト $C=11$ となります
$k=4$ のとき、強さを $Y=2$ にすることでコスト $C=13$ となります
$k=5$ のとき、強さを $Y=3$ にすることでコスト $C=15$ となります
上記のコストの値 $C$ が各 $k$ における最適値であり、各 $k$ においてこれよりコストを小さくすることは出来ません。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}

namespace po167{
template <class T,T (*op)(T,T),T(*e)()>
struct segment_tree{
	int _n,size;
	std::vector<T> seg;
	int ceil_pow2(int a){
		int b=1;
		while(a>b){
			b<<=1;
		}
		return b;
	}
	void update(int k){seg[k]=op(seg[k*2],seg[k*2+1]);};
	segment_tree(int n) :_n(n){
		size=ceil_pow2(n);
		seg=std::vector<T>(size*2,e());
	}
	segment_tree(std::vector<T> &p) :_n((int) p.size()){
		size=ceil_pow2(_n);
		seg=std::vector<T>(size*2,e());
		for(int i=0;i<_n;i++) seg[i+size]=p[i];
		for(int i=size-1;i>0;i--) update(i);
	}
	void set(int ind,T val){
		assert(0<=ind&&ind<_n);
		ind+=size;
		seg[ind]=val;
		while(ind!=1){
			ind>>=1;
			update(ind);
		}
	}
    void addl(int ind,T val){
        set(ind,op(get(ind),val));
    }
    void addr(int ind,T val){
        set(ind,op(val,get(ind)));
    }
	T get(int ind){
		assert(0<=ind&&ind<_n);
		return seg[ind+size];
	}
	T query(int l,int r){
		assert(0<=l&&l<=r&&r<=_n);
		T l_val=e();
		T r_val=e();
		l+=size,r+=size;
		while(l<r){
			if(l&1) l_val=op(l_val,seg[l]),l+=1;
			if(r&1) r-=1,r_val=op(seg[r],r_val);
			r>>=1;
			l>>=1;
		}
		return op(l_val,r_val);
	}
	template <bool (*f)(T)> int max_right(int l) {
        return max_right(l, [](T x) { return f(x); });
    }
	template <class F> int max_right(int l, F f) {
		assert(0<=l&&l<=_n);
		assert(f(e()));
		if(f(query(l,_n))) return _n;
		T val=e();
		l+=size;
		while(true){
			while(l%2==0) l>>=1;
			if(!f(op(val,seg[l]))){
				while(l<size){
					l*=2;
					if(f(op(val,seg[l]))){
						val=op(val,seg[l]);
						l++;
					}
				}
				return l-size;
			}
			val=op(val,seg[l]);
			l++;
		}
	}
	template <bool (*f)(T)> int min_left(int r) {
        return min_left(r, [](T x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        T sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(seg[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(seg[r], sm))) {
                        sm = op(seg[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(seg[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

};
}
using po167::segment_tree;


using F= pair<ll,ll>;
F op(F a,F b){return {a.first+b.first,a.second+b.second};}
F e(){return {0,0};}
int target;
bool f(F x){
	return x.second<target;
}


void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
	//while(1) solve();
}

void solve(){
	ll N,A,B;
	cin>>N>>A>>B;
	vector<ll> X(N);
	vector<int> order(N),rev(N);
	rep(i,N) order[i]=i,cin>>X[i];
	sort(all(order),[&](int l,int r){
		return X[l]<X[r];
	});
	rep(i,N) rev[order[i]]=i;
	segment_tree<F,op,e> seg(N);
	rep(i,N){
		seg.set(rev[i],{X[i],1});
		target=(B*(i+1)+A+B-1)/(A+B);
		int a=seg.max_right<f>(0);
		auto L=seg.query(0,a);
		auto R=seg.query(a,N);
		//cout<<X[a]<<" "<<L.first<<" "<<L.second<<" "<<R.first<<" "<<R.second<<"\n";
		cout<<(X[order[a]]*L.second-L.first)*A+B*(R.first-X[order[a]]*R.second)<<"\n";
	}
}
accuracy: 1
time_ms: 30
memory_kb: 8828
final_rank: 4

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3212.cc: Intimate Slimes
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;

/* typedef */

typedef long long ll;

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

/* global variables */

int xs[MAX_N], uxs[MAX_N];
BIT<int> bit0;
BIT<ll> bit1;

/* subroutines */

ll check(int m, int a, int b, int x) {
  int k = lower_bound(uxs, uxs + m, x) - uxs;
  int l0 = bit0.sum(k), l1 = bit0.sum(m) - l0;
  ll s0 = bit1.sum(k), s1 = bit1.sum(m) - s0;

  return ((ll)x * l0 - s0) * a + (s1 - (ll)x * l1) * b;
}

/* main */

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

  copy(xs, xs + n, uxs);
  sort(uxs, uxs + n);
  int m = unique(uxs, uxs + n) - uxs;

  bit0.init(m);
  bit1.init(m);
  int minx = INF, maxx = 0;

  for (int i = 0; i < n; i++) {
    int ki = lower_bound(uxs, uxs + m, xs[i]) - uxs;

    bit0.add(ki + 1, 1);
    bit1.add(ki + 1, xs[i]);
    minx = min(minx, xs[i]);
    maxx = max(maxx, xs[i]);

    int x0 = minx, x1 = maxx;
    while (x0 + 2 < x1) {
      int xx0 = ((ll)x0 * 2 + (ll)x1) / 3;
      int xx1 = ((ll)x0 + (ll)x1 * 2) / 3;
      ll c0 = check(m, a, b, xx0);
      ll c1 = check(m, a, b, xx1);
      if (c0 > c1) x0 = xx0;
      else x1 = xx1;
    }

    ll minc = LINF;
    for (int x = x0; x <= x1; x++) minc = min(minc, check(m, a, b, x));

    printf("%lld\n", minc);
  }

  return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 4460
final_rank: 10

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

enum Type{
	COUNT,
	VALUE,
};

int N;
ll BIT[2][SIZE],X[SIZE];
map<ll,int> MAP;

void add(int loc,ll value,Type type){

	BIT[type][loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[type][loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(int loc,Type type){

	if(loc == 0)return 0;

	ll sum = BIT[type][loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[type][loc];
		loc -= loc & -loc;
	}
	return sum;
}


int getPos(int index,Type type){

	int left = 1,right = N,mid = (left+right)/2;
	int ret = N;

	while(left <= right){

		if(getSum(mid,type) >= index){

			ret = mid;
			right = mid-1;
		}else{

			left = mid+1;
		}
		mid = (left+right)/2;
	}
	return ret;
}

int main(){

	ll A,B;
	scanf("%d %lld %lld",&N,&A,&B);

	vector<ll> vec;
	for(int i = 1; i <= N; i++){

		scanf("%lld",&X[i]);
		vec.push_back(X[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	for(int i = 0; i <= N; i++){

		BIT[COUNT][i] = 0;
		BIT[VALUE][i] = 0;
	}

	ll index = 1;
	for(ll i = 0; i < vec.size(); i++){

		MAP[vec[i]] = index++;
	}

	for(ll k = 1; k <= N; k++){

		add(MAP[X[k]],1,COUNT);
		add(MAP[X[k]],X[k],VALUE);

		if(k == 1){

			printf("0\n");
			continue;
		}

		ll ans = HUGE_NUM;

		ll BASE = (B*k)/(A+B);

		//base番目に小さい数を基準値とする
		for(ll base = max(1LL,BASE-10); base <= min(k,BASE+10); base++){

			int tmp_pos = getPos(base,COUNT); //base番目に小さい値の座標
			ll num = getSum(tmp_pos,COUNT)-getSum(tmp_pos-1,COUNT); //同じ値がいくつあるか
			ll tmp_sum = getSum(tmp_pos,VALUE)-getSum(tmp_pos-1,VALUE); //値の総和

			ll val = tmp_sum/num; //基準値

			//val以下の値は、大きくする
			ll L = A*(val*getSum(tmp_pos,COUNT)-getSum(tmp_pos,VALUE));
			//valより大きい値は小さくする
			ll R = B*(getSum(N,VALUE)-getSum(tmp_pos,VALUE)-val*(getSum(N,COUNT)-getSum(tmp_pos,COUNT)));

			ans = min(ans,L+R);
		}

		printf("%lld\n",ans);
	}

	return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 12376
final_rank: 14

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

enum Type{
	COUNT,
	VALUE,
};

int N;
ll BIT[2][SIZE];
map<ll,ll> MAP,REV;
ll X[SIZE];


void add(int loc,ll value,Type type){

	BIT[type][loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[type][loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(int loc,Type type){

	if(loc == 0)return 0;

	ll sum = BIT[type][loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[type][loc];
		loc -= loc & -loc;
	}
	return sum;
}

ll getPos(Type type,ll index){

	ll left = 1,right = N,mid = (left+right)/2;
	ll ret = N;

	while(left <= right){

		if(getSum(mid,type) >= index){

			ret = mid;
			right = mid-1;
		}else{

			left = mid+1;
		}
		mid = (left+right)/2;
	}
	return ret;
}

//https://drken1215.hatenablog.com/entry/2020/12/12/200700

int main(){


	ll A,B;
	scanf("%d %lld %lld",&N,&A,&B);

	for(int i = 0; i <= N; i++){

		BIT[COUNT][i] = 0;
		BIT[VALUE][i] = 0;
	}

	vector<ll> vec;
	for(int i = 1; i <= N; i++){

		scanf("%lld",&X[i]);
		vec.push_back(X[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	ll index = 1;
	for(ll i = 0; i < vec.size(); i++){

		MAP[vec[i]] = index;
		REV[index] = vec[i];
		index++;
	}

	for(ll k = 1; k <= N; k++){

		ll tmp_loc = MAP[X[k]];
		add(tmp_loc,1,COUNT);
		add(tmp_loc,X[k],VALUE);

		if(k == 1){

			printf("0\n");
			continue;
		}

		ll ans = HUGE_NUM;
		ll base = (k*B)/(A+B);

		// 現在loc番目の値が基準値
		for(ll loc = max(1LL,base-10); loc <= min(k,base+10); loc++){

			ll tmp_pos = getPos(COUNT,loc); //loc番目の位置
			ll num_div = getSum(tmp_pos,COUNT)-getSum(tmp_pos-1,COUNT); //tmp_posの個数
			ll NUM = getSum(tmp_pos,VALUE)-getSum(tmp_pos-1,VALUE);

			ll base_val = NUM/num_div; //複数同じ値がある場合あり


			ll sum_L = getSum(tmp_pos,VALUE);
			ll L = A*(base_val*getSum(tmp_pos,COUNT)-sum_L);

			ll num_R = getSum(N,COUNT)-getSum(tmp_pos,COUNT); //複数同じ値がある場合あり
			ll sum_R = getSum(N,VALUE)-getSum(tmp_pos,VALUE);
			ll R = B*(sum_R-base_val*num_R);

			ans = min(ans,L+R);
		}

		printf("%lld\n",ans);
	}

	return 0;
}
accuracy: 1
time_ms: 520
memory_kb: 18428
final_rank: 16

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




struct Kou{
	Kou(ll arg_value){

		value = arg_value;
	}
	bool operator<(const struct Kou& arg) const{

		return value < arg.value; //降順(PQ)
	}
	ll value;
};

struct Syou{
	Syou(ll arg_value){

		value = arg_value;
	}
	bool operator<(const struct Syou &arg) const{

		return value > arg.value; //昇順(PQ)
	}

	ll value;
};

ll N,A,B;

int main(){

	scanf("%lld %lld %lld",&N,&A,&B);

	ll sum_L = 0;
	ll sum_R = 0;

	//中央値の管理用のPQ
	priority_queue<Kou> L;
	priority_queue<Syou> R;

	ll X;
	ll all = 0;
	ll num = 0;
	ll mini = HUGE_NUM,maxi = -HUGE_NUM;

	for(ll loop = 0; loop < N; loop++){

		scanf("%lld",&X);

		all += X;
		mini = min(mini,X);
		maxi = max(maxi,X);
		num++;

		if(L.size() > R.size()){ //基本的にRに入れようとする

			if(X < L.top().value){

				ll tmp = L.top().value;
				sum_L -= tmp;
				L.pop();

				L.push(Kou(X));
				sum_L += X;

				R.push(Syou(tmp));
				sum_R += tmp;

			}else{

				R.push(Syou(X));
				sum_R += X;
			}


		}else{ //基本的にLに入れようとする

			if(L.size() == 0){

				sum_L += X;
				L.push(Kou(X));

			}else{

				if(X > R.top().value){

					ll tmp = R.top().value;
					sum_R -= tmp;
					R.pop();

					R.push(Syou(X));
					sum_R += X;

					L.push(Kou(tmp));
					sum_L += tmp;

				}else{

					sum_L += X;
					L.push(Kou(X));

				}
			}
		}

		ll add = L.top().value*L.size()-sum_L;
		ll minus = sum_R-L.top().value*R.size();

		ll val_min = B*(all-mini*num); //最小値に合わせる
		ll val_chu = A*add+B*minus; //中央値に合わせる
		ll val_maxi = A*(maxi*num-all); //最大値に合わせる

		printf("%lld\n",min(val_min,min(val_chu,val_maxi)));
	}

	return 0;
}
accuracy: 0.029411764705882353
time_ms: 10
memory_kb: 3900
final_rank: 17

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()

#define MOD 1000000007

template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-6, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int modpow(ll x, ll n, int mod) {
  if(x == 0) return 0;
  
  ll res = 1;
  while(n) {
    if(n&1) res = res*x % mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

template<typename T = int> struct BIT{
  vector<T> node;
 
  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }
  void add(int i, T x){

    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }
  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> x(N); REP(i,N) cin >> x[i];
  multiset<ll> st;
  set<ll> st2;
  REP(i,N) {
    st.insert(x[i]);
    st2.insert(x[i]);
  }
  vector<ll> v;
  REP(i,N) v.push_back(x[i]);
  sort(all(v));
  v.erase(unique(all(v)), v.end());

  BIT<ll> sums(v.size()+1), kosu(v.size()+1);
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, x[i]);
    kosu.add(j+1, 1);
  }

  auto f = [&](ll t) {
    int j = lower_bound(all(v), t) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);
    
    ll t1 = (lowerkosu * t - lower) * A;
    ll t2 = (upper - upperkosu * t) * B;
    return t1+t2;  
  };


  ll mi = (1LL<<60);
  int num = -1;
  REP(i,N) {
    if(mi > f(x[i])) {
      mi = f(x[i]);
      num = x[i];
    }
  }
  vector<ll> ans(N);
  for(int i=N-1; i>=0; i--) {


    ans[i] = f(num);

    // 削除操作
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, -x[i]);
    kosu.add(j+1, -1);
    st.erase(st.find(x[i]));
    if(st.find(x[i]) == st.end()) st2.erase(x[i]);
    if(i == 0) break;

    //更新
    auto itr = st2.lower_bound(num);
    ll mi = (1LL<<60);
    ll nxt = -1;
    int t = 0;
    while(itr != st2.end() && t<=10) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      itr++;
      t++;
    }
    itr = st2.lower_bound(num);
    t = 0;
    while(t <= 10) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      if(itr == st2.begin()) break;
      itr--;
      t++;
    }
    num = nxt;
  }
  REP(i,N) {
    cout << ans[i] << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 16224
final_rank: 12

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()

#define MOD 1000000007

template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-6, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int modpow(ll x, ll n, int mod) {
  if(x == 0) return 0;
  
  ll res = 1;
  while(n) {
    if(n&1) res = res*x % mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

template<typename T = int> struct BIT{
  vector<T> node;
 
  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }
  void add(int i, T x){

    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }
  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> x(N); REP(i,N) cin >> x[i];
  multiset<ll> st;
  set<ll> st2;
  REP(i,N) {
    st.insert(x[i]);
    st2.insert(x[i]);
  }
  vector<ll> v;
  REP(i,N) v.push_back(x[i]);
  sort(all(v));
  v.erase(unique(all(v)), v.end());

  BIT<ll> sums(v.size()+1), kosu(v.size()+1);
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, x[i]);
    kosu.add(j+1, 1);
  }

  ll mi = (1LL<<60);
  int num = -1;
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);

    ll t1 = (lowerkosu * x[i] - lower) * A;
    ll t2 = (upper - upperkosu * x[i]) * B;
    if(mi > t1+t2) {
      mi = t1+t2;
      num = x[i];
    }

  }

  auto f = [&](ll t) {
    int j = lower_bound(all(v), t) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);
    
    ll t1 = (lowerkosu * t - lower) * A;
    ll t2 = (upper - upperkosu * t) * B;
    return t1+t2;  
  };

  vector<ll> ans(N);

  for(int i=N-1; i>=0; i--) {


    ans[i] = f(num);

    // 削除操作
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, -x[i]);
    kosu.add(j+1, -1);
    st.erase(st.find(x[i]));
    if(st.find(x[i]) == st.end()) st2.erase(x[i]);
    if(i == 0) break;

    //idxを更新する
    auto itr = st2.lower_bound(num);
    
    ll mi = (1LL<<60);
    ll nxt = -1;
    int t = 0;
    while(itr != st2.end() && t<=10) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      itr++;
      t++;
    }
    itr = st2.lower_bound(num);
    t = 0;
    while(t <= 10) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      if(itr == st2.begin()) break;
      itr--;
      t++;
    }
    num = nxt;
  }
  REP(i,N) {
    cout << ans[i] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 16224
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()

#define MOD 1000000007

template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-6, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int modpow(ll x, ll n, int mod) {
  if(x == 0) return 0;
  
  ll res = 1;
  while(n) {
    if(n&1) res = res*x % mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

template<typename T = int> struct BIT{
  vector<T> node;
 
  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }
  void add(int i, T x){

    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }
  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> x(N); REP(i,N) cin >> x[i];
  multiset<ll> st;
  REP(i,N) st.insert(x[i]);
  vector<ll> v;
  REP(i,N) v.push_back(x[i]);
  sort(all(v));
  v.erase(unique(all(v)), v.end());

  BIT<ll> sums(v.size()+1), kosu(v.size()+1);
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, x[i]);
    kosu.add(j+1, 1);
  }

  ll mi = (1LL<<60);
  int num = -1;
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);

    ll t1 = (lowerkosu * x[i] - lower) * A;
    ll t2 = (upper - upperkosu * x[i]) * B;
    if(mi > t1+t2) {
      mi = t1+t2;
      num = x[i];
    }

  }

  auto f = [&](ll t) {
    int j = lower_bound(all(v), t) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);
    
    ll t1 = (lowerkosu * t - lower) * A;
    ll t2 = (upper - upperkosu * t) * B;
    return t1+t2;  
  };

  vector<ll> ans(N);

  for(int i=N-1; i>=0; i--) {


    ans[i] = f(num);

    // 削除操作
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, -x[i]);
    kosu.add(j+1, -1);
    st.erase(st.find(x[i]));

    if(i == 0) break;

    //idxを更新する
    auto itr = st.lower_bound(num);
    
    ll mi = (1LL<<60);
    ll nxt = -1;
    int t = 0;
    while(itr != st.end() && t<=3) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      itr++;
      t++;
    }
    itr = st.lower_bound(num);
    t = 0;
    while(t <= 3) {
      if(mi > f(*itr)) {
        mi = f(*itr);
        nxt = *itr;
      }
      if(itr == st.begin()) break;
      itr--;
      t++;
    }
    num = nxt;
  }
  REP(i,N) {
    cout << ans[i] << endl;
  }
  return 0;
}
accuracy: 0.029411764705882353
time_ms: 100
memory_kb: 8880
final_rank: 20

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()

#define MOD 1000000007

template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-6, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int modpow(ll x, ll n, int mod) {
  if(x == 0) return 0;
  
  ll res = 1;
  while(n) {
    if(n&1) res = res*x % mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

template<typename T = int> struct BIT{
  vector<T> node;
 
  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }
  void add(int i, T x){

    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }
  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> x(N); REP(i,N) cin >> x[i];
  multiset<ll> st;
  REP(i,N) st.insert(x[i]);
  vector<ll> v;
  REP(i,N) v.push_back(x[i]);
  sort(all(v));
  v.erase(unique(all(v)), v.end());

  BIT<ll> sums(v.size()+1), kosu(v.size()+1);
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, x[i]);
    kosu.add(j+1, 1);
  }

  ll mi = (1LL<<60);
  int num = -1;
  REP(i,N) {
    int j = lower_bound(all(v), x[i]) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);

    ll t1 = (lowerkosu * x[i] - lower) * A;
    ll t2 = (upper - upperkosu * x[i]) * B;
    if(mi > t1+t2) {
      mi = t1+t2;
      num = x[i];
    }

  }

  auto f = [&](ll t) {
    int j = lower_bound(all(v), t) - v.begin();
    ll upper = sums.sum(v.size()) - sums.sum(j+1);
    ll lower = sums.sum(j);

    ll upperkosu = kosu.sum(v.size()) - kosu.sum(j+1);
    ll lowerkosu = kosu.sum(j);
    
    ll t1 = (lowerkosu * t - lower) * A;
    ll t2 = (upper - upperkosu * t) * B;
    return t1+t2;  
  };

  vector<ll> ans(N);

  for(int i=N-1; i>=0; i--) {


    ans[i] = f(num);

    // 削除操作
    int j = lower_bound(all(v), x[i]) - v.begin();
    sums.add(j+1, -x[i]);
    kosu.add(j+1, -1);
    st.erase(st.find(x[i]));

    if(i == 0) break;

    //idxを更新する
    auto itr = st.lower_bound(num);
    if(itr == st.end()) {
      itr--;
      num = *itr;
    }else if(itr != st.begin()){
      ll nxt = *itr;
      ll nxt2 = *(--itr);
      if(f(nxt) < f(nxt2)) num = nxt;
      else num = nxt2;
    }else{
      num = *itr;
    }
  }
  REP(i,N) {
    cout << ans[i] << endl;
  }
  return 0;
}
accuracy: 0.029411764705882353
time_ms: 90
memory_kb: 8832
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

template <typename T>
struct DynamicKthPQ{
    T TINF, sum_L, sum_R;
    priority_queue<T, vector<T>, greater<T>> pq_R;
    priority_queue<T> pq_L;

    DynamicKthPQ(){
        TINF = numeric_limits<T>::max()/2;
        sum_L = 0;
        sum_R = 0;
    }

    // pq_LのサイズがKになるように調整
    // adjust が遅い場合使えないので注意
    void adjust(int K){
        while((int)pq_L.size() < K){
            T tmp = pq_R.top();
            pq_R.pop();
            sum_R -= tmp;

            pq_L.push(tmp);
            sum_L += tmp;
        }

        while((int)pq_L.size() > K){
            T tmp = pq_L.top();
            pq_L.pop();
            sum_L -= tmp;

            pq_R.push(tmp);
            sum_R += tmp;
        }

        return;
    }    

    // x を集合に挿入して，K-thを返す
    // !!!! K-th は 1-indexed !!!!
    T insert(T x, int K){
        assert(K > 0); // guarantee 1-indexed
        ll front_L = (pq_L.empty() ? -TINF : pq_L.top());

        if(x > front_L){
            pq_R.push(x);
            sum_R += x; 
        }else{
            pq_L.push(x);
            sum_L += x; 
        }

        adjust(K);

        assert((int)pq_L.size() == K);
        return pq_L.top();
    }

};

int main(){

    ll N, A, B;
    cin >> N >> A >> B;
    V<ll> X(N);
    REP(i, N) cin >> X[i];

    DynamicKthPQ<ll> dkpq;

    REP(i, N){
        int K = ((i+1)*B)/(A+B) + 1;
        ll v = dkpq.insert(X[i], K);
        cout << A * ((ll)dkpq.pq_L.size() * v - dkpq.sum_L) + B * (dkpq.sum_R - (ll)dkpq.pq_R.size() * v) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5412
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, A, B;
    cin >> N >> A >> B;
    V<ll> X(N);
    REP(i, N) cin >> X[i];

    priority_queue<ll, vector<ll>, greater<ll>> right_pq;
    priority_queue<ll> left_pq;
    ll left_sum = 0, right_sum = 0;

    REP(i, N){
        ll left_next = ((i+1)*B)/(A+B) + 1;
        
        ll left_front = (left_pq.empty() ? -INF : left_pq.top());
        if(X[i]>left_front){
            right_pq.push(X[i]);
            right_sum += X[i];
        }else{
            left_pq.push(X[i]);
            left_sum += X[i];
        }

        ll left_sz = left_pq.size();
        if(left_sz < left_next){

            ll tmp = right_pq.top();
            right_pq.pop();
            right_sum -= tmp;

            left_pq.push(tmp);
            left_sum += tmp;

        }else if(left_sz > left_next){
            ll tmp = left_pq.top();
            left_pq.pop();
            left_sum -= tmp;

            right_pq.push(tmp);
            right_sum += tmp;
        }
        assert((ll)left_pq.size() == left_next);

        ll v = left_pq.top();
        left_sz = left_pq.size();
        ll right_sz = right_pq.size();

        cout << A * (left_sz * v - left_sum) + B * (right_sum - right_sz * v) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5524
final_rank: 3

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

class Bit {
	vector<long long int> vec;
public:
	Bit(int size) : vec(size, 0) {};
	void add(int position, int value) {
		while (position < vec.size()) {
			vec[position] += value;
			position += ~position & (position + 1);
		}
	}
	long long int get(int position) const {
		long long int result{ 0 };
		while (position >= 0) {
			result += vec[position];
			position -= ~position & (position + 1);
		}
		return result;
	}
};
struct List {
	int prev, next;
};
int main() {
	int n; long long int a, b; cin >> n >> a >> b;
	vector<int> slime(n); for (auto& s : slime) cin >> s;
	auto sorted = slime; sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
	Bit count(sorted.size() + 1), sum(sorted.size() + 1);
	map<int, int> rank;
	for (auto i = 0; i < sorted.size(); ++i) {
		rank[sorted[i]] = i;
	}
	long long int all_sum = 0;
	for (auto i = 0; i < n; ++i) {
		count.add(rank[slime[i]], 1);
		sum.add(rank[slime[i]], slime[i]);
		all_sum += slime[i];
		auto y_min = 0;
		auto y_max = sorted.size() - 1;
		while (y_min < y_max) {
			const auto y_mid = (y_min + y_max) >> 1;
			const auto lower = count.get(y_mid);
			const auto upper = i - lower + 1;
			const auto diff = lower * a - upper * b;
			if (diff >= 0) {
				y_max = y_mid;
			}
			else {
				y_min = y_mid + 1;
			}
		}
		const auto lower = count.get(y_max);
		const auto upper = i + 1 - lower;
		const auto lower_sum = sum.get(y_max);
		const auto upper_sum = all_sum - lower_sum;
		cout << (lower * sorted[y_max] - lower_sum) * a + (upper_sum - upper * sorted[y_max]) * b << '\n';
	}
}
accuracy: 1
time_ms: 90
memory_kb: 10240
final_rank: 8

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    LL n,m;
    LL p,q;
    int i,j,k;
    LL a,b,c;
    map<int,LL> m1;
    cin>>n>>p>>q;
    LL cnt=0,mid=0;
    LL s=0;
    for(i=0;i<n;i++){
        cin>>a;
        m1[a]++;
        if(i==0)mid=a;
        else if(a<mid)s+=(mid-a)*p,cnt++;
        else s+=(a-mid)*q;
        auto itr=m1.upper_bound(mid);
        b=m1[mid]+cnt;
        if(b*p<(i+1-b)*q){
            c=itr->first;
            s-=((i+1-b)*q-b*p)*(c-mid);
            cnt=b,mid=c;
        }
        if(cnt*p>(i+1-cnt)*q){
            itr--,itr--;
            c=itr->first;
            s-=(cnt*p-(i+1-cnt)*q)*(mid-c);
            mid=c;cnt-=m1[c];
        }
        cout<<s<<endl;
    }
}
accuracy: 1
time_ms: 120
memory_kb: 9732
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#else
#define dbg(x) {}
#endif

// 1-indexed BIT (i : [1, len])
template <typename T> struct BIT : std::vector<T> {
    BIT(int len = 0) : std::vector<T>(len + 1) {}
    void reset() { fill(this->begin(), this->end(), 0); }
    void add(int pos, T v) {
        while (pos > 0 and pos < (int)this->size()) (*this)[pos] += v, pos += pos & -pos;
    }
    T sum(int pos) const { // (0, pos]
        T res = 0;
        while (pos > 0) res += (*this)[pos], pos -= pos & -pos;
        return res;
    }
    friend std::ostream &operator<<(std::ostream &os, const BIT &bit) {
        T prv = 0;
        os << '[';
        for (int i = 1; i < (int)bit.size(); i++) {
            T now = bit.sum(i);
            os << now - prv << ",";
            prv = now;
        }
        return os << ']';
    }
};

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename TK, typename TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;


int main()
{
    int N;
    lint A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for (auto &x : X) cin >> x;

    const vector<int> z = sort_unique(X);
    BIT<lint> bit(z.size() + 1);
    BIT<int> bcnt(z.size() + 1);

    pbds_set<pint> se;
    REP(i, N) {
        int p = lower_bound(z.begin(), z.end(), X[i]) - z.begin() + 1;
        bit.add(p, X[i]);
        bcnt.add(p, 1);
        se.insert(pint(X[i], i));

        int j = B * lint(i + 1) / (A + B);
        lint xc = se.find_by_order(j)->first;
        lint pc = lower_bound(z.begin(), z.end(), xc) - z.begin() + 1;
        lint sumall = bit.sum(z.size()), sumsub = bit.sum(pc - 1), cntsub = bcnt.sum(pc - 1);
        lint ret = (sumall - sumsub - (i + 1 - cntsub) * xc) * B + (cntsub * xc - sumsub) * A;
        cout << ret << '\n';
    }
}
accuracy: 1
time_ms: 60
memory_kb: 11300
final_rank: 7

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<29;
const ll linf = 1LL<<60;
const int MAX = 510000;
// int dy[8] = {0,1,0,-1,1,-1,-1,1};
// int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

template<typename T> struct BIT{
	vector<T> dat;
	ll sz;
	//all 1-indexed
	BIT(ll sz) : sz(sz){
		dat.assign(++sz, 0);
	}

	T sum(ll k){
		T ret = 0;
		for(++k; k > 0; k -= k & -k) ret += dat[k];
		return (ret);
	}

	void add(ll k, T x){
		for(++k; k < dat.size(); k += k & -k) dat[k] += x;
	}
	
	ll get(T k){
		if(k <= 0) return 0; 
		ll ret = 0;
		int n = 1; while(n < sz) n *= 2;
		for(int i=n/2; i>0; i/=2){
			if(ret+i < sz && dat[ret+i] < k){
				k -= dat[ret+i];
				ret += i;
			}
		}
		return ret;
	}
};

template<typename T> struct range_BIT{
	vector<BIT<T>> bit;
	int sz;

	range_BIT(int sz) : sz(sz) {
		rep(j,2) bit.push_back(BIT<T>(sz));
	}

	void add(int l, int r, T x){
		if(l > r) return;
		bit[0].add(l,-x*(l-1));
		bit[0].add(r+1,x*r);
		bit[1].add(l,x);
		bit[1].add(r+1,-x);
	}

	T sum(int k){
		return bit[0].sum(k) + bit[1].sum(k) * k;
	}
};

template <typename T> struct Compress{
	vector<T> comp;

	Compress(vector<T> v) : comp(v){
		sort(comp.begin(), comp.end());
		comp.erase(unique(comp.begin(), comp.end()), comp.end());
	}

	ll get(T x){
		return lower_bound(comp.begin(), comp.end(), x) - comp.begin();
	}

	T operator[](int id){
		return comp[id];
	}

	ll siz(){
		return comp.size();
	}
};

int main(){
	ll n,a,b; cin >> n >> a >> b;
	vl x(n); rep(i,n) cin >> x[i];
	vl c;
	rep(i,n) c.push_back(x[i]);
	Compress<ll> comp(c);
	int m = comp.siz();
	range_BIT<ll> slope(m+1);
	BIT<ll> sum(m+1),cnt(m+1);
	rep(k,n){
		int id = comp.get(x[k]);
		slope.add(0,id-1,-b);
		slope.add(id,m,a);
		cnt.add(id,1);
		sum.add(id,x[k]);
		int l = -1, r = m-1;
		while(r-l > 1){
			int mid = (l+r) / 2;
			if(slope.sum(mid) - slope.sum(mid-1) >= 0) r = mid;
			else l = mid;
		}
		ll cn = cnt.sum(r);
		ll ans = (comp[r]*cn-sum.sum(r))*a + (sum.sum(m)-sum.sum(r)-comp[r]*((k+1)-cn))*b;
		cout << ans << "\n";
	}
}
accuracy: 1
time_ms: 90
memory_kb: 8408
final_rank: 5

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}
struct BIT {
private:
    vector<ll> node; int n;
public:
    BIT(int n_) {
        n = n_; node.resize(n, 0);
    }
    //0-indexed
    void add(int a, ll w) {
        for (int i = a; i < n; i |= i + 1)node[i] += w;
    }
    //[0,a)
    ll sum(int a) {
        ll ret = 0;
        for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1)ret += node[i];
        return ret;
    }
    //[a,b)
    ll sum(int a, int b) {
        return sum(b) - sum(a);
    }
};
void solve() {
    int n, a, b; cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n)cin >> x[i];
    vector<ll> v = x; sort(all(v)); v.erase(unique(all(v)), v.end());
    BIT cbt(v.size()), sbt(v.size());
    auto calc = [&](ll x) {
        ll res = 0;
        int id = lower_bound(all(v), x) - v.begin();
        ll cl = cbt.sum(0, id);
        ll cr = cbt.sum(id, v.size());
        ll sl = sbt.sum(0, id);
        ll sr = sbt.sum(id, v.size());
        res += (cl * x - sl) * a;
        res += (sr - cr * x) * b;
        return res;
    };
    rep(i, n) {
        int id = lower_bound(all(v), x[i]) - v.begin();
        cbt.add(id, 1);
        sbt.add(id, x[i]);
        ll le = -1, ri = 1000000005;
        while (ri - le > 2) {
            ll x = (le + ri) / 2;
            ll c1 = calc(x);
            ll c2 = calc(x + 1);
            if (c1 > c2) {
                le = x;
            }
            else {
                ri = x;
            }
        }
        ll ans = 1e+18; ans += 10;
        for (ll i = le - 1; i <= ri + 1; i++) {
            ans = min(ans, calc(i));
        }
        cout << ans << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}
accuracy: 1
time_ms: 400
memory_kb: 22676
final_rank: 15

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<29;
const ll linf = 1LL<<60;
const int MAX = 510000;
// int dy[8] = {0,1,0,-1,1,-1,-1,1};
// int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

template<typename T> struct BIT{
	vector<T> dat;
	ll sz;
	//all 1-indexed
	BIT(ll sz) : sz(sz){
		dat.assign(++sz, 0);
	}

	T sum(ll k){
		T ret = 0;
		for(++k; k > 0; k -= k & -k) ret += dat[k];
		return (ret);
	}

	void add(ll k, T x){
		for(++k; k < dat.size(); k += k & -k) dat[k] += x;
	}
	
	ll get(T k){
		if(k <= 0) return 0; 
		ll ret = 0;
		int n = 1; while(n < sz) n *= 2;
		for(int i=n/2; i>0; i/=2){
			if(ret+i < sz && dat[ret+i] < k){
				k -= dat[ret+i];
				ret += i;
			}
		}
		return ret;
	}
};

template <typename T> struct Compress{
	vector<T> comp;

	Compress(vector<T> v) : comp(v){
		sort(comp.begin(), comp.end());
		comp.erase(unique(comp.begin(), comp.end()), comp.end());
	}

	ll get(T x){
		return lower_bound(comp.begin(), comp.end(), x) - comp.begin();
	}

	T operator[](int id){
		return comp[id];
	}

	ll siz(){
		return comp.size();
	}
};

int main(){
	ll n,a,b; cin >> n >> a >> b;
	vl x(n); rep(i,n) cin >> x[i];
	vl c;
	rep(i,n) c.push_back(x[i]);
	Compress<ll> comp(c);
	set<int> se;
	ll ans = 0;
	ll now = 0;
	BIT<ll> bit(n+1);
	rep(k,n){
		se.insert(x[k]);
		if(k == 0){
			cout << 0 << "\n";
			now = x[k];
			bit.add(comp.get(x[k]),1);
			continue;
		}
		ll res;
		int id = comp.get(x[k]);
		ll diff = abs(now-x[k]);
		if(now < x[k]){
			res = ans + diff*b;
			auto itr = se.find(now);
			itr++;
			if(itr != se.end()){
				int t = *itr;
				int cnt = bit.sum(id);
				if(chmin(res, ans + diff*a*cnt - diff*b*(k-cnt))){
					now = x[k];
				}
			}
		}else{
			res = ans + diff*a;
			auto itr = se.find(now);
			if(itr != se.begin()){
				itr--;
				int t = *itr;
				int cnt = bit.sum(id);
				if(chmin(res, ans + diff*b*(k-cnt) - diff*a*cnt)){
					now = x[k];
				}
			}
		}
		bit.add(id,1);
		ans = res;
		cout << ans << "\n";
	}
}
accuracy: 0.029411764705882353
time_ms: 30
memory_kb: 5612
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;
// const long long MOD=998244353;
#define LOCAL
#pragma region Macros
typedef long long ll;
typedef __int128_t i128;
typedef unsigned int uint;
typedef unsigned long long ull;
#define ALL(x) (x).begin(),(x).end()
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U,typename V>
ostream&operator<<(ostream &os,const tuple<T,U,V> &t){
    os << '(' << get<0>(t) << ',' << get<1>(t) << ',' << get<2>(t) << ')';
    return os;
}
template<typename T,typename U,typename V,typename W>
ostream&operator<<(ostream &os,const tuple<T,U,V,W> &t){
    os << '(' << get<0>(t) << ',' << get<1>(t) << ',' << get<2>(t) << ',' << get<3>(t) << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const unordered_map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const multiset<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const unordered_set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const deque<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

template<typename T>
class BinaryIndexedTree{
    T sum(int i){
        T res=T();
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
public:
    int n;
    vector<T> dat;
    BinaryIndexedTree(int n_):n(n_+1),dat(n+1,0){}
    void add(int i,const T &x){
        for (++i;i<=n;i+=(i&-i)) dat[i]+=x;
    }
    T query(int l,int r){return sum(r)-sum(l);}
    int lower_bound(T x) const {
        if (x<=0) return 0;
        int pos=0,k=1;
        while (k<n) k<<=1;
        for (;k>0;k>>=1){
            if (pos+k<=n&&dat[pos+k]<x){
                x-=dat[pos+k]; pos+=k;
            }
        }
        return pos;
    }
    int upper_bound(T x) const {return lower_bound(x+1);}
    T operator[](int i){return query(i,i+1);}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll A,B; cin >> N >> A >> B;
    vector<int> X(N);
    for (int i=0;i<N;++i) cin >> X[i];

    vector<int> comp(X);
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());
    map<int,int> mp;
    for (int i=0;i<comp.size();++i) mp[comp[i]]=i;

    int n=mp.size();
    BinaryIndexedTree<int> BIT_cnt(n);
    BinaryIndexedTree<ll> BIT_sum(n);

    for (int i=0;i<N;++i){
        BIT_cnt.add(mp[X[i]],1);
        BIT_sum.add(mp[X[i]],X[i]);
        int need=(ll(i+1)*B+A+B-1)/(A+B);
        int C=BIT_cnt.lower_bound(need);
        int cnt=BIT_cnt.query(0,C+1),mid=comp[C];
        ll sum=BIT_sum.query(0,C+1);
        ll ans=A*((ll)mid*cnt-sum)+B*(BIT_sum.query(0,n)-sum-(ll)mid*(i+1-cnt));
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 70
memory_kb: 9492
final_rank: 6

code_snippet: //
// Created by zeronosu77108 on Dec 12, 2020.
//
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <complex>
#include <climits>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;}

using int64 = long long;

vector<long long> trans;

class SegTree {
private:
    vector<long long> cnt;
    vector<long long> seg;
    const long long n, e;
public:
    SegTree(const long long _n, const long long _e) : n(_n), e(_e), seg(_n*2+1, _e), cnt(_n*2+1, _e) {}
    void update(int i, const int x) {
        const auto t = trans[i];
        i+=n;
        cnt[i] += x;
        seg[i] = cnt[i] * t;
        while(i/=2) {
            cnt[i] = cnt[2*i] + cnt[2*i+1];
            seg[i] = seg[2*i] + seg[2*i+1];
        }
    };

    pair<long long, long long> query(int l, int r) {
        l+=n; r+=n;
        pair<long long, long long> res = {e, e};
        while(l<r) {
            if (l%2) res.first+=cnt[l], res.second+=seg[l], l++;
            if (r%2) --r, res.first+=cnt[r], res.second+=seg[r];
            l/=2; r/=2;
        }
        return res;
    }
};

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector x(n, 0);
    for (int i=0; i<n; i++) {
        cin >> x[i];
        trans.push_back(x[i]);
    }
    sort(trans.begin(), trans.end());
    trans.erase(unique(trans.begin(), trans.end()), trans.end());
    for (auto& xi : x) {
        xi = lower_bound(trans.begin(), trans.end(), xi) - trans.begin();
    }
    long m = trans.size();

    SegTree seg(m, 0);

    auto f = [&](const long long y) {
        auto l = seg.query(0, y);
        auto r = seg.query(y+1, m);
        long long lc = abs(l.first*trans[y] - l.second);
        long long rc = abs(r.second - r.first*trans[y]);
        return lc*a + rc*b;
    };

    for (const auto& xi : x) {
        seg.update(xi, 1);

        long l = 0;
        long r = m-1;
        while(l+10 < r) {
            long ll = (l+l+r) / 3;
            long rr = (l+r+r) / 3;
            if (f(ll) < f(rr)) {
                r = rr;
            } else {
                l = ll;
            }
        }

        long long ans = LONG_MAX;
        for (long i=l; i<=r; i++) ans = min(ans, f(i));
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 470
memory_kb: 7448
final_rank: 11

code_snippet: #include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B; cin>>N>>A>>B;
    vi a(N);
    rep(i,N) cin>>a[i];

    priority_queue<int> left;
    priority_queue<int,vi,greater<int> > right;
    ll lsum=0,rsum=0;
    auto balance = [&](){
        if (left.empty()||right.empty()) return;
        int s = left.top();
        int t = right.top();
        if (!right.empty() && s>t){
            left.pop(); right.pop();
            left.push(t); right.push(s);
            lsum+=t-s; rsum+=s-t;
        }
    };
    rep(i,N){
        ll n = (B*(i+1)+A+B-1)/(A+B);
        if (left.size()<n){
            left.push(a[i]);
            lsum+=a[i];
            balance();
        }else{
            right.push(a[i]);
            rsum+=a[i];
            balance();
        }
        int L = left.size();
        int R = right.size();
        int p = left.top();
        ll ans = A*((ll)L*p-lsum) + B*(rsum-(ll)R*p);
        cout<<ans<<"\n";
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4404
final_rank: 1