August Long Challenge Problem Difficulties Solution

Problem Difficulties Solution

You have prepared four problems. The difficulty levels of the problems are A1,A2,A3,A4A1,A2,A3,A4 respectively. A problem set comprises at least two problems and no two problems in a problem set should have the same difficulty level. Output the maximum number of problem sets you can create using the four problems.

Also See: August Long Challenge 2021 Solutions

Input Format

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains four space-separated integers A1A1, A2A2, A3A3, A4A4, difficulty levels of the four problems.

Output Format

For each test case, output in a single line the maximum number of problem sets you can create using the four problems.


  • 1≤T≤10001≤T≤1000
  • 1≤A1,A2,A3,A4≤101≤A1,A2,A3,A4≤10


Subtask #1 (100 points): Original constraints

Sample Input 1 

1 4 3 2
4 5 5 5
2 2 2 2

Sample Output 1 



Test case 11: You can prepare the first problem set using the first two problems and the second problem set using the next two problems. So the problem sets will be [1,4][1,4] and [3,2][3,2].

Test case 22: You can prepare one problem set using one problem having a difficulty level of 44 and the other having a difficulty level of 55. There is no way to prepare more than one problem set.

Test case 33: There is no way to prepare a problem set.


Program Python:

import collections
tC = int(input())
for __ in range(tC):
    P = list(map(int,input().split()))
    counter = {x : P.count(x) for x in P}
    print(1) if 2<=len(set(P)) and any(2<value for value in counter.values()) else print(2) if 2<=len(set(P)) else print(0)

Program C++:


using namespace std;

int main(){
	int t;
		long long arr[4];
		sort(arr, arr + 5);
		int answer;
		if(arr[0] == arr[1]  && arr[1] == arr[2] && arr[2] == arr[3]){
			answer = 0;
		else if(arr[0] != arr[1] && arr[2] != arr[3]){
			answer = 2;
		else if(arr[0] != arr[2] && arr[1] != arr[3]){
		    answer = 2;
		else answer = 1;

	return 0;

Codechef Long Challenges

August Long Challenge 2021 Solutions

July Long Challenge 2021 Solutions

Leave a Comment