Validate the test set

Every practice problem needs a good set of tests. Write the validator that the project's own checks perform.

What to build

A program that finds the problems in a set of tests.

Requirements

  • Each test line is KIND|INPUT|OUTPUT where KIND is S (sample) or H (hidden). INPUT and OUTPUT are text without |.
  • If there are fewer than 2 S tests print problem: needs at least 2 sample tests. If there are fewer than 3 H tests print problem: needs at least 3 hidden tests.
  • Then, in test order (numbering from 0): for a test whose OUTPUT is empty print problem: test I has no expected output; for a test whose INPUT equals the input of an earlier test print problem: test I repeats the input of test J, where J is the first test with that input. A test with both problems prints the empty-output line first.
  • Finally print COUNT problem(s).

Input

The first line has n (1 to 30). Each of the next n lines is a test.

Output

The problem lines, then the count line.

Constraints

1 ≤ n ≤ 30.

Example

Input:

5
S|2 3|5
S|10 -4|6
H|0 0|0
H|7 8|15
H|1 1|2

Output:

0 problem(s)

Why it works

The set-level rules need only the counts, and the test-level rules need one pass with a dictionary that remembers where each input was first seen, so each rule is a small, separate check.

Examples

Example 1 · Input
5
S|2 3|5
S|10 -4|6
H|0 0|0
H|7 8|15
H|1 1|2
Expected output
0 problem(s)
Example 2 · Input
4
S|2 3|5
H|0 0|0
H|7 8|
H|1 1|2
Expected output
problem: needs at least 2 sample tests
problem: test 2 has no expected output
2 problem(s)

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Split each line into three parts with split("|", 2): kind, input and output.

Hint 2

Remember the first position of every input in a dictionary to find repeats.

Hint 3

Print the problems in the order given, then the count.

Solution

Show one correct solution (try it yourself first)
n = int(input())
tests = []
for _ in range(n):
    kind, given, wanted = input().split("|", 2)
    tests.append((kind, given, wanted))
problems = []
if sum(1 for t in tests if t[0] == "S") < 2:
    problems.append("needs at least 2 sample tests")
if sum(1 for t in tests if t[0] == "H") < 3:
    problems.append("needs at least 3 hidden tests")
first = {}
for i, (kind, given, wanted) in enumerate(tests):
    if not wanted:
        problems.append(f"test {i} has no expected output")
    if given in first:
        problems.append(f"test {i} repeats the input of test {first[given]}")
    else:
        first[given] = i
for p in problems:
    print("problem:", p)
print(f"{len(problems)} problem(s)")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Your first contribution →