# PROBLEM LINK:

Practice

Contest: Division 1

Contest: Division 2

Contest: Division 3

Contest: Division 4

* Author:* Aatman Supkar

*Jeevan Jyot Singh, Hriday*

**Testers:***Nishank Suresh*

**Editorialist:**# DIFFICULTY:

1512

# PREREQUISITES:

None

# PROBLEM:

N students receive a math assignment of 5 questions. You are given which questions each student knows to solve.

Is it possible for some pair of students to solve all the questions together?

# EXPLANATION

N is quite small, so a straightforward brute force solution is good enough.

Iterate over each pair of students, and check if together they cover all 5 questions. This check can be done in a variety of ways, for example:

- Insert all the questions solvable by one of the two students into a set, then check if this set has size 5; or
- Keep an array of size 5, initially all zero. Mark each question one of the two students can solve with a 1. Finally, check if every index is marked; or
- Represent the set of questions a given student can solve with a 5-bit bitmask, i.e, an integer from 0 to 31. Then, check if the bitwise OR of the two studentsâ€™ bitmasks equals 31.

# TIME COMPLEXITY

\mathcal{O}(N^2) per test case.

# CODE:

## Editorialist's code (Python)

```
for _ in range(int(input())):
n = int(input())
a = []
for i in range(n):
solved = list(map(int, input().split()))[1:]
a.append(solved)
ans = 'no'
for i in range(n):
for j in range(n):
if len(set(a[i] + a[j])) == 5:
ans = 'yes'
print(ans)
```