#include <bits/stdc++.h>
using namespace std;
long long mod;
long long multandmod(long long a, long long b) {
  a = a % mod;
  long long res = 0;
  while (b) {
    if (b & 1) {
      res = res + a;
      if (res >= mod) res = res - mod;
    }
    a = a << 1;
    if (a >= mod) a = a - mod;
    b = b >> 1;
  }
  return res;
}
long long modandexp(long long a, long long b) {
  a = a % mod;
  long long res = 1;
  while (b >= 1) {
    if (b & 1) res = multandmod(res, a);
    a = multandmod(a, a);
    b = b >> 1;
  }
  return res;
}
struct mat {
  long long m[2][2];
} I;
mat mat_mul(mat a, mat b) {
  int i, j, k;
  mat c;
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++) {
      c.m[i][j] = 0;
      for (k = 0; k < 2; k++)
        c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % mod;
    }
  return c;
}
mat mat_power(mat a, long long n) {
  mat c = I;
  for (; n; n >>= 1) {
    if (n & 1) c = mat_mul(c, a);
    a = mat_mul(a, a);
  }
  return c;
}
mat fac, fac3;
void init() {
  I.m[0][0] = I.m[1][1] = 1;
  I.m[0][1] = I.m[1][0] = 0;
  fac3.m[0][0] = 3;
  fac3.m[0][1] = 0;
  fac3.m[1][0] = -1;
  fac3.m[1][1] = 1;
  fac.m[0][0] = 1;
  fac.m[0][1] = 1;
  fac.m[1][0] = 1;
  fac.m[1][1] = 0;
}
long long s[1000010];
int main() {
  init();
  int n;
  long long x, y;
  cin >> n >> x >> y >> mod;
  long long sum = 0;
  long long l, m, r;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &s[i]);
    if (i != 1 && i != n) sum = (sum + s[i]) % mod;
  }
  if (n == 1) {
    cout << s[1] % mod << endl;
    return 0;
  }
  l = s[1];
  r = s[n];
  m = s[n - 1];
  long long p, q;
  mat A, B;
  sum *= modandexp(3, x);
  sum %= mod;
  A = mat_power(fac3, x);
  p = l * (A.m[0][0] + A.m[1][0]);
  p %= mod;
  if (p < 0) p += mod;
  q = r * (A.m[0][0] + A.m[1][0]);
  q %= mod;
  if (q < 0) q += mod;
  sum = (sum + p) % mod;
  sum = (sum + q) % mod;
  sum = (sum - l) % mod;
  if (sum < 0) sum += mod;
  B = mat_power(fac, x);
  r = r * B.m[0][0] + m * B.m[1][0];
  r %= mod;
  sum = (sum - r) % mod;
  if (sum < 0) sum += mod;
  sum *= modandexp(3, y);
  sum %= mod;
  A = mat_power(fac3, y);
  p = l * (A.m[0][0] + A.m[1][0]);
  p %= mod;
  if (p < 0) p += mod;
  q = r * (A.m[0][0] + A.m[1][0]);
  q %= mod;
  if (q < 0) q += mod;
  sum = (sum + p) % mod;
  sum = (sum + q) % mod;
  cout << sum << endl;
  return 0;
}
