


Each person gets at least one item.
Exactly one person among all the three people gets the maximum number of items.
The first and the only line of input will contain an integer N, denoting the total number of items.
0 <= N <= 10^9
Time Limit: 1sec
The only line of output prints the total number of ways to distribute the items.
As we need to divide N items into 3 parts satisfying the given conditions, each part can have values lying between [1, N - 2] as a minimum each should get at least 1, at max can get (N-2)(when the other two have minimum values i.e 1). So we will explore all possible ways to divide and satisfying the given conditions,
Using permutation & combination we can find the total number of ways to distribute the N items to 3 persons i.e(distribute N identical objects into R distinct groups = (N + R - 1)C(R - 1) where any group can get any number of items including 0),
Using the above formula we can also find that,
The total number of ways to distribute N identical items into R distinct groups such that each group should get at least 1 item = (N - 1)C(R-1)
Given R = 3,
Using permutation & combination we can find the total number of ways to distribute the N items to 3 persons i.e(distribute N identical objects into R distinct groups = N + R - 1CR - 1 where any group can get any number of items including 0),
Using the above formula we can also find that,
The total number of ways to distribute N identical items into R distinct groups such that each group should get at least 1 item = N - 1CR-1
Given R = 3,
To find these let’s solve some equations,
The given case can be represented as (x, x, y) x + x + y = N 2x + y = N,
Now y is the third value should be greater than 0, the maximum value of x will be possible when y is minimum and minimum y = 1,
y > 0 , N - 2x > 0, x<N2
Also, y should be less than x
y < x
N - 2x < x
x > N3
Thus total such ways of selecting (x, y) pair equals = 3 *((N- 1)2 - (N - 3)3)
Add this to count.