#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if(y < x) x = y; } template static void amax(T &x, U y) { if(x < y) x = y; } int main() { int A[3]; while(~scanf("%d%d%d", &A[0], &A[1], &A[2])) { sort(A, A + 3); int N; scanf("%d", &N); vector X(N); for(int i = 0; i < N; ++ i) scanf("%d", &X[i]); sort(X.begin(), X.end()); vector events(N + 1); { int i = 0; rep(k, 3) { for(; i < N && X[i] < A[k]; ++ i); amax(events[i], 3 - k); } } vector> dp(N + 1, vector(N + 1)); dp[N][0] = events[N] == 0 ? 1 : 0; for(int i = N - 1; i >= 0; -- i) { for(int j = N - i; j >= 0; -- j) if(events[i] <= j) { dp[i][j] += dp[i + 1][j]; if(j > 0) dp[i][j] += dp[i + 1][j - 1]; } } ll ans = accumulate(dp[0].begin(), dp[0].end(), 0LL); printf("%lld\n", ans); } return 0; }