#include <bits/stdc++.h>
long long x, y, mod;
void modplus(long long& c, long long a) {
  c += a;
  if (c >= mod) c -= mod;
}
void modmul(long long& c, long long a, long long b) { c = (c + a * b) % mod; }
struct mix {
  long long a[2][2];
} one, aa, bb;
void mixmul(mix& c, mix a, mix b) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      c.a[i][j] = 0;
      for (int k = 0; k < 2; k++) {
        modmul(c.a[i][j], a.a[i][k], b.a[k][j]);
      }
    }
}
void init() {
  one.a[0][0] = one.a[1][1] = 1;
  one.a[1][0] = one.a[0][1] = 0;
  aa.a[0][0] = 3;
  aa.a[0][1] = 1;
  aa.a[1][0] = 0;
  aa.a[1][1] = 1;
  bb.a[0][0] = bb.a[0][1] = bb.a[1][0] = 1;
  bb.a[1][1] = 0;
}
void pm(mix a) {
  printf("%I64d %I64d\n", a.a[0][0], a.a[0][1]);
  printf("%I64d %I64d\n\n", a.a[1][0], a.a[1][1]);
}
void mixpow(mix& c, long long ti, mix a) {
  if (ti == 0) {
    c = one;
    return;
  }
  mix tmp;
  mixpow(tmp, ti >> 1, a);
  mixmul(c, tmp, tmp);
  if (ti & 1) {
    tmp = c;
    mixmul(c, a, tmp);
  }
}
long long mixget(long long who, long long use, mix aa, long long ti) {
  mix c;
  mixpow(c, ti, aa);
  long long ret = 0;
  modmul(ret, who, c.a[0][0]);
  modmul(ret, use, c.a[0][1]);
  return ret;
}
long long num[1000010];
int main() {
  init();
  int n;
  scanf("%d%I64d%I64d%I64d", &n, &x, &y, &mod);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    num[i] %= mod;
    if (i != 0 && i != n - 1) {
      modplus(sum, num[i]);
    }
  }
  if (n == 1) {
    printf("%d\n", num[0]);
    return 0;
  }
  long long a0 = num[0], an = num[n - 1];
  sum = mixget(sum, (a0 + an) % mod, aa, x);
  modplus(sum, an);
  an = mixget(num[n - 1], num[n - 2], bb, x);
  modplus(sum, mod - an);
  sum = mixget(sum, (a0 + an) % mod, aa, y);
  modplus(sum, (a0 + an) % mod);
  printf("%I64d\n", sum);
}
