Under construction

Still being built. Things may change

Finalists

Time limit3sMemory limit1024 MB

Summary
Given the World Finals slot count N and six regionals' statistics, compute how many slots the Taiwan regional receives under the site-score allocation rules.
Level

Easy3 of 10

Topics
Implementation, Sorting, Simulation
Solved
No attempts yet

Problem

Frank is trying his best to win a slot in Asia Pacific to the World Finals. But he could not find the selection rules to estimate his chance. Last night, Frank's coach found the following document.

=====================================================================
World Finals team selection rules from Asia Pacific (2022 cycle)

Due to COVID-19 outbreak, this year's Asia Pacific rules will
again be quite different from those of usual years. The plan
for having an Asia Pacific semi-final contest (play-off contest)
has been cancelled and postponed to the next year.

Only the following six regionals will be held this year.

Ho Chi Minh, Vietnam
Jakarta, Indonesia
Manila, Philippines
Seoul, Korea
Taoyuan, Taiwan
Yokohama, Japan

We have set a team participation rule. This rule is a special one
for this year (2022 cycle) only.

Teams from a hosting country (Indonesia, Japan, Korea, Philippines,
Taiwan and Vietnam) can only join the regional held in their own
country. Universities from non-hosting countries should choose a
regional. Note that all teams from a single university have to join
the same regional.

World Finals team selection rules are as follows.

Apply Steps A1 through A4 below in this order.

A1. Define the site score of a regional as follows.
0.56 * number of universities in regional
+ 0.24 * number of teams in regional
+ 0.14 * number of universities in preliminary contests
+ 0.06 * number of teams in preliminary contests
+ 0.3 * number of foreign teams

Only teams or universities solving at least one problem are counted.

A2. Sort our six regionals according to their site scores.

A3. Let N be the number of World Finals slots given from the ICPC
Headquarters. Until the sum of the number of allocated slots
reaches N, allocate slots to regionals, one by one, in the
descending order of their site scores. When all six regionals
are allocated one slot each, continue from the regional with the
highest site score in the round robin fashion.

A4. For each regional, let M be the number of slots allocated to the
regional through the step A3. Select the M highest ranked
universities. The team with the highest rank in the university
is automatically selected.
=====================================================================

Assume that the document is the final selection rules for teams from Asia Pacific. Given NN and the necessary numbers to calculate the site scores, write a program that computes the number of slots allocated to Taiwan.

Input

There are seven lines in the input. The first line contains NN, the number of World Finals slots given from the ICPC Headquarters. Each of the following six lines consists of one string ss and five non-negative integers p_tp\_t, p_up\_u, r_tr\_t, r_ur\_u, ff, separated by spaces.

ss is the country hosting a regional contest. p_tp\_t is the number of teams solving at least one problem in the preliminary contests hosted by the country ss. p_up\_u is the number of universities solving at least one problem in the preliminary contests hosted by the country ss. r_tr\_t is the number of teams solving at least one problem in the regional contest hosted by the country ss. r_ur\_u is the number of universities solving at least one problem in the regional contest hosted by the country ss. ff is the number of foreign teams solving at least one problem in the regional hosted by the country ss.

Output

Output the number of slots allocated to Taiwan.

Constraints

  • NN is at least 66 and at most 5050.
  • Each line has a distinct ss.
  • ss is one of the following countries: Vietnam, Indonesia, Philippines, Korea, Taiwan, and Japan.
  • 0≤p_u≤p_t≤50000 \le p\_u \le p\_t \le 5000
  • 0≤r_u≤r_t≤3000 \le r\_u \le r\_t \le 300
  • 0≤f≤300 \le f \le 30
  • You may assume that distinct regional contests have different site scores.
  • The size of an input file is no more than 64 kilobytes.

Hint

The document in the problem statement is not official. Please refer to Prof. CJ Hwang's blog https://icpcasia.wp.txstate.edu/ for the official rules.

Examples2

  1. Example 1

    Input
    17
    Japan 500 95 40 30 5
    Vietnam 400 50 150 40 20
    Indonesia 700 25 80 35 20
    Taiwan 200 30 100 35 1
    Korea 600 100 100 70 0
    Philippines 50 10 40 15 15
    
    Expected output
    3
    
  2. Example 2

    Input
    16
    Japan 500 95 40 30 5
    Taiwan 200 30 100 35 1
    Indonesia 700 25 80 35 20
    Philippines 50 10 40 15 15
    Korea 600 100 100 70 0
    Vietnam 400 50 150 40 20
    
    Expected output
    2