// Template begins
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin()+1,(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b),(c)))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    for(auto v : V) os << v << " ";
    return cout << "";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    for(auto s:S) os<<s<<" ";
    return cout << "";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << P.first << " " << P.second;
}
#define inf 999999999999
#define eps 0.0000001
#define PI 3.1415926535
#define dbl double
ll mod=998244353;

// Template ends

ll i,j,f2,t,k,d,f,b,n,a,l,r,q1,q2,x,y,arr[200200],lsum[200200],rsum[200200];
int main() {
  fio;
  t=1;
  //cin>>t;
  while(t--){
    cin>>n>>l>>r>>q1>>q2;
    fo(i,1,n) cin>>arr[i];
    lsum[0]=0;  rsum[n+1]=0;
    fo(i,1,n){
      lsum[i]=lsum[i-1]+arr[i];
    }
    for(i=n;i>=1;i--){
      rsum[i]=rsum[i+1]+arr[i];
    }
    ll ans=inf;
    fo(i,1,n){
      ll minn=0;
      if(i<=n/2){
        minn+=i*(lsum[i]*l+rsum[n+1-i]*r);
        minn+=(rsum[i+1]-rsum[n+1-i])*r+q2*(n-2*i-1);
        ans=min(ans,minn);
      }
      else{
        j=n-i;
        minn+=j*(lsum[j]*l+rsum[n+1-j]*r);
        minn+=(rsum[j+1]-rsum[n+1-j])*r+q2*(n-2*j-1);
        ans=min(ans,minn);
      }
    }
    cout<<ans;
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m){
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d",&n,&l,&r,&q1,&q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d",&w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0]*l;
	right[n - 1] = w[n - 1]*r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i]*l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i]*r;

	ll MIN = 1e18;

	for (int i = 0; i <n-1; ++i)
	{
		int am = n-1- i;

		if (ABS(i+1 - am) <= 1 || am==i+1)
		{
			MIN = min(left[i]+right[i+1],MIN);
			continue;
		}
		if (am < i+1)
			MIN = min(left[i] + right[i + 1]+ABS(am-(i+1)-1)*q1, MIN);
		else
			MIN = min(left[i] + right[i + 1] + ABS(am-(i+1)-1)*q2, MIN);

	}
	if (n == 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1]);
	}
	if (n >= 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1]+q1*(n-2));
	}

	MIN = min(MIN,left[n-1]+(n-1)*q1);
	MIN = min(MIN, right[0] + (n - 1)*q2);

	cout << MIN << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m) {
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d", &n, &l, &r, &q1, &q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0] * l;
	right[n - 1] = w[n - 1] * r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i] * l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i] * r;

	ll MIN = 1e18;
	if (n == 1)
	{
		cout << min((ll)w[0]*l,(ll)w[0]*r)<<endl;
		return 0;
	}

	for (int i = 1; i <=n; ++i)
	{
		int index = i - 1;
		int lef = n - i;
		ll am = left[index]+(index+1>=n?0:right[index+1]);
		if (i>lef+1)
			am += (i - (i==n?1:(lef+1)))*q1;
		if(lef>i+1)
			am += (lef-(i+1))*q2;
		MIN = min(MIN,am);
	}

	MIN = min(MIN,right[0]+(n-1)*q2);

	cout << MIN << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m){
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d",&n,&l,&r,&q1,&q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d",&w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0]*l;
	right[n - 1] = w[n - 1]*r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i]*l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i]*r;

	ll MIN = 1e18;

	for (int i = 0; i < n; ++i)
	{
		int am = n - i;
		int diff = am - i;

	    if (am>i)
		{
			MIN = min(left[i] + (i+1>=n?0:right[i + 1]) +q2*ABS(diff<=1?0:1), MIN);

		}
		else if (am == i)
		{
			MIN=min(left[i] + (i + 1 >= n ? 0 : right[i + 1]), MIN);
		}
		else if(am<i)
		{
		  MIN = min(MIN, left[i]+ (i + 1 >= n ? 0 : right[i + 1]) + q1*(diff<=1?0:diff));
		}

	}

	cout << MIN << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m){
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d",&n,&l,&r,&q1,&q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d",&w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0]*l;
	right[n - 1] = w[n - 1]*r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i]*l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i]*r;

	ll MIN = 1e18;

	for (int i = 0; i <n-1; ++i)
	{
		int am = n-1- i;

		if (ABS(i+1 - am) <= 1 || am==i+1)
		{
			MIN = min(left[i]+right[i+1],MIN);
			continue;
		}
		if (am < i+1)
			MIN = min(left[i] + right[i + 1]+ABS(am-(i+1)-1)*q1, MIN);
		else
			MIN = min(left[i] + right[i + 1] + ABS(am-(i+1)-1)*q2, MIN);

	}
	MIN = min(MIN,left[n-1]+(n-1)*q1);
	MIN = min(MIN, right[0] + (n - 1)*q2);

	cout << MIN << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m) {
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d", &n, &l, &r, &q1, &q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0] * l;
	right[n - 1] = w[n - 1] * r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i] * l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i] * r;

	ll MIN = 1e18;

	for (int i = 0; i <n - 1; ++i)
	{
		int am = n - (i + 1);

		if (ABS(i + 1 - am) <= 1 || am == i + 1)
		{
			MIN = min(left[i] + right[i + 1], MIN);
			continue;
		}
		if (am < i + 1)
			MIN = min(left[i] + right[i + 1] + ABS((i+2) - (am ))*q1, MIN);
		else
			MIN = min(left[i] + right[i + 1] + ABS(am - (i + 2))*q2, MIN);

	}
	if (n == 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1]);
	}
	if (n > 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1] + q1*(n - 2));
	}

	MIN = min(MIN, left[n - 1] + (n - 1)*q1);
	MIN = min(MIN, right[0] + (n - 1)*q2);

	cout << MIN << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <ctype.h>
#include <list>
using namespace std;
typedef long long ll;
int oo = 2e9;
//ll oo = 1e18;

const ll mod = 1000000009;
int ABS(int val)
{
	return val < 0 ? -val : val;
}
string toString(int val)
{
	stringstream ss;
	ss << val;
	return ss.str();
}

int power(ll n, ll m){
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return (int)ret;
}

int main()
{
	int n, l, r, q1, q2;
	vector<int> w;
	scanf("%d%d%d%d%d",&n,&l,&r,&q1,&q2);
	w.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d",&w[i]);

	vector<ll> left(n), right(n);
	left[0] = w[0]*l;
	right[n - 1] = w[n - 1]*r;
	for (int i = 1; i < n; ++i)
		left[i] = left[i - 1] + w[i]*l;

	for (int i = n - 2; i >= 0; --i)
		right[i] = right[i + 1] + w[i]*r;

	ll MIN = 1e18;

	for (int i = 0; i <n-1; ++i)
	{
		int am = n- (i+1);

		if (ABS(i+1 - am) <= 1 || am==i+1)
		{
			MIN = min(left[i]+right[i+1],MIN);
			continue;
		}
		if (am < i+1)
			MIN = min(left[i] + right[i + 1]+ABS(i-(am+2))*q1, MIN);
		else
			MIN = min(left[i] + right[i + 1] + ABS(am-(i+2))*q2, MIN);

	}
	if (n == 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1]);
	}
	if (n >= 3)
	{
		MIN = min(MIN, left[n - 2] + right[n - 1]+q1*(n-2));
	}

	MIN = min(MIN,left[n-1]+(n-1)*q1);
	MIN = min(MIN, right[0] + (n - 1)*q2);

	cout << MIN << endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>
#include<fstream>

typedef long long ll ;

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
int L[100002] , R[100002];
int a[100000];
ll ans,sum ;
int   n , l , r , ql , qr ;
int main ()
{
scanf ("%d%d%d%d%d" , &n ,&l , &r ,&ql ,&qr);
for (int i =0 ; i < n ;i++)
{

  scanf ("%d" , a+i );
  sum += a[i];
}
for (int i =1 , j = n ; i <= n ; i++ , j--)
{
  L[i] += L[i-1] + a[i-1];
}
ans = 1e18 ;
for (int i = 1,j=n-1;  i <= n ; i++,j--)
{
  ans = min ( ans , 1LL*L[i] *l + 1LL*(sum-L[i]) * r  + (  abs (i-j) < 2 ? 0 :  ( i > j ?  1LL*(abs(i-j)-1)*ql   : 1LL*(abs(i-j)-1) * qr  )  ));
}
printf ("%lld\n" , ans );

  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>
#include<fstream>

typedef long long ll ;

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
int L[100002] , R[100002];
int a[100000];
ll ans,sum ;
int   n , l , r , ql , qr ;
int main ()
{
scanf ("%d%d%d%d%d" , &n ,&l , &r ,&ql ,&qr);
for (int i =0 ; i < n ;i++)
{

  scanf ("%d" , a+i );
  sum += a[i];
}
for (int i =1 , j = n ; i <= n ; i++ , j--)
{
  L[i] += L[i-1] + a[i-1];
}
ans = 1e18 ;
for (int i = 1,j=n-1;  i <= n ; i++,j--)
{
  ans = min ( ans , 1LL*L[i] *l + 1LL*(sum-L[i]) * r  + (  abs (i-j) < 2 ? 0 :  ( i > j ?  1LL*(abs(i-j)-1)*ql   : 1LL*(abs(i-j)-1) * qr  )  ));
}
ans = min (ans ,  min ( 1LL * sum * l + (n-1) * ql , 1LL* sum * r + (n-1)*qr  )  );
printf ("%lld\n" , ans );

  return 0;
}


/**/
#include<iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include<stack>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef pair< ll, ll > lll;
typedef pair< int, ii > iii;
typedef vector< ii > vii;
typedef vector< ll > vll;
typedef vector< lll > vlll;
#define INF 1e9
#define GETLINE(x) fgets(x,500,stdin)
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size()-1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }
int n,l,r,Ql,Qr;
int w[110];
int fr[110];
int bc[110];
int main () {
#ifdef XVENOM
	freopen("inp.txt", "r", stdin);
	freopen("oup.txt", "w", stdout);
#endif
	scanf("%d %d %d %d %d",&n,&l,&r,&Ql,&Qr);
	for(int i=1;i<=n;i++)scanf("%d",&w[i]);
	for(int i=1;i<=n;i++)fr[i]+=l*w[i]+fr[i-1];
	for(int i=n;i>=1;i--)bc[i]+=r*w[i]+bc[i+1];
	int x;
	int ans=1e9;
	for(int i=1;i<=n;i++){
		x=fr[i]+bc[i+1];
		if(i>n-i)x+=(i-(n-i)-1)*Ql;
		if(n-i>i)x+=(n-i-i-1)*Qr;
		ans=min(ans,x);
	}
	printf("%d\n",ans);
}


/**/
#include<iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include<stack>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef pair< ll, ll > lll;
typedef pair< int, ii > iii;
typedef vector< ii > vii;
typedef vector< ll > vll;
typedef vector< lll > vlll;
#define INF 1e9
#define GETLINE(x) fgets(x,500,stdin)
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size()-1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }
int n,l,r,Ql,Qr;
int w[110];
int fr[110];
int bc[110];
int main () {
#ifdef XVENOM
	freopen("inp.txt", "r", stdin);
	freopen("oup.txt", "w", stdout);
#endif
	scanf("%d %d %d %d %d",&n,&l,&r,&Ql,&Qr);
	for(int i=1;i<=n;i++)scanf("%d",&w[i]);
	for(int i=1;i<=n;i++)fr[i]+=l*w[i]+fr[i-1];
	for(int i=n;i>=1;i--)bc[i]+=r*w[i]+bc[i+1];
	int x;
	int ans=1e9;
	for(int i=0;i<=n;i++){
		x=fr[i]+bc[i+1];
		if(i>n-i)x+=(i-(n-i)-1)*Ql;
		if(n-i>i)x+=(n-i-i-1)*Qr;
		ans=min(ans,x);
	}
	printf("%d\n",ans);
}


/**/
#include<iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include<stack>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef pair< ll, ll > lll;
typedef pair< int, ii > iii;
typedef vector< ii > vii;
typedef vector< ll > vll;
typedef vector< lll > vlll;
#define INF 1e9
#define GETLINE(x) fgets(x,500,stdin)
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size()-1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }
int n,l,r,Ql,Qr;
int w[100100];
int fr[100100];
int bc[100100];
int main () {
#ifdef XVENOM
	freopen("inp.txt", "r", stdin);
	freopen("oup.txt", "w", stdout);
#endif
	scanf("%d %d %d %d %d",&n,&l,&r,&Ql,&Qr);
	for(int i=1;i<=n;i++)scanf("%d",&w[i]);
	for(int i=1;i<=n;i++)fr[i]+=l*w[i]+fr[i-1];
	for(int i=n;i>=1;i--)bc[i]+=r*w[i]+bc[i+1];
	int x;
	int ans=1e9;
	for(int i=0;i<=n;i++){
		x=fr[i]+bc[i+1];
		if(i>n-i)x+=(i-(n-i)-1)*Ql;
		if(n-i>i)x+=(n-i-i-1)*Qr;
		ans=min(ans,x);
	}
	printf("%d\n",ans);
}


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

// =============================================================================
// BEGIN template
// =============================================================================
#ifdef ONLINE_JUDGE
  #define fastio        std::ios::sync_with_stdio(false)
  #define dbg(X)
  #define _             _
#else
  #include <unistd.h>
  #define fastio
  #define dbg(X)        cerr << ">>> (" << #X << ") = (" << X << ")\n"
  #define _             << " _ " <<
#endif
#define   ff            first
#define   ss            second
#define   pb            push_back
#define   eb            emplace_back
#define   em            emplace
#define   pq            priority_queue
#define   pqmin(X)      priority_queue<X,vector<X>,greater<X>>
#define   all(X)        (X).begin(),(X).end()
#define   sci1(X)       scanf("%d",&(X))
#define   sci2(X,Y)     scanf("%d%d",&(X),&(Y))
#define   sci3(X,Y,Z)   scanf("%d%d%d",&(X),&(Y),&(Z))
#define   scl(X)        scanf("%lld",&(X))
#define   scs(X)        scanf("%s",X)
#define   flush         fflush(stdout)
#define   pc(X)         __builtin_popcountll(X)
#define   lg(X)         (63 - __builtin_clzll(X))
#define   LG(X)         (lg(X)+((1<<lg(X)) < (X)))
#define    rp(i,L,R)    for (ll i = L, __R = R; i <= __R; i++)
#define   rpd(i,R,L)    for (ll i = R, __L = L; __L <= i; i--)

// dps
#define DP1(type,X)\
  static type dp[X];\
  static bool mark[X];\
  auto& ans = dp[i];\
  if (mark[i]) return ans;\
  mark[i] = true;
#define DP2(type,X,Y)\
  static type dp[X][Y];\
  static bool mark[X][Y];\
  auto& ans = dp[i][j];\
  if (mark[i][j]) return ans;\
  mark[i][j] = true;
#define DP3(type,X,Y,Z)\
  static type dp[X][Y][Z];\
  static bool mark[X][Y][Z];\
  auto& ans = dp[i][j][k];\
  if (mark[i][j][k]) return ans;\
  mark[i][j][k] = true;

// overloads
#define GET_SCI(_1,_2,_3,NAME,...) NAME
#define sci(...) GET_SCI(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define GET_DP(_1,_2,_3,_4,NAME,...) NAME
#define DP(...) GET_DP(__VA_ARGS__,DP3,DP2,DP1)(__VA_ARGS__)

// types
typedef   long long     ll;
typedef   pair<int,int> ii;
typedef   vector<int>   vi;
typedef   vector<bool>  vb;
typedef   set<int>      si;

// constants
const ll  oo =          0x3f3f3f3f3f3f3f3fll;
const int LGN =         25;
const int MOD =         1e9+7;
const int N =           1e5+5;
// =============================================================================
// END template
// =============================================================================

int main() {
  fastio;
  sci(n,l,r);
  sci(ql,qr);
  rp(i,1,n) sci(w[i]);
  static int sl[N],sr[N];
  rp(i,1,n) sl[i] = sl[i-1]+w[i];
  rpd(i,n,1) sr[i] = sr[i+1]+w[i];
  ll ans = oo;
  rp(i,0,n) {
    ll j = n-i;
    ll alt = sl[i]*l + sr[i+1]*r;
    if (i != j) {
      ll rem = max(i,j)-min(i,j)-1;
      alt += (ql*(i>j) + qr*(i<j))*rem;
    }
    ans = min(ans,alt);
  }
  printf("%lld\n", ans);
  return 0;
}


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

// =============================================================================
// BEGIN template
// =============================================================================
#ifdef ONLINE_JUDGE
  #define fastio        std::ios::sync_with_stdio(false)
  #define dbg(X)
  #define _             _
#else
  #include <unistd.h>
  #define fastio
  #define dbg(X)        cerr << ">>> (" << #X << ") = (" << X << ")\n"
  #define _             << " _ " <<
#endif
#define   ff            first
#define   ss            second
#define   pb            push_back
#define   eb            emplace_back
#define   em            emplace
#define   pq            priority_queue
#define   pqmin(X)      priority_queue<X,vector<X>,greater<X>>
#define   all(X)        (X).begin(),(X).end()
#define   sci1(X)       scanf("%d",&(X))
#define   sci2(X,Y)     scanf("%d%d",&(X),&(Y))
#define   sci3(X,Y,Z)   scanf("%d%d%d",&(X),&(Y),&(Z))
#define   scl(X)        scanf("%lld",&(X))
#define   scs(X)        scanf("%s",X)
#define   flush         fflush(stdout)
#define   pc(X)         __builtin_popcountll(X)
#define   lg(X)         (63 - __builtin_clzll(X))
#define   LG(X)         (lg(X)+((1<<lg(X)) < (X)))
#define    rp(i,L,R)    for (ll i = L, __R = R; i <= __R; i++)
#define   rpd(i,R,L)    for (ll i = R, __L = L; __L <= i; i--)

// dps
#define DP1(type,X)\
  static type dp[X];\
  static bool mark[X];\
  auto& ans = dp[i];\
  if (mark[i]) return ans;\
  mark[i] = true;
#define DP2(type,X,Y)\
  static type dp[X][Y];\
  static bool mark[X][Y];\
  auto& ans = dp[i][j];\
  if (mark[i][j]) return ans;\
  mark[i][j] = true;
#define DP3(type,X,Y,Z)\
  static type dp[X][Y][Z];\
  static bool mark[X][Y][Z];\
  auto& ans = dp[i][j][k];\
  if (mark[i][j][k]) return ans;\
  mark[i][j][k] = true;

// overloads
#define GET_SCI(_1,_2,_3,NAME,...) NAME
#define sci(...) GET_SCI(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define GET_DP(_1,_2,_3,_4,NAME,...) NAME
#define DP(...) GET_DP(__VA_ARGS__,DP3,DP2,DP1)(__VA_ARGS__)

// types
typedef   long long     ll;
typedef   pair<int,int> ii;
typedef   vector<int>   vi;
typedef   vector<bool>  vb;
typedef   set<int>      si;

// constants
const ll  oo =          0x3f3f3f3f3f3f3f3fll;
const int LGN =         25;
const int MOD =         1e9+7;
const int N =           1e5+5;
// =============================================================================
// END template
// =============================================================================

int n,l,r,ql,qr,w[N];

int main() {
  fastio;
  sci(n,l,r);
  sci(ql,qr);
  rp(i,1,n) sci(w[i]);
  static int sl[N],sr[N];
  rp(i,1,n) sl[i] = sl[i-1]+w[i];
  rpd(i,n,1) sr[i] = sr[i+1]+w[i];
  ll ans = oo;
  rp(i,0,n) {
    ll j = n-i;
    ll alt = sl[i]*l + sr[i+1]*r;
    if (i != j) {
      ll rem = max(i,j)-min(i,j)-1;
      alt += (ql*(i>j) + qr*(i<j))*rem;
    }
    ans = min(ans,alt);
  }
  printf("%lld\n", ans);
  return 0;
}


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

// =============================================================================
// BEGIN template
// =============================================================================
#ifdef ONLINE_JUDGE
  #define fastio        std::ios::sync_with_stdio(false)
  #define dbg(X)
  #define _             _
#else
  #include <unistd.h>
  #define fastio
  #define dbg(X)        cerr << ">>> (" << #X << ") = (" << X << ")\n"
  #define _             << " _ " <<
#endif
#define   ff            first
#define   ss            second
#define   pb            push_back
#define   eb            emplace_back
#define   em            emplace
#define   pq            priority_queue
#define   pqmin(X)      priority_queue<X,vector<X>,greater<X>>
#define   all(X)        (X).begin(),(X).end()
#define   sci1(X)       scanf("%d",&(X))
#define   sci2(X,Y)     scanf("%d%d",&(X),&(Y))
#define   sci3(X,Y,Z)   scanf("%d%d%d",&(X),&(Y),&(Z))
#define   scl(X)        scanf("%lld",&(X))
#define   scs(X)        scanf("%s",X)
#define   flush         fflush(stdout)
#define   pc(X)         __builtin_popcountll(X)
#define   lg(X)         (63 - __builtin_clzll(X))
#define   LG(X)         (lg(X)+((1<<lg(X)) < (X)))
#define    rp(i,L,R)    for (ll i = L, __R = R; i <= __R; i++)
#define   rpd(i,R,L)    for (ll i = R, __L = L; __L <= i; i--)

// dps
#define DP1(type,X)\
  static type dp[X];\
  static bool mark[X];\
  auto& ans = dp[i];\
  if (mark[i]) return ans;\
  mark[i] = true;
#define DP2(type,X,Y)\
  static type dp[X][Y];\
  static bool mark[X][Y];\
  auto& ans = dp[i][j];\
  if (mark[i][j]) return ans;\
  mark[i][j] = true;
#define DP3(type,X,Y,Z)\
  static type dp[X][Y][Z];\
  static bool mark[X][Y][Z];\
  auto& ans = dp[i][j][k];\
  if (mark[i][j][k]) return ans;\
  mark[i][j][k] = true;

// overloads
#define GET_SCI(_1,_2,_3,NAME,...) NAME
#define sci(...) GET_SCI(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define GET_DP(_1,_2,_3,_4,NAME,...) NAME
#define DP(...) GET_DP(__VA_ARGS__,DP3,DP2,DP1)(__VA_ARGS__)

// types
typedef   long long     ll;
typedef   pair<int,int> ii;
typedef   vector<int>   vi;
typedef   vector<bool>  vb;
typedef   set<int>      si;

// constants
const ll  oo =          0x3f3f3f3f3f3f3f3fll;
const int LGN =         25;
const int MOD =         1e9+7;
const int N =           1e2+5;
// =============================================================================
// END template
// =============================================================================

int n,l,r,ql,qr,w[N];

ll f(int i, int j, int k) {
  if (j < i) return 0;
  DP(ll,N,N,3);
  ll lef = w[i]*l+(k==1)*ql+f(i+1,j,1);
  ll rig = w[j]*r+(k==2)*qr+f(i,j-1,2);
  return ans = min(lef,rig);
}

int main() {
  fastio;
  sci(n,l,r);
  sci(ql,qr);
  rp(i,1,n) sci(w[i]);
  static int sl[N],sr[N];
  rp(i,1,n) sl[i] = sl[i-1]+w[i];
  rpd(i,n,1) sr[i] = sr[i+1]+w[i];
  ll ans = oo;
  rp(i,0,n) {
    ll j = n-i;
    ll alt = sl[i]*l + sr[i+1]*r;
    if (i != j) {
      ll rem = max(i,j)-min(i,j)-1;
      alt += (ql*(i>j) + qr*(i<j))*rem;
    }
    ans = min(ans,alt);
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
	int n,l,r,ql,qr,i,j,k;
	int w[100005];
	scanf("%d%d%d%d%d",&n,&l,&r,&ql,&qr);
	for(i=1 ; i <= n ; i++)
		scanf("%d",w+i);
	int p[100005],q[100005];
	p[0]=q[n+1]=0;
	for (i=1 ; i <= n ; i++) {
		p[i]= p[i-1]+w[i];
		q[n-i+1]=q[n-i+2]+w[n-i+1];
	}
	int ans=INT_MAX;
	for (i=1 ; i <= n  ; i++) {
		int x = p[i]*l + q[n-i]*r;
		if (i > n-i)
			x += (2*i-n-1)*ql;
		if (i < n-i)
			x += (n-2*i-1)*qr;
		ans = min(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
	int n,l,r,ql,qr,i,j,k;
	int w[100005];
	scanf("%d%d%d%d%d",&n,&l,&r,&ql,&qr);
	for(i=0 ; i < n ; i++)
		scanf("%d",w+i);
	int p[100005],q[100005];
	p[0]=w[0],q[n-1]=w[n-1];
	for (i=1 ; i < n ; i++) {
		p[i]= p[i-1]+w[i];
		q[n-i-1]=q[n-i]+w[n-i-1];
	}
	int ans=INT_MAX;
	for (i=0 ; i < n  ; i++) {
		int x = p[i]*l + q[n-i]*r;
		if (i > n-i)
			x += (2*i-n-1)*ql;
		if (i < n-i)
			x += (n-2*i-1)*qr;
		ans = min(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
	int n,l,r,ql,qr,i,j,k;
	int w[100005];
	w[0]=0;
	scanf("%d%d%d%d%d",&n,&l,&r,&ql,&qr);
	for(i=1 ; i <= n ; i++) {
		scanf("%d",w+i);
		w[i] += w[i-1];
	}
	int ans=mod;
	for (i=0 ; i <= n  ; i++) {
		int x = w[i]*l + (w[n]-w[i])*r;
		if (2*i-n-1>0)
			x += (2*i-n-1)*ql;
		if (n-2*i-1>0)
			x += (n-2*i-1)*qr;
		ans = min(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstring>					//  For memset
#include <sstream>

using namespace std;

#define lop(i,n) for(int i = 0 ; i < n ;i++)
#define VI	vector<int>
#define VLL	vector<ll>
#define VPI	vector<pair<int , int>>
#define VII	vector<VI>
#define all(v)	v.begin() , v.end()
#define SORT(v)	sort(all(v))
#define ll	long long
#define scni(x)	scanf("%d",&x)				//  int
#define scnll(x)	scanf("%lld",&x)			//  ll
#define scnd(x)	scanf("%lf",&x)			//  double
#define prnti(x)	printf("%d\n",x)				//  int
#define prntll(x)	printf("%lld",x)				//  int
#define prntd(x)	printf("%.9f",x)				//  int
#define sz(x)  x.size()
#define SPC  <<" "<<
#define INF int(1e9)
#define pp push_back
#define P pair<int , int>
#define mp make_pair

const double EPS = 1e-9;
const double PI = 3.14159265359;

//  O( n * log(log(n)) )
vector<ll> primes;
void GeneratingPrimes(int top){
	vector<bool> p (top+1 , 1);
//	vector<ll> primes;
	p[0] = p[1] = 0;

	for(int i = 2; i <= sqrt(top) ; i++){
		if(!p[i])continue;
		if(p[i]){
			for(int j = i*i ; j <= top ; j+=i){
				p[j]=0;
			}
		}
	}
	lop(i , top+1)
		if(p[i])primes.push_back(i);
//	return primes;
}

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

void EXTgcd(ll a , ll b , int & x0 , int & y0){
	if(b==0){ x0 =1 , y0 = 0; return; }
	EXTgcd( b , a%b , x0 , y0 );
	ll x1 = y0;
	ll y1 = x0 - (a/b) * y0;
	x0 = x1;
	y0 = y1;
}

ll POW(ll x , ll p , ll mod){
	if(!p)return 1;
	ll ret=1;
	while(p > 1){
		if(p&1)ret *= (x);
		ret %= mod;
		x *= x;
		x %= mod;
		p /= 2;
	}
	ret *= (x%mod);
	return ret;
}

double dist(int a , int b , int x, int y){ return sqrt( pow( a-x ,2) + pow( b-y ,2) ); }

int xadd[9]= { 1 , -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 };
int yadd[9]= { 1 , -1 , 0 ,-1 ,  0 , 1 , 0 ,  1, -1 };

#define no  { cout<<"NO\n"; }
#define yes { cout<<"YES\n";}

///////////////////////////////////////////////////////////////////

ll n  , l , r , ql , qr , ans=0;
int v[123456];

int RP(int x , int y){
	return max(x-1 - y , 0);
}

int main(){

	cin >> n >>  l >> r >> ql >> qr;
	lop(i ,n)cin >> v[i];
	vector<int> L , R;

	int x=0, y=n-1;
	while(x < y){
		L.push_back(v[x++]);
		R.push_back(v[y--]);
	}
	if(n & 1){ if(l<r)L.push_back(v[x]);else R.push_back(v[x]); }

	int idx_r = L.size();
	int idx_l = R.size();

	if(l < r){
		int s =0 , cnt=0;
		for(int i= sz(R)-1 ; i >= 0 ; i--){
			cnt= RP(sz(L)+sz(R)-i , i);
			s+=R[i];
			if(cnt*ql+s*l < v[i]*r)idx_l=i;
		}
		for(int i = idx_l ; i<sz(R) ; i++){ ans += l*R[i]; }
		ans += ql * RP( sz(L)+sz(R)-idx_l , idx_l );

	}else if(r < l){
		int s =0 , cnt=0;
		for(int i= sz(L)-1 ; i >= 0 ; i--){
			s+=L[i];
			cnt= RP(sz(L)+sz(R)-i , i);
			if(cnt*qr+s*r < v[i]*l)idx_r=i;
		}
		for(int i = idx_r ; i<sz(L) ; i++){ ans += r*L[i]; }
		ans += qr * RP( sz(L)+sz(R)-idx_r , idx_r );

	}
	lop(i,idx_l)ans += r*R[i];
	lop(i,idx_r)ans += l*L[i];

	cout << ans;

return 0;}


#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstring>					//  For memset
#include <sstream>

using namespace std;

#define lop(i,n) for(int i = 0 ; i < n ;i++)
#define VI	vector<int>
#define VLL	vector<ll>
#define VPI	vector<pair<int , int>>
#define VII	vector<VI>
#define all(v)	v.begin() , v.end()
#define SORT(v)	sort(all(v))
#define ll	long long
#define scni(x)	scanf("%d",&x)				//  int
#define scnll(x)	scanf("%lld",&x)			//  ll
#define scnd(x)	scanf("%lf",&x)			//  double
#define prnti(x)	printf("%d\n",x)				//  int
#define prntll(x)	printf("%lld",x)				//  int
#define prntd(x)	printf("%.9f",x)				//  int
#define sz(x)  x.size()
#define SPC  <<" "<<
#define INF int(1e9)
#define pp push_back
#define P pair<int , int>
#define mp make_pair

const double EPS = 1e-9;
const double PI = 3.14159265359;

//  O( n * log(log(n)) )
vector<ll> primes;
void GeneratingPrimes(int top){
	vector<bool> p (top+1 , 1);
//	vector<ll> primes;
	p[0] = p[1] = 0;

	for(int i = 2; i <= sqrt(top) ; i++){
		if(!p[i])continue;
		if(p[i]){
			for(int j = i*i ; j <= top ; j+=i){
				p[j]=0;
			}
		}
	}
	lop(i , top+1)
		if(p[i])primes.push_back(i);
//	return primes;
}

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

void EXTgcd(ll a , ll b , int & x0 , int & y0){
	if(b==0){ x0 =1 , y0 = 0; return; }
	EXTgcd( b , a%b , x0 , y0 );
	ll x1 = y0;
	ll y1 = x0 - (a/b) * y0;
	x0 = x1;
	y0 = y1;
}

ll POW(ll x , ll p , ll mod){
	if(!p)return 1;
	ll ret=1;
	while(p > 1){
		if(p&1)ret *= (x);
		ret %= mod;
		x *= x;
		x %= mod;
		p /= 2;
	}
	ret *= (x%mod);
	return ret;
}

double dist(int a , int b , int x, int y){ return sqrt( pow( a-x ,2) + pow( b-y ,2) ); }

int xadd[9]= { 1 , -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 };
int yadd[9]= { 1 , -1 , 0 ,-1 ,  0 , 1 , 0 ,  1, -1 };

#define no  { cout<<"NO\n"; }
#define yes { cout<<"YES\n";}

///////////////////////////////////////////////////////////////////

ll n  , l , r , ql , qr , ans=9876543219876;
ll L[123456] , R[123456];

ll RP(int x , int y){
	return max(x-1 - y , 0);
}

int main(){

	cin >> n >>  l >> r >> ql >> qr;
	lop(i ,n)cin >> L[i+1] ,  R[i+1] = L[i+1];

	for(int i=1; i <= n ; i++)L[i+1] += L[i];
	for(int i=n ; i > 1 ; i--)R[i-1] += R[i];

	for(int i =1 ; i<=n; i++){
		L[i] = L[i]*l + ql*RP(i , n-i);
	}
	for(int i =n+1 ; i>=1; i--){
		R[i] = R[i]*r + qr*RP(n-i+1 , i-1);
		ans = min(ans , R[i] + L[i-1]);
	}

	cout << ans;

return 0;}


#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstring>					//  For memset
#include <sstream>

using namespace std;

#define lop(i,n) for(int i = 0 ; i < n ;i++)
#define VI	vector<int>
#define VLL	vector<ll>
#define VPI	vector<pair<int , int>>
#define VII	vector<VI>
#define all(v)	v.begin() , v.end()
#define SORT(v)	sort(all(v))
#define ll	long long
#define scni(x)	scanf("%d",&x)				//  int
#define scnll(x)	scanf("%lld",&x)			//  ll
#define scnd(x)	scanf("%lf",&x)			//  double
#define prnti(x)	printf("%d\n",x)				//  int
#define prntll(x)	printf("%lld",x)				//  int
#define prntd(x)	printf("%.9f",x)				//  int
#define sz(x)  x.size()
#define SPC  <<" "<<
#define INF int(1e9)
#define pp push_back
#define P pair<int , int>
#define mp make_pair

const double EPS = 1e-9;
const double PI = 3.14159265359;

//  O( n * log(log(n)) )
vector<ll> primes;
void GeneratingPrimes(int top){
	vector<bool> p (top+1 , 1);
//	vector<ll> primes;
	p[0] = p[1] = 0;

	for(int i = 2; i <= sqrt(top) ; i++){
		if(!p[i])continue;
		if(p[i]){
			for(int j = i*i ; j <= top ; j+=i){
				p[j]=0;
			}
		}
	}
	lop(i , top+1)
		if(p[i])primes.push_back(i);
//	return primes;
}

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

void EXTgcd(ll a , ll b , int & x0 , int & y0){
	if(b==0){ x0 =1 , y0 = 0; return; }
	EXTgcd( b , a%b , x0 , y0 );
	ll x1 = y0;
	ll y1 = x0 - (a/b) * y0;
	x0 = x1;
	y0 = y1;
}

ll POW(ll x , ll p , ll mod){
	if(!p)return 1;
	ll ret=1;
	while(p > 1){
		if(p&1)ret *= (x);
		ret %= mod;
		x *= x;
		x %= mod;
		p /= 2;
	}
	ret *= (x%mod);
	return ret;
}

double dist(int a , int b , int x, int y){ return sqrt( pow( a-x ,2) + pow( b-y ,2) ); }

int xadd[9]= { 1 , -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 };
int yadd[9]= { 1 , -1 , 0 ,-1 ,  0 , 1 , 0 ,  1, -1 };

#define no  { cout<<"NO\n"; }
#define yes { cout<<"YES\n";}

///////////////////////////////////////////////////////////////////

ll n  , l , r , ql , qr , ans;
int v[123456];

int main(){

	cin >> n >>  l >> r >> ql >> qr;
	lop(i ,n)cin >> v[i];
	vector<int> L , R;

	int x=0, y=n-1;
	while(x < y){
		L.push_back(v[x++]);
		R.push_back(v[y--]);
	}
	if(n & 1){ if(l<r)L.push_back(v[x]);else R.push_back(v[x]); }

	int idx_r = L.size();
	int idx_l = R.size();

	if(l < r){
		int s =0 , cnt=0;
		for(int i= sz(R)-1 ; i >= 0 ; i--){
			cnt++;
			s+=R[i];
			if(cnt*ql+s*l < s*r)idx_l=i;
		}
		for(int i = idx_l ; i<sz(R) ; i++){ ans += l*R[i];ans+=ql; }

	}else if(r < l){
		int s =0 , cnt=0;
		for(int i= sz(L)-1 ; i >= 0 ; i--){
			s+=L[i];
			if(cnt*qr+s*r < v[i]*l)idx_r=i;
			cnt++;
		}
		for(int i = idx_r ; i<sz(L) ; i++){ ans += r*L[i];ans+=qr; }
	}
	lop(i,idx_l)ans += r*R[i];
	lop(i,idx_r)ans += l*L[i];

	cout << ans;

return 0;}


#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstring>					//  For memset
#include <sstream>

using namespace std;

#define lop(i,n) for(int i = 0 ; i < n ;i++)
#define VI	vector<int>
#define VLL	vector<ll>
#define VPI	vector<pair<int , int>>
#define VII	vector<VI>
#define all(v)	v.begin() , v.end()
#define SORT(v)	sort(all(v))
#define ll	long long
#define scni(x)	scanf("%d",&x)				//  int
#define scnll(x)	scanf("%lld",&x)			//  ll
#define scnd(x)	scanf("%lf",&x)			//  double
#define prnti(x)	printf("%d\n",x)				//  int
#define prntll(x)	printf("%lld",x)				//  int
#define prntd(x)	printf("%.9f",x)				//  int
#define sz(x)  x.size()
#define SPC  <<" "<<
#define INF int(1e9)
#define pp push_back
#define P pair<int , int>
#define mp make_pair

const double EPS = 1e-9;
const double PI = 3.14159265359;

//  O( n * log(log(n)) )
vector<ll> primes;
void GeneratingPrimes(int top){
	vector<bool> p (top+1 , 1);
//	vector<ll> primes;
	p[0] = p[1] = 0;

	for(int i = 2; i <= sqrt(top) ; i++){
		if(!p[i])continue;
		if(p[i]){
			for(int j = i*i ; j <= top ; j+=i){
				p[j]=0;
			}
		}
	}
	lop(i , top+1)
		if(p[i])primes.push_back(i);
//	return primes;
}

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

void EXTgcd(ll a , ll b , int & x0 , int & y0){
	if(b==0){ x0 =1 , y0 = 0; return; }
	EXTgcd( b , a%b , x0 , y0 );
	ll x1 = y0;
	ll y1 = x0 - (a/b) * y0;
	x0 = x1;
	y0 = y1;
}

ll POW(ll x , ll p , ll mod){
	if(!p)return 1;
	ll ret=1;
	while(p > 1){
		if(p&1)ret *= (x);
		ret %= mod;
		x *= x;
		x %= mod;
		p /= 2;
	}
	ret *= (x%mod);
	return ret;
}

double dist(int a , int b , int x, int y){ return sqrt( pow( a-x ,2) + pow( b-y ,2) ); }

int xadd[9]= { 1 , -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 };
int yadd[9]= { 1 , -1 , 0 ,-1 ,  0 , 1 , 0 ,  1, -1 };

#define no  { cout<<"NO\n"; }
#define yes { cout<<"YES\n";}

///////////////////////////////////////////////////////////////////

ll n  , l , r , ql , qr , ans=0;
ll v[123456];

int RP(int x , int y){
	return max(x-1 - y , 0);
}

int main(){

	cin >> n >>  l >> r >> ql >> qr;
	lop(i ,n)cin >> v[i];
	vector<int> L , R;

	int x=0, y=n-1;
	while(x < y){
		L.push_back(v[x++]);
		R.push_back(v[y--]);
	}
	if(n & 1){ if(l<r)L.push_back(v[x]);else R.push_back(v[x]); }

	int idx_r = L.size();
	int idx_l = R.size();

	if(l < r){
		ll s =0 , cnt=0;
		for(int i= sz(R)-1 ; i >= 0 ; i--){
			cnt= RP(sz(L)+sz(R)-i , i);
			s+=R[i];
			if(cnt*ql+s*l < v[i]*r)idx_l=i;
		}
		for(int i = idx_l ; i<sz(R) ; i++){ ans += l*R[i]; }
		ans += ql * RP( sz(L)+sz(R)-idx_l , idx_l );

	}else if(r < l){
		ll s =0 , cnt=0;
		for(int i= sz(L)-1 ; i >= 0 ; i--){
			s+=L[i];
			cnt= RP(sz(L)+sz(R)-i , i);
			if(cnt*qr+s*r < v[i]*l)idx_r=i;
		}
		for(int i = idx_r ; i<sz(L) ; i++){ ans += r*L[i]; }
		ans += qr * RP( sz(L)+sz(R)-idx_r , idx_r );

	}
	lop(i,idx_l)ans += r*R[i];
	lop(i,idx_r)ans += l*L[i];

	cout << ans;

return 0;}


#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstring>					//  For memset
#include <sstream>

using namespace std;

#define lop(i,n) for(int i = 0 ; i < n ;i++)
#define VI	vector<int>
#define VLL	vector<ll>
#define VPI	vector<pair<int , int>>
#define VII	vector<VI>
#define all(v)	v.begin() , v.end()
#define SORT(v)	sort(all(v))
#define ll	long long
#define scni(x)	scanf("%d",&x)				//  int
#define scnll(x)	scanf("%lld",&x)			//  ll
#define scnd(x)	scanf("%lf",&x)			//  double
#define prnti(x)	printf("%d\n",x)				//  int
#define prntll(x)	printf("%lld",x)				//  int
#define prntd(x)	printf("%.9f",x)				//  int
#define sz(x)  x.size()
#define SPC  <<" "<<
#define INF int(1e9)
#define pp push_back
#define P pair<int , int>
#define mp make_pair

const double EPS = 1e-9;
const double PI = 3.14159265359;

//  O( n * log(log(n)) )
vector<ll> primes;
void GeneratingPrimes(int top){
	vector<bool> p (top+1 , 1);
//	vector<ll> primes;
	p[0] = p[1] = 0;

	for(int i = 2; i <= sqrt(top) ; i++){
		if(!p[i])continue;
		if(p[i]){
			for(int j = i*i ; j <= top ; j+=i){
				p[j]=0;
			}
		}
	}
	lop(i , top+1)
		if(p[i])primes.push_back(i);
//	return primes;
}

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

void EXTgcd(ll a , ll b , int & x0 , int & y0){
	if(b==0){ x0 =1 , y0 = 0; return; }
	EXTgcd( b , a%b , x0 , y0 );
	ll x1 = y0;
	ll y1 = x0 - (a/b) * y0;
	x0 = x1;
	y0 = y1;
}

ll POW(ll x , ll p , ll mod){
	if(!p)return 1;
	ll ret=1;
	while(p > 1){
		if(p&1)ret *= (x);
		ret %= mod;
		x *= x;
		x %= mod;
		p /= 2;
	}
	ret *= (x%mod);
	return ret;
}

double dist(int a , int b , int x, int y){ return sqrt( pow( a-x ,2) + pow( b-y ,2) ); }

int xadd[9]= { 1 , -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 };
int yadd[9]= { 1 , -1 , 0 ,-1 ,  0 , 1 , 0 ,  1, -1 };

#define no  { cout<<"NO\n"; }
#define yes { cout<<"YES\n";}

///////////////////////////////////////////////////////////////////

ll n  , l , r , ql , qr , ans=0;
ll v[123456];

int RP(int x , int y){
	return max(x-1 - y , 0);
}

int main(){

	cin >> n >>  l >> r >> ql >> qr;
	lop(i ,n)cin >> v[i];
	vector<ll> L , R;

	int x=0, y=n-1;
	while(x < y){
		L.push_back(v[x++]);
		R.push_back(v[y--]);
	}
	if(n & 1){ if(l<r)L.push_back(v[x]);else R.push_back(v[x]); }

	int idx_r = L.size();
	int idx_l = R.size();

	if(l < r){
		ll s =0 , cnt=0;
		for(int i= sz(R)-1 ; i >= 0 ; i--){
			cnt= RP(sz(L)+sz(R)-i , i);
			s+=R[i];
			if(cnt*ql+s*l < v[i]*r)idx_l=i;
		}
		for(int i = idx_l ; i<sz(R) ; i++){ ans += l*R[i]; }
		ans += ql * RP( sz(L)+sz(R)-idx_l , idx_l );

	}else if(r < l){
		ll s =0 , cnt=0;
		for(int i= sz(L)-1 ; i >= 0 ; i--){
			s+=L[i];
			cnt= RP(sz(L)+sz(R)-i , i);
			if(cnt*qr+s*r < v[i]*l)idx_r=i;
		}
		for(int i = idx_r ; i<sz(L) ; i++){ ans += r*L[i]; }
		ans += qr * RP( sz(L)+sz(R)-idx_r , idx_r );

	}
	lop(i,idx_l)ans += r*R[i];
	lop(i,idx_r)ans += l*L[i];

	cout << ans;

return 0;}


#include<bits/stdc++.h>
#define ll long long
#define N 100009
#define MOD 1000000007
#define inf 1e16
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define wt(x) cout <<#x<<" = " << x << endl
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std ;
void read (int a =0 )
{
    freopen ("in","r",stdin);   if(a) freopen("out","w",stdout);
}
ll sum [N][2];ll a[N] ;

int main ()
{
    ll n , pri[2],q[2];
    cin >> n ;

    cin >> pri[0] >> pri[1];
    cin >> q[0] >> q[1] ;

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

    ll time = 2 ;
    bool type = 1 ;
    ll mi = inf ;

    sum [-1][0]=0 ;
    for (int i =0 ;i<n; i++ )
    {
        sum [i][0]=a[i] + sum [i-1][0] ;
    }
    sum [n][1]= 0 ;
    for (int i=n-1 ; i>=0 ;i -- )
    {
        sum [i][1] = a[i] + sum [i+1][1];
    }

    while (time -- )
    {

        ll dir[2]={0,n-1} ;
         ll ans = 0 ;bool done = 0 ;ll key ;
         while (dir[0]<=dir[1])
         {
             ll tmp = sum [dir[type]][!type] - sum [dir[!type]-1+2*(!type)][!type];
             tmp *=pri[!type];

             if(!done )
             {

                 key = n-1  ;
             }
             else
             {
                 key --;
             }

             tmp +=q[!type]*(key);
             if(!done )
             {
                 done = 1 ;
                 key = n;
             }

             if (tmp <= a[dir[type]]*pri[type])
             {
                 ans+=tmp ;
                 break ;
             }
             else
             {
                 ans+=  a[dir[type]]*pri[type] ;
                 dir[type]+= 1-2*(type) ;
                 type= ! type ;
             }

         }

         mi = min (ans , mi );

         type = 0 ;
         reverse (a,a+n);
         dir[0]=0;
         dir[1]=n-1;

    }
    cout << mi ;

}


#include<bits/stdc++.h>
#define ll long long
#define N 100009
#define MOD 1000000007
#define inf 1e16
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define wt(x) cout <<#x<<" = " << x << endl
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std ;
void read (int a =0 )
{
    freopen ("in","r",stdin);   if(a) freopen("out","w",stdout);
}
ll sum [N][2];ll a[N] ;

int main ()
{
    ll n , pri[2],q[2];
    cin >> n ;

    cin >> pri[0] >> pri[1];
    cin >> q[0] >> q[1] ;

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

    ll time = 2 ;
    bool type = 1 ;
    ll mi = inf ;

    sum [-1][0]=0 ;
    for (int i =0 ;i<n; i++ )
    {
        sum [i][0]=a[i] + sum [i-1][0] ;
    }
    sum [n][1]= 0 ;
    for (int i=n-1 ; i>=0 ;i -- )
    {
        sum [i][1] = a[i] + sum [i+1][1];
    }

    while (time -- )
    {

        ll dir[2]={0,n-1} ;
         ll ans = 0 ;bool done = 0 ;ll key ;
         while (dir[0]<=dir[1])
         {
             ll tmp = sum [dir[type]][!type] - sum [dir[!type]-1+2*(!type)][!type];
             tmp *=pri[!type];

             if(!done )
             {

                 key = n-1  ;
             }
             else
             {
                 key --;
             }

             tmp +=q[!type]*(key);

             if(!done )
             {
                 done = 1 ;
                 key = n;
             }

             if (tmp <= a[dir[type]]*pri[type])
             {
                 ans+=tmp ;
                 break ;
             }
             else
             {
                 ans+=  a[dir[type]]*pri[type] ;
                 dir[type]+= 1-2*(type) ;
                 type= ! type ;
             }

         }

         mi = min (ans , mi );

         type = 0 ;

         dir[0]=0;
         dir[1]=n-1;

    }
    cout << mi ;

}


import java.util.*;
import java.awt.*;

public class iou {
	Scanner in = new Scanner(System.in);

	public static void main(String args[]) {

		new iou().go();
	}

	public void go() {
		long sum=0;
		int n = in.nextInt();
		int m = in.nextInt();
		int arr[][]= new int[n][2];

		for(int i=0;i<m;i++){
			int a=in.nextInt();
			int b= in.nextInt();
			int c=in.nextInt();
			arr[a-1][1]+=c;
			arr[b-1][0]+=c;
		}

		//System.out.println(list);
		for(int i=0;i<n;i++){
			if(arr[i][0]>arr[i][1]){
				arr[i][0]-=arr[i][1];
				arr[i][1]=0;
			}else{
				arr[i][1]-=arr[i][0];
				arr[i][0]=0;
			}
		}
		for(int i=0;i<n;i++){
			sum+=arr[i][0]+arr[i][1];
		}
		System.out.println(sum/2);
	}
}


import java.util.*;
import java.awt.*;

public class iou {
	Scanner in = new Scanner(System.in);

	public static void main(String args[]) {

		new iou().go();
	}

	public void go() {
		long sum=0;
		int n = in.nextInt();
		int m = in.nextInt();
		ArrayList<Point> list= new ArrayList<Point>();
		for(int i=0;i<m;i++){
			list.add(new Point(in.nextInt(), in.nextInt(), in.nextInt()));
		}
		Collections.sort(list, new Comparator<Point>(){

			@Override
			public int compare(Point arg0, Point arg1) {
				return arg1.d-arg0.d;
			}

		});
		HashSet<Integer> left= new HashSet<Integer>();
		HashSet<Integer> right= new HashSet<Integer>();
		//System.out.println(list);
		for(int i=0;i<list.size();i++){
			Point t= list.get(i);

			if(right.contains(t.a)){

				continue;
			}
			if(left.contains(t.b)) {
				sum-=t.d;
				continue;
			}
			left.add(t.a);
			right.add(t.b);
			//System.out.println(t);
			sum+=t.d;
		}
		System.out.println(sum);
	}
}
class Point{
	int a;
	int b;
	int d;
	public Point(int a, int b, int d) {
		super();
		this.a = a;
		this.b = b;
		this.d = d;
	}
	@Override
	public String toString() {
		return "Point [a=" + a + ", b=" + b + ", d=" + d + "]";
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Created by 875k on 12/24/13.
 */
public class CF221B {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(tok.nextToken());
        int m = Integer.parseInt(tok.nextToken());
        int[] arr = new int[200];
        for(int i = 0; i < m; i++) {
            tok = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(tok.nextToken());
            int b = Integer.parseInt(tok.nextToken());
            int c = Integer.parseInt(tok.nextToken());
            arr[b] += c;
            arr[a] -= c;
        }
        int ct = 0;
        for(int i = 1; i < n + 1; i++) {
            if(arr[i] > 0) ct += arr[i];
        }
        System.out.println(ct);
    }
}


import java.util.*;
import java.awt.geom.*;
import java.io.*;

public class Main{

    private void doit(){
        InStream sc = new InStream();
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            long [] data = new long[n + 1];
            for(int i = 0; i < m; i++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();

                data[a] -= c;
                data[b] += b;
            }
            long res = 0;
            for(long num: data){
                if(num < 0){
                    res += num * -1;
                }
            }
            System.out.println(res);
        }
    }

    class InStream{
        BufferedReader in;StringTokenizer st;
        public InStream() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.st = null;
        }
        String next() {
            while (st==null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (Exception e) {}
            }
            return st.nextToken();
        }
        boolean hasNext(){
            try{
                st = new StringTokenizer(in.readLine());
                return true;
            }catch(Exception e){return false;}
        }
        int nextInt() { return Integer.parseInt(next());}
        long nextLong() {return Long.parseLong(next());}
        double nextDouble() {return Double.parseDouble(next());}
    }

    private void debug(Object... o) {
        System.out.println("debug = " + Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new Main().doit();
    }
}


import java.util.*;
import java.awt.geom.*;
import java.io.*;

public class Main{

    private void doit(){
        InStream sc = new InStream();
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            long [] data = new long[n + 1];
            for(int i = 0; i < m; i++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();

                data[a] -= c;
                data[b] += c;
            }
            long res = 0;
            for(long num: data){
                if(num < 0){
                    res += num * -1;
                }
            }
            System.out.println(res);
        }
    }

    class InStream{
        BufferedReader in;StringTokenizer st;
        public InStream() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.st = null;
        }
        String next() {
            while (st==null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (Exception e) {}
            }
            return st.nextToken();
        }
        boolean hasNext(){
            try{
                st = new StringTokenizer(in.readLine());
                return true;
            }catch(Exception e){return false;}
        }
        int nextInt() { return Integer.parseInt(next());}
        long nextLong() {return Long.parseLong(next());}
        double nextDouble() {return Double.parseDouble(next());}
    }

    private void debug(Object... o) {
        System.out.println("debug = " + Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new Main().doit();
    }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

public class Main2{

    public static InputStream inputStream = System.in;
    public static OutputStream outputStream = System.out;
    public static FastReader in = new FastReader(inputStream);
    public static PrintWriter out = new PrintWriter(outputStream);

    public static void main(String[] args)throws java.lang.Exception{
        new Main2().run();
        out.close();
    }

    void run()throws java.lang.Exception{
        int n= in.nextInt();
        int m= in.nextInt();
        int[][] a = new int[n][n];
        for(int i=0; i<m; i++){
            int x = in.nextInt()-1;
            int y = in.nextInt()-1;
            int cost = in.nextInt();
            a[x][y] = cost;
        }
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                for(int k=0; k<n; k++){
                    if(i==j || j==k){
                        continue;
                    }
                    int minCost = Math.min(a[i][j], a[j][k]);
                    a[i][j] -= minCost;
                    a[j][k] -= minCost;
                    if(i!=k){
                        a[i][k] += minCost;
                    }
                }
            }
        }
        long v = 0L;
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                v += a[i][j];
            }
        }
        System.out.println(v);
    }
}

class FastReader{
    private boolean finished = false;

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream){
        this.stream = stream;
    }

    public int read(){
        if (numChars == -1){
            throw new InputMismatchException ();
        }
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read (buf);
            } catch (IOException e){
                throw new InputMismatchException ();
            }
            if (numChars <= 0){
                return -1;
            }
        }
        return buf[curChar++];
    }

    public int peek(){
        if (numChars == -1){
            return -1;
        }
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read (buf);
            } catch (IOException e){
                return -1;
            }
            if (numChars <= 0){
                return -1;
            }
        }
        return buf[curChar];
    }

    public int nextInt(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-'){
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do{
            if(c==','){
                c = read();
            }
            if (c < '0' || c > '9'){
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nextLong(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-'){
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do{
            if (c < '0' || c > '9'){
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String nextString(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do{
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c){
        if (filter != null){
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c){
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private String readLine0(){
        StringBuilder buf = new StringBuilder ();
        int c = read ();
        while (c != '\n' && c != -1){
            if (c != '\r'){
                buf.appendCodePoint (c);
            }
            c = read ();
        }
        return buf.toString ();
    }

    public String nextLine(){
        String s = readLine0 ();
        while (s.trim ().length () == 0)
            s = readLine0 ();
        return s;
    }

    public String nextLine(boolean ignoreEmptyLines){
        if (ignoreEmptyLines){
            return nextLine ();
        }else{
            return readLine0 ();
        }
    }

    public BigInteger nextBigInteger(){
        try{
            return new BigInteger (nextString ());
        } catch (NumberFormatException e){
            throw new InputMismatchException ();
        }
    }

    public char nextCharacter(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public double nextDouble(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-'){
            sgn = -1;
            c = read ();
        }
        double res = 0;
        while (!isSpaceChar (c) && c != '.'){
            if (c == 'e' || c == 'E'){
                return res * Math.pow (10, nextInt ());
            }
            if (c < '0' || c > '9'){
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        }
        if (c == '.'){
            c = read ();
            double m = 1;
            while (!isSpaceChar (c)){
                if (c == 'e' || c == 'E'){
                    return res * Math.pow (10, nextInt ());
                }
                if (c < '0' || c > '9'){
                    throw new InputMismatchException ();
                }
                m /= 10;
                res += (c - '0') * m;
                c = read ();
            }
        }
        return res * sgn;
    }

    public boolean isExhausted(){
        int value;
        while (isSpaceChar (value = peek ()) && value != -1)
            read ();
        return value == -1;
    }

    public String next(){
        return nextString ();
    }

    public SpaceCharFilter getFilter(){
        return filter;
    }

    public void setFilter(SpaceCharFilter filter){
        this.filter = filter;
    }

    public interface SpaceCharFilter{
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
public class bb {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n= input.nextInt(), m = input.nextInt();
    int[][] g = new int[n][n];
    for(int i = 0; i<m; i++)
    {
        int a = input.nextInt()-1, b = input.nextInt()-1, c = input.nextInt();
        g[a][b] += c;
    }
    for(int k = 0; k<n; k++)
        for(int i = 0; i<n; i++)
            for(int j = 0; j<n; j++)
            {
                int x = Math.min(g[i][k], g[k][j]);
                g[i][k] -= x;
                g[k][j] -= x;
                g[i][j] += x;
            }
    int res = 0;
    for(int i = 0; i<n; i++)
        for(int j = 0; j<n; j++)
            if(i != j) res += g[i][j];
    System.out.println(res);
}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;

public class B{

    public static void main(String args[]) throws Exception {

        B in = new B();
        in.init(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int arr[] = new int[n+1];
        for(int x=0;x<m;x++)
        {
            int a1 = in.nextInt();
            int b1 = in.nextInt();
            int c1 = in.nextInt();
            arr[a1]-=c1;
            arr[b1]+=c1;
        }
        int ans=0;
        for(int x=0;x<arr.length;x++)
        {
            if(arr[x]>0)
                ans+=arr[x];
        }
        System.out.println(ans);
    }

    void init(InputStream in)
    {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }
    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

}


import java.util.Arrays;
import java.util.Scanner;

public class B {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[]g=new int[n];
        for(int i=0;i<m;i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            int c = sc.nextInt();
            g[a]+=c;g[b]-=c;

        }
        int ans=0;
        for(int i=0;i<n;i++){
            if(g[i]>0)
                ans+=g[i];
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;

public class IOU {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] p = new int[n];

		for(int i = 0; i < m; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			int t = scan.nextInt();
			p[a]-=t;
			p[b]+=t;
		}

		int t = 0;

		for(int i = 0; i < n; i++) {
			if(p[i]<0)
				t+=p[i];
		}

		System.out.println(-t);
	}

}


import java.util.Scanner;

public class IOU {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] p = new int[n];

		for(int i = 0; i < m; i++) {
			int a = scan.nextInt()-1;
			int b = scan.nextInt()-1;
			int t = scan.nextInt();
			p[a]-=t;
			p[b]+=t;
		}

		int t = 0;

		for(int i = 0; i < n; i++) {
			if(p[i]<0)
				t+=p[i];
		}

		System.out.println(-t);
	}

}


import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < m; i++) {
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            int c = in.nextInt();
            A[x] -= c;
            A[y] += c;
        }
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += Math.max(0, A[i]);
        System.out.println(sum);
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author pttrung
 */
public class B {

    public static void main(String[] args) throws FileNotFoundException {

        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        //     PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        int n = in.nextInt();
        int m = in.nextInt();
        int []num = new int[n];
        for(int i = 0; i < m; i++){
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            int c = in.nextInt();
            num[a] -=c;
            num[b] += c;
        }
        int val = 0;
        for(int i = 0; i < n; i++){
            if(num[i] > 0){
                val += num[i];
            }
        }
        out.println(val);
        out.close();
    }

    static class Node{
        int a, b, num;

        public Node(int a, int b, int num) {
            this.a = a;
            this.b = b;
            this.num = num;
        }

    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

    public static double dist(Point a, Point b) {
        double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(val);
    }

    public static class Point {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static long pow(long a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * val * a;
        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //br = new BufferedReader(new FileReader(new File("input.txt")));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.Scanner;

public class IOU
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int m = input.nextInt();
		int[] debt = new int[n];
		for (int i = 0; i < n; ++i)
		{
			debt[i] = 0;
		}
		int a, b, c;
		for (int i = 0; i < m; ++i)
		{
			a = input.nextInt();
			b = input.nextInt();
			c = input.nextInt();
			debt[a - 1] += c;
			debt[b - 1] -= c;
		}
		int res = 0;
		for (int i = 0; i < n; ++i)
		{
			if (debt[i] > 0)
			{
				res += debt[i];
			}
		}
		System.out.println(res);
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.naming.BinaryRefAddr;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt(), a[][] = new int[n][n];
		for (int i = 0; i < m; i++) {
			int f = in.nextInt() - 1, e = in.nextInt() - 1;
			a[f][e] = in.nextInt();
			a[e][f] = -a[f][e];
		}
		int res = 0;
		for (int i = 0; i < a.length; i++) {
			int k = 0;
			for (int j = 0; j < a.length; j++) {
				k += a[i][j];
			}
			res += Math.max(0, k);
		}
		System.out.println(res);
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

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

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

	public float nextFloat() {
		return Float.parseFloat(next());
	}

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


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ,\t");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                //String filePath="circles.in";
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);

        }

        public B(String inputFile)
        {
        	openInput(inputFile);
    		StringBuilder sb = new StringBuilder();
    		readNextLine();
    		int N=NextInt();
    		int M=NextInt();
    		int [] a = new int[N];

    		for(int i=0; i<M; i++)
    		{
    			readNextLine();
    			int x=NextInt()-1, y=NextInt()-1, d=NextInt();
    			a[x]+=d;
    			a[y]-=d;
    		}
    		long r=0;
    		for(int i=0; i<N; i++)
    			r+=Math.abs(a[i]);
    		r/=2;
        	sb.append(r);
        	System.out.println(sb);
    		closeInput();

        }

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ,\t");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                //String filePath="circles.in";
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);

        }

        public B(String inputFile)
        {
        	openInput(inputFile);
    		StringBuilder sb = new StringBuilder();
    		readNextLine();
    		int N=NextInt();
    		int M=NextInt();
    		int [] a = new int[N];

    		for(int i=0; i<M; i++)
    		{
    			readNextLine();
    			int x=NextInt(), y=NextInt(), d=NextInt();
    			a[x]+=d;
    			a[y]-=d;
    		}
    		long r=0;
    		for(int i=0; i<N; i++)
    			r+=Math.abs(a[i]);
    		r/=2;
        	sb.append(r);
        	System.out.println(sb);
    		closeInput();

        }

}


import java.util.Scanner;

public class BIOU {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int people = sc.nextInt();
		int debts = sc.nextInt();

		int[][] map = new int[people][people];

		for (int i = 0; i < debts; i++) {
			int source = sc.nextInt();
			int dest = sc.nextInt();

			map[source][dest] = sc.nextInt();
		}

		long total = 0;

		for (int i = 0; i < people; i++) {
			long req = 0;
			long rec = 0;
			for (int j = 0; j < people; j++) {
				req += map[i][j];
				rec += map[j][i];
			}
			long diff = Math.max(0, req - rec);
			total += diff;
		}

		System.out.println(total);

		sc.close();
	}

}


import java.util.Scanner;

public class BIOU {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int people = sc.nextInt();
		int debts = sc.nextInt();

		int[][] map = new int[people][people];

		for (int i = 0; i < debts; i++) {
			int source = sc.nextInt();
			int dest = sc.nextInt();

			map[source - 1][dest - 1] = sc.nextInt();
		}

		long total = 0;

		for (int i = 0; i < people; i++) {
			long req = 0;
			long rec = 0;
			for (int j = 0; j < people; j++) {
				req += map[i][j];
				rec += map[j][i];
			}
			long diff = Math.max(0, req - rec);
			total += diff;
		}

		System.out.println(total);

		sc.close();
	}

}


'use strict';

// let inpFileStrArr = `
// 4 3
// 1 2 1
// 2 3 1
// 3 1 1
// `.trim().split('\n'), inpFileCounter = 0;
// function readline() {
//   return inpFileStrArr[inpFileCounter++];
// }
// function print(x) {
//   console.log(x);
// }

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _readline$split$map = readline().split(' ').map(Number);

var _readline$split$map2 = _slicedToArray(_readline$split$map, 2);

var n = _readline$split$map2[0];
var m = _readline$split$map2[1];var arr = [];

for (var i = 0; i < n; i++) {
  arr.push(0);
}

for (var _i = 0; _i < m; _i++) {
  var _readline$split$map3 = readline().split(' ').map(Number);

  var _readline$split$map4 = _slicedToArray(_readline$split$map3, 3);

  var a = _readline$split$map4[0];
  var b = _readline$split$map4[1];
  var c = _readline$split$map4[2];

  arr[a - 1] -= c;arr[b - 1] += c;
}

print(arr.filter(function (x) {
  return x > 0;
}).reduce(function (a, b) {
  return a + b;
}, 0));


// Generated by CoffeeScript 1.4.0
(function() {
  var a, add, b, c, d, global, i, m, max, min, n, readints, x, _i, _ref, _ref1, _ref2;

  readints = function() {
    var x, _i, _len, _ref, _results;
    _ref = readline().split(' ');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      x = _ref[_i];
      _results.push(x | 0);
    }
    return _results;
  };

  add = function(a, b) {
    return a + b;
  };

  global = (function() {
    return this;
  })();

  _ref = [Math.max, Math.min], max = _ref[0], min = _ref[1];

  _ref1 = readints(), n = _ref1[0], m = _ref1[1];

  d = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i <= n : _i >= n; 0 <= n ? _i++ : _i--) {
      _results.push(0);
    }
    return _results;
  })();

  for (i = _i = 0; 0 <= m ? _i < m : _i > m; i = 0 <= m ? ++_i : --_i) {
    _ref2 = readints(), a = _ref2[0], b = _ref2[1], c = _ref2[2];
    d[a] += c;
    d[b] -= c;
  }

  d = (function() {
    var _j, _len, _results;
    _results = [];
    for (_j = 0, _len = d.length; _j < _len; _j++) {
      x = d[_j];
      _results.push(max(x, 0));
    }
    return _results;
  })();

  print(d.reduce(add));

}).call(this);


var nm = readline().trim().split(' ').map((x)=>parseInt(x));
var n=nm[0],m=nm[1];
var d = {};
var _d={};
var debt= function(a,b,c) {
	this.a=a;
	this.b=b;
	this.c=c;

	if(d[a]==undefined)
		d[a]=0;

	if(_d[b]==undefined)
		_d[b]=0;

	d[a]+=c;
	_d[b]+=c;
}

var debts=[];
var input;
for (var i = 0; i <m; i++) {
	input = readline().trim().split(' ').map((x)=>parseInt(x));
	debts.push(new debt(input[0],input[1],input[2]));
}

var ans=0;
for (var i in d) {
	ans+=Math.max(d[i]-(_d[i]==undefined?0:_d[i]),0);
}

print(ans);


function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1];

	var funds = [];
	for (var i = 0; i < n; i += 1) {
		funds.push(0);
	}

	for (var i = 0; i < m; i += 1) {
		var integers = tokenizeIntegers(readline());
		var a = integers[0], b = integers[1], debt = integers[2];
		funds[a-1] -= debt;
		funds[b-1] += debt;
	}

	var total = 0;
	for (var i = 0; i < n; i += 1) {
		if (funds[i] > 0) {
			total += funds[i];
		}
	}

	print(total);
}

main();


function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1];

	var funds = [];
	for (var i = 0; i < n; i += 1) {
		funds.push(0);
	}

	for (var i = 0; i < m; i += 1) {
		var integers = tokenizeIntegers(readline());
		var a = integers[0], b = integers[1], debt = integers[2];
		funds[a-1] -= debt;
		funds[b-1] += debt;
	}

	var total = 0;
	for (var i = 0; i < n; i += 1) {
		total += Math.abs(funds[i]);
	}

	print(total/2);
}

main();


function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1];

	var funds = [];
	for (var i = 0; i < n; i += 1) {
		funds.push(0);
	}

	for (var i = 0; i < m; i += 1) {
		var integers = tokenizeIntegers(readline());
		var a = integers[0], b = integers[1], debt = integers[2];
		funds[a] -= debt;
		funds[b] += debt;
	}

	var total = 0;
	for (var i = 0; i < n; i += 1) {
		if (funds[i] > 0) {
			total += funds[i];
		}
	}

	print(total);
}

main();


var input = readline();
    input = input.split(' ');
    var people = [];
    var n = input[0],
        m = input[1];
    for(var i=0; i<n; i++) people[i]=0;
    for(var i=0; i<m; i++)
    {
        input = readline();
        input = input.split(' ');
        var a = parseInt(input[0]),
            b = parseInt(input[1]),
            c = parseInt(input[2]);
        people[a-1]-=c;
        people[b-1]+=c;
    }
    var result=0;
    for(var i=0; i<n; i++) result+=Math.abs(people[i]);
    print(result/2);


#include <iostream>
#include "memory"
using namespace std;
int main(int argc, char *argv[])
{
    int n,m;
    while(cin>>n>>m)
    {
        int debt[105][105];
        memset(debt,0,sizeof(debt));
        int i;
        for(i=0;i<m;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            debt[a][b]=c;
        }
        int j;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(j==i)
                {
                    continue;
                }
                if(debt[i][j])  //有欠款
                {
                    if(debt[j][i])  //有相互欠的
                    {
                        if(debt[j][i]>debt[i][j])
                        {
                            debt[j][i]-=debt[i][j];
                            debt[i][j]=0;
                        }else if(debt[i][j]>debt[j][i])
                        {
                            debt[i][j]-=debt[j][i];
                            debt[j][i]=0;
                        }else if(debt[i][j]==debt[j][i])
                        {
                            debt[i][j]=0;
                            debt[j][i]=0;
                        }
                    }
                    int k;
                    for(k=1;k<=n;k++)
                    {
                        if(k==i)
                        {
                            continue;
                        }
                        if(debt[i][j]>debt[j][k])
                        {
                            debt[i][j]-=debt[j][k];
                        }else if(debt[i][j]<debt[j][k])
                        {
                            debt[j][k]-=debt[i][j];

                            debt[i][j]=0;
                            break;

                        }else if(debt[i][j]==debt[j][k])
                        {
                            debt[i][k]=debt[i][j];
                            debt[i][j]=0;
                            debt[j][k]=0;
                        }
                    }

                }

            }
        }
        int countt=0;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(j==i)
                {
                    continue;
                }
                countt+=debt[i][j];
            }
        }
        cout<<countt<<endl;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;
int iabs(int x)
{
	return -x;
}
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int debt[105];
		int i;
		for(i=0;i<=n;i++)
		{
			debt[i]=0;
		}
		int a,b,c;
		for(i=0;i<m;i++)
		{
			cin>>a>>b>>c;
			debt[a]-=c;
			debt[b]+=c;
		}
		int countt=0;
		for(i=1;i<=n;i++)
		{
			if(debt[i]<0)
			{
				countt+=iabs(debt[i]);
			}
		}
		cout<<countt<<endl;

	}
	return 0;
}


#include <iostream>
using namespace std;
struct debt
{
	int a;
	int b;
	int de;
};
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int i;
		debt d[10005];
		for(i=0;i<m;i++)
		{
			cin>>d[i].a>>d[i].b>>d[i].de;
		}
		for(i=0;i<m;i++)
		{
			if(d[i].de)
			{
				int ii;
				for(ii=i+1;ii<m;ii++)
				{
					if(ii==i)
					{
						continue;
					}
					if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de>d[ii].de)	//两者互欠
					{
						d[i].de-=d[ii].de;
						d[ii].de=0;
					}
					else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de<d[ii].de)
					{
						d[ii].de-=d[i].de;
						d[i].de=0;
					}else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de==d[ii].de)
					{
						d[i].de=0;
						d[ii].de=0;
					}
					else if((d[ii].a==d[i].b)&&(d[i].de<d[ii].de))
					{
						d[ii].de-=d[i].de;
						d[ii].a=d[i].a;
						d[i].de=0;
						break;
					}else if((d[ii].a==d[i].b)&&(d[i].de>d[ii].de))
					{
						d[i].de-=d[ii].de;
					}else if(d[ii].a==d[i].b&&(d[i].de==d[ii].de))	//相等的情况
					{
						d[ii].a=d[i].a;
						d[i].de=0;
					}
				}
			}
		}
		int countt=0;
		for(i=0;i<m;i++)
		{
			countt+=d[i].de;
		}
		cout<<countt<<endl;
	}
	return 0;
}


#include <iostream>
#include "memory"
using namespace std;
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int debt[105][105];
		int ii,jj;
		for(ii=0;ii<105;ii++)
		{
			for(jj=0;jj<105;jj++)
			{
				debt[ii][jj]=0;
			}
		}
		int i;
		for(i=0;i<m;i++)
		{
			int a,b,c;
			cin>>a>>b>>c;
			debt[a][b]=c;
		}
		int j;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(j==i)
				{
					continue;
				}
				if(debt[i][j])	//有欠款
				{
					if(debt[j][i])	//有相互欠的
					{
						if(debt[j][i]>debt[i][j])
						{
							debt[j][i]-=debt[i][j];
							debt[i][j]=0;
						}else if(debt[i][j]>debt[j][i])
						{
							debt[i][j]-=debt[j][i];
							debt[j][i]=0;
						}else if(debt[i][j]==debt[j][i])
						{
							debt[i][j]=0;
							debt[j][i]=0;
						}
					}
					int k;
					for(k=1;k<=n;k++)
					{
						if(k==i)
						{
							continue;
						}
						if(debt[i][j]>debt[j][k])
						{
							debt[i][j]-=debt[j][k];
						}else if(debt[i][j]<debt[j][k])
						{
							debt[j][k]-=debt[i][j];

							debt[i][j]=0;
							break;

						}else if(debt[i][j]==debt[j][k])
						{
							debt[i][k]=debt[i][j];
							debt[i][j]=0;
							debt[j][k]=0;
						}
					}

				}

			}
		}
		int countt=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(j==i)
				{
					continue;
				}
				countt+=debt[i][j];
			}
		}
		cout<<countt<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int debt[105][105];
		memset(debt,0,sizeof(debt));
		int i;
		for(i=0;i<m;i++)
		{
			int a,b,c;
			cin>>a>>b>>c;
			debt[a][b]=c;
		}
		int j;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(j==i)
				{
					continue;
				}
				if(debt[i][j])	//有欠款
				{
					if(debt[j][i])	//有相互欠的
					{
						if(debt[j][i]>debt[i][j])
						{
							debt[j][i]-=debt[i][j];
							debt[i][j]=0;
						}else if(debt[i][j]>debt[j][i])
						{
							debt[i][j]-=debt[j][i];
							debt[j][i]=0;
						}else if(debt[i][j]==debt[j][i])
						{
							debt[i][j]=0;
							debt[j][i]=0;
						}
					}
					int k;
					for(k=1;k<=n;k++)
					{
						if(k==i)
						{
							continue;
						}
						if(debt[i][j]>debt[j][k])
						{
							debt[i][j]-=debt[j][k];
						}else if(debt[i][j]<debt[j][k])
						{
							debt[j][k]-=debt[i][j];

							debt[i][j]=0;
							break;

						}else if(debt[i][j]==debt[j][k])
						{
							debt[i][k]=debt[i][j];
							debt[i][j]=0;
							debt[j][k]=0;
						}
					}

				}

			}
		}
		int countt=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(j==i)
				{
					continue;
				}
				countt+=debt[i][j];
			}
		}
		cout<<countt<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
struct debt
{
	int a;
	int b;
	int de;
};
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int i;
		debt d[10005];
		for(i=0;i<m;i++)
		{
			cin>>d[i].a>>d[i].b>>d[i].de;
		}
		for(i=0;i<m;i++)
		{
			if(d[i].de)
			{
				int ii;
				for(ii=0;ii<m;ii++)
				{
					if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de>d[ii].de)	//两者互欠
					{
						d[i].de-=d[ii].de;
						d[ii].de=0;
					}
					else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de<d[ii].de)
					{
						d[ii].de-=d[i].de;
						d[i].de=0;
					}else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de==d[ii].de)
					{
						d[i].de=0;
						d[ii].de=0;
					}
					else if((d[ii].a==d[i].b)&&(d[i].de<d[ii].de))
					{
						d[ii].de-=d[i].de;
						d[ii].a=d[i].a;
						d[i].de=0;
						break;
					}else if((d[ii].a==d[i].b)&&(d[i].de>d[ii].de))
					{
						d[i].de-=d[ii].de;
					}else if(d[ii].a==d[i].b&&(d[i].de==d[ii].de))	//相等的情况
					{
						d[ii].a=d[i].a;
						d[i].de=0;
					}
				}
			}
		}
		int countt=0;
		for(i=0;i<m;i++)
		{
			countt+=d[i].de;
		}
		cout<<countt<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
struct debt
{
	int a;
	int b;
	int de;
};
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int i;
		debt d[10005];
		for(i=0;i<m;i++)
		{
			cin>>d[i].a>>d[i].b>>d[i].de;
		}
		for(i=0;i<m;i++)
		{
			if(d[i].de)
			{
				int ii;
				for(ii=0;ii<m;ii++)
				{
					if(ii==i)
					{
						continue;
					}
					if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de>d[ii].de)	//两者互欠
					{
						d[i].de-=d[ii].de;
						d[ii].de=0;
					}
					else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de<d[ii].de)
					{
						d[ii].de-=d[i].de;
						d[i].de=0;
					}else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de==d[ii].de)
					{
						d[i].de=0;
						d[ii].de=0;
					}
					else if((d[ii].a==d[i].b)&&(d[i].de<d[ii].de))
					{
						d[ii].de-=d[i].de;
						d[ii].a=d[i].a;
						d[i].de=0;
						break;
					}else if((d[ii].a==d[i].b)&&(d[i].de>d[ii].de))
					{
						d[i].de-=d[ii].de;
					}else if(d[ii].a==d[i].b&&(d[i].de==d[ii].de))	//相等的情况
					{
						d[ii].a=d[i].a;
						d[i].de=0;
					}
				}
			}
		}
		int countt=0;
		for(i=0;i<m;i++)
		{
			countt+=d[i].de;
		}
		cout<<countt<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
struct debt
{
	int a;
	int b;
	int de;
};
int main(int argc, char *argv[])
{
	int n,m;
	while(cin>>n>>m)
	{
		int i;
		debt d[10005];
		for(i=0;i<m;i++)
		{
			cin>>d[i].a>>d[i].b>>d[i].de;
		}
		for(i=0;i<m;i++)
		{
			if(d[i].de)
			{
				int ii;
				for(ii=0;ii<m;ii++)
				{
					if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de>d[ii].de)	//两者互欠
					{
						d[i].de-=d[ii].de;
						d[ii].de=0;
					}
					else if(d[i].a==d[ii].b&&d[i].b==d[ii].a&&d[i].de<d[ii].de)
					{
						d[ii].de-=d[i].de;
						d[i].de=0;
					}else if(d[i].a==d[ii].b&&d[i].b==d[ii].a)
					{
						d[i].de=0;
						d[ii].de=0;
					}
					else if((d[ii].a==d[i].b)&&(d[i].de<d[ii].de))
					{
						d[ii].de-=d[i].de;
						d[ii].a=d[i].a;
						d[i].de=0;
						break;
					}else if((d[ii].a==d[i].b)&&(d[i].de>d[ii].de))
					{
						d[i].de-=d[ii].de;
					}else if(d[ii].a==d[i].b)	//相等的情况
					{
						d[ii].a=d[i].a;
						d[i].de=0;
					}
				}
			}
		}
		int countt=0;
		for(i=0;i<m;i++)
		{
			countt+=d[i].de;
		}
		cout<<countt<<endl;
	}
	return 0;
}


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

int main() {
	int n,m,i,j,k,a_i,b_i,c_i,sum=0;
	cin>>n;
	cin>>m;
	int a[n+1]={0};
	for(i=0;i<m;i++){
		cin >> a_i;
		cin >> b_i;
		cin >> c_i;
		a[a_i]=a[a_i]-c_i;
		a[b_i]=a[b_i]+c_i;
	}
	for(i=0;i<n;i++){
		if(a[i]<0)
		sum = sum + (-1*a[i]);
	}
	cout << sum;
	return 0;
}


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

int main() {
	int n,m,i,j,k,a_i,b_i,c_i,sum=0;
	cin>>n;
	cin>>m;
	int a[n+1]={0};
	for(i=0;i<m;i++){
		cin >> a_i;
		cin >> b_i;
		cin >> c_i;
		a[a_i]=a[a_i]-c_i;
		a[b_i]=a[b_i]+c_i;
	}

	for(i=1;i<n+1;i++){
		if(a[i]<0)
		sum = sum + (-1*a[i]);
	}
	cout << sum;
	return 0;
}


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

int main() {
    int n,m,i,j,k,a_i,b_i,c_i,sum;
    cin>>n;
    cin>>m;
    int a[n+1]={0};
    for(i=0;i<m;i++){
        cin >> a_i;
        cin >> b_i;
        cin >> c_i;
        a[a_i]=a[a_i]-c_i;
        a[b_i]=a[b_i]+c_i;
    }
    for(i=0;i<n;i++){
        if(a[i]>0)
        sum = sum + a[i];
    }
    cout << sum;
    return 0;
}


#include <iostream>
using namespace std;
int a[101],b,c,c1,c2,d,x,y,n,i,k,m;
int main(){
cin>>n>>m;
    for(i=1; i<m; i++){
        cin>>x>>y>>c;
        a[x]=a[x]-c;
        a[y]=a[y]+c;
    }
    for (i=1; i<n; i++)
    if (a[i]>0) k=k+a[i];

    cout<<k<<endl;

}


#include <iostream>
using namespace std;
int a[101],b,c,c1,c2,d,x,y,n,i,k,m;
int main(){
cin>>n>>m;
    for(i=0; i<m; i++){
        cin>>x>>y>>c;
        a[x]=a[x]-c;
        a[y]=a[y]+c;
    }
    for (i=1; i<n; i++)
    if (a[i]>0) x=a[i]+a[i];

    cout<<x<<endl;

}


#include <iostream>
using namespace std;
int a[101],b,c,c1,c2,d,x,y,n,i,k,m;
int main(){
cin>>n>>m;
    for(i=1; i<m; i++){
        cin>>x>>y>>c;
        a[x]=a[x]-c;
        a[y]=a[y]+c;
    }
    for (i=1; i<n; i++)
    if (a[i]>0) k=k+a[i];

    cout<<x<<endl;

}


#include <iostream>
using namespace std;
int a[101],b,c,c1,c2,d,x,y,n,i,k,m;
int main(){
cin>>n>>m;
    for(i=0; i<m; i++){
        cin>>x>>y>>c;
        a[x]=a[x]-c;
        a[y]=a[y]+c;
    }
    for (i=1; i<=n; i++)
    if (a[i]>0) k=k+a[i];

    cout<<k<<endl;

}