ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2201. Esports Tournament

Time limit: 2.5 second
Memory limit: 256 MB
Ilya is the administrator of the most popular multiplayer esports discipline. The management sends him on business trips every time to administer offline tournaments. Ilya is a professional in his field, so the management is confident that all competitions he administers will proceed without technical issues!
At one of the largest tournaments, Ilya was once again the administrator and had the nickname “admin” (without quotes). Of course, our hero is very responsible and arrived at work early, immediately logging into the game, and plans to stay late without distractions.
As is known, organizing tournaments is a very complex and lengthy task. While all participants connect to the competition, some may step away for various reasons and not be online, causing delays often due to them. Meanwhile, while all players are connecting, everyone in the chat wishes each other good luck and fun in the upcoming match. Out of sheer boredom, Ilya became curious about the luck each player has in the match. Ilya considers luck to be a positive real number that each player possesses.
A message of the GLHF format is defined as a message consisting only of the letters from the alphabet {“gl”, “hf”} (without quotes). In other words, a GLHF format message is a string that contains only pairs of letters “gl” and “hf”. For example: “glglglhfhf”, “hf”, “hfgl”. In particular, all GLHF format messages have an even length. Players send messages only in the GLHF format.
Each player (including the administrator) initially has a luck value of one. Ilya believes that a player’s luck increases by a factor of A every time they see a good luck wish (“gl” — good luck), and decreases by a factor of B every time they see a wish to have fun (“hf” — have fun) (as it is known, in a tense match, one should not relax and have fun). If the message contains “gl” and/or “hf” multiple times, the luck increases by A and decreases by B for each pair of characters “gl” and “hf” respectively.
Considering all this, Ilya wanted to compare the luck of the players, and although he has plenty of time for it, he entrusted you with implementing a small utility.
Your small utility receives correct logs as input — messages in the format: “[hh:mm:ss] AUTHOR_NICK: /command”, where [hh:mm:ss] is the time in the format [hours:minutes:seconds], AUTHOR_NICK is the player’s nickname, and command is the command. There are several possible commands:
  • /j, /join — the player AUTHOR_NICK connects to the game. After connecting, the player can see all subsequent personal and public messages in the chat. The server can respond to this command with:
    • “Successful” — if at the time of executing the command the player was not in the game.
    • “Failed: AUTHOR_NICK is already on the server” — if the player is already in the game.
  • /q, /quit — the player AUTHOR_NICK disconnects from the game. After disconnecting, the player does not receive any subsequent personal or public messages until they log in again. Leaving the server does not change the player’s luck, and upon rejoining, the luck will be as it was when they left. The server should respond with:
    • “Successful”
  • /o, /online — the player AUTHOR_NICK wants to know how many people are currently online. The server should output:
    • “There are X players on the server” — where X is the number of people on the server (including the administrator).
  • /s [glhf], /say [glhf] — the player AUTHOR_NICK writes a GLHF format message in the public chat, not exceeding M characters in length. This message will be seen by all connected players (including the administrator). Such messages do not affect the author’s luck. The server should respond with:
    • “AUTHOR_NICK: [glhf]” — outputting the player’s name and their message.
  • /w<RECIPIENT_PLAYER> [glhf], /write<RECIPIENT_PLAYER> [glhf] — the player AUTHOR_NICK writes a personal message to player RECIPIENT_PLAYER in GLHF format, not exceeding M characters in length. In this case, only RECIPIENT_PLAYER sees the message, but only if they are connected to the game. If the recipient is not on the server, no error messages are generated. Such messages do not affect the author’s luck. A player cannot send a message to themselves. The server should respond with:
    • “AUTHOR_NICK (to RECIPIENT_PLAYER): [glhf]” — outputting the player’s name, the recipient’s name, and the message.
  • /c<PLAYER>, /compare<PLAYER> — this command is only available to the player admin. The command is intended to compare the luck of the administrator with the player PLAYER. The server can respond to this command with:
    • “Failed: you have no such rights” — if AUTHOR_NICK is not admin (highest priority check).
    • “Failed: PLAYER is not on the server” — if PLAYER is currently not in the game.
    • “PLAYER is a loser” — if admin’s luck is greater than PLAYER’s luck.
    • “PLAYER is good” — if admin’s luck is equal to PLAYER’s luck.
    • “PLAYER is a lucky guy” — if admin’s luck is less than PLAYER’s luck.
  • /c<PLAYER1>-<PLAYER2>, /compare<PLAYER1>-<PLAYER2> — this command is also only available to the player admin. The command is intended to compare the luck of player PLAYER1 with the luck of player PLAYER2. The server can respond to this command with:
    • “Failed: you have no such rights” — if AUTHOR_NICK is not admin (highest priority check).
    • “Failed: PLAYER1 is not on the server” — if PLAYER1 is currently not in the game (next priority check).
    • “Failed: PLAYER2 is not on the server” — if PLAYER2 is currently not in the game.
    • “PLAYER2 is a loser” — if PLAYER1’s luck is greater than PLAYER2’s luck.
    • “Their luck is equal” — if PLAYER1’s luck is equal to PLAYER2’s luck.
    • “PLAYER2 is a lucky guy” — if PLAYER1’s luck is less than PLAYER2’s luck.
For each encountered substring “gl” and “hf”, the player’s luck increases by A or decreases by B respectively. It is worth noting that a player’s luck does not reset after disconnecting and reconnecting to the game.
Your task is to implement this utility!

Input

The first line contains space-separated integers N, M, A, B — the number of commands the server will receive, the maximum number of characters in a message, the multiplier for a player’s luck when they see the message “gl”, and the divisor for a player’s luck when they see the message “hf”, respectively (1 ≤ N ≤ 86400, 2 ≤ M ≤ 10, 1 ≤ A, B ≤ 109).
Next, there are N lines containing the server logs in chronological order, each line has the following format:
“[hh:mm:ss] AUTHOR_NICK: /command” (without quotes). The timestamps consist of hours hh (from 0 to 23), minutes mm (from 0 to 59), and seconds ss (from 0 to 59); each of these numbers has exactly 2 digits and is padded with a leading zero if necessary. The timestamps do not repeat and are strictly in ascending order. The player’s nickname AUTHOR_NICK, as well as all nicknames in the arguments of the /write and /compare commands, are strings consisting of uppercase and lowercase Latin letters, digits, and the “_” character (code 95); the length of each nickname does not exceed 8 characters.
The tournament logs are correct, and it is guaranteed that there are no incoming commands from participants who are not connected to the game, except for the /join commands. All messages adhere to the GLHF format and have a length of no more than M characters.
Initially, it is assumed that there are no players on the server except for the administrator, who has the nickname “admin”. The administrator never leaves the server.
It is guaranteed that if the luck comparison operation between two players shows that their luck differs, then their luck values differ by a factor of at least 1.0001.

Output

The output should contain N lines — the server’s responses to the requests, where the i-th line corresponds to the server’s response to the request in the i + 1 line of the input data.

Sample

inputoutput
18 4 2 4
[00:00:23] admin: /online
[00:01:02] j0e: /j
[00:01:15] j0e: /s hfhf
[00:01:17] j0e: /q
[00:01:18] admin: /write<j0e> hfhf
[00:03:25] Tea_: /join
[00:04:11] j0e: /join
[00:07:54] Tea_: /j
[00:08:30] admin: /say glgl
[00:08:37] admin: /write<j0e> hfhf
[00:09:00] Tea_: /compare<j0e>
[00:13:41] admin: /c<j0e>-<Tea_>
[00:13:44] j0e: /quit
[00:13:57] admin: /compare<j0e>
[00:27:49] j0e: /j
[00:28:01] j0e: /s hfhf
[00:30:19] admin: /compare<j0e>
[00:30:43] admin: /compare<Tea_>-<j0e>
There are 1 players on the server
Successful
j0e: hfhf
Successful
admin (to j0e): hfhf
Successful
Successful
Failed: Tea_ is already on the server
admin: glgl
admin (to j0e): hfhf
Failed: you have no such rights
Tea_ is a lucky guy
Successful
Failed: j0e is not on the server
Successful
j0e: hfhf
j0e is a lucky guy
Their luck is equal

Notes

Explanation of the example:
  • After the command “[00:01:15] j0e: /s hfhf”, the luck of admin decreased by 42 times. The luck of j0e does not change.
  • After the command “[00:01:18] admin: /write<j0e> hfhf”, the luck of player j0e does not change since he is disconnected from the game. The luck of admin also does not change.
  • After the command “[00:08:30] admin: /say glgl”, the luck of j0e and Tea_ increases by 22 times. The luck of admin does not change. Now the players’ luck is as follows:
    • admin: 1/42;
    • j0e: 22;
    • Tea_: 22.
  • After the command “[00:08:37] admin: /write<j0e> hfhf”, the luck of j0e decreases by 42 times and becomes 22/42. The luck of admin does not change.
  • Executing the command “[00:09:00] Tea_: /compare<j0e>” will result in an error because Tea_ does not have sufficient rights to execute it.
  • The command “[00:13:41] admin: /c<j0e>-<Tea_>” compares the luck of players j0e and Tea_. Their luck is equal to 22/42 and 22 respectively. Since Tea_ has higher luck, the server’s response is: “Tea_ is a lucky guy”.
  • Executing the command “[00:13:57] admin: /compare<j0e>” will result in an error since player j0e is not connected to the game. The server’s response is: “Failed: j0e is not on the server”.
  • After the command “[00:28:01] j0e: /s hfhf”, the luck of players admin and Tea_ decreases by 42 times. The luck of j0e does not change.
  • With the command “[00:30:19] admin: /compare<j0e>”, admin wishes to compare his luck with that of player j0e. Their lucks are 1/44 and 22/42 respectively. Since j0e has higher luck, the server’s response is: “j0e is a lucky guy”.
  • With the command “[00:30:43] admin: /compare<Tea_>-<j0e>”, admin wishes to compare the luck of player Tea_ with that of player j0e. Their lucks are equal to 22/42 and 22/42 respectively. Their lucks are equal, so the server’s response is: “Their luck is equal”.
Problem Author: Vadim Barinov
Problem Source: University academic school olympiad in informatics 2020