#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    ll ans = 0;
    map<ll, ll> mp;
    rep(i, n) {
        for(auto p : mp){
            ans += (a[i] - p.first) * (a[i] - p.first) * p.second;
        }
        mp[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long long int x,y,a,b;
    cin >> x >> y >> a >> b;
    long long int ans=0;
    while((double)a*x<=2e18 && a*x<=x+b && a*x<y ){
        ans+=1;
        x*=a;

    }
    cout << ans+(y-1-x)/b <<endl;
}