CF BUDDY
← Problems·

1393B · Applejack and Storages

1400 · constructive algorithms, data structures, greedy

Problem: This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).

Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend's company. Initially, the company storehouse has nn planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack's friend can provide her with information about each operation. For convenience, he will give her information according to the following format:

  • ++ xx: the storehouse received a plank with length xx
  • - xx: one plank with length xx was removed from the storehouse (it is guaranteed that the storehouse had some planks with length xx).

Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help!

We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides.

Input Format: The first line contains a single integer nn (1n1051 \le n \le 10^5): the initial amount of planks at the company's storehouse, the second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1051 \le a_i \le 10^5): the lengths of the planks.

The third line contains a single integer qq (1q1051 \le q \le 10^5): the number of events in the company. Each of the next qq lines contains a description of the events in a given format: the type of the event (a symbol ++ or -) is given first, then goes the integer xx (1x1051 \le x \le 10^5).

Output Format: After every event in the company, print "YES" if two storages of the required shape can be built from the planks of that company's set, and print "NO" otherwise. You can print each letter in any case (upper or lower).

Note: After the second event Applejack can build a rectangular storage using planks with lengths 11, 22, 11, 22 and a square storage using planks with lengths 11, 11, 11, 11.

After the sixth event Applejack can build a rectangular storage using planks with lengths 22, 22, 22, 22 and a square storage using planks with lengths 11, 11, 11, 11.

Sample Cases

Case 1

Input

6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2

Output

NO
YES
NO
NO
NO
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback