Can the project ship?

A project may use a dependency only if the licenses fit. This is a simplified model of the check companies run (it is not legal advice).

What to build

A program that checks every dependency license against the project's license and gives a verdict.

Requirements

  • MIT, BSD-3-Clause, Apache-2.0 and LGPL-3.0 dependencies are fine in any project.
  • A GPL-3.0 dependency needs a project licensed GPL-3.0 or AGPL-3.0. An AGPL-3.0 dependency needs a project licensed AGPL-3.0.
  • Any other license, including NONE, is a conflict.
  • Print NAME: ok or NAME: conflict for each dependency in the input order. Then print verdict: can ship if there is no conflict, or verdict: cannot ship (K conflict(s)).

Input

The first line is the project's license. The second line has n (1 to 50). Each of the next n lines is NAME LICENSE separated by a space.

Output

One line per dependency, then the verdict.

Constraints

1 ≤ n ≤ 50.

Example

Input:

MIT
3
requests Apache-2.0
fastgrid GPL-3.0
mystery NONE

Output:

requests: ok
fastgrid: conflict
mystery: conflict
verdict: cannot ship (2 conflict(s))

Why it works

The rule for each dependency depends on both licenses, so one function decides it; counting the conflicts then gives the verdict, and a single conflict is enough to block shipping.

Examples

Example 1 · Input
MIT
3
requests Apache-2.0
fastgrid GPL-3.0
mystery NONE
Expected output
requests: ok
fastgrid: conflict
mystery: conflict
verdict: cannot ship (2 conflict(s))
Example 2 · Input
GPL-3.0
2
fastgrid GPL-3.0
colorama BSD-3-Clause
Expected output
fastgrid: ok
colorama: ok
verdict: can ship

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

Hints

Hint 1

Keep the rules in one function that takes the project license and a dependency license.

Hint 2

GPL-3.0 needs a project that is GPL-3.0 or AGPL-3.0; AGPL-3.0 needs AGPL-3.0 exactly.

Hint 3

Count conflicts and use the count in the verdict.

Solution

Show one correct solution (try it yourself first)
FREE = ["MIT", "BSD-3-Clause", "Apache-2.0", "LGPL-3.0"]


def allowed(project, dependency):
    if dependency in FREE:
        return True
    if dependency == "GPL-3.0":
        return project in ("GPL-3.0", "AGPL-3.0")
    if dependency == "AGPL-3.0":
        return project == "AGPL-3.0"
    return False


project = input().strip()
n = int(input())
conflicts = 0
for _ in range(n):
    name, license_id = input().split()
    if allowed(project, license_id):
        print(f"{name}: ok")
    else:
        print(f"{name}: conflict")
        conflicts += 1
if conflicts == 0:
    print("verdict: can ship")
else:
    print(f"verdict: cannot ship ({conflicts} conflict(s))")

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

Lesson: Open-source licenses →