#include <bits/stdc++.h>
int niz[1000004];
int N, mod;
long long X, Y;
struct Matrix {
  int mat[2][2];
  inline int *operator[](int x) { return mat[x]; }
  inline const int *operator[](int x) const { return mat[x]; }
};
inline void Identity(int &x) { x = 1; }
inline void Identity(Matrix &x) {
  x[0][0] = x[1][1] = 1;
  x[0][1] = x[1][0] = 0;
}
inline Matrix MULT(const Matrix &A, const Matrix &B) {
  Matrix result;
  memset(&result, 0, sizeof(result));
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
        result[i][j] = (result[i][j] + (long long)A[i][k] * B[k][j]) % mod;
  return result;
}
inline int MULT(int x, int y) { return ((long long)x * y) % mod; }
template <class _T>
inline _T power(_T x, long long y) {
  _T result;
  Identity(result);
  for (;;) {
    if (y & 1) result = MULT(result, x);
    y >>= 1;
    if (y == 0) return result;
    x = MULT(x, x);
  }
}
inline int run_pair(long long K, int A, int B) {
  Matrix M;
  M[0][0] = 3;
  M[0][1] = -1;
  M[1][0] = 0;
  M[1][1] = 1;
  M = power(M, K);
  return ((long long)(A + B) * (M[0][0] + M[0][1] - 1)) % mod;
}
inline int run(long long K, int sum, int A, int B) {
  return (MULT(power(3, K), sum) - run_pair(K, A, B) + mod) % mod;
}
inline int maximum(long long K, int A, int B) {
  Matrix fib;
  fib[0][0] = fib[0][1] = fib[1][0] = 1;
  fib[1][1] = 0;
  fib = power(fib, K);
  return ((long long)B * fib[0][0] + (long long)A * fib[0][1]) % mod;
}
int main(void) {
  scanf("%d%I64d%I64d%d", &N, &X, &Y, &mod);
  long long S0 = 0;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", niz + i);
    S0 += niz[i];
  }
  S0 %= mod;
  int naj = maximum(X, niz[N - 1], niz[N]);
  int SX = run(X, S0, niz[1], niz[N]);
  int SY = run(Y, SX, niz[1], naj);
  printf("%d\n", SY);
  return 0;
}
