Under construction

Still being built. Things may change

Disgruntled Diner

Time limit2sMemory limit1024 MB

Summary
Given the order log and partly hidden pinned tickets, decide whether all tickets for table t are item m, or find the fewest tickets to flip to check it.
Level

Medium7 of 10

Topics
Graph, String, Hash map
Solved
No attempts yet

Problem

Diana is the head chef at the Batavian Authentic Prestigious Cuisine. All orders are logged to a central computer. To organize the kitchen, each ordered item is also printed on a separate ticket. On the back of each ticket, Diana writes the table number, so servers can check where to deliver the food. When a ticket is completed, Diana pins it to a board. A table may order the same item more than once, so duplicate tickets can exist.

Halfway through service, a disgruntled diner complains: "We have been waiting for hours, but so far we were only served tomato soup! Could you please hurry up?" Diana must address this immediately, since the restaurant's reputation is at stake. However, some customers have been dishonest in the past to demand faster service, so the complaint must be verified before Diana instructs the kitchen staff.

The board is always up to date, so verification means checking the relevant tickets. Let tt and mm be the table number and menu item in the complaint. Diana checks the claim: "All pinned-up tickets for table tt correspond to menu item mm." If there are no completed tickets for table tt, the claim is true. The customer may have misspoken, but they still deserve extra attention.

Only one side of each ticket is visible on the board, either the menu item or the table number. Diana does not have time to flip hundreds of tickets. By cross-referencing the central computer, some tickets can be safely ignored. Find the minimum set of pinned-up tickets that must be flipped. Or prove or disprove the claim without flipping any tickets. Diana must decide which tickets to flip before she starts flipping, because she is too strained to make deductions on the fly.

Input

The input consists of:

  • One line with two integers nn and kk (1≤k≤n≤5001 \le k \le n \le 500), the number of orders in the computer and the number of pinned-up tickets.
  • One line with nn strings representing the orders in the computer, each string consisting of one English uppercase letter (the menu item, A-Z) and one digit (the table number, 0-9).
  • One line with kk characters representing the pinned-up tickets, each character being either an English uppercase letter or a digit.
  • One line with a digit tt (0-9) and an English uppercase letter mm (A-Z), specifying the claim: "All pinned-up tickets for table tt correspond to menu item mm."

The pinned-up tickets are guaranteed to correspond to (a subset of) the orders in the computer.

Output

If, without flipping any tickets, the claim is provably true or false, output true or false, respectively. Otherwise, output the minimum number of pinned-up tickets that need to be flipped, followed by their 11-based indices, in any order.

Examples3

  1. Example 1

    Input
    6 4
    A1 A2 B1 B2 C1 C2
    A B 1 2
    1 A
    
    Expected output
    2
    3 2
    
  2. Example 2

    Input
    5 4
    A1 B1 C2 C1 A2
    2 A B 1
    1 A
    
    Expected output
    false
    
  3. Example 3

    Input
    4 4
    Z0 Z0 F9 F9
    Z 0 9 9
    4 F
    
    Expected output
    true