1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;

ll p, half;
ll mul(ll a, ll b){
    return a*b%p;
}

ll number(ll a, ll b, ll c){
    ll ans = mul(mul(a-c+b-1, c-b+a), half);
    ans += mul(c-a+1, a);
    ans %= p;
    return ans;
}

typedef int I;
int lis(const vector<I>& S) {
	if (S.empty()) return {};
	vi prev(sz(S));
	typedef pair<I, int> p;
	vector<p> res;
	rep(i,0,sz(S)) {
		// change 0 -> i for longest non-decreasing subsequence
		auto it = lower_bound(all(res), p{S[i], 0});
		if (it == res.end()) res.emplace_back(), it = res.end()-1;
		*it = {S[i], i};
		prev[i] = it == res.begin() ? 0 : (it-1)->second;
	}
	int L = sz(res);
	return L;
}

ll brute(int a, int b, int c){
    int n = number(a,b,c);
    assert(n<14);
    vi ord(n);
    iota(all(ord),0);
    int cnt = 0;
    do{
        vi up(n);
        rep(i,0,n){
            up[i] = 1;
            rep(j,0,i) if (ord[j] < ord[i]){
                up[i] = max(up[i], up[j] + 1);
            }
        }

        vi down(n);
        for(int i = n-1; i >=0; --i){
            down[i] = 1;
            for(int j = i+1; j < n; ++j) if (ord[j] < ord[i]){
                down[i] = max(down[i], down[j] + 1);
            }
        }

        int mxa=0, mxb=0, mxc=0;
        rep(i,0,n){
            mxa = max(mxa, up[i]);
            mxb = max(mxb, down[i]);
            mxc = max(mxc, up[i] + down[i] - 1);
        }
        cnt += mxa == a and mxb == b and mxc == c; 
    }while(next_permutation(all(ord)));
    return cnt;
}

ll modpow(ll a, ll e){
    ll ans = 1;
    while(e){
        if (e&1) ans = mul(ans,a);
        a = mul(a,a);
        e/=2;
    }return ans;
}

ll fact(ll n){
    ll ans = 1;
    for(int i = 1; i <=n; ++i){
        ans = mul(ans,i);
    }
    return ans;
}

ll ndimCat(ll dim, ll n){
    if (dim==1) return 1;

    ll top = 1;
    ll ft = 1;
    rep(i,2,dim+1){
        top = mul(top,ft);
        ft = mul(ft, i);
    }

    top = mul(top, fact(dim*n));

    ll bot = 1;
    ft = fact(n);
    rep(i,n+1,n+dim+1){
        bot = mul(bot,ft);
        ft = mul(ft,i);
    }

    ll ans = mul(top, modpow(bot, p-2));

    return ans;
}

ll count(ll a, ll b){
    ll ans = ndimCat(a, b);
    ans = mul(ans,ans);
    return ans;
}

int main(){
    cin.tie(NULL),cin.sync_with_stdio(false);
    
    ll a,b,c; cin >> a >> b >> c >> p;
    if (p<0) p = 1e9+7;
    half = (p+1)/2;

    cout << number(a,b,c) << ' ' << count(a,b) << '\n';
}

/*
1 smth -> altijd 1

2 2 -> 4 = 2^2 
2 3 -> 25 = 5^2
2 4 -> 196 = 14^2
2 5 -> 1764 = 42^2

2 smth -> catalan(b)^2

3 3 -> 1764 = 42^2
3 4

3 smth -> 3d catalan numbers ^ 2

-> seems to be catalan(2*a + b)^2
*/