Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

ACL

Unfortunately, even though your efforts were kinda successful, some AI bots were able to enter into our most secure servers and started to check our files. Who knows, maybe they will even download the ranking of the programming contest as well (which is totally not decided beforehand...ahem-ahem)! Luckily our system administrators were keen enough to set permissions for the sensitive files and folders, so the bots are not able to access everything. Your task is to decide the amount of "damage" caused by the bots by determining if they can access a given folder or not.

Input

The input is a single line, ended with an end of line character. The structure of the line is the following:

  • The first part of the line is a list enclosed between { } characters. Inside this list we have the following:
    • At most 255 strings, each enclosed between " " characters which all has the structure "xyz_allow" or "xyz_deny", where xyz is the name of a folder or the * (wildcard) character.
    • Except for the last string, the closing " of these strings are followed by a comma and a single space character. The closing " of the last string is followed by the list-closing } character.
  • The second half of the line starts exactly one space character away from the closing } of the list and contains a single string, enclosed between " " characters.
Note: the string in the second part is the name of the folder what the AI bot wants to access.

Output

The output is the number 1 if the AI bot is able to open the folder specified in the second part of the line and the number 0 if not. The bot is able to open a folder if that folder is in an "allow" state in the list (e.g. "books_allow"), or if the * star allows it (e.g. "*_allow"). Important however that the * character is overwritten by the specific entries, so e.g. "*_allow", "books_deny" means that the bot can download everything except books. Moreover the system administrators were a bit tired while setting these permissions, so there can be conflicting entries, which always return a "deny" state (e.g. "books_allow", "books_deny" translates to "books_deny"). If the * character has a conflicting entry, then we also translate it to "*_deny", however based on the above lines the specific entries can overwrite this.

Note: the task will always be solvable, so there will be no undecidable cases.

Example

Input:
  1. {"*_allow", "books_allow", "movies_deny"} "games"
download as text file Output:
  1. 1
download as text file Input:
  1. {"*_allow", "*_deny", "movies_allow", "books_allow"} "games"
download as text file Output:
  1. 0
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024