P15872 [NOI1998] Individual Income Tax.
Background
NOI1998 D1T1.
Description
A country's individual income tax law stipulates that the main taxable income items for ordinary citizens and the tax amounts are as follows.
For wages and salaries, tax is calculated monthly. The taxable income for a month is the monthly income minus a deduction of $800$ yuan. The tax rates are shown in the table below.
| Bracket | Monthly taxable income | Tax rate |
| :-----------: | :-----------: | :-----------: |
| $1$ | The part not exceeding $500$ yuan | $5\%$ |
| $2$ | The part from $500$ to $2000$ yuan | $10\%$ |
| $3$ | The part from $2000$ to $5000$ yuan | $15\%$ |
| $4$ | The part from $5000$ to $20000$ yuan | $20\%$ |
| $5$ | The part from $20000$ to $40000$ yuan | $25\%$ |
| $6$ | The part from $40000$ to $60000$ yuan | $30\%$ |
| $7$ | The part from $60000$ to $80000$ yuan | $35\%$ |
| $8$ | The part from $80000$ to $100000$ yuan | $40\%$ |
| $9$ | The part exceeding $100000$ yuan | $45\%$ |
For one-time labor remuneration income, tax is calculated per payment. If a single payment does not exceed $4000$ yuan, deduct $800$ yuan; if it exceeds $4000$ yuan, deduct $20\%$ as expenses, and the remaining amount is the taxable income. The tax rates are shown in the table below.
| Bracket | Taxable income per payment | Tax rate |
| :----------: | :----------: | :----------: |
| $1$ | The part not exceeding $20000$ yuan | $20\%$ |
| $2$ | The part from $20000$ to $50000$ yuan | $30\%$ |
| $3$ | The part exceeding $50000$ yuan | $40\%$ |
From the above, we can see that both wages/salaries and one-time labor remuneration income are taxed using a progressive tax rate (marginal tax rate). The progressive tax rate divides the taxable income into several brackets by amount. Each bracket has a tax rate, and the rates increase bracket by bracket. For each taxpayer, their taxable income is split across the brackets it falls into, each part is taxed at the corresponding rate, and the sum of these results is the total tax payable.
For example, suppose a person's total wage for a certain month is $3800$ yuan. After subtracting $800$ yuan, the taxable income is $3000$ yuan. This includes $500$ yuan in bracket $1$, $1500$ yuan in bracket $2$, and $1000$ yuan in bracket $3$. The tax rates are $5\%$, $10\%$, and $15\%$, respectively. The total tax payable is $500\times5\%+1500\times10\%+1000\times15\%=325$. The calculation process is shown in the figure below.
::::align{center}

::::
Now you need to write a program that, given all income information (income type, income time, income amount) for all employees of a company within one year, calculates the total individual income tax payable by all employees of the company for that year.
Input Format
The first line contains a positive integer $M$ ($M\leq50000$), which is the total number of employees in the company (employee IDs are $1,2,\cdots,M$).
Each of the following lines describes one income record of an employee within the year, in the following format:
- Wages and salaries income record: `PAY employee_id income_time income_amount`;
- One-time labor remuneration income record: `INCOME employee_id income_time income_amount`.
Among them, the income time format is: $\tt{MM/DD}$. $\tt{MM}$ denotes the month ($1\leq \tt{MM}\leq 12$), and $\tt{DD}$ denotes the day ($1\leq \tt{DD}\leq 31$). The income amount is a positive integer (unit: yuan), and assume that for each person, each income amount is less than $10^6$ yuan.
The input ends with the character `#`. In the input file, adjacent items on the same line are separated by one or more spaces.
Output Format
Output a single positive number $P$, which is the total individual income tax payable by all employees of the company within the year (unit: yuan). Keep two digits after the decimal point.
Explanation/Hint
- Subtask 0 uses the official CCF testdata, with lower difficulty.
- Subtask 1 uses community testdata.
Translated by ChatGPT 5