We need to parse the problem: "Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share reference code more than once." This seems like a combinatorial counting: each pair of distinct users can share reference code at most once, and each such sharing yields a free drive? But careful: The description: "a user gets a free drive when he shares a reference code with another Amer app user." So when a user shares his reference code with another user, that sharing user gets a free drive. But what about the other user? Perhaps also they get a free drive if they share? Actually typical referral: The referrer gets a reward when someone signs up using their code. Here they say: "a user gets a free drive when he shares a reference code with another Amer app user." So if user A shares his code with user B, then A gets a free drive. But could B also share with A? Then B would get a free drive. So each directed sharing (from one user to another) yields one free drive for the sharer. And they say: "Two same users cannot share reference code more than once." That likely means that a given ordered pair (A, B) can have at most one sharing from A to B. Since sharing is directed. But is it directed? It might be undirected: "shares a reference code with another user" implies that the sharing is from one to the other. So each time A shares his code with B, A gets a free drive. But could B also share his code with A? That would be a separate sharing, but they say "Two same users cannot share reference code more than once." Could be interpreted as a pair of users cannot have more than one sharing event between them, regardless of direction? Let's think.
If there are N users, what is the maximum total number of free drives? If each user can share his code with every other user (but each directed pair at most once), then the maximum free drives = N * (N-1) because each user can share with N-1 others. But the sample: N=2 gives 1. If it were directed, each user could share with the other, resulting in 2 free drives (user A shares with B -> A gets 1; user B shares with A -> B gets 1). But sample output is 1, so it's not directed; it's undirected: each unordered pair can share exactly once, and the sharer gets a free drive. But who is the sharer? Could be either user? In an unordered sharing, how do we decide which one gets the free drive? Actually maybe the model: When two users interact, they exchange reference codes? That doesn't make sense.
Alternatively, maybe the scheme is: Each user can share his reference code with others; each time a user successfully shares (i.e., the other user uses it?), they get a free drive. But there is constraint that each pair can only share once (maybe because you cannot refer the same person twice). So total possible referrals = number of ordered pairs where referrer != referee, but with the condition that a given user cannot refer another user more than once. That's just N*(N-1). But sample N=2 gives 2? Actually 2*(1)=2. But sample output is 1. So perhaps the scheme: "a user gets a free drive when he shares a reference code with another Amer app user." Maybe it's that only the sharer gets a free drive, but it's not necessary that every sharing happens; perhaps the sharing is not mandatory, but we want total possible free drives given that each pair can share at most once? But the problem statement: "Given N number of app users, output total number of free drives gained by all of them." Usually these problems ask for the maximum possible number of distinct referrals? Or maybe it's simply the number of edges in a complete graph? For N=2, complete graph has 1 edge. That yields 1 free drive? But then who gets the free drive? Possibly each sharing yields one free drive, but if an edge represents a sharing event, it's undirected and yields one free drive total. But how is that decided? Possibly they consider that when two users share codes, they both get a free drive? That would be 2 for N=2, but it's not.
Let's examine the sample explanation: "Case 2 : There are 2 app users, so reference code is shared once, hence 1 free drive." That says: With 2 app users, reference code is shared once. That indicates that there is exactly one sharing event: one user shares his reference code with the other. The other does not share? Why wouldn't both share? Possibly because each user can only share his code with others, but the act of sharing is initiated by the user. In a group of 2, maybe only one of them shares because the other might not? But the problem likely expects the maximum possible free drives? Or the total possible number of distinct referrals? Or maybe it's the number of ways to choose a directed edge such that each user can be referrer only once? Hmm.
Alternatively, think of a well-known combinatorial problem: "Given N people, each pair can exchange gifts, but each gift exchange yields a gift for the giver? etc." But not typical.
Let's re-read: "Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share reference code more than once." Possibly they mean that each unordered pair of users can share codes exactly once, and that sharing results in a free drive for both users? But sample N=2 would be 2 then. However maybe it's only the sharer gets the drive, and each pair can have two possible sharing events (A to B and B to A) but they restrict that "Two same users cannot share reference code more than once." Could be interpreted as a given pair (A,B) can only have one sharing event, and it could be initiated by either A or B. So among the two possible directed sharings, only one can happen. That would give maximum total free drives = number of unordered pairs = C(N,2). For N=2, C(2,2)=1. That matches sample. For N=3, C(3,2)=3. Let's test with N=3: If each unordered pair can share once, and the sharer gets a free drive. But who is the sharer? Could be either one, but we count only one free drive per pair. So total free drives = number of pairs = N choose 2. That seems plausible. But is there any scenario where more free drives could be obtained? Possibly if we allow multiple sharings among different pairs, maximum is indeed C(N,2) because each pair can only have at most one sharing (either direction). But can a single user share with multiple others? Yes, a user can share with many others, each distinct pair yields a sharing. So a user can get multiple free drives by sharing with multiple others. That aligns with C(N,2): total free drives = sum over users of number of others they share with. That sum is total number of directed sharings, but if each unordered pair yields exactly one directed sharing, then the sum of out-degrees = number of edges (undirected) = C(N,2). So each user's free drives = number of people they shared with. That sum = C(N,2). So total free drives = C(N,2). For N=1, C(1,2)=0. Sample matches.
Thus the problem reduces to: For each test case with N, output N*(N-1)/2.
But wait constraints: 0 < N < 10^6. So N can be up to 10^6-1. N*(N-1)/2 can be up to roughly (10^6)^2/2 = 5e11, which fits in 64-bit. So use long long.
Now confirm with more reasoning: "Two same users cannot share reference code more than once." This likely means that between any two specific users, there can be at most one sharing event (so you can't refer the same person multiple times to get multiple free drives). That matches our interpretation. And we are to find the total number of free drives gained by all of them, presumably assuming that all possible shares (maximally) occur? Usually these problems ask for the maximum possible number of referrals given that each pair can refer at most once. The sample explanation: "There are 2 app users, so reference code is shared once" implies that with 2 users, only one share is possible. They don't mention maximizing, but it's implied that we count the number of possible distinct shares. So it's combinatorial.
Thus answer is N*(N-1)/2.
But wait: Could it be that each user gets a free drive only when someone shares with them? The phrase "gets a free drive when he shares a reference code" clearly indicates the sharer gets it. So each sharing yields one free drive. So total free drives = number of shares.
Now, can a user share with himself? No.
Thus each share corresponds to an ordered pair (i, j) where i ≠ j and i shares with j. However with the constraint "Two same users cannot share reference code more than once." Could be interpreted as: For any two users, they cannot share more than once, meaning perhaps that i shares with j at most once, but j could also share with i? That would be a different "pair" of users? "Two same users" might refer to the same unordered pair. Usually if you say "two same users", it might mean the same two users. So between user A and user B, they can only share once in total, meaning either A shares with B or B shares with A, but not both. That yields undirected edges. That matches sample.
If it were directed, they would say "a user cannot share reference code with the same user more than once." But they said "Two same users cannot share reference code more than once." That is ambiguous but likely means between any two specific users, the sharing (the act) can't happen more than once. So only one sharing per unordered pair.
Thus the answer is C(N,2) = N*(N-1)/2.
Let's test with N=3: output 3. Could we have more than 3? If A shares with B, A gets 1; B shares with A, B gets 1; that would be 2 from that pair, but that violates the rule? The rule says "Two same users cannot share reference code more than once." If A and B are the two users, can they share reference code more than once? That could be interpreted as they cannot have more than one sharing event between them, regardless of direction. So A sharing with B and B sharing with A would be two separate sharing events, which involve the same two users. So that would be disallowed. So only one of those two possible directed shares can occur. So total maximum is C(N,2). Yes.
Thus for N=4, max = 6. That seems plausible.
But is it always achievable? Yes, by letting each unordered pair have exactly one sharing, e.g., the one with the smaller ID shares with the larger ID. That yields each pair gives one free drive, and no pair violates constraint.
Thus answer = N*(N-1)/2.
Now, input: T up to 1000, each N up to 10^6. So we can compute using 64-bit.
Edge case: N=0? Constraint says 0 < N, so N >= 1. So fine.
Thus implement: read T, loop, read N, compute N*(N-1)/2, output each.
Let's double-check sample: N=1 -> 0, N=2 -> 1. Good.
Thus solution is straightforward.
But wait, might there be other interpretations? Some might think it's sum_{i=1}^{N-1} i = N(N-1)/2. So that's consistent.
I'll produce final answer.
However, I should consider if any trick: The constraints are large, but using 64-bit is fine.
Thus final code:
#include
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
long long N;
cin >> N;
cout << (N * (N-1)) / 2 << endl;
}
return 0;
}
In Python: for _ in range(int(input())): n=int(input()); print(n*(n-1)//2)
Given the problem format, we can write accordingly.
But before final, let's think if there's any other nuance: The problem says "output total number of free drives gained by all of them." If each sharing gives a free drive to the sharer, then total free drives is total number of shares. If we count per user free drives, that's same.
Thus answer is C(N,2).
Thus solution is simple.
I'll produce answer accordingly. The total number of free drives is the maximum number of distinct referral shares possible, which equals the number of unordered pairs of users since each pair can share at most once. Therefore, for each test case with N users, the answer is ( \binom{N}{2} = \frac{N(N-1)}{2} ).
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
idx = 1
for _ in range(t):
n = int(data[idx])
idx += 1
out.append(str(n * (n - 1) // 2))
sys.stdout.write("\n".join(out))
if __name__ == "__main__":
solve()