This page is still under construction.

Parts of this page are still being built. What you see may change.

Football Statistics

Interview

Time limit2sMemory limit1024 MB

Summary
Process a stream of football match records and queries, maintaining per-team and per-player goal statistics, minutes of goals, and score-opening counts.
Level

Medium5 of 10

Topics
Hash map, Implementation, Simulation, String matching
Solved
No attempts yet

Problem

Asya Vutkina is a famous football commentator. As a professional, Asya follows every match of every European league closely.

With the information she has accumulated, Asya can mention an interesting statistic during a broadcast, for example: "Inzaghi has scored in the 9th minute for three matches in a row" or "Materazzi has never opened the score in a match."

But Asya's brain is not unlimited, and remembering the entire history of football is simply impossible. So Asya has asked you to write a program that collects match statistics and can answer some queries about the history of football.

Information about a match is given to the program in the following form:

"<Name of team 1>" - "<Name of team 2>" <Score of team 1>:<Score of team 2>}
<Scorer of the 1st goal for team 1> <Minute the goal was scored>'
<Scorer of the 2nd goal for team 1> <Minute the goal was scored>'
...
<Scorer of the last goal for team 1> <Minute the goal was scored>'
<Scorer of the 1st goal for team 2> <Minute the goal was scored>'
...
<Scorer of the last goal for team 2> <Minute the goal was scored>'

Queries to the program are of the following kinds:

  • Total goals for "<Team name>": the number of goals this team has scored in all matches.
  • Mean goals per game for "<Team name>": the average number of goals this team scores per match. It is guaranteed that by the time such a query is made, the team has already played at least one match.
  • Total goals by <Player name>: the number of goals this player has scored in all matches.
  • Mean goals per game by <Player name>: the average number of goals this player scores per match of their team. It is guaranteed that by the time such a query is made, the player has already scored at least one goal.
  • Goals on minute <Minute> by <Player name>: the number of goals this player has scored exactly on the given minute of a match.
  • Goals on first <$T$> minutes by <Player name>: the number of goals this player has scored on minutes 1 through TT inclusive.
  • Goals on last <$T$> minutes by <Player name>: the number of goals this player has scored on minutes (91−T)(91 - T) through 90 inclusive.
  • Score opens by "<Team name>": the number of times this team has opened the score in a match.
  • Score opens by <Player name>: the number of times this player has opened the score in a match.

Input

The input file contains information about matches and queries in the order they arrive at Asya Vutkina's program.

The input file contains information about at most 100 matches, and at most 10 goals are scored in each of them. At most 20 teams participate in the league, and at most 10 players on each team score goals.

All team names and player names consist only of uppercase and lowercase Latin letters and spaces, and their length does not exceed 30. Uppercase and lowercase letters are considered distinct. Names do not begin or end with a space and do not contain two consecutive spaces. Each name contains at least one letter.

The minute on which a goal is scored is an integer from 1 to 90. Goals scored in extra time are conventionally said to be scored on the 90th minute.

For simplicity, we assume that own goals are not scored in European leagues, and that at most one goal can be scored on a single minute of a match, including the 90th. During the league, players do not transfer from one club to another.

The number of queries in the input file does not exceed 500.

Output

For each query in the input file, print the answer to that query on a separate line. Answers to queries that imply a non-integer answer must be correct to three digits after the decimal point.

Examples2

  1. Example 1

    Input
    "Juventus" - "Milan" 3:1
    Inzaghi 45'
    Del Piero 67'
    Del Piero 90'
    Shevchenko 34'
    Total goals for "Juventus"
    Total goals by Pagliuca
    Mean goals per game by Inzaghi
    "Juventus" - "Lazio" 0:0
    Mean goals per game by Inzaghi
    Mean goals per game by Shevchenko
    Score opens by Inzaghi
    
    Expected output
    3
    0
    1
    0.5
    1
    0
    
  2. Example 2

    Input
    Total goals by Arshavin
    
    Expected output
    0