#include <bits/stdc++.h>
using namespace std;
int N;
long long P;
long long x, y;
long long a[1000005];
inline long long modsq(long long x) { return (x * x) % P; }
long long modpow(long long x, long long n) {
  if (n == 0) return 1LL;
  if (n % 2 == 0) return modsq(modpow(x, n / 2));
  return ((modsq(modpow(x, n / 2))) * x) % P;
}
inline void mult(long long *a00, long long *a01, long long *a10, long long *a11,
                 long long b00, long long b01, long long b10, long long b11) {
  long long c00 = ((*a00 * b00) % P + (*a01 * b10) % P) % P;
  long long c01 = ((*a00 * b01) % P + (*a01 * b11) % P) % P;
  long long c10 = ((*a10 * b00) % P + (*a11 * b10) % P) % P;
  long long c11 = ((*a10 * b01) % P + (*a11 * b11) % P) % P;
  *a00 = c00;
  *a01 = c01;
  *a10 = c10;
  *a11 = c11;
}
void go(long long *a00, long long *a01, long long *a10, long long *a11,
        long long n) {
  if (n == 0) {
    *a00 = 1;
    *a01 = 0;
    *a10 = 0;
    *a11 = 1;
    return;
  }
  if (n % 2 == 1) {
    long long b00 = *a00;
    long long b01 = *a01;
    long long b10 = *a10;
    long long b11 = *a11;
    go(a00, a01, a10, a11, n / 2);
    mult(a00, a01, a10, a11, *a00, *a01, *a10, *a11);
    mult(a00, a01, a10, a11, b00, b01, b10, b11);
  } else {
    go(a00, a01, a10, a11, n / 2);
    mult(a00, a01, a10, a11, *a00, *a01, *a10, *a11);
  }
}
int main(void) {
  cin >> N >> x >> y >> P;
  if (x == 0) swap(x, y);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    a[i] %= P;
  }
  if (N == 1) {
    cout << a[0] % P << "\n";
    return 0;
  }
  long long a00 = +3;
  long long a01 = +0;
  long long a10 = P - 1;
  long long a11 = +1;
  go(&a00, &a01, &a10, &a11, x);
  long long b00 = +3;
  long long b01 = +0;
  long long b10 = P - 1;
  long long b11 = +1;
  go(&b00, &b01, &b10, &b11, y);
  long long c00 = +0;
  long long c01 = +1;
  long long c10 = +1;
  long long c11 = +1;
  go(&c00, &c01, &c10, &c11, x + 1);
  long long g =
      ((a00 * b00) % P + (a01 * b10) % P + (a10 * b00) % P + (a11 * b10) % P) %
      P;
  long long f = (modpow(3, x) * modpow(3, y)) % P;
  long long g0 = (b00 + b10) % P;
  long long Sol = 0;
  for (int i = 1; i < N - 1; ++i) {
    Sol = (Sol + (f * a[i]) % P) % P;
  }
  Sol = (Sol + (g * a[0]) % P) % P;
  Sol = (Sol + (g * a[N - 1]) % P) % P;
  long long best = ((c00 * (a[N - 2])) % P + (c10 * (a[N - 1])) % P) % P;
  if (y) {
    Sol = (Sol + P - ((g0 * a[N - 1]) % P)) % P;
    Sol = (Sol + P - ((modpow(3, y) * best) % P)) % P;
    Sol = (Sol + (g0 * best) % P) % P;
    Sol = (Sol + (modpow(3, y) * a[N - 1]) % P) % P;
  }
  cout << Sol << "\n";
  return 0;
}
