#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 5;
int n, mod;
int a[maxN];
long long x, y;
inline long long calPow(long long v) {
  long long ret = 1, pw = 3;
  while (v) {
    if (v & 1) ret = (ret * pw) % mod;
    v /= 2;
    pw = (pw * pw) % mod;
  }
  return ret % mod;
}
inline pair<long long, long long> fib(long long v) {
  long long mat[2][2] = {{1, 1}, {1, 0}};
  long long ret[2][2] = {{1, 0}, {0, 1}};
  while (v) {
    long long tmp[2][2];
    if (v & 1) {
      for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++) tmp[i][j] = ret[i][j];
      for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
          ret[i][j] = tmp[i][0] * mat[0][j] + tmp[i][1] * mat[1][j];
      for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++) ret[i][j] %= mod;
    }
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) tmp[i][j] = mat[i][j];
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        mat[i][j] = tmp[i][0] * tmp[0][j] + tmp[i][1] * tmp[1][j];
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) mat[i][j] %= mod;
    v /= 2;
  }
  return make_pair(ret[0][1] % mod, ret[0][0] % mod);
}
inline long long get3(long long v) {
  if (v == 0) return 1;
  if (v & 1) {
    long long tmp = get3(v - 1);
    return (3 * tmp - 1) % mod;
  }
  long long tmp = get3(v / 2);
  return (2 * tmp * (tmp - 1) + 1) % mod;
}
int main() {
  scanf("%d %I64d %I64d %d", &n, &x, &y, &mod);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  sum %= mod;
  if (n == 1) {
    printf("%d\n", a[1] % mod);
    return 0;
  }
  long long powx = calPow(x), powy = calPow(y);
  pair<long long, long long> FIB = fib(x);
  long long maxi = (FIB.first * a[n - 1] + FIB.second * a[n]) % mod;
  long long res1 =
      (((sum - a[1] - a[n]) * powx) + ((a[1] + a[n]) * get3(x))) % mod;
  long long res2 =
      (((res1 - a[1] - maxi) * powy) + ((a[1] + maxi) * get3(y))) % mod;
  printf("%I64d\n", (res2 + mod) % mod);
  return 0;
}
