Codechef•Jun 22, 2025
Chef and Races
Hazrat Ali
Codechef
Chef has an arch-rival who is, unfortunately, the only person participating who is better than Chef, i.e, Chef can't defeat the arch-rival in any of the four race categories but can defeat anyone else. Chef's arch-rival is also participating in exactly 2 of the four categories.
Chef hopes to not fall into the same categories as that of the arch-rival.
Given X,Y,A,B where X,Y are the races that Chef participates in, and A,B are the races that Chef's arch-rival participates in, find the maximum number of gold medals (first place) that Chef can win.
Input Format
- The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows.
- Each testcase consists of a single line containing four space-separated integers — the values of X,Y,A, and B respectively.
Output Format
- For each testcase, print a single line containing one integer the maximum number of gold medals that Chef can win.
Constraints
- 1≤T≤144
- 1≤X,Y,A,B≤4
- X≠Y
- A≠B
Subtasks
Subtask #1 (100 points): Original constraints
Sample 1:
Input
3 4 3 1 2 4 2 1 2 2 1 1 2
Output
2 1 0
Solution
t = int(input())
for _ in range(t):
x, y, a, b = map(int, input().split())
chef_races = {x, y}
rival_races = {a, b}
wins = len(chef_races - rival_races)
print(wins)