CF BUDDY
← Problems·

1166E · The LCMs Must be Large

2100 · bitmasks, brute force, constructive algorithms

Problem: Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?

There are nn stores numbered from 11 to nn in Nlogonia. The ii-th of these stores offers a positive integer aia_i.

Each day among the last mm days Dora bought a single integer from some of the stores. The same day, Swiper the fox bought a single integer from all the stores that Dora did not buy an integer from on that day.

Dora considers Swiper to be her rival, and she considers that she beat Swiper on day ii if and only if the least common multiple of the numbers she bought on day ii is strictly greater than the least common multiple of the numbers that Swiper bought on day ii.

The least common multiple (LCM) of a collection of integers is the smallest positive integer that is divisible by all the integers in the collection.

However, Dora forgot the values of aia_i. Help Dora find out if there are positive integer values of aia_i such that she beat Swiper on every day. You don't need to find what are the possible values of aia_i though.

Note that it is possible for some values of aia_i to coincide in a solution.

Input Format: The first line contains integers mm and nn (1m501\leq m \leq 50, 1n1041\leq n \leq 10^4) — the number of days and the number of stores.

After this mm lines follow, the ii-th line starts with an integer sis_i (1sin11\leq s_i \leq n-1), the number of integers Dora bought on day ii, followed by sis_i distinct integers, the indices of the stores where Dora bought an integer on the ii-th day. The indices are between 11 and nn.

Output Format: Output must consist of a single line containing "possible" if there exist positive integers aia_i such that for each day the least common multiple of the integers bought by Dora is strictly greater than the least common multiple of the integers bought by Swiper on that day. Otherwise, print "impossible".

Note that you don't have to restore the integers themselves.

Note: In the first sample, a possible choice for the values of the aia_i is 3,4,3,5,23, 4, 3, 5, 2. On the first day, Dora buys the integers 3,43, 4 and 33, whose LCM is 1212, while Swiper buys integers 55 and 22, whose LCM is 1010. On the second day, Dora buys 3,53, 5 and 22, whose LCM is 3030, and Swiper buys integers 33 and 44, whose LCM is 1212.

Sample Cases

Case 1

Input

2 5
3 1 2 3
3 3 4 5

Output

possible

Case 2

Input

10 10
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10

Output

impossible

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback