Under construction

Still being built. Things may change

Stock Simulation

Time limit1sMemory limit1024 MB

Summary
Simulate buying, selling, and price changes across companies grouped by number, then print the cash and total liquidation value at each menu 6 or 7 query.
Level

Easy3 of 10

Topics
Simulation, Hash map, Implementation
Solved
No attempts yet

Problem

Hayi lost money in the stock market again today. Yutil, who had watched Hayi keep losing money, gave Hayi a USB drive with a stock simulation program and suggested practicing with it.

Hayi got home and plugged the USB into the computer. When the program started, seven menus appeared.

  • 1 AA BB: Buy BB shares of company AA. If Hayi cannot afford BB shares with the cash currently held, nothing is bought.
  • 2 AA BB: Sell BB shares of company AA. If Hayi holds SAS_A shares of company AA, and SA=0S_A = 0, nothing happens. If B≥SAB \ge S_A, all SAS_A shares are sold.
  • 3 AA CC: The stock price of company AA rises by CC won. If C<0C < 0, the price falls by ∣C∣|C| won.
  • 4 DD CC: The stock prices of the companies in group DD rise by CC won. If C<0C < 0, the prices fall by ∣C∣|C| won.
  • 5 DD EE: The stock prices of the companies in group DD rise by EE%. If E<0E < 0, the prices fall by ∣E∣|E|%.
  • 6: Print the cash Hayi currently holds.
  • 7: Print the total cash Hayi would have if all currently held shares were sold.

The program manual has the following details.

  • At the start, Hayi holds no shares.
  • Company names are case-sensitive.
  • Shares are bought and sold in units of 10 won. For menu 5, the prices are updated by the rate first, and then the ones digit is truncated.
  • At all times, the stock price PiP_i of each company satisfies 0≤Pi≤2×1090 \le P_i \le 2 \times 10^{9} (1≤i≤N1 \le i \le N).
  • At all times, the total cash obtained by selling every share Hayi holds does not exceed 2×10122 \times 10^{12} won.
  • In menu inputs 1, 2, and 3, AA is always a company listed on the market.
  • In menu inputs 4 and 5, at least one company belongs to group DD.
  • Menu 6 or 7 appears at least once.

Hayi started trying the program with various data. Then a problem appeared. When Hayi chose menu 6 or 7, the program should print the cash, but it printed only ???.

Hayi called Yutil and said the program had a problem. Yutil said that if Hayi gave all the input data, he would report the results for menu 6 or 7. However, Yutil was too busy building another program, so he asked whether you could handle this task instead. Let's help Yutil!

Input

The first line contains the number of listed companies NN, the cash Hayi holds MM, and the number of menu inputs QQ, separated by spaces. (1≤N≤1001 \le N \le 100; 106≤M≤10710^6 \le M \le 10^7; 1≤Q≤5001 \le Q \le 500)

From the second line through the next NN lines, each line contains the group number GG of a company, the company name HH, and the price PP of one share at the start of the simulation, separated by spaces. A company name is a string of up to 30 English letters, and no company name appears more than once. (1≤G≤1001 \le G \le 100; 0≤P≤30 0000 \le P \le 30\,000; PP is a multiple of 10)

From the next line through the next QQ lines, the menu inputs are given. (1≤B≤1001 \le B \le 100; −5 000≤C≤5 000-5\,000 \le C \le 5\,000; 1≤D≤1001 \le D \le 100; −30≤E≤30-30 \le E \le 30; CC is a multiple of 10)

All numbers in the input are integers.

Output

Print the results of menu 6 and menu 7 inputs, one per line.

Examples2

  1. Example 1

    Input
    3 5200000 12
    1 AAA 20000
    1 BBB 25000
    2 CCC 30000
    1 AAA 100
    1 BBB 23
    6
    1 CCC 7
    3 AAA 4350
    7
    4 1 -5000
    5 2 15
    7
    2 AAA 3
    2 CCC 1
    6
    
    Expected output
    2625000
    5635000
    5051500
    2507550
    
  2. Example 2

    Input
    3 1000000 12
    1 wolhyang 28310
    1 ArenA 18420
    2 UTIL 9560
    1 wolhyang 1
    1 ArenA 6
    6
    1 UTIL 9
    4 1 -5000
    7
    3 wolhyang -1270
    5 2 15
    7
    2 ArenA 2
    2 UTIL 7
    6
    
    Expected output
    861170
    965000
    976600
    878900