We need to parse the problem: given initial strength str, int, and exp free points. Must allocate all exp points to either str or int (each point increases respective attribute by 1). After allocation, final strength S = str + x, final intelligence I = int + (exp - x), where x is number of points invested in strength, 0 ≤ x ≤ exp. Then condition: S > I (strictly greater). So we need count of integer x in [0, exp] such that:
(str + x) > (int + exp - x) => str + x > int + exp - x => 2x > int + exp - str => x > (int + exp - str) / 2.
Also x must be integer, so the smallest integer x satisfying x > (int + exp - str)/2. Also x must be ≤ exp and ≥ 0.
Let's denote D = int + exp - str. Then condition: 2x > D => x > D/2. So x must be at least floor(D/2) + 1, provided that floor(D/2)+1 ≤ exp and also x must be ≤ exp.
Also note that x must be integer, and if D is negative? Then D/2 negative, condition x > negative value. Possibly x can be 0, etc.
The count of x in [0, exp] satisfying x > D/2 is: total exp+1 numbers from 0 to exp. The ones <= D/2 are not allowed. The allowed are those with x >= L, where L = floor(D/2) + 1. But careful: if D/2 is not integer, then condition x > D/2 is equivalent to x ≥ floor(D/2)+1. If D is even, D/2 integer, then condition x > D/2 means x >= D/2+1. So both cases we can define L = floor(D/2) + 1.
Thus count = max(0, exp - L + 1) if L ≤ exp, else 0. Also need to ensure that x >= 0 automatically, but L might be negative; if L <= 0 then allowed x starts at 0? But L defined as floor(D/2)+1. If D is negative enough, floor(D/2)+1 might be ≤ 0. But condition x > D/2 (with D negative) imposes a lower bound which may be negative; but x is at least 0, so the effective lower bound is max(0, L). However careful: Suppose D = -10, then D/2 = -5, condition x > -5 means x >= -4? Actually x integer > -5 => smallest integer x satisfying is -4? But x must be >=0. So all x>=0 satisfy condition because all are > -5. So count = exp+1. In terms of L = floor(D/2)+1. D = -10, floor(-10/2) = floor(-5) = -5? Actually careful: floor of negative number: floor(-5) = -5. Then L = -5+1 = -4. That is <0. So if we take L as lower bound, then the condition x >= L (since x > D/2 => x >= L) yields x >= -4. But x is also >=0. So the actual feasible x start at 0. So count = exp - 0 + 1 = exp+1. That matches max(0, exp - max(L,0) + 1) if L <0? Actually if L <=0, then allowed x from 0 to exp, so count = exp+1. So we can unify by L_eff = max(L, 0). Then count = max(0, exp - L_eff + 1). But also need to consider the case L_eff > exp, then count = 0.
Alternatively, we can derive directly: number of x satisfying:
x > (int + exp - str)/2
with 0 ≤ x ≤ exp.
Solve: x_min = floor((int + exp - str)/2) + 1.
If x_min < 0 then x_min = 0.
Then count = max(0, exp - x_min + 1).
Thus answer = max(0, exp - max( floor((int+exp-str)/2) + 1, 0) + 1)
Simplify? Let's denote A = str, B = int, C = exp.
Condition: A + x > B + C - x => 2x > B + C - A => x > (B + C - A)/2.
Set t = (B + C - A). Then x_min = floor(t/2) + 1. If t < 0, floor(t/2) may be negative, e.g., t=-1 => floor(-0.5) = -1? Actually careful: floor of -0.5 is -1. Then x_min = -1+1=0. That yields x_min=0, which is okay. t=-2 => t/2 = -1, floor(-1) = -1, x_min = 0. t=-3 => -1.5 floor = -2, x_min = -1? Actually floor(-1.5) = -2, then x_min = -2+1 = -1. That would be negative, but x_min should be 0 because all x≥0 satisfy? Let's check: t = B+C-A = -3 => (B+C-A)/2 = -1.5, condition x > -1.5 => x >= -1? Because smallest integer > -1.5 is -1? Actually if we consider integer x, the inequality x > -1.5 is satisfied by x = -1, 0, 1, ... But x cannot be negative. So the allowed x are 0,1,... So x_min should be 0. Using formula x_min = floor(t/2)+1. For t = -3, floor(t/2) = floor(-1.5) = -2, x_min = -2+1 = -1. That's less than 0. So we need to clamp at 0. Indeed.
So count = max(0, C - max(floor(t/2)+1, 0) + 1). But careful: if floor(t/2)+1 is negative, max with 0 yields 0, so x_min_eff = 0. That's correct.
Now if floor(t/2)+1 > C, then count = 0.
Thus answer = max(0, C - max( floor((B+C-A)/2) + 1, 0 ) + 1 ).
Alternatively, we could compute using inequality: Need x in [0, C] such that A + x > B + C - x => 2x > B + C - A => x > (B + C - A)/2.
Let lower = (B + C - A) / 2. Then the smallest integer x is floor(lower) + 1 if lower is not integer, but if lower is integer, then x must be > that integer, so floor(lower)+1 also works. So unified as floor(lower) + 1.
But if lower is negative, floor(lower)+1 could be ≤0; then the smallest integer x that satisfies condition is 0? Actually if lower is -0.5, floor(-0.5) = -1, +1 = 0, correct. If lower = -1, floor(-1) = -1, +1 = 0, correct. If lower = -1.2, floor(-1.2) = -2, +1 = -1, but x must be >=0, and condition x > -1.2 is satisfied by x = -1? But x=-1 not allowed. However, x = 0 > -1.2, so 0 is allowed. But is -1 allowed? No. So if x_min = -1, the allowed integers start at 0 because -1 is not in domain. So effectively, the lower bound for x in domain is max(0, floor(lower)+1). That's it.
Thus answer = number of integers x in [0, C] with x >= L_eff, where L_eff = max(0, floor((B+C-A)/2)+1). Count = max(0, C - L_eff + 1).
Thus we can compute.
Alternatively, we might derive a simpler formula: The condition S > I implies A + x > B + C - x => 2x > B + C - A => x > (B + C - A)/2.
Let d = A - B. Then condition becomes x > (C - d)/2? Because B + C - A = C - (A - B) = C - d. So condition: x > (C - d)/2. Then x_min = floor((C - d)/2) + 1.
But essentially same.
We need to handle large numbers up to 1e8, but calculations fit in 64-bit. T up to 100.
Check examples:
-
A=5, B=3, C=4 => d = 2 => C-d=2 => (C-d)/2 =1 => x>1 => x_min = floor(1)+1=2? Actually (C-d)=2, /2=1 exactly, so floor(1)=1, x_min=2. So allowed x = 2,3,4? Let's check: x=2 => S=7, I=5 => 7>5 ok; x=3 => 8,4 ok; x=4 =>9,3 ok. Count=3. exp=4, L_eff = max(0,2) =2, count=4-2+1=3. Good.
-
A=2,B=1,C=0 => d=1, C-d=-1, (C-d)/2 = -0.5, floor(-0.5) = -1, x_min = 0, L_eff=0, count=0-0+1=1 => (2,1) okay.
-
A=3,B=5,C=5 => d = -2, C-d=5-(-2)=7, (7)/2=3.5, floor=3, x_min=4, L_eff=4, count=5-4+1=2. matches (x=4 => S=7,I=6; x=5=>8,5). ok.
-
A=4,B=10,C=6 => d=-6, C-d=6-(-6)=12, /2=6, floor=6, x_min=7, L_eff=7 > C=6 => count=0.
All good.
Edge Cases: If str and int are huge, but exp also huge; we must compute floor of division. Since everything integer, we can compute using integer arithmetic.
We can compute t = B + C - A. Then floor(t/2) can be tricky for negative values: In C++ integer division truncates towards zero for negative numbers, but we need floor. So we cannot simply use t/2 if t is negative and odd. For example t=-3, t/2 in C++ with integer division (since C++11) truncates toward zero: -3/2 = -1. But floor(-1.5) = -2. So we need floor division: floor(t/2) = (t >= 0) ? t/2 : (t - 1) / 2? Actually for negative, floor(t/2) = (t - (denom-1)) / denom? Let's derive: For integers a, b>0, floor(a/b) = a//b if a>=0, else (a - (b-1))//b? Actually in C++ we can compute floor division as: (t >= 0) ? t/2 : (t-1)/2. Because if t negative, say -3: (-3-1)/2 = -4/2 = -2, correct. For -4: (-4-1)/2 = -5/2 = -2.5 integer division yields -2? Wait C++ integer division truncates toward zero, so (-5)/2 = -2 (since -2.5 truncates to -2). That would be -2, but floor(-2) is -2? Actually -4/2 = -2 exactly, floor(-2)= -2, we want -2. Using (t-1)/2 for -4 gives -5/2 = -2.5 truncates to -2, correct. For -5: floor(-2.5) = -3. (t-1)/2 = (-5-1)/2 = -6/2 = -3, correct. So formula: floor(t/2) = (t >= 0) ? t/2 : (t-1)/2 in C++ integer truncation division. But careful: t/2 when t>=0 yields floor because truncation toward zero equals floor for non-negative.
Alternatively, we can compute using condition: x_min = (t // 2) + 1, but where // is floor division. In Python it's fine because integer division floors. But we need to implement in C++ perhaps. We'll be using Python (the answer expects Python?). The problem is from Codeforces? Usually they accept Python solutions. We'll be coding in Python, where integer division // is floor division. So we can directly compute:
t = int + exp - str
x_min = t // 2 + 1 # because floor division
if x_min < 0: x_min = 0
count = max(0, exp - x_min + 1)
But careful: For t negative, t // 2 in Python floors (e.g., -3 // 2 = -2). Then x_min = -2+1 = -1. That would be negative. Then we clamp to 0. So that works. However, if t negative and even? e.g., t = -2: -2 // 2 = -1 (since floor(-1) = -1). Then x_min = 0. That's correct. Good.
Thus Python's floor division is appropriate.
But we must also consider that x must be integer between 0 and exp inclusive. So answer = max(0, exp - max(t//2 + 1, 0) + 1). Alternatively, we could compute:
If str > int + exp, then all allocations result in str > int? Actually condition: final strength > final intelligence. If initial str is already > int + exp? Let's analyze: str > int + exp means that even if we put all points into int (x=0), S = str, I = int+exp, and str > int+exp, so condition holds for any x? Check: If we add some to strength, S increases, I decreases, so condition holds even stronger. So all x in [0, exp] are valid. That would be exp+1 builds. Does our formula give that? t = int+exp-str <0, so t negative. t//2+1 might be <=0. max with 0 yields 0, count = exp+1. Good.
If str + exp <= int? Actually worst case: after allocating all points to strength, S = str+exp, I = int. If str+exp <= int, then S <= I, meaning even at best (all to strength) we cannot exceed int, so no builds. That is when str+exp <= int => str+exp <= int => str - int <= -exp => (int - str) >= exp. Let's see our formula: t = int+exp - str. Condition for no builds is that even x=exp fails: S = str+exp, I = int, condition str+exp > int => str+exp > int. If str+exp <= int, then condition fails for x=exp. Also maybe fails for all. Our formula should give 0. Let's see: For x=exp to be valid, we need 2*exp > int+exp - str => exp > int - str? Actually from inequality: x > (int+exp-str)/2. For x=exp, condition becomes exp > (int+exp-str)/2 => 2exp > int+exp - str => exp > int - str => str+exp > int. So indeed if str+exp <= int, then exp <= int - str, so (int - str) >= exp. Then t = int+exp-str = (int-str)+exp >= exp+exp = 2exp? Actually if int-str >= exp, then t >= exp + exp = 2exp? Wait t = (int - str) + exp, so if int-str = d, d >= exp, then t >= exp+exp=2exp. So t >= 2exp. Then t//2 >= exp, so x_min = t//2+1 >= exp+1. So count = max(0, exp - (>=exp+1) + 1) = 0. Good.
Thus formula works.
Edge Cases: exp=0. Then we must invest all points (0). So we have only one build: (str, int). Condition: str > int? If yes, count=1; else 0. Our formula: t = int+0 - str = int - str. x_min = t//2+1. For exp=0, count = max(0, 0 - max(x_min,0) + 1). If str > int, then int-str negative, t negative, t//2 maybe negative, x_min negative or zero? Let's compute: str=5, int=3, exp=0 => t=-2, -2//2 = -1, x_min = 0, max=0, count=0-0+1=1. Good. If str <= int, e.g., str=3, int=5, exp=0 => t=2, 2//2=1, x_min=2, max=2 > exp? Count = max(0, 0-2+1) = max(0, -1) = 0. Good.
Now we need to output answer for each query.
Complexities: O(T) time.
Potential pitfalls: overflow? Python handles big ints. But within 1e8, it's fine.
We'll implement as described.
Double-check with some random values manually.
Let's test str=1, int=1, exp=1. Options: x=0 => (1,2) => 1>2 false; x=1 => (2,1) => 2>1 true. So count=1. Formula: t = 1+1-1=1, t//2=0, x_min=1, max=1, count = 1-1+1=1. OK.
str=1, int=1, exp=2: Options: x=0 => (1,3) false; x=1 => (2,2) false (strict >); x=2 => (3,1) true. Count=1. Formula: t=1+2-1=2, t//2=1, x_min=2, max=2, count=2-2+1=1. OK.
str=10, int=10, exp=10: t=10+10-10=10, t//2=5, x_min=6, count=10-6+1=5. Let's verify: Condition: str + x > int + (10 - x) => 10 + x > 10 + 10 - x => x > 5 => x >=6. So x=6..10 inclusive, that's 5 values. OK.
Now test with negative t large: str=100, int=1, exp=10: t=1+10-100 = -89, t//2 in Python: -89//2 = -45? Actually floor division: -89/2 = -44.5, floor = -45. So t//2 = -45, x_min = -44, max(0,-44)=0, count=10-0+1=11. Indeed all allocations work because str is much larger than int even after putting all points to int: At x=0: S=100, I=11 -> 100>11 true. So all 11 builds. Good.
Thus formula works.
But wait, is there any other constraint? The problem statement: "you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence)." And "you must invest all free points". That's all. So the formula should be correct.
Thus solution: For each test case, compute t = int + exp - str; compute low = (t // 2) + 1; if low < 0: low = 0; answer = max(0, exp - low + 1). Print answer.
But careful: Could there be any off-by-one due to t being odd? Already accounted.
Simplify: low = (int + exp - str) // 2 + 1; if low < 0: low = 0; ans = exp - low + 1; if ans < 0: ans = 0.
We can also compute ans = max(0, exp - max( (int + exp - str)//2 + 1, 0) + 1).
Now we must handle T up to 100. That's trivial.
Now the explanation for the solution in the answer: need to produce code? The user asked "Calculate the number of different character builds...". So we need to output the answer. The input is given as described.
Thus we can code in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
T = int(next(it))
out = []
for _ in range(T):
str0 = int(next(it)) # careful: 'str' is built-in, better not use
int0 = int(next(it))
exp = int(next(it))
t = int0 + exp - str0
low = t // 2 + 1
if low < 0:
low = 0
ans = exp - low + 1
if ans < 0:
ans = 0
out.append(str(ans))
sys.stdout.write("\n".join(out))
But is there any nuance about str and int being keywords? They are not but safe to rename.
Now think about the formula again from another angle: Number of solutions for x from 0 to exp such that str + x > int + exp - x. Rearranged: 2x > int + exp - str => x > (int + exp - str)/2. So min integer x = floor((int+exp-str)/2) + 1. So count = max(0, exp - (floor((int+exp-str)/2) + 1) + 1) = max(0, exp - floor((int+exp-str)/2)). Actually check: exp - (floor(...)+1) + 1 = exp - floor(...). So answer = max(0, exp - floor((int+exp-str)/2)). That's simpler! Because:
Count = number of integers x in [0, exp] with x > L, where L = (int+exp-str)/2. So that is exp - floor(L) if L >= 0? Let's derive properly:
For real L, number of integers x in [0, exp] such that x > L. That is the number of integers in (L, exp]. The smallest integer > L is floor(L)+1. Then count = exp - (floor(L)+1) + 1 = exp - floor(L). Provided floor(L)+1 <= exp. If floor(L) < 0, then floor(L) is negative, exp - floor(L) > exp, but we must also consider that x must be >=0. But our derivation with floor(L)+1 as lower bound gave count = exp - max(floor(L)+1, 0) + 1. If floor(L)+1 <=0, then lower bound effectively 0, count = exp+1 = exp - floor(L) if floor(L) negative? Let's check: if floor(L) = -k (k>0), then exp - floor(L) = exp + k, which could be > exp+1. So that's not equal to actual count. For example: str=10, int=1, exp=5 => L = (1+5-10)/2 = -2, floor(L) = -2, exp - floor(L) = 5 - (-2) = 7, but actual count is 6? Wait compute: t = -4, L = -2 exactly? Actually (int+exp-str)=1+5-10=-4, L = -4/2 = -2. So floor(L) = -2. Condition x > -2, x from 0 to 5: all x satisfy, count = 6. exp - floor(L) = 5 - (-2) = 7, which is off by 1. Because the formula exp - floor(L) counts something incorrectly. Let's re-derive:
The count of integer x in [0, exp] such that x > L: If L < 0, then all x >=0 satisfy? Actually condition x > L: if L = -2, then x > -2 includes x = -1, 0, 1, ... But x must be >=0, so x = 0,1,...,exp all satisfy because 0 > -2 true. So count = exp+1. For L = -2, floor(L) = -2, exp - floor(L) = exp+2 = 7, not correct. So why did the earlier derivation using floor(L)+1 lower bound produce? floor(L)+1 = -1, which is <0, so we set lower bound to 0, count = exp - 0 + 1 = exp+1 = 6. Good. So the simplification to exp - floor(L) is not valid when L < 0, because the lower bound effectively max(floor(L)+1, 0) not simply floor(L)+1.
But we can unify by noticing that if floor(L) < 0, then count = exp+1, while exp - floor(L) would be larger. So need to handle.
Thus we stick with the previous formula.
Alternatively, we can consider the complement: number of x that do NOT satisfy condition: x <= L. The number of integers x in [0, exp] with x <= L. That number is: max(0, floor(L) - 0 + 1?) Actually x <= L inclusive. The count of integers x in [0, exp] with x <= L is:
If L < 0: then none (since smallest x is 0 > L), so count_bad = 0.
If L >= 0: then count_bad = min(exp, floor(L)) - 0 + 1? But careful: The condition x <= L, but x also ≤ exp. So the integers satisfying both 0 <= x <= exp and x <= L are from 0 to min(exp, floor(L)). So count_bad = max(0, min(exp, floor(L)) - 0 + 1) if floor(L) >=0 else 0. But this gets messy.
Better to keep the straightforward clamp.
Thus final answer is as derived: ans = max(0, exp - max( (int + exp - str)//2 + 1, 0) + 1).
We can also simplify: if (int + exp - str)//2 + 1 <= 0 then ans = exp + 1 else ans = max(0, exp - ((int+exp-str)//2 + 1) + 1) = max(0, exp - (int+exp-str)//2). Because exp - (t//2 +1) +1 = exp - t//2. So if t//2 +1 > 0, ans = max(0, exp - t//2). But if t//2+1 <=0, we set ans = exp+1. However, t//2+1 <=0 means t//2 <= -1 => t <= -2? Actually t//2 <= -1 when t <= -1? Let's test: t = -1, t//2 = -1 (since -1//2 = -1 in Python), then t//2+1 =0, which is not >0, but is equal to 0. In that case, ans = exp - 0 + 1? Wait our formula: low = max(t//2+1, 0). If low = 0, then ans = exp - 0 + 1 = exp+1. So when low = 0 (i.e., t//2+1 <=0?), actually if t//2+1 =0, low = max(0,0)=0, ans = exp+1. So condition for ans = exp+1 is t//2+1 <= 0 (i.e., <=0). That is t//2 <= -1? Because t//2+1 <=0 => t//2 <= -1. For t = -1: t//2 = -1, -1 <= -1 true, so condition holds, ans = exp+1. Let's test with earlier example: str=10,int=1,exp=5 => t=-4, t//2 = -2, t//2 <= -1 true, ans = exp+1 = 6. Good. For t = 0: t//2 = 0, t//2+1=1>0, so ans = exp - t//2 = exp - 0 = exp? Actually ans = max(0, exp - t//2) => exp? But check: str=5, int=5, exp=0 => t=0, t//2=0, ans = max(0,0-0)=0? Wait condition: exp=0, we need str > int? Actually str=5,int=5, exp=0 => no build. But our derived formula for case low>0 says ans = max(0, exp - t//2). For t=0, exp=0 => ans=0, correct. For t=0, exp=2: str=5,int=5,exp=2 => we need str+x > int+2-x => 5+x > 5+2-x => x >1 => x=2 only? Actually x=2 gives 7>5 => ok. x=1 => 6>6? false. x=0 =>5>7 false. So count=1. t=0, t//2=0, exp=2 => ans= max(0,2-0)=2? That's wrong. So our case separation is flawed. Because when t=0, low = t//2+1 = 1, which is >0, so ans = exp - low + 1 = 2 -1 +1 =2? Wait compute: ans = exp - low + 1 = 2 - 1 + 1 = 2. But that's incorrect because we found only 1 valid build. Let's recalc: t = int+exp-str = 5+2-5=2? Oops I miscomputed: str=5,int=5,exp=2 => t = 5+2-5 = 2, not 0. My bad. Let's test t=0 case: For t=0, that would be int+exp-str =0 => str = int+exp. Example: str=7, int=5, exp=2 => t=5+2-7=0. Then condition: x > 0 => x >=1. So valid x = 1,2? Let's check: x=1 => S=8, I=6 => 8>6 ok; x=2 => S=9, I=5 => 9>5 ok. So count=2. And exp=2, low = t//2+1 =0+1=1, ans=2-1+1=2, correct. So okay.
Thus the simplified ans = exp - max(t//2+1,0) + 1 is fine. And if we want a one-liner: ans = max(0, exp - max(t//2 + 1, 0) + 1). That's robust.
But we can also compute ans = max(0, (exp + str - int + 1) // 2?) Let's see if there's a direct formula. From inequality: 2x > int + exp - str => x >= floor((int + exp - str)/2) + 1. Since x <= exp, number of x = max(0, exp - (floor((int+exp-str)/2)+1) + 1) = max(0, exp - floor((int+exp-str)/2)). Actually check: exp - (floor(...)+1) + 1 = exp - floor(...). So count = max(0, exp - floor((int+exp-str)/2)). But we saw this fails when floor(...) is negative because then count would be > exp+1, which is impossible. However if floor(...) is negative, exp - floor(...) > exp, but the actual count is exp+1, which is less than that if floor(...) < -1. So we need to cap at exp+1. Actually we can say count = min(exp+1, max(0, exp - floor((int+exp-str)/2)))? Not exactly, because if floor(...) is negative, exp - floor(...) > exp+1 possibly, and the correct count is exp+1. So we could set count = max(0, min(exp+1, exp - floor((int+exp-str)/2)))? But for the earlier example: exp=5, floor(...)=-2 => exp - (-2)=7, min(6,7)=6, correct. But is min(exp+1, ...) always correct? Let's test other negative floor values: floor = -1 => exp - (-1) = exp+1, min(exp+1, exp+1) = exp+1, which is correct because all builds valid. floor = 0? Then exp - 0 = exp, min(exp+1, exp) = exp, but is that always correct? For floor = 0, that means (int+exp-str)/2 is between 0 and 1? Actually floor=0 implies -1 < (int+exp-str)/2 < 1? Wait floor=0 when the real value L is in [0,1) or (-1,0]? Actually floor(L)=0 for L in [0,1). But if L negative? L in (-1,0] floor is -1 or 0? For L in (-1,0), floor = -1. So floor=0 only when L >=0 and <1. Then count should be exp - 0? Let's test: exp=5, L=0.5, floor=0, condition x > 0.5 => x>=1, so valid x = 1,2,3,4,5 => count=5, which equals exp? Actually exp=5, count=5, exp - floor =5. But exp+1=6, min(6,5)=5. Good. But what about L=0 exactly? floor=0, condition x > 0 => x>=1, same as above, count=5. So exp - floor =5. Good. So min(exp+1, exp - floor) works? For floor positive: floor>=1, exp - floor may be less than exp+1, and it yields correct count (provided it's non-negative). For floor negative and large magnitude: exp - floor could be > exp+1, min gives exp+1, correct. However need to ensure that count is not negative: if exp - floor < 0? That would happen if floor > exp, then exp - floor negative, min(exp+1, negative) = negative, but we need 0. So we need max(0, min(exp+1, exp - floor)). Actually for floor > exp, exp - floor negative, min(exp+1, negative) = negative, then max with 0 gives 0. That would be correct because if floor > exp, then the lower bound > exp, so no builds. For floor = exp+1? exp - floor = -1 => 0 after max, correct. So we can compute: floor_val = (int + exp - str) // 2; ans = max(0, min(exp+1, exp - floor_val)). But is this always equivalent to the earlier formula? Let's test with some random values.
Case: exp=5, floor_val = -2 => exp - floor_val = 7, min(6,7)=6 => ans=6. Works.
Case: exp=5, floor_val = -1 => exp - (-1)=6, min(6,6)=6 => ans=6. Works.
Case: exp=5, floor_val = 0 => 5, min(6,5)=5 => ans=5.
Case: exp=5, floor_val = 3 => 2, min(6,2)=2 => ans=2.
Case: exp=5, floor_val = 5 => 0, min(6,0)=0 => ans=0.
Case: exp=5, floor_val = 6 => -1, min(6,-1)=-1, max(0,-1)=0 => ans=0.
Case: exp=0, floor_val =? t = int - str. For str>int, t negative, floor_val negative, say floor_val=-1 => exp - floor_val = 1, min(1,1)=1 => ans=1, correct. For str<=int, say str=3,int=5 => t=2, floor_val=1 => exp - floor_val = -1, min(1,-1)=-1 => max(0,-1)=0, correct.
Thus this alternative formula also works. But we must be careful with integer division: floor_val = (int+exp-str) // 2, using floor division (in Python it's fine). But note that (int+exp-str) may be negative, and floor division works as floor. So ans = max(0, min(exp+1, exp - floor_val)). This is concise. But is it always correct? Let's derive more formally: Let L = (int+exp-str)/2. The number of x in [0,exp] satisfying x > L is:
If L < 0: then condition holds for all x >=0, so count = exp+1.
If 0 <= L < exp+something? Actually if L >= 0, then the count is the number of integers in (L, exp] = exp - floor(L). Since floor(L) may be >=0.
But if L >= exp? Then count = 0 because even exp is not > L. However, careful: If L = exp exactly, condition x > exp, no integer x in [0,exp] satisfies. So count=0.
So we have:
If L < 0: count = exp+1.
Else: count = max(0, exp - floor(L)).
Now L < 0 is equivalent to (int+exp-str) < 0 => str > int+exp. But we can also combine as: count = exp - floor(L) but then we need to cap at exp+1 when floor(L) negative? Because if L negative, floor(L) is negative, exp - floor(L) > exp, but the true count is exp+1. So we could say count = min(exp+1, exp - floor(L)) when L may be negative? But does min(exp+1, exp - floor(L)) equal exp+1 when floor(L) negative? Since exp - floor(L) > exp+1 if floor(L) <= -2? Actually if floor(L) = -k, k>0, exp - (-k) = exp+k. This could be > exp+1 for k>=2. So min(exp+1, exp+k) = exp+1. For floor(L) = -1, exp - (-1) = exp+1, min(exp+1, exp+1) = exp+1. So indeed min(exp+1, exp - floor(L)) yields exp+1 when floor(L) <= -1. And when floor(L) >=0, exp - floor(L) ≤ exp, so min(exp+1, that) = exp - floor(L), which is correct. But we also need to ensure that count is not negative when exp - floor(L) negative? Actually if floor(L) > exp, then exp - floor(L) negative, min(exp+1, negative) = negative, but we want 0. So we then max with 0: ans = max(0, min(exp+1, exp - floor_val)). That handles all.
Thus ans = max(0, min(exp+1, exp - ((int+exp-str)//2))).
But careful: floor(L) = floor((int+exp-str)/2) = t//2, indeed.
Thus we can compute ans = max(0, min(exp+1, exp - t//2)).
Check example: str=5, int=3, exp=4 => t = 3+4-5=2, t//2=1, exp - t//2 = 3, min(5,3)=3, max(0,3)=3. Good.
str=4, int=10, exp=6 => t=10+6-4=12, t//2=6, exp -6 = 0, min(7,0)=0, ans=0.
str=2,int=1,exp=0 => t=1+0-2=-1, t//2=-1 (since -1//2=-1), exp - (-1)=1, min(1,1)=1, ans=1.
str=1,int=1,exp=2 => t=1+2-1=2, t//2=1, exp-1=1, min(3,1)=1, ans=1.
str=1,int=1,exp=1 => t=1+1-1=1, t//2=0, exp-0=1, min(2,1)=1, ans=1.
str=10,int=1,exp=5 => t=-4, t//2=-2, exp - (-2)=7, min(6,7)=6, ans=6.
So it works. It's simpler.
But wait, the min(exp+1, ...) is effectively capping at exp+1. The max(0, ...) ensures non-negative. So we can compute answer as:
t = int + exp - str
floor_val = t // 2 # floor division
ans = exp - floor_val
if ans > exp+1: ans = exp+1 # but ans can't be negative, but we can use min/max
if ans < 0: ans = 0
In Python: ans = max(0, min(exp+1, exp - t//2))
So we can output that.
Let's verify with more random tests.
Case: str=100, int=50, exp=30: t=50+30-100=-20, t//2=-10, exp - (-10) = 40, min(31,40)=31, ans=31? exp+1=31. So count should be 31, meaning all builds? Let's check condition: str=100, int=50, exp=30. Even if we allocate all points to int (x=0), final S=100, I=80 => 100>80 true. So all builds valid. So 31 builds. Good.
Case: str=80, int=70, exp=10: t=70+10-80=0, t//2=0, exp - 0 =10, min(11,10)=10. So count=10. Let's check: condition: x > 0? Actually t=0 => x > 0 => x>=1. So x=1..10 inclusive, that's 10 builds. At x=0: S=80, I=80 => not >. So 10 builds. Correct.
Case: str=80, int=70, exp=0: t=0, t//2=0, exp-0=0, min(1,0)=0, ans=0. Actually there is one build: x=0, S=80, I=70? Wait int=70, str=80, exp=0 => final: S=80, I=70, so S > I, should be 1 build. Let's compute: t = 70+0-80 = -10? Actually int+exp-str = 70+0-80 = -10, not 0. Oops I miscomputed: str=80, int=70, exp=0 => t = 70+0-80 = -10. So t//2 = -5, exp - (-5) = 5, min(1,5)=1, ans=1. So correct.
So the formula holds.
Now note: In the min(exp+1, exp - t//2), when exp is 0, exp+1=1, and exp - t//2 may be negative? For str=80, int=70, exp=0, t=-10, t//2=-5 => exp - (-5)=5, min(1,5)=1, good.
For str=70, int=80, exp=0: t=80-70=10, t//2=5, exp - 5 = -5, min(1,-5) = -5, max(0,-5)=0, correct.
So it's robust.
Therefore we can implement simply:
ans = max(0, min(exp+1, exp - (int+exp-str)//2))
But careful: (int+exp-str) may be large, but that's fine.
Now is there any off-by-one due to integer division? Let's test borderline case when t is odd positive, say t=1, exp=0? That would be str and int such that int+exp-str=1, but exp=0 so int-str=1 => str=int-1. For example str=4, int=5, exp=0: condition str > int? 4>5 false, count=0. t=1, t//2=0 (since 1//2=0), exp - 0 = 0, min(1,0)=0 => ans=0. Good.
When t=1, exp=1? str=4, int=5, exp=1 => t=5+1-4=2? Actually t=2. Let's find case: t odd: need (int+exp-str) odd, say str=4, int=5, exp=0 gave t=1. exp=0 we did. Now exp=1: t=5+1-4=2 (even). For odd t with exp>0: e.g., str=4, int=5, exp=2 => t=5+2-4=3. Then t//2=1, exp - 1 = 1, min(3,1)=1 => ans=1. Let's test manually: options x=0: S=4, I=7 => false; x=1: S=5, I=6 => false; x=2: S=6, I=5 => true => 1 build. Good.
Now for negative odd t: say str=10, int=1, exp=1 => t=1+1-10=-8? Even. Another: str=10, int=1, exp=0 => t=-9, t//2 = -5? In Python -9//2 = -5 (since floor(-4.5) = -5). exp - t//2 = 0 - (-5) =5, min(1,5)=1 => ans=1. Indeed only build: x=0, S=10,I=1 => ok.
All good.
Thus we have a very simple solution.
Now, we should note that str and int are up to 1e8, exp up to 1e8, but the sum may go up to 3e8, which fits in Python int. So fine.
Now produce final answer.
Now in the problem example, they gave:
4
5 3 4
2 1 0
3 5 5
4 10 6
Output: 3,1,2,0.
Our formula yields:
-
t=3+4-5=2, t//2=1, exp - t//2 = 3, min(5,3)=3 =>3
-
t=1+0-2=-1, t//2=-1, exp - (-1)=1, min(1,1)=1 =>1
-
t=5+5-3=7, t//2=3, exp - 3=2, min(6,2)=2 =>2
-
t=10+6-4=12, t//2=6, exp - 6=0, min(7,0)=0 =>0.
Matches.
Thus final code is straightforward.
Edge Cases: All good.
Now we need to output T integers, each on new line.
I'll write in Python.
Potential pitfalls: reading input, using appropriate variable names. We'll also handle when T=0? But constraints say T>=1.
Thus final solution.
Now, maybe there is another nuance: the problem states "resulting strength is strictly greater than the resulting intelligence." That's what we used.
Thus answer is as derived.
We'll now produce the final answer.
But the user might expect not just code but explanation? The problem statement is from Codeforces (e.g., problem "Jogging" maybe? Actually it's from Codeforces Round # 173? I recall a problem "Joker" or something, but anyway). The user asked: "Calculate the number of different character builds you can create...". And gave input format. It appears they want the solution. So we need to output the answer. Usually in such interactive environment we just output numbers. So we provide the code.
But I'm ChatGPT, I can provide explanation and code. However, as per instructions, I'm to provide the answer. Since the user didn't explicitly ask for code, but the problem is to "Calculate the number...", it's typical to provide code that does that. The user gave an example. They might want the solution algorithm. But given the format, I think providing a Python solution is appropriate.
Thus final answer: Python code.
But to be thorough, we can also present a formula: The answer is max(0, min(exp+1, exp - (int+exp-str)//2 )). I'll include explanation.
Now let's write final. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
s = int(next(it))
i = int(next(it))
exp = int(next(it))
t = i + exp - s # B + C - A
floor_half = t // 2 # floor((B+C-A)/2)
ans = exp - floor_half # candidate answer
ans = min(exp + 1, ans) # cannot exceed all possible builds
ans = max(0, ans) # non‑negative
out_lines.append(str(ans))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()