// 2020-11-28 21:00:40
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
void answer() {
  ll a, b, x, y;
  cin >> a >> b >> x >> y;
  ll ans = 0;
  if (a == b) {
    ans = x;
  } else if (a > b) {
    int d = a - b;
    if (x * 2 < y) {
      ans += x * (d - 1) * 2;
    } else {
      ans += y * (d - 1);
    }
    ans += x;
  } else if (a < b) {
    int d = b - a;
    if (x * 2 < y) {
      ans += x * d * 2;
    } else {
      ans += y * d;
    }
    ans += x;
  }
  cout << ans << '\n';
}

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

// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}

// Main
int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    queue<int> qs, qt;
    rep(i, n) {
        if (s[i] == '1') qs.push(i);
        if (t[i] == '1') qt.push(i);
    }

    ll ans = 0;
    while (!qt.empty()) {
        int z = qt.front();
        if (qs.empty()) {
            cout << "-1\n";
            return 0;
        }
        int x = qs.front();
        if (x < z) {
            qs.pop();
            if (qs.empty()) {
                cout << "-1\n";
                return 0;
            }
            int y = qs.front();
            qs.pop();
            ans += y - x;
        } else {
            ans += x - z;
            qs.pop();
            qt.pop();
        }
    }
    while (!qs.empty()) {
        int x = qs.front();
        qs.pop();
        if (qs.empty()) {
            cout << "-1\n";
            return 0;
        }
        int y = qs.front();
        qs.pop();
        ans += y - x;
    }
    cout << ans << "\n";
}


//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

// Taken From Striver_79
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846
#define all(x) (x).begin(),(x).end()
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
void printv(vector<ll> v) { ll sz = v.size(); for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << v[i] << "\n"; else cout << v[i] << " ";}}
void input(ll a[], ll sz) {for(ll i=0;i<sz;i++) cin >> a[i];}
void print(ll a[], ll sz) {for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};

ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
ll power(ll x,ll y,ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
// a+b=xor(a,b)+2*(a&b)//
ll convert(string num){
    ll sum=0;
    for(int i=0;i<num.size();i++){
        sum=sum*10;
        sum+=(num[i]-'0');
    }
    return sum;
}
bool ispeed2ime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool isPowerof2(ll n){
    while(n>1){
        if(n%2!=0){
            return true;
        }
        n/=2;
    }
    return false;
}
ll dp[100][3];
ll cost(vector<ll>& a, string s[], ll pos,ll n,ll res){
    if(pos>=n){
        if(res==1){
            return 1;
        }
        return 0;
    }
    if(dp[pos][res]!=-1){
        return dp[pos][res];
    }
    ll ans=0;
    if(s[pos]=="AND"){
        ans+=cost(a,s,pos+1,n,a[pos]&res);
    }
    else{
        ans+=cost(a,s,pos+1,n,a[pos]||res);
    }
    a[pos]=1;
    if(s[pos]=="AND"){
        ans+=cost(a,s,pos+1,n,a[pos]&res);
    }
    else{
        ans+=cost(a,s,pos+1,n,a[pos]||res);
    }
    a[pos]=0;
    return dp[pos][res] = ans;
}
void solve()
{
    ll n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    memset(dp,-1,sizeof(dp));
    vector<ll> a(n,0);
    ll ans = cost(a,s,0,n,0)+cost(a,s,0,n,1);
    cout<<ans<<endl;
}

int main()
{
	fio;
// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif

	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long n,ans=1;
int main() {
	scanf("%lld",&n);
	for (int i=1;i<=n;++i) {
		char str[11];
		scanf("%s",&str);
		if (str[0]=='O') ans+=1LL<<i;
	}
	printf("%lld",ans);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

template <class T>
class SegmentTree{
    struct node{
        int l, r;
        T x;
    };
    unsigned int sz;
    vector<node> a;
    // --- modify this for different operations ---
    T zero = 0;
    void merge(int to, int from1, int from2){
        a[to].l = a[from1].l;
        a[to].r = a[from2].r;
        a[to].x = a[from1].x ^ a[from2].x;
    }
    // ---
public:
    SegmentTree<T>(vector<T>& a){
        sz = 1;
        while(sz < a.size()) sz <<= 1;
        this->a.resize(2*sz);
        for(int i = sz; i<2*sz; i++){
            if (i-sz < a.size())
                this->a[i].x = a[i - sz];
            else
                this->a[i].x = zero;
            this->a[i].l = this->a[i].r = i - sz;
        }
        for(int i = sz-1; i>0; i--)
            merge(i, 2*i, 2*i+1);
    }
    inline int mid(int l, int r){ return l+(r-l)/2;}
    void upd(int pos, int l, int r, int dx){
        if (r < a[pos].l || a[pos].r < l) return;
        if (a[pos].l == a[pos].r && a[pos].l == l) {
            a[pos].x ^= dx;
            return;
        }
        upd(2*pos, l, r, dx);
        upd(2*pos+1, l, r, dx);
        merge(pos, 2*pos, 2*pos+1);
    }
    void upd(int l, int r, int dx){
        upd(1, l, r, dx);
    }
    void upd(int i, int dx){
        upd(i, i, dx);
    }
    T get(int pos, int l, int r){
        if (r < a[pos].l || a[pos].r < l) return zero;
        if (l <= a[pos].l && a[pos].r <= r)
            return a[pos].x;
        int m = mid(a[pos].l, a[pos].r);
        int x1 = get(2*pos, l, r);
        int x2 = get(2*pos+1, l, r);
        return x1 ^ x2;
    }
    T get(int l, int r){
        return get(1, l, r);
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, q;
    cin >> n >> q;
    vector<int> a(n+1);
    FOR1(i, n) cin >> a[i];

    SegmentTree<int> st(a);

//    FOR1(x, n)
//        cout << st.get(1, x) << endl;
//    return 0;

    FOR(i, q){
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1){
            st.upd(x, y);
        }
        else{
            int ans = st.get(x, y);
            cout << ans << '\n';
        }
    }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vint a(n + 1);
    rep(i,n+1) cin >> a[i];
    int k = inf;
    rep(i,n) k = min(k, abs(a[i + 1] - a[i]));
    vvint b(k, vint(n + 1));
    rep(i,n+1) {
        rep(j,k) b[j][i] = a[i] / k;
        for (int j = k - a[i] % k; j < k; j++) b[j][i]++;
    }
    cout << k << endl;
    rep(i,k) {
        rep(j,n+1) printf("%d%s", b[i][j], j != n ? " " : "\n");
    }
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//namespace mp = boost::multiprecision;
//using Bll = mp::cpp_int;
using namespace std;
#define ll long long
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define rrep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S) \
    vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<ll, ll>
#define tint tuple<ll, ll, ll>
#define paf(L, R) pair<L, R>
#define mod 998244353
#define MAX 10010
#define ALL(a) a.begin(), a.end()
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a*d - b * c << endl;
}

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

int main(void)
{
    long long a,b,c,d;
    long long ans=0;
    cin >> a >> b >> c >> d;

    ans=(a*d)-(b*c);

    cout << ans << endl;

    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <iostream>
#include <iomanip>

constexpr int HeighestDim = 505000;

int n, m, k;
long long int res[101];
int dim_a = 0, dim_b = 0;
int A[HeighestDim + 1], B[HeighestDim];

void mult_a(int v){
    for(int i = dim_a, j = i - v; j >= 0; --i, --j){ A[i] -= A[j]; if(A[i] < 0) A[i] += m; }
}
void div_a(int v){
    for(int i = v, j = 0; i <= dim_a; ++i, ++j){
        A[i] += A[j]; if(A[i] >= m) A[i] -= m;
    }
}

void mult_b(int v){
    dim_b += v;
    for(int i = dim_b, j = i - v; j >= 0; --i, --j){
        B[i] -= B[j]; if(B[i] < 0) B[i] += m;
    }
}
void div_b(int v){
    for(int i = v, j = 0; i <= dim_b; ++i, ++j){
        B[i] += B[j]; if(B[i] >= m) B[i] -= m;
    }
}

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);
    A[0] = 1; B[0] = 1;
    std::cin >> n >> k >> m; ++k;
    const int hd = (n >> 1) + (n & 1);
    {
        int i, j;
        for(i = 1, j = k; i <= hd; ++i, j += k){ dim_a += j; mult_a(j); div_a(i); }
        for(; i < n; ++i, j += k){ mult_a(j); div_a(i); }
    }
    for(int i = 0, j = n, I = k, J = k * (n - 1); ; I += k, J -= k){
        long long int res_v = 0;
        for(int d = 0; d <= dim_b; ++d) res_v += static_cast<long long int>(A[d]) * B[d] % m;
        if(res_v) res_v = (k * res_v - 1) % m; else res_v = m - 1;
        res[i++] = res_v; res[--j] = res_v;
        if(i > j) break;
        mult_a(j); div_a(J);
        mult_b(I); div_b(i);
    }

    for(int i = 0; i < n; ++i) std::cout << res[i] << '\n';
    return 0;
}

# include <bits/stdc++.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
# define rrep(i,r,l) for(int i=(r); i>=l; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
typedef long long lint;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define INF ((1LL<<62)-(1LL<<31)) /*オーバーフローしない程度に大きい数*/
#define MOD 1000000007
lint gcd(lint a,lint b){
    if(!b)return a;
    return gcd(b,a%b);
}

lint lcm(lint a,lint b){
    return a*b/gcd(a,b);
}

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

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

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

void solve() {
    int h,w,n;
    cin >> h >>w >> n;
    vector<int> a(w,h),b(h,w);

    rep(i,0,n){
        int x,y;
        cin >> x >> y;x--,y--;
        chmin(a[y],x);
        chmin(b[x],y);
    }
    lint ans=0;
    rep(y,0,b[0]) ans+=a[y];
    rep(x,0,a[0]) ans+=b[x];

    BinaryIndexedTree<int> t(w);
    rep(i,0,b[0]) t.add(i, 1);

    vector<vector<int>> ends(h+1);
    rep(y,0,b[0]) ends[a[y]].push_back(y);

    rep(x,0,a[0]){
        for(int y:ends[x]) t.add(y,-1);
        ans-=t.sum(b[x]-1);
    }
    cout << ans << endl;

}

signed main() {

    solve();

    return 0;
}


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

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

  if(n <= 6){
    cout << n << endl;
    return 0;
  }
  int sum = 0;
  for(int i = 7; i <= n; i++){
    int x = i;
    int dif = 0;

    do{
      if(x % 10 == 7){
        sum++;
        dif = 1;
        break;
      }
      else{
        x /= 10;
      }
    }while(x != 0);

    x = i;
    if(dif == 0){
      do{
        if(x % 8 == 7){
          sum++;
          break;
        }
        else{
          x /= 8;
        }
      }while(x != 0);
    }

  }

  cout << n - sum << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fe 2*idx
#define fd fe+1
#define mid (l+r)/2
int aux[1007], n;
int main(){
    fastio; cin>>n;
    int mx = 0, k;
    for(int i=1; i<=n; i++){
        int ai; cin>>ai;
        for(int j=2; j<=ai; j++){
            if(ai%j == 0)aux[j]++;
        }
    }
    for(int i=2; i<=1000; i++){
        if(aux[i] > mx){
            mx = aux[i]; k = i;
        }
    }
    cout<<k<<endl;
}


#include<stdio.h>
int main(){
	int t;
  scanf("%d",&t);
  long long l[20000];
  long long r[20000];
  for(int i=0;i<t;i++){
  	scanf("%ld%ld",&l[i],&r[i]);
  }
   for(int i=0;i<t;i++){
     long long ll=l[i];
     long long rr=r[i];
     if(!(rr-ll>=ll&&rr-ll<=rr))printf("0\n");
  	else if(ll!=rr)printf("%ld\n",(rr-ll*2+1)*(rr-ll*2+2)/2);
     else printf("%d\n",ll==0);
  }
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi p(n), pl(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
    pl[p[i]] = i;
  }
  vi ans, box(n-1);
  bool flg = false;
  rep(i, n) {
    while(pl[i] != i) {
      int u = p[pl[i]-1];
      swap(p[pl[i]], p[pl[i]-1]);
      if(box[pl[i]-1]) {
        flg = true;
        break;
      }
      box[pl[i]-1] = 1;
      ans.emplace_back(pl[i]-1);
      swap(pl[i], pl[u]);
    }
  }
  if(int(ans.size()) != n-1) flg = true;
  if(flg) cout << "-1\n";
  else {
    rep(i, n-1) {
      cout << ans[i]+1 << '\n';
    }
  }
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    ll vall = 0;
    REP(i,n) {
        cin >> v[i];
        vall += v[i];
    }
    sort(RALL(v));
    ll ans = 0;
    REP(i,n-1) {
        ll x = v[i] * (n-i-1);
        vall -= v[i];
        ans += x - vall;
    }

    cout << ans << '\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
  pair<int,int>,
  null_type,
  less<pair<int,int>>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
bool sev1(lli n){
    while(n > 0){
        if(n%10 == 7)
            return true;
        n /=10;
    }
    return false;
}
bool sev2(lli n){
    while(n > 0){
        if(n%8 == 7)
            return true;
        n /=8;
    }
    return false;
}
void solve(){
    lli n;
    cin>>n;
    vector <lli> arr(n);
    for(lli i = 0; i<n; i++){
        cin>>arr[i];
    }
    sort(arr.begin(),arr.end());
    lli add = n-1, sub = 0;
    lli ans = 0;
    for(lli i = n-1; i>=0; i--){
        ans += arr[i]*add;
        ans -= arr[i]*sub;
        add--;
        sub++;
    }
    cout<<ans<<endl;
}
int main(){
    /* freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /*  for(lli i = 1; i<MAX-5; i++){
        fact[i] = i*fact[i-1]%MOD;
        invfact[i] = binpow(fact[i],MOD-2);
    } */
    lli t;
    t = 1;
   // cin>>t;
    while(t--)
        solve();
}


/*Remember me,
shall you deny,
death will reply*/

#include <iostream>
#include<vector>
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long int ll;

ll ncr(ll n,ll r)
{
    ll num=1;
    for(ll i=2;i<=n;i++)
        num*=i;
    ll den1=1,den2=1;
    for(ll i=2;i<=r;i++)
        den1*=i;
    for(ll i=2;i<=n-r;i++)
        den2*=i;
    return num/(den1*den2);
}

int main()
{
    //optimization tool
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll a[5]={0,1,14,36,24};
    string s;
    cin>>s;
    ll x=0,y=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='o')
           x++;
        if(s[i]=='?')
            y++;
    }
    if(x>4||(x==0&&y==0))
    {
        cout<<0<<endl;
        return 0;
    }
    //cout<<"x "<<x<<" "<<y<<endl;
    ll res=a[x];
   // cout<<res<<" res"<<endl;
    ll i=1;
    while(x+i<=4&&y>=i)
    {
        res+=ncr(y,i)*a[x+i];
        //cout<<"here "<<ncr(y,i)<<" "<<a[x+i]<<endl;
        i++;
    }
    cout<<res<<endl;
    return 0;
}

// give up
#include <bitset>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

// alias, using declaration
using llint = long long; using ldouble = long double;
template <class T = llint> using vector = std::vector<T>;
template <class T = llint> using deque = std::deque<T>;
template <class T = llint, class U = llint, class... V> using map = std::map<T, U, V...>;
template <class T = llint, class... U> using set = std::set<T, U...>;
template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>;
template <class T = llint> using uset = std::unordered_set<T>;
template <class T = llint, class U = T> using pair = std::pair<T, U>;
template <class T = llint> using varray = std::valarray<T>;
template <class T = llint, class... U> using pqueue = std::priority_queue<T, U...>;
using std::bitset; using std::string; using std::tuple;

// constant
constexpr llint INF4 = 0x3FFFFFFF;
constexpr llint INF8 = 0x3FFFFFFFFFFFFFFF;
constexpr llint INVALID = 0x8000000000000000;

namespace io {
  // in
  template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;}
  template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;}
  template <size_t N, class T = llint, class... U, class... A> auto in(A... a) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(a...); else return in<T, U...>(std::index_sequence_for<T, U...>(), a...);}
  // out
  template <bool F = true, class T, class... U> void out(const T& a, const U&... b) {(F ? std::cout : std::cerr) << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out<F>(b...);}
  template <bool F = true, class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) (F ? std::cout : std::cerr) << b << (&b != &a.back() ? d : "\n");}
}

int main() {
  // input
  auto [N, M] = io::in<2>();
  auto [A, B] = io::in<2>(M);
  for (auto& i : A) i--;
  for (auto& i : B) i--;

  // solve
  vector<vector<>> graph(N);
  for (llint i = 0; i < M; i++) {
    graph[A[i]].emplace_back(B[i]);
  }
  auto dfs = [&graph](auto f, llint node, uset<>& visited) -> void {
    visited.emplace(node);
    for (auto next : graph[node]) {
      if (visited.count(next) > 0) continue;
      f(f, next, visited);
    }
  };
  llint sum = 0;
  for (llint i = 0; i < N; i++) {
    uset<> visited;
    dfs(dfs, i, visited);
    sum += visited.size();
  }

  // output
  auto result = sum;
  io::out(result);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
using graph = vector<VI>;
template<class T = ll> using w_graph = vector<vector<pair<int, T>>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

int main() {
    init();

    int n; cin >> n;
    VI v(n * 2); cin >> v;

    ll ans = 0;
    PQ<ll> q;
    FOR(i, 0, n) {
        q.push(v[n - 1 - i]);
        q.push(v[n + i]);
        ans += q.top();
        q.pop();
    }
    print(accumulate(all(v), 0LL) - ans);

    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 998244353;
typedef long long LL;

vector<vector<LL>> dp;

template<typename T>
auto makeNdVector(int n, const T& v) {
  return vector<T>(n, v);
}

template<typename T, typename N, typename... Tail>
auto makeNdVector(const N& n, const Tail&... tail) {
  auto vec = makeNdVector<T>(tail...);
  vector<decltype(vec)> vecs(n, vec);
  return vecs;
}

LL dfs(int n, int k) {
  if (n < k) return 0;
  if (dp[n][k] >= 0) return dp[n][k];

  LL a = dfs(n-1, k-1);
  LL b = dfs(n, 2 * k);
  dp[n][k] = (a + b) % kMod;
  return dp[n][k];
}

int main() {
  int N, K; cin >> N >> K;
  dp = makeNdVector<LL>(N + 1, N + 1, -1LL);
  for (int i = 0; i <= N; ++i) { dp[0][i] = 0, dp[i][0] = 0; }
  for (int i = 0; i <= N; ++i) dp[i][i] = 1;

  LL ans = dfs(N, K);
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
const long long INF = 1LL << 60;
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,1,-1};
const int dx8[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int dy8[8]={ 1, 0,-1, 0, 1,-1, 1,-1};
const int MOD = 1e9 + 7;
void add(ll &a, ll b) {a = (a+b) % MOD;}
#define fast  \
  cin.tie(0); \
  ios::sync_with_stdio(false);

int main() {
  ll N,M,T; cin >> N >> M >> T;
  vector<ll> A(M),B(M);
  rep(i,M) cin >> A.at(i) >> B.at(i);

  bool ok = true;
  ll start = 0;
  ll total = N;
  rep(i,M) {
    total -= A[i] - start;
    if (total <= 0) ok = false;
    start = B[i];
    total += B[i] - A[i];
    if (total > N) total = N;
  }

  total -= T - B[B.size()-1];
  if (total > 0 && ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,m,t;
	cin>>n>>m>>t;
	ll batt=n;
	ll a[1001]={0},b[1001]={0};
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
	}
	a[0]=0;
	b[0]=0;
	batt-=(a[1]);
	if(batt<=0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=1;i<m;i++)
	{
		batt+=(b[i]-a[i]);
		if(batt>n)
		{
			batt=n;
		}
		batt-=(a[i+1]-b[i]);
		if(batt<=0)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	batt+=(b[m]-a[m]);
	if(batt>n)
	{
		batt=n;
	}
	batt-=(t-b[m]);
	if(batt<=0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define sz size()
#define all(c) (c).begin(), (c).end()

using namespace std;

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

const int MOD = 1e9 + 7;
const int maxn = 5e5 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> cnt(7, 0);
    for(int i = 0; i < 3; i++){
        int x;
        cin >> x;
        cnt[x]++;
    }
    bool ok = true;
    for(int i = 0; i < 7; i++){
        if(cnt[i] == 3){
            ok = true;
            cout << i;
            return 0;
        }
        if(cnt[i] == 2){
            for(int j = 0; j < 7; j++){
                if(cnt[j] == 1)cout << j;
            }
            return 0;
        }
    }
    cout << 0;
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<iomanip>
#define pi 3.14159265358979323846
#define mod 1000000007
#define int long long
#define elif else if
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
signed main(){
  int n, a, b;
  cin >> n >> a >> b;
  cout << n - a + b << "\n";
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class DLetsPlayNim {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int T;
        cin >> T;
        while (T--) {
            int N;
            cin >> N;
            vector<int> a(N);
            REP(i, N) cin >> a[i];
            int res = 0;
            REP(i, N) res ^= a[i];
            if (res != 0) {
                if (N % 2 == 0) {
                    cout << "First" << endl;
                } else {
                    cout << "Second" << endl;
                }
            } else {
                map<int, int> cnt;
                for (auto n : a) {
                    cnt[n]++;
                }
                bool ok = true;
                for (auto kv : cnt) {
                    if (kv.second % 2 == 1) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    cout << "Second" << endl;
                    continue;
                }
                if (N % 2 == 0) {
                    cout << "First" << endl;
                } else {
                    cout << "Second" << endl;
                }
            }
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DLetsPlayNim solver;
    solver.solve(in, out);
    return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1000000000;

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

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

    a %= 10;
    if(a == 0) {
        cout << 0 << endl;
        return 0;
    }

    int x = a, y = 0;
    REP(i, 10){
        x *= a;
        x %= 10;
        if(a == x) {
            y = i+1;
            break;
        }
    }

    int res = modpow(b, c, y);

    int ans = 1;
    if(res == 0) res = y;
    REP(i, res){
        //cout << "U" << endl;
        ans *= a;
        ans %= 10;
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define T third
#define endl '\n'
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
const int C=1e9+7;
void yes(){
    cout<<"YES\n";
}
void no(){
    cout<<"NO\n";
}
long long binpow(long long a, long long b, long long m=C) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//Variables********************************************
bool p[200001];
//Functions********************************************
ll f(int k){
    vll v;
    for(int i=2;i<=k;i++){
        int cnt{};
        if(!p[i]) continue;
        while(k%i==0){
            k/=i;
            cnt++;
        }
        v.pb(cnt);
    }
    ll req=1;
    for(auto x:v){
        req*=(x+2)*(x+1)/2;
    }
    return req;
}

//*****************************************************
void solve(){
    int a,b,c; cin>>a>>b>>c;
    int la=a%10,lb=b%10;
    if(la==1||la==5||la==6||la==0){
        cout<<la<<endl;
        return;
    }
    if(la==9){
        if(lb%2){
            cout<<9<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return;
    }
    if(la==4){
        if(lb%2){
            cout<<4<<endl;
        }
        else{
            cout<<6<<endl;
        }
        return;
    }
    int x=binpow(b,c,4);
    if(la==2){
        if(x==0){
            cout<<6<<endl;
        }
        if(x==1){
            cout<<2<<endl;
        }
        if(x==2){
            cout<<4<<endl;
        }
        if(x==3){
            cout<<8<<endl;
        }
    }
    if(la==3){
        if(x==0){
            cout<<1<<endl;
        }
        if(x==1){
            cout<<3<<endl;
        }
        if(x==2){
            cout<<9<<endl;
        }
        if(x==3){
            cout<<7<<endl;
        }
    }
    if(la==7){
        if(x==0){
            cout<<1<<endl;
        }
        if(x==1){
            cout<<7<<endl;
        }
        if(x==2){
            cout<<9<<endl;
        }
        if(x==3){
            cout<<3<<endl;
        }
    }
    if(la==8){
        if(x==0){
            cout<<6<<endl;
        }
        if(x==1){
            cout<<8<<endl;
        }
        if(x==2){
            cout<<4<<endl;
        }
        if(x==3){
            cout<<2<<endl;
        }
    }
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1; //cin>>t;
    while(t--){
        solve();
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

using vi = vector<int>;

vi pf(int x) {
    vi r;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            r.push_back(i);
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        r.push_back(x);
    }
    return r;
}

long long f(vi const& a) {
    if (a.empty())
        return 1;
    long  long r = 9e18;
    for (int p : pf(a.front())) {
        vi b;
        copy_if(begin(a), end(a), back_inserter(b), [p](int x) { return x % p; });
        r = min(r, p * f(b));
    }
    return r;
}

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

    int n;
    cin >> n;
    vi a(n);
    for (int& x : a) {
        cin >> x;
    }
    cout << f(a) << '\n';
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

ll mod=998244353;
int ma=310;
ll f(ll x,ll n){
  if(n==0)return 1;
  if(n==1)return x;
  if(n%2)return x*f(x,n-1)%mod;
  ll res=f(x,n/2);
  return res*res%mod;
}

vll fac(ma,1),inv(ma,1),vac(ma,1);
void ready(){
  rep(i,2,ma){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    vac[i]=vac[i-1]*inv[i]%mod;
  }
}
ll nck(ll n,ll k){
  if(n<k || n<0||k<0)return 0;
  return fac[n]*vac[n-k]%mod*vac[k]%mod;
}

int main(){
  cci(n,k);
  vi v(n);
  k++;
  rep(i,0,n)ci(v[i]);

  vll All(k+1,n);
  V<vll> num(k+1,vll(n,1));

  rep(x,1,k+1){
    ll now=0;
    rep(i,0,n)(now+=num[x][i]=num[x-1][i]*v[i]%mod)%=mod;
    All[x]=now;
  }

ready();

  rep(x,1,k){
    ll ans=(mod+n-f(2,x-1))*All[x]%mod;
    ll now=0;
    rep(i,1,x){
      now+=nck(x,i)*All[i]%mod*All[x-i]%mod;
      now%=mod;
    }
    ans+=now*inv[2]%mod;

    co(ans%mod);
  }
}


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

// 枝定義
struct Edge
{
	ll	to;
	ll	dist;
	ll	rash;
	Edge(){}
	Edge(int to, ll dist, ll rash) : to(to), dist(dist), rash(rash){}
};

// グラフ定義(二次元配列)
template <class E>
using Graph = vector<vector<E>>;

// ダイクストラ
class Dijkstra
{
public:
	// res[i] = sからiまでの最短距離
	vector<ll> res;

	// 復元パス
	//	vector<int> pathList;

	vector<ll> pathRev;
	const ll inf = 1e15;

	ll getVal(ll stTime, ll D) {

		ll low = floor((sqrt(D)) - 1) - 2;
		low = max(low, stTime);

		ll ans = inf;
		REPN(t, low, low + 10) {
			ll rashTime = t + D / (t + 1);
			ans = min(ans, rashTime);
		}
		return ans;
	}

public:
	template<class E>
	Dijkstra(const Graph<E> &G, int startFrom)
	{
		int V = (int)G.size();
		res = vector<ll>(V, inf);
		pathRev.resize(V, -1);

		using P = pair<ll, int>;
		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, startFrom));
		res[startFrom] = 0;

		while (!que.empty()) {
			P p = que.top(); que.pop();
			int egdeFrom = p.second;

			// 違う最短距離がキューにあるのでスキップ
			if (res[egdeFrom] < p.first) {
				continue;
			}

			// 最短距離を更新
			for (const E &edge : G[egdeFrom]) {
				ll rashCost = getVal(p.first, edge.rash);
				ll nextDist = edge.dist + rashCost;
				if (nextDist < res[edge.to]) {
					res[edge.to] = nextDist;
					pathRev[edge.to] = egdeFrom;
					que.push(P(nextDist, edge.to));
				}
			}
		}
	}

	// 経路を取得する
	vector<ll> getPath(ll dstPos)
	{
		vector<ll> pathList;

		while (dstPos != -1) {
			pathList.push_back(dstPos);
			dstPos = pathRev[dstPos];
		}
		reverse(pathList.begin(), pathList.end());
		return pathList;
	}
};

// 処理
void Solve()
{
	int N, M;
	cin >> N >> M;
	Graph<Edge>	G(N);
	REP(i, M) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--;
		G[a].emplace_back(Edge(b, c, d));
		G[b].emplace_back(Edge(a, c, d));
	}

	Dijkstra dijk(G, 0);
	ll ans = dijk.res[N - 1];
	if (ans == 1e15) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}

#include<bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define MP make_pair
#define PB emplace_back
using namespace std;
const int MAX_N = 100001;
int C[MAX_N], D[MAX_N];
vector<pair<int, int>> e[MAX_N];
long long dis[MAX_N];
long long f(long long v, int eid) {
    int sq = sqrt(D[eid]+(long double)0.1);
    while(sq * sq < D[eid]) { sq++; }
    if((v + 1) <= sq) {
        return sq - 1 + C[eid] + D[eid] / sq;
    } else {
        return v + C[eid] + D[eid] /  (v + 1);
    }
}
void solve() {
    int N, M;
    scanf("%d%d", &N, &M);
    for(int i = 0; i < M; i++) {
        int A, B;
        scanf("%d%d%d%d", &A, &B, &C[i], &D[i]);
        e[A].PB(MP(B,i));
        e[B].PB(MP(A,i));
    }
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>>pq;
    pq.push(MP(0, 1));
    for(int i = 2; i <= N; i++) {
        dis[i] = 1e18;
    }
    while(!pq.empty()) {
        auto x = pq.top();
        pq.pop();
        if(x.second == N) {
            printf("%lld\n", x.first);
            return;
        }
        if(dis[x.second] < x.first) {
            continue;
        }
        for(auto ee: e[x.second]) {
            int y, eid;
            tie(y, eid) = ee;
            long long nxt_v = f(x.first, eid);
            if(dis[y] > nxt_v) {
                dis[y] = nxt_v;
                pq.push(MP(nxt_v, y));
            }
        }
    }
    puts("-1");
}
int main() {
    solve();
    return 0;
}


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

int adj[30][30];

int main() {
    cout.tie(nullptr)->sync_with_stdio(false);
    int N; cin >> N;
    vector<tuple<int, int, int>> points(N);
    for (int i = 0; i < N; ++i) {
        int a, b, c; cin >> a >> b >> c;
        --a, --b, --c;
        points[i] = make_tuple(a, b, c);
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            //if (i == j) continue;
            int ai, bi, ci, aj, bj, cj;
            tie(ai, bi, ci) = points[i];
            tie(aj, bj, cj) = points[j];
            adj[i][j] = abs(ai - aj) + abs(bi - bj) + max(0, cj - ci);
        }
    }
    vector<vector<int>> dp(1<<N, vector<int>(N, INT_MAX/2));
    for (int a = 1; a < N; ++a)
        dp[1 << a][a] = adj[0][a];
    for (int s = 0; s < (1<<N); s++)    //iterating through all subsets in lexicographical order
        for (int a = 0; a < N; a++) {
            int r = dp[s][a];
            for (int v = 0; v < N; v++) {   //looking through all transitions (cities to visit next)
                if (s & (1<<v)) continue;     //we cannot visit cities that are already visited
                int ns = s | (1<<v);          //perform transition
                int nr = r + adj[a][v];      //by adding edge (a - v) distance
                dp[ns][v] = min(dp[ns][v], nr); //relax result for state (ns,na) with nr
            }
        }
    cout << dp[(1 << N) - 1][0] << '\n';
}

//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int dp[1 << 17][17];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vi x(n), y(n), z(n);
    rep(i, n) cin >> x[i] >> y[i] >> z[i];
    auto dist = [&](int i, int j) {
        return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);
    };
    rep(i, 1 << n) rep(j, n) dp[i][j] = inf;
    dp[1][0] = 0;
    int ans = inf;
    rep2(bit, 1, 1 << n) rep(j, n) {
            if (bit == (1 << n) - 1) {
                chmin(ans, dp[bit][j] + dist(j, 0));
            }
            rep(k, n) {
                if (bit >> k & 1) continue;
                chmin(dp[bit | 1 << k][k], dp[bit][j] + dist(j, k));
            }
        }
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> vec = A;
  vector<int> MAX = A;

  REP(i, N-1) vec[i+1] += vec[i];

  int now = 0;
  int p = 0;
  REP(i, N-1){
    now += A[i];
    chmax(p, now);
    MAX[i+1] = p;
  }

  int ans = 0;
  now = 0;
  REP(i, N){
    chmax(ans, now+MAX[i]);

    now += vec[i];

    chmax(ans, now);
  }

  cout << ans << "\n";

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fs first
#define sc second
#define ll long long

// svarið er bara hversu mörg mismunandi gcd getum við búið til sem eru minni en
// eða jöfn minnstu tölunni í upprunalega listanum.

// generally hversu mörg mismunandi gcd er hægt að búa til?
// loop down from min to 2 and find if there are two numbers who are both multiples of this number
// then it is a valid gcd
// gcd(a, b) <= min(a, b)
// ef ég fer út fyrir sqrt(10^9) þá get ég bara returnað stærðinni af listanum
// fyrst að ég veit að það er það eina sem er eftir og það er aðeins eitt eintak af því
// max í einhverri af tölunum. Eða ég tölunum eins oft og ég get með prime factornum
// og þá get ég checkað hversu mörg duplicates
vector<int> primes;
void sieve(int n) {
	vector<bool> vis(n + 1, false);
	for(int i = 2; i <= n; i++) {
		for(int j = i + i; j <= n; j += i) {
			vis[j] = true;
		}
	}
	for(int i = 2; i <= n; i++) {
		if(!vis[i]) {
			primes.pb(i);
		}
	}

}

int n;
vector<int> A;

void getDivisors(int at, int cur, vector<pair<int, int>>& divs, vector<int>& res) {
	if(at == divs.size()) return;
	int a = cur;
	for(int i = 0; i <= divs[at].sc; i++) {
		if(a != 1) res.pb(a);
		getDivisors(at + 1, a, divs, res);
		a *= divs[at].fs;
	}
}

vector<ll> find_divisors(ll n){ // finds unique divisors, a divisor occurs only once in the result
	vector<pair<int,int>> pf;
	for(int p : primes) {
		if(p > n || n == 1) {
			break;
		}
		if(n % p == 0) {
			int cnt = 0;
			while(n % p == 0) {
				cnt++;
				n /= p;
			}
			pf.pb({p, cnt});
		}
	}
	if(n != 1) {
		pf.pb({n, 1});
	}
	vector<int> res = {1};
	getDivisors(0, 1, pf, res);
	return res;
}

signed main() {
	cin.sync_with_stdio(false);
	cin >> n;
	A = vector<int>(n);
	for(int i = 0; i < n; i++) {
		cin >> A[i];
	}

	sieve(sqrt(1e9) + 10);

	int mn = *min_element(A.begin(), A.end());

	unordered_map<int, int> t;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j * j <= A[i] && j < mn; j++) {
			if(A[i] % j == 0) {
				if(!t.count(j)) {
					t[j] = A[i];
				}else {
					t[j] = __gcd(t[j], A[i]);
				}
				if(A[i] / j < mn) {
					if(!t.count(A[i] / j)) {
						t[A[i] / j] = A[i];
					}else {
						t[A[i] / j] = __gcd(t[A[i] / j], A[i]);
					}
				}
			}
		}
	}

	int ans = 1;
	for(auto [a, b] : t) {
		if(a == b) ans++;
	}
	cout << ans << endl;

}


#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));}
template<class P>struct comp_pair_by_second{bool operator()(const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);}};

int main()
{
    ll h=in(),w=in(),a=in(),b=in();
    stack<ll>states;
    states.push(0);
    ll ans=0;
    while(!states.empty()){
        ll s=states.top();states.pop();
        if(__builtin_popcountll(s)==2*a){
            ++ans;
        }else{
            for(ll i=0;i<h;++i){
                for(ll j=0;j<w;++j){
                    if((s&(1<<(i*w+j)))==0){
                        if(i!=h-1&&(s&(1<<((i+1)*w+j)))==0){
                            states.push(s|(1<<(i*w+j))|(1<<((i+1)*w+j)));
                        }
                        if(j!=w-1&&(s&(1<<(i*w+j+1)))==0){
                            states.push(s|(1<<(i*w+j))|(1<<(i*w+j+1)));
                        }
                    }
                }
            }
        }
    }
    cout<<ans/[](ll n){ll ret=1;for(ll i=1;i<=n;++i)ret*=i;return ret;}(a)<<endl;
}

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

#define SIZE 2100005

ll fact[SIZE],inv_fact[SIZE];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	if(k > n)return 0;

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}

ll nPk(ll n,ll k){

	if(k > n)return 0;

	ll ret = fact[n]*inv_fact[n-k];

	return ret%MOD;
}

int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	ll N,M,K;
	scanf("%lld %lld %lld",&N,&M,&K);

	if(N > M+K){

		printf("0\n");

	}else{

		ll base = nCk(N+M,N);
		ll minus = nCk(N+M,M+K+1);

		printf("%lld\n",(base-minus+MOD)%MOD);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
const int kMod = 1e9 + 7;
const int kInf = (~(1 << 31)) / 2 - 500;
const ll kInfL = (~(1LL << 63)) / 2 - 2000;

int main() {
  vector<int> A(3);
  for (int i = 0; i < 3; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if (A[0] == A[1]) {
    cout << A[2] << endl;
    return 0;
  } else if (A[1] == A[2]) {
    cout << A[0] << endl;
    return 0;
  }
  cout << 0 << endl;
  return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;        typedef vector<int> vi;
typedef vector<vl> vvl;          typedef vector<vi> vvi;
typedef pair<ll, ll> pll;    typedef pair<int, int> pii;
typedef vector<pll> vpl;    typedef vector<pii> vpi;
typedef vector<vpl> vvpl;    typedef vector<vpi> vvpi;
#define s second
#define F first
#define v vector
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define inp(v,n) f(i,0,n,1) cin>>v[i];
#define out(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
bool isPrime(int x) {
    for (int d = 2; d * d <= x; d++) {
        if (x % d == 0)
            return false;
    }
    return true;
}
void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b) cout<<c;
    else if(b==c) cout<<a;
    else if(a==c) cout<<b;
    else cout<<0;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


/* Author : Rohan Tirkey */
/*        IIITA          */

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

#define int             long long int
#define fl(i,l,r)       for(int i=l ; i<=r ; i++)
#define flr(i,r,l)      for(int i=r;i>=l;i--)
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;
#define pi              3.14159265358979323846
#define vi              vector<int>
#define vip             vector< pair<int,int> >
#define test            int t; cin>>t; while(t--)
#define min(a, b)       ((a) < (b) ? (a) : (b))
#define max(a, b)       ((a) < (b) ? (b) : (a))

#define trav(x)         for(auto &it:x)
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int ceil(int a, int b){  return (a%b==0) ? a/b : a/b +1 ;}
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define debug(x)        cout << '>' << #x << ':' << x << endl;
#define debug2(x, y)    cout << '>' << #x << ':' << x << " | " << #y << ':' << y << "\n";
#define debug3(x, y, z) cout << '>' << #x << ':' << x << " | " << #y << ':' << y << " | " << #z << ':' << z << "\n";
#define debug4(x, y, z, w) cout << '>' << #x << ':' << x << " | " << #y << ':' << y << " | " << #z << ':' << z << " | " << #w << ':' << w << "\n";
clock_t time_p=clock();
void time(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"sec\n";}

/*-------------------------------------------------------------------------------------------------------------------------------------------------*/

void solve()
{
  int n; cin>>n;
  int sum=0;
  fl(i,1,n)
  {
    int a; cin>>a;
    if(a>10)
    {
        sum+=(a-10);
    }
  }
  cout<<sum<<"\n";
}
signed main()
{
    fastio
    #ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif

 //test {
      solve();
  //}
  time();
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long double> vd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<ll,ll>> vp;

#define int ll
#define PB push_back
#define pb pop_back
#define in insert
#define endl "\n"
#define MP make_pair
#define f first
#define PI 3.141592653589
#define nd second
#define Trav(a,x) for(auto &a: x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
const int MOD  = 998244353;
const int maxn = 2e6+1;

int a,b,c,d,e,k,n,m,t,s,q,x,y,ans;

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

	int n; cin>>n;
	ans = 0;
	for(int i = 0; i < n; i++){
		cin>>a;
		if(a > 10)ans += (a-10);
	}

	cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
int main()
{
    fio;
    long long n;
    cin>>n;
    long long sum=0;
    long long i=0;
    while(sum<n)
    {
        i++;
        sum=sum+i;
    }
   cout<<i;

}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#define LL long long
#define PII pair<int,int>
#define x first
#define y second
using namespace std;

constexpr const int N = 2e5 + 10;

int n, w;
int a[N], b[N];
LL s[N], ss[N], ans = 0x7fffffffffffffff;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    cin >> n >> w;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= w; ++i) cin >> b[i];

    sort(a + 1, a + 1 + n);

    for(int i = 3; i <= n; i += 2) s[i] = s[i - 2] + abs(a[i - 1] - a[i - 2]);
    for(int i = n - 2; i >= 1; i -= 2) ss[i] = ss[i + 2] + abs(a[i + 1] - a[i + 2]);

    for(int i = 1; i <= w; i++)
    {
        int pos = lower_bound(a + 1, a + 1 + n, b[i]) - a;
        if(pos % 2 == 0) pos--;
        ans = min(ans, s[pos] + ss[pos] + abs(b[i] - a[pos]));
    }

    cout << ans;

    return 0;
}

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

#define SIZE 100005

struct Info{
	Info(){

		len = value = 0;
	}
	Info(ll arg_len,ll arg_value){
		len = arg_len;
		value = arg_value;
	}
	bool operator<(const struct Info& arg) const{

		return len < arg.len;
	}
	ll len,value;
};

ll W[10];
Info info[SIZE];

int main(){

	ll N,M;
	scanf("%lld %lld",&N,&M);

	ll max_W = 0;

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

		scanf("%lld",&W[i]);
		max_W = max(max_W,W[i]);
	}

	for(ll i = 0; i < M; i++){

		scanf("%lld %lld",&info[i].len,&info[i].value);
		if(max_W > info[i].value){

			printf("-1\n");
			return 0;
		}
	}

	/*
	 * 自分以下の耐荷重で、より長い橋があったら不可
	 * →長さの降順に見て、過去最少の耐荷重ならOK
	 * */

	sort(info,info+M);

	vector<Info> V;

	ll mini = HUGE_NUM;
	for(ll i = M-1; i >= 0; i--){
		if(info[i].value < mini){
			mini = info[i].value;
			V.push_back(info[i]);
		}
	}

	reverse(V.begin(),V.end());

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

		vec.push_back(i);
	}

	ll ans = HUGE_NUM;

	do{ //ラクダの並び順を全探索

		ll work[N];
		ll rui[N];

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

			rui[i] = W[vec[i]];
			if(i > 0){

				rui[i] += rui[i-1];
			}
			work[i] = -1;
		}

		work[0] = 0;
		for(int i = 1; i < N; i++){
			for(int head = 0; head <= i-1; head++){	//一団となる先頭のラクダ

				ll tmp_W;

				if(head == 0){

					tmp_W = rui[i];
				}else{

					tmp_W = rui[i]-rui[head-1];
				}

				//tmp_Wで崩壊する、最長の長さの橋を二分探索
				int left = 0,right = V.size()-1,mid = (left+right)/2;
				int max_len = -1;

				while(left <= right){
					if(V[mid].value < tmp_W){

						max_len = V[mid].len;
						left = mid+1;
					}else{

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

				if(max_len == -1){ //崩落しない

					work[i] = max(work[i],work[head]);

				}else{

					work[i] = max(work[i],work[head]+max_len);
				}
			}
		}

		ans = min(ans,work[N-1]);

	}while(next_permutation(vec.begin(),vec.end()));

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

	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
	int n=read(),m=read(),ans=1;
	inv[1]=1;
	for(register int i=2;i<=20;++i){
		inv[i]=1ll*inv[P%i]*(P-P/i)%P;
	}
	for(register int i=2,t;i<=m;++i){
		if(!v[i]){
			f[i]=n,g[i]=1,p[++r]=i;
		}
		for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
			v[t]=1;
			if(i%p[j]){
				f[t]=1ll*f[i]*n%P,g[t]=1;
			}
			else{
				f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
				break;
			}
		}
		ans+=f[i];
		(ans>=P)&&(ans-=P);
	}
	printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;

int main() {
      int x, y, z; cin >> x >> y;

      if(x == 0) {
            if(y == 0) z = 0;
            if(y == 1) z = 2;
            if(y == 2) z = 1;
      }

      if(x == 1) {
            if(y == 0) z = 2;
            if(y == 1) z = 1;
            if(y == 2) z = 0;
      }
      if(x == 2) {
            if(y == 0) z = 1;
            if(y == 1) z = 0;
            if(y == 2) z = 2;
      }

      cout << z << endl;

}


#include <iostream>
using namespace std;

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

    cout<<N-1;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const ll MOD = 1000000007;
// const int MOD = 998244353;

// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;

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

int main() {
  ll n;cin>>n;
  ll k = 0;
  while(k*(k+1)<=2*(n+1)) k++;
  cout << n - (k-2) << endl;
}


#include<bits/stdc++.h>
const int maxn=65536+5;
using namespace std;

int p[maxn];
int al(int n){
	int ans=1;
	while(n--){
		ans=ans*2;
	}
	return ans;
}

int main(){
	int n;
	cin>>n;
	int nn=al(n);
	int a,aa=0,b,bb=0;
	for(int i=1;i<=nn/2;i++){
		cin>>p[i];
		if(p[i]>aa){
			a=i;
			aa=p[i];
		}
	}
	for(int i=nn/2+1;i<=nn;i++){
		cin>>p[i];
		if(p[i]>bb){
			b=i;
			bb=p[i];
		}
	}
	if(p[a]>p[b]) cout<<b;
	else cout<<a;
	return 0;
}

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

int FindIndex(vector<int> v, int val)
{
    int index = 0;
    int i = 0;
    bool found = false;

    while(!found && i < v.size())
    {
        if (v[i] == val)
        {
            index = i;
            found = true;
        }
        i++;
    }

    return index + 1;
}

int main ()
{
    int n; cin >> n;
    vector<int> p;
    vector<int> indexes;
    vector<int> storage;
    for (int i = 0; i < pow(2, n); i++)
    {
        int x; cin >> x;
        p.push_back(x);
        storage.push_back(x);
    }

    while(p.size() != 2)
    {
        for (int i = 0; i < p.size(); i += 2)
        {
            if (p[i] < p[i + 1])
            {
                indexes.push_back(p[i + 1]);
            }
            else
            {
                indexes.push_back(p[i]);
            }
        }
        p = indexes;
        indexes.clear();
    }

    if (p[0] > p[1])
        cout << FindIndex(storage, p[1]);
    else
        cout << FindIndex(storage, p[0]);
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    int q;
    cin >> q;
    vector<vector<int>> queries(q, vector<int>(3));
    rep(i,q){
        int t, a, b;
        cin >> t >> a >> b;
        a--;b--;
        queries[i] = {t, a, b};
    }

    bool flip=false;
    for(auto query : queries){
        if(query[0]==2){
            flip = !flip;
        }
        if(query[0]==1){
            if(flip){
                query[1]+=n;
                query[1]%=2*n;
                query[2]+=n;
                query[2]%=2*n;
            }
            char tmp;
            tmp = s[query[1]];
            s[query[1]] = s[query[2]];
            s[query[2]] = tmp;
        }
    }
    if(flip){
        s = s.substr(n) + s.substr(0, n);
    }
    cout << s << endl;
    return 0;
}

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

//#define kk
#define int long long
#define mat vector<vector<int>>
#define vi vector<int>
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define inf 1000000000
#define mod 998244353
#define endl "\n"

const ll INF=1e18+5;

const int naxN=55;
int fact[naxN], inv_fact[naxN];

int power(int a, int n){
	int res=1;

	while(n){
		if(n%2) res=(res*a)%mod, n--;
		else a=(a*a)%mod, n/=2;
	}
	return res;
}

void init(){
	fact[0]=inv_fact[0]=1;

	for(int i=1; i<naxN; i++){
		fact[i]=(i*fact[i-1])%mod;
		inv_fact[i]=power(fact[i], mod-2)%mod;
	}
}

int ncr(int a, int b){
	if(a<0 || b<0 || a<b) return 0;

	return (fact[a]%mod*inv_fact[b]%mod*inv_fact[a-b]%mod)%mod;
}

int dx[8]={-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8]={-1, 0, 1, 1, 1, 0, -1, -1};

//****DO NOT TOUCH ABOVE THIS LINE****//

const int maxN=2e5+5;

#define M 998244353

int arr[55][55];

int par[55];
int R[55];

int find(int a){
	if(par[a]<0) return a;
	return par[a]=find(par[a]);
}

void merge(int a, int b){
	a=find(a);
	b=find(b);

	if(a==b) return;

	if(R[a]>=R[b]){
		par[b]=a;
		R[a]+=R[b];
	}
	else{
		par[a]=b;
		R[b]+=R[a];
	}
}

void solve(){
	int n, K;
	cin>>n>>K;

	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			cin>>arr[i][j];
		}
	}

	for(int i=1; i<=n; i++){
		par[i]=-1;
		R[i]=1;
	}

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			int can=1;
			for(int k=1; k<=n; k++){
				if(arr[i][k]+arr[j][k]>K){
					can=0;
					break;
				}
			}

			if(can) merge(i, j);
		}
	}

	init();

	int ans1=1;

	for(int i=1; i<=n; i++){
		if(par[i]==-1) ans1*=fact[R[i]]%=M;
	}

	for(int i=1; i<=n; i++){
		par[i]=-1;
		R[i]=1;
	}

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			int can=1;
			for(int k=1; k<=n; k++){
				if(arr[k][i]+arr[k][j]>K){
					can=0;
					break;
				}
			}

			if(can) merge(i, j);
		}
	}

	int ans2=1;

	for(int i=1; i<=n; i++){
		if(par[i]==-1) ans2*=fact[R[i]]%=M;
	}

	int ans=(ans1*ans2)%M;

	cout<<ans<<endl;
}

//****DO NOT TOUCH BELOW THIS LINE****//

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cout<<fixed<<setprecision(6);

	#ifdef kk
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif

	int T=1;
	//cin>>T;

	while(T--){
		solve();
	}
}


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

int main()
{
    int L;
    cin >> L;
    unordered_map<int, int> mp;
    for (int i = 0; i < 11; i++) {
        int n = L - 12 + 11 - i;
        for (int k = 2; k * k <= n; k++) {
            while (n % k == 0) {
                mp[k]++;
                n /= k;
            }
        }
        if (n != 1) mp[n]++;
    }
    mp[2] -= 8;
    mp[3] -= 4;
    mp[5] -= 2;
    mp[7] -= 1;
    mp[11] -= 1;
    long long ans = 1;
    for (auto kv : mp) {
        while (kv.second) {
            ans *= kv.first;
            kv.second--;
        }
    }
    cout << ans << endl;
}

#include <iostream>
using namespace std;

const int N = 300, R = 20;
long long com[N][R];

long long combi(int n, int r) {
    if(com[n][r]!=0) return com[n][r];
    if(n==r) return com[n][r] = 1;
    if(r==0) return com[n][r] = 1;
    return com[n][r] = combi(n-1,r) + combi(n-1,r-1);
}

int main() {
    int l;
    cin>>l;
    long long ans;
    ans = combi(l-1,11);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x.size()))
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
int n, m;
vector<array<int, 2>> black;
bool qry(int x, int y, int l, int r) {
	array<int, 2> target = {x, y};
	int it = lower_bound(black.begin() + l, black.begin() + r, target) - black.begin();
	if (it < r && black[it] == target)
		return 1;
	return 0;
}
void pb(vector<array<int, 2>> & tmp, int l, int r) {
	array<int, 2> it = {l, r};
	while(sz(tmp) && it[0] <= tmp.back()[1]) {
		it[0] = min(tmp.back()[0], it[0]);
		tmp.pop_back();
	}
	tmp.pb(it);
}
int main() {
	scanf("%d%d", &n, &m);
	black.resize(m);
	for(auto &it : black) scanf("%d%d", &it[0], &it[1]);
	sort(all(black));
	set<int> point; point.insert(n);
	for(int l = 0, r = 0; l < m; l = r) {
		while(r < m && black[r][0] == black[l][0]) r++;
		vi diff;
		rep(i, l, r) {
			int blk = black[i][1];
			if (point.count(blk)) {
				if (!point.count(blk - 1) && !point.count(blk + 1)) {
					diff.pb(blk);
				}
			} else {
				if (point.count(blk - 1) || point.count(blk + 1)) {
					diff.pb(blk);
				}
			}
		}
		for(auto &p : diff) {
			if (point.count(p)) point.erase(p);
			else point.insert(p);
		}
	}
	printf("%d\n", sz(point));
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T> void print(T& v){ for(auto it : v) cout << it << " "; cout << endl; }
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    vector<pii> v(m);
    FOR(i, m) cin >> v[i].first >> v[i].second;
    map<int, vi> H;
    FOR(i, v.size())
        H[v[i].first].push_back(v[i].second);

    set<int> S;
    S.insert(n);
    for(auto it : H){
        vi& tocheck = it.second;
        vi torem, toadd;
        for(auto it : tocheck)
            if (!S.count(it-1) && !S.count(it+1))
                torem.push_back(it);
            else
                toadd.push_back(it);
        for(auto it : torem)
            S.erase(it);
        for(auto it : toadd)
            S.insert(it);
    }
    cout << S.size() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD    = 998244353;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int _mod(int a) {return a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

int x, y;
int ext_gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return 0;
  }
  int d = ext_gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int inv(int n) {
  ext_gcd(n, MOD, x, y);
  return x;
}

class CRobotOnGrid {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int H, W, K;
    cin >> H >> W >> K;
    int INV = inv(3);
    VV<char> grid2(H + 2, V<char>(W + 2));
    rep(i, K) {
      int h, w;
      char c;
      cin >> h >> w >> c;
      grid2[h][w] = c;
    }
    VV<mint> grid(H + 2, V<mint>(W + 2));
    grid[1][1] = _pow(3, H * W - K);
    rep2(i, 1, H + 1) {
      rep2(j, 1, W + 1) {
        if (grid2[i][j]) {
          if (grid2[i][j] == 'R') {
            grid[i][j + 1] += grid[i][j];
          } else if (grid2[i][j] == 'D') {
            grid[i + 1][j] += grid[i][j];
          } else {
            grid[i][j + 1] += grid[i][j];
            grid[i + 1][j] += grid[i][j];
          }
        } else {
          grid[i + 1][j] += grid[i][j] * INV;
          grid[i + 1][j] += grid[i][j] * INV;
          grid[i][j + 1] += grid[i][j] * INV;
          grid[i][j + 1] += grid[i][j] * INV;
        }
      }
    }
    cout << grid[H][W] << endl;
  }
};

signed main() {
  CRobotOnGrid solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define Rep(i,j,n) for(int i = j; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a == 0 && b == 0) {
        cout << '=' << endl;
    }else if(a == b){
        cout << '=' << endl;
    }else if(a >= 0 && b >= 0){
        if(a > b) cout << '>' << endl;
        else if(a == b) cout << '=' << endl;
        else cout << '<' << endl;
    }else if(a >= 0 && b < 0){
        if(c%2 == 0){
            b *= -1;
            if(a == b) cout << '=' << endl;
            else if(a > b) cout << '>' << endl;
            else cout << '<' << endl;
        }else{
            cout << '>' << endl;
        }
    }else if(a < 0 && b >= 0){
        if(c%2 == 0){
            a *= -1;
            if(a > b) cout << '>' << endl;
            else if(a == b) cout << '=' << endl;
            else cout << '<' << endl;
        }else{
            cout << '<' << endl;
        }
    }else{
        if(c%2 == 0){
            a *= -1;
            b *= -1;
            if(a > b) cout << '>' << endl;
            else if(a == b) cout << '=' << endl;
            else cout << '<' << endl;
        }else{
            if(a > b) cout << '>' << endl;
            else if(a == b) cout << '=' << endl;
            else cout << '<' << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P = pair<int,int>;
const int INF=1001001001;
const int mod =1e9+7;
vector<bool>seen;
vector<int>ans;
int N,M;
vector<vector<pair<int,int>>>G;
void dfs(int v){
  seen[v]=true;
  for(auto c:G[v]){
    if(seen[c.first]){continue;}
    else if(ans[v]==c.second){ans[c.first]=ans[v]%N+1;}
    else{ans[c.first]=c.second;}
    dfs(c.first);
  }
}
int main() {
  cin>>N>>M;
  ans.resize(N);
  G.resize(N);
  seen.resize(N,false);
  rep(i,M){
    int u,v,c;cin>>u>>v>>c;u--;v--;
    G[u].push_back({v,c});
    G[v].push_back({u,c});
  }
  ans[0]=1;
  dfs(0);
  rep(i,N){cout<<ans[i]<<endl;}
  return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N) {
        for (int i=0; i<N; i++) {
            par[i]=i,siz[i]=1;
        }
    }
    int root(int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
        siz[ry]+=siz[rx];
    }
    bool same(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
    int size (int x) {
        return siz[root(x)];
    }
};

int main() {
   int N,M;
   cin >> N >> M;
   vector<vector<pair<int,int>>> G(N);
   UnionFind tree(N);
   int A[N];
   memset(A,0,sizeof(A));
   for (int i=0; i<M; i++) {
       int u,v,c;
       cin >> u >> v >> c;
       if (tree.same(u-1,v-1)) continue;
       tree.unite(u-1,v-1);
       G[u-1].push_back({v-1,c});
       G[v-1].push_back({u-1,c});
   }
   queue<tuple<int,int,int>> q;
   for (int i=0; i<N; i++) {
       if (G[i].size()==1) {
           q.push(make_tuple(i,G[i][0].first,G[i][0].second));//position,position,distance
           A[i]=1;
           break;
       }
   }
   while (!q.empty()) {
       tuple<int,int,int> p=q.front();
       q.pop();
       int a=get<0>(p),b=get<1>(p),d=get<2>(p);
       if (d==A[a]) {
           if (d==1) A[b]=2;
           else A[b]=1;
       }
       else A[b]=d;
       for (auto x:G[b]) {
           int a=x.first;
           if (A[a]==0) {
               q.push(make_tuple(b,x.first,x.second));
           }
       }
   }
   for (int i=0; i<N; i++) cout << A[i] << endl;
}


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

int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));

  for (int i = 0; i < H; i++) {
  for (int j = 0; j < W; j++) {
    cin >> data.at(i).at(j);
    }
  }
  int a = 0;
  int b = 0;
  for (int i = 0; i < H-1; i++) {
  for (int j = 0; j < W; j++) {
    if (data.at(i).at(j) == '.' && data.at(i+1).at(j) == '.'){
      a++;
    }
  }
  }
  for (int i = 0; i < H; i++) {
  for (int j = 0; j < W-1; j++) {
    if (data.at(i).at(j) == '.' && data.at(i).at(j+1) == '.'){
      b++;
    }
  }
  }
  cout << a+b << endl;
}

#include<bits/stdc++.h>
using namespace std;
long long int n,k,cnt=0;

struct name
{
    long long int bianhao;
    long long int x;
}num[200005];
bool cmp(name a,name b)
{
    return a.bianhao<b.bianhao;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>num[i].bianhao>>num[i].x;
    }
    sort(num,num+n,cmp);
    long long int index=0;
    long long int res=0;
    for(long long int i=0;i<n;i++)
    {
        if(index!=num[i].bianhao)
        {
            index=num[i].bianhao;
            res=i;
        }else{
                num[res].x+=num[i].x;
                num[i].x=0;
        }
    }
    // for(int i=0;i<n;i++)
    // {
    //     cout<<num[i].bianhao<<" "<<num[i].x<<endl;
    // }
    long long int l=0;
    while(1)
    {
        if(k-(num[cnt].bianhao-l)>=0&&cnt<n)
        {
            k=k-(num[cnt].bianhao-l);
            l=num[cnt].bianhao;
            k+=num[cnt].x;
            cnt++;
        }else{
            l+=k;
            k=0;
        }
        if(k<=0)
        {
            cout<<l;
            break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

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

using namespace std;
using ll = long long;

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

    string s, t;
    cin >> s >> t;

    if(s == "Y") transform(t.begin(), t.end(), t.begin(), ::toupper);
    cout << t << "\n";

    return 0;
}

#include<iostream>
#include<vector>
#include<chrono>
#include<iomanip>
#include<set>
#include<algorithm>
#include<bitset>

#define int long long
#define fi first
#define se second

using namespace std;

const int MAXN = 205;
const int MOD = 1e9 + 7;
//const int INF = 1e18;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios_base :: sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> s;
    if (s[0] != s.back()) {
        cout << 1;
        return 0;
    }
    for (int i = 1; i < n - 2; i++) {
        if (s[i] != s[0] && s[i + 1] != s[0]) {
            cout << 2;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int main(){
   int n,q;
   cin>>n>>q;
   vector<ll> a(n+1,0);
   rep(i,1,n+1)cin>>a[i];
   vector<ll> rui(n+1,0);
   rep(i,0,n){
      rui[i+1]=rui[i]+(a[i+1]-a[i]-1);
   }

   while(q--){
      ll x;
      cin>>x;
      int idx=lower_bound(ALL(rui),x)-rui.begin()-1;
      x-=rui[idx];
      cout<<a[idx]+x<<'\n';
   }
   return 0;
}

#include<stdio.h>

int main(){
  long int n, q, a[100005], k[100005];
  scanf("%ld %ld", &n, &q);

  for(int i = 0; i < n; i++){
    scanf("%ld", &a[i]);
    a[i] -= i;
  }

  for(int i = 0; i < q; i++){
    scanf("%ld", &k[i]);
  }

  long int mid, left, right;
  for(int i = 0; i < q; i++){
    left = -1;
    right = n;
    mid = (left + right) / 2;
    while((right - left) > 1){
      if(k[i] < a[mid]){
        right = mid;
      }else{
        left = mid;
      }
      mid = (right + left) / 2;
    }
    printf("%ld\n", k[i] + right);
  }
  return 0;
}


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

vector<vector<int>> tree, depths;
vector<pair<int,int>> times;
int t = 0;

void dfs(int root, int depth) {
	times[root].first = t;
  	depths[depth].push_back(t++);

  	for (auto v: tree[root]) {
    	dfs(v, depth + 1);
    }

  	times[root].second = t++;
}

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

 	int n; cin >> n;
  	tree.resize(n);
  	depths.resize(n);
  	times.resize(n);
  	fill(times.begin(), times.end(), make_pair(0,0));

  	for (int i = 1; i < n; i++) {
    	int u; cin >> u; u--;
      	tree[u].push_back(i);
    }

  	dfs(0, 0);

  	int q; cin >> q;
  	while (q--) {
    	int u,d; cin >> u >> d; u--;
      	int l = lower_bound(depths[d].begin(), depths[d].end(), times[u].first) - depths[d].begin();
      	int r = upper_bound(depths[d].begin(), depths[d].end(), times[u].second) - depths[d].begin() - 1;

      	int ans = max(0, r - l + 1);
      	cout << ans << '\n';
    }
}

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

const int M = 2e5 + 10;

vll g[M];
int n,t,m;
int sz[M],son[M],h[M];
void run(int u,int pa=0){
	sz[u]=1;
	for(auto v:g[u])if(v!=pa){
		h[v]=h[u]+1;
		run(v,u),sz[u]+=sz[v];
		if(sz[v]>sz[son[u]])son[u]=v;
	}
}
int ans[M],sum;
int mx,ch;
vector<pii> q[M];
int cnt[M];

void up(int u,int pa,int y){
	// add
	cnt[h[u]]+=y?1:-1;
	for(auto v:g[u])if(v!=pa and v!=ch) up(v,u,y);
}
void dfs(int u,int pa=0,bool ok=1){
	for(auto v:g[u])if(v!=pa and v!=son[u]) dfs(v,u);
	if(son[u]) dfs(son[u],u,0),ch=son[u];
	up(u,pa,1),ch=0;
	// cal answer
	for(auto p:q[u]) {
		if(p.fi<h[u]) continue;
		ans[p.se]=cnt[p.fi];
	}
	if(ok) up(u,pa,0);
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   	cin>>n;
   	rep(i,2,n+1){
   		int p;
   		cin>>p;
   		g[p].pb(i);
   	}
   	run(1);
   	int t;
   	cin>>t;
   	rep(i,0,t) {
   		int u,d;
   		cin>>u>>d;
   		q[u].pb({d,i});
   	}
   	dfs(1);
   	rep(i,0,t) cout<<ans[i]<<"\n";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=0x7fffffff;
const int eps=1e-7;
const long long mod=1e9+7;
const int maxn=210000;
int n,m,x[maxn],y[maxn];
int main(void)
{
    cin>>n>>m;
    map<int,set<int>>mp;
    for(int i=0;i<m;++i)cin>>x[i]>>y[i],mp[x[i]].insert(y[i]);
    set<int>ans;
    ans.insert(n);
    for(auto it=mp.begin();it!=mp.end();++it)
    {
        set<int>temp;
        for(auto pos:it->second)
        {
            temp.insert(pos-1);
            temp.insert(pos+1);
            temp.insert(pos);
        }
        set<int>pass;
        for(auto pos:temp)
        {
            if(ans.count(pos-1)&&it->second.count(pos)||ans.count(pos)&&!it->second.count(pos)||ans.count(pos+1)&&it->second.count(pos))pass.insert(pos);
        }
        for(auto pos:temp)
        {
            if(ans.count(pos))ans.erase(pos);
        }
        for(auto pos:pass)
        {
            ans.insert(pos);
        }
    }
    cout<<ans.size()<<endl;
    return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

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

	int N = getint();
	int kei = 0;
	ll kei2 = 0;
	rep(i, N) {
		int a = getint();
		kei += a;
		kei2 += a * a;
	}

	printf("%lld", kei2 * N - (ll)kei * kei);

	Would you please return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <numeric>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits>
#include <limits.h>
#include <iomanip>
#include <algorithm>
using namespace std;

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

// Returns factorial of n
long long fact(int n) {
    long long res = 1;
    for (int i = 2; i <= n; i++)
        res *= i;
    return res;
}

long long nCr(int n, int r) {
    return fact(n) / (fact(r) * fact(n - r));
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<string> arr(N);
    for(auto &x : arr)
        cin >> x;

    long long cnt1_even = 0, cnt1_odd = 0;
    for(int i = 0; i < N; i++) {
        int cnt = 0;
        for(auto &x : arr[i]) {
            if(x == '1')
                cnt++;
        }
        if(cnt%2==1)
            cnt1_odd++;
        else
            cnt1_even++;
    }
    long long ans = cnt1_even * cnt1_odd;
    cout << ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    IOS;

    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
template<class T>using uset = unordered_set<T>;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N, M);
    vl P(2);
    ll cnt = 0;
    REP(i, N){
        I(string, _S);
        ll X = stoi(_S, nullptr, 2);
        ll parity = __builtin_parity(X);
        cnt += P[!parity];
        P[parity]++;
    }
    cout << cnt << el;
}