Under construction

Still being built. Things may change

Mixture

Time limit2sMemory limit256 MB

Summary
After each add or remove of a bottle, find the fewest shelf bottles whose nonnegative combination gives the target salt:pepper:garlic ratio, or 0 if none exists.
Level

Hard8 of 10

Topics
Geometry, Segment tree, Math
Solved
No attempts yet

Problem

Serge is the chef of the famous restaurant "Salt, Pepper & Garlic". He wants to earn his first Michelin star. He has been told that a secret expert will visit the restaurant this evening.

The expert's name is not disclosed, but Serge knows which dish the expert will order and what the expert likes. The expert requires a very precise ratio of salt, pepper, and garlic powder in the dish.

Serge keeps bottles of mixtures of salt, pepper, and garlic powder on a special shelf. For each bottle, he knows the exact amount of each ingredient in kilograms. He can combine any number of bottled mixtures, or use one bottle directly, to get a mixture with the ratio the dish needs.

The amount of mixture added to a dish is very small, so you may assume the bottles always contain enough ingredients. The ratio values can be very large, however.

Serge wants to know whether he can make the expert's favourite mixture from the bottles on the shelf and, if so, the minimum number of bottles needed. The shelf changes over time as Serge receives new bottles or lends his bottles to other chefs, so he needs the answer after each change.

MixtureSalt (kg)Pepper (kg)Garlic powder (kg)
1102030
2300200100
3121527

Table 1: Bottles on the shelf

The expert's favourite mixture is 1 : 1 : 1, and the shelf has three bottles (Table 1). Bottles 1 and 2 used in equivalent amounts are enough to make the desired mixture. If bottle 2 is removed, the desired mixture can no longer be made.

Input

The first line contains three non-negative integers SfS_f, PfP_f, and GfG_f (0≤Sf,Pf,Gf0 \le S_f, P_f, G_f, 0<Sf+Pf+Gf≤1060 < S_f + P_f + G_f \le 10^6), the amounts of salt, pepper, and garlic powder in the expert's favourite mixture. For any real α>0\alpha > 0, (αSf,αPf,αGf)(\alpha S_f, \alpha P_f, \alpha G_f) is also a favourite mixture.

The second line contains a positive integer NN (N≤100000N \le 100000), the number of changes to the shelf. The shelf is empty at the start. Each of the next NN lines describes one change.

  • To add a bottle, the line starts with the letter A, followed by three non-negative integers SiS_i, PiP_i, and GiG_i (0≤Si,Pi,Gi0 \le S_i, P_i, G_i, 0<Si+Pi+Gi≤1060 < S_i + P_i + G_i \le 10^6). Bottles are numbered consecutively from 1, so the ii-th added bottle has number ii.
  • To remove a bottle, the line starts with the letter R, followed by the bottle number rir_i. All removed numbers are distinct, and rir_i never exceeds the number of bottles added so far.

Output

Print NN lines. The jj-th line contains the minimum number of bottles needed to make a mixture with the expert's favourite proportions, using the bottles on the shelf after the first jj changes. Print 0 if the mixture cannot be made.

Hint

Bottles 1 and 3 contain salt, pepper, and garlic powder in the same proportions.

Examples1

  1. Example 1

    Input
    1 2 3
    6
    A 5 6 7
    A 3 10 17
    R 1
    A 15 18 21
    A 5 10 15
    R 3
    
    Expected output
    0
    2
    0
    2
    1
    1