description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
def main():
n = int(ii())
data = idata()
slov = {}
sum2, sum4 = 0, 0
for i in range(n):
slov[data[i]] = 1 if data[i] not in slov else slov[data[i]] + 1
if slov[data[i]] % 2 == 0:
sum2 += 1
if slov[data[i]] % 4 == 0:
sum4 += 1
for i in range(int(ii())):
d = input().split()
if d[0] == "+":
slov[int(d[1])] = 1 if int(d[1]) not in slov else slov[int(d[1])] + 1
if slov[int(d[1])] % 2 == 0:
sum2 += 1
if slov[int(d[1])] % 4 == 0:
sum4 += 1
else:
slov[int(d[1])] -= 1
if slov[int(d[1])] % 2 == 1:
sum2 -= 1
if slov[int(d[1])] % 4 == 3:
sum4 -= 1
if sum2 > 3 and sum4 > 0:
print("YES")
else:
print("NO")
main() | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
dic = {}
ans = {(8): 0, (2): 0, (6): 0, (4): 0}
for i in arr:
if dic.get(i, -1) == -1:
dic[i] = 1
else:
dic[i] += 1
for i in dic:
if dic[i] >= 8:
ans[8] += 1
if dic[i] >= 6:
ans[6] += 1
if dic[i] >= 4:
ans[4] += 1
if dic[i] >= 2:
ans[2] += 1
for i in range(int(input())):
s, x = input().split()
flag = False
if s == "+":
x = int(x)
if dic.get(x, -1) != -1:
if dic[x] == 7:
ans[8] += 1
elif dic[x] == 5:
ans[6] += 1
elif dic[x] == 3:
ans[4] += 1
elif dic[x] == 1:
ans[2] += 1
dic[x] += 1
else:
dic[x] = 1
if ans[8] >= 1:
flag = True
elif ans[6] >= 1 and ans[2] >= 2:
flag = True
elif ans[4] >= 2:
flag = True
elif ans[4] >= 1 and ans[2] >= 3:
flag = True
else:
x = int(x)
if dic[x] == 8:
ans[8] -= 1
elif dic[x] == 6:
ans[6] -= 1
elif dic[x] == 4:
ans[4] -= 1
elif dic[x] == 2:
ans[2] -= 1
dic[x] -= 1
if ans[8] >= 1:
flag = True
elif ans[6] >= 1 and ans[2] >= 2:
flag = True
elif ans[4] >= 2:
flag = True
elif ans[4] >= 1 and ans[2] >= 3:
flag = True
if flag:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
n = int(input())
L = list(map(int, input().split()))
q = int(input())
ct2 = 0
ct4 = 0
ct6 = 0
ct8 = 0
ct = [0] * (10**5 + 10)
for i in L:
ct[i] += 1
for i in ct:
if i > 1:
ct2 += 1
if i > 3:
ct4 += 1
if i > 5:
ct6 += 1
if i > 7:
ct8 += 1
for i in " " * q:
a, b = input().split()
b = int(b)
if a == "+":
ct[b] += 1
if ct[b] == 2:
ct2 += 1
if ct[b] == 4:
ct4 += 1
if ct[b] == 6:
ct6 += 1
if ct[b] == 8:
ct8 += 1
else:
ct[b] -= 1
if ct[b] == 1:
ct2 -= 1
if ct[b] == 3:
ct4 -= 1
if ct[b] == 5:
ct6 -= 1
if ct[b] == 7:
ct8 -= 1
if ct2 >= 2 and ct6 >= 1:
print("YES")
elif ct2 >= 3 and ct4 >= 1:
print("YES")
elif ct4 >= 2:
print("YES")
elif ct8:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
sys.setrecursionlimit(10000)
n = int(input())
my_dict = {}
four_same = 0
two_same = 0
a = list(map(int, input().split()))
for i in a:
if i in my_dict:
my_dict[i] += 1
if my_dict[i] % 4 == 0:
four_same += 1
two_same -= 1
elif my_dict[i] % 2 == 0:
two_same += 1
else:
my_dict[i] = 1
q = int(input())
for _ in range(q):
symbol, x = input().split()
x = int(x)
if symbol == "+":
if x in my_dict:
my_dict[x] += 1
if my_dict[x] % 4 == 0:
four_same += 1
two_same -= 1
elif my_dict[x] % 2 == 0:
two_same += 1
else:
my_dict[x] = 1
else:
if my_dict[x] % 4 == 0:
four_same -= 1
two_same += 1
elif my_dict[x] % 2 == 0:
two_same -= 1
my_dict[x] -= 1
if four_same == 1 and two_same > 1:
print("YES")
elif four_same > 1:
print("YES")
else:
print("NO") | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
ans = []
n = int(input())
a = list(map(int, input().split()))
freq = [0] * 100001
c2, c4, c6, c8 = 0, 0, 0, 0
for k in a:
freq[k] += 1
if freq[k] == 2:
c2 += 1
elif freq[k] == 4:
c2 -= 1
c4 += 1
elif freq[k] == 6:
c4 -= 1
c6 += 1
elif freq[k] == 8:
c6 -= 1
c8 += 1
q = int(input())
for _ in range(q):
s, k_str = input().split()
k = int(k_str)
if s == "+":
freq[k] += 1
if freq[k] == 2:
c2 += 1
elif freq[k] == 4:
c2 -= 1
c4 += 1
elif freq[k] == 6:
c4 -= 1
c6 += 1
elif freq[k] == 8:
c6 -= 1
c8 += 1
else:
freq[k] -= 1
if freq[k] == 1:
c2 -= 1
elif freq[k] == 3:
c4 -= 1
c2 += 1
elif freq[k] == 5:
c6 -= 1
c4 += 1
elif freq[k] == 7:
c8 -= 1
c6 += 1
if c8 >= 1 or c4 + c6 >= 2 or c4 >= 1 and c2 >= 2 or c6 >= 1 and c2 >= 1:
ans.append("YES")
else:
ans.append("NO")
print("\n".join(ans)) | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = False
lengths = input().split()
length_count = {}
number_of_2 = 0
number_of_4 = 0
number_of_6 = 0
number_of_8 = 0
for l in lengths:
if l in length_count:
length_count[l] += 1
if length_count[l] == 8:
number_of_8 += 1
number_of_6 -= 1
if length_count[l] == 6:
number_of_6 += 1
number_of_4 -= 1
if length_count[l] == 4:
number_of_4 += 1
number_of_2 -= 1
if length_count[l] == 2:
number_of_2 += 1
else:
length_count[l] = 1
for _ in range(int(input())):
x, l = input().split()
if x == "+":
if l in length_count:
length_count[l] += 1
if length_count[l] == 8:
number_of_8 += 1
number_of_6 -= 1
if length_count[l] == 6:
number_of_6 += 1
number_of_4 -= 1
if length_count[l] == 4:
number_of_4 += 1
number_of_2 -= 1
if length_count[l] == 2:
number_of_2 += 1
else:
length_count[l] = 1
else:
if length_count[l] == 8:
number_of_8 -= 1
number_of_6 += 1
if length_count[l] == 6:
number_of_6 -= 1
number_of_4 += 1
if length_count[l] == 4:
number_of_4 -= 1
number_of_2 += 1
if length_count[l] == 2:
number_of_2 -= 1
length_count[l] -= 1
if number_of_8 >= 1:
print("YES")
elif number_of_6 >= 1 and number_of_6 + number_of_2 + number_of_4 >= 2:
print("YES")
elif number_of_4 >= 2:
print("YES")
elif number_of_4 >= 1 and number_of_2 >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
N = 100010
n = ni()
a = nl()
q = ni()
mmp = [0] * N
for i in a:
mmp[i] += 1
cnt1, cnt2 = 0, 0
for i in range(0, N):
if mmp[i] >= 4:
cnt1 += 1
cnt2 += mmp[i] // 2
for _ in range(q):
ch, x = input().split(" ")
x = int(x)
if ch == "+":
cnt2 -= mmp[x] // 2
mmp[x] += 1
cnt2 += mmp[x] // 2
if mmp[x] == 4:
cnt1 += 1
else:
cnt2 -= mmp[x] // 2
mmp[x] -= 1
cnt2 += mmp[x] // 2
if mmp[x] == 3:
cnt1 -= 1
print("YES" if cnt1 > 0 and cnt2 > 3 else "NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | a = [0] * (10**5 + 1)
n = int(input())
num2 = 0
num4 = 0
m = list(map(int, input().split()))
for i in range(n):
a[m[i]] += 1
if a[m[i]] % 4 == 0:
num4 += 1
if a[m[i]] % 2 == 0:
num2 += 1
q = int(input())
for i in range(q):
op, x = map(str, input().split())
x = int(x)
if op == "+":
a[x] += 1
if a[x] % 4 == 0:
num4 += 1
if a[x] % 2 == 0:
num2 += 1
if op == "-":
a[x] -= 1
if a[x] % 4 == 3:
num4 -= 1
if a[x] % 2 == 1:
num2 -= 1
if num4 >= 1 and num2 >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | boards = {}
min2, min4 = 0, 0
def record(sign, x):
global min2, min4
if sign == "+":
if x in boards:
boards[x] += 1
if boards[x] % 4 == 0:
min4 += 1
min2 -= 1
elif boards[x] % 2 == 0:
min2 += 1
else:
boards[x] = 1
else:
boards[x] -= 1
if boards[x] % 4 == 3:
min4 -= 1
min2 += 1
elif boards[x] % 2 == 1:
min2 -= 1
n = int(input())
for x in input().split():
record("+", int(x))
for qi in range(int(input())):
sign, x = input().split()
record(sign, int(x))
print("YES" if min4 > 1 or min4 and min2 > 1 else "NO") | ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF IF VAR STRING IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
L = list(map(int, input().split()))
store = [(0) for i in range(100001)]
ctr4 = set()
ctr2 = set()
ctr6 = set()
ctr8 = set()
for i in L:
store[i] += 1
if store[i] % 8 == 0:
ctr8.add(i)
ctr6.remove(i)
elif store[i] % 6 == 0:
ctr6.add(i)
ctr4.remove(i)
elif store[i] % 4 == 0:
ctr4.add(i)
ctr2.remove(i)
elif store[i] % 2 == 0:
ctr2.add(i)
t = int(input())
for T in range(t):
op = input().split()
if op[0] == "+":
i = int(op[1])
store[i] += 1
if store[i] % 8 == 0:
ctr8.add(i)
ctr6.remove(i)
elif store[i] % 6 == 0:
ctr6.add(i)
ctr4.remove(i)
elif store[i] % 4 == 0:
ctr4.add(i)
ctr2.remove(i)
elif store[i] % 2 == 0:
ctr2.add(i)
else:
i = int(op[1])
if store[i] % 8 == 0:
ctr6.add(i)
ctr8.remove(i)
elif store[i] % 6 == 0:
ctr4.add(i)
ctr6.remove(i)
elif store[i] % 4 == 0:
ctr2.add(i)
ctr4.remove(i)
elif store[i] % 2 == 0:
ctr2.remove(i)
store[i] -= 1
if (
len(ctr8) >= 1
or len(ctr4) >= 2
or len(ctr6) >= 1
and len(ctr2) >= 1
or len(ctr4) >= 1
and len(ctr2) >= 2
or len(ctr4) >= 1
and len(ctr6) >= 1
or len(ctr6) >= 2
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
lis = list(map(int, input().split()))
has = [0] * 100005
for i in lis:
has[i] += 1
tmp = sorted(has[:], reverse=True)
q = int(input())
for _ in range(q):
a, b = list(map(str, input().split()))
if a == "+":
b = int(b)
fin = has[b]
l = 0
r = 100000
while l <= r:
mid = l + (r - l) // 2
if tmp[mid] <= fin:
r = mid - 1
else:
l = mid + 1
has[b] += 1
tmp[l] += 1
if (
tmp[0] >= 8
or tmp[0] >= 6
and tmp[1] >= 2
or tmp[0] >= 4
and tmp[1] >= 2
and tmp[2] >= 2
or tmp[0] >= 4
and tmp[1] >= 4
):
print("YES")
else:
print("NO")
else:
b = int(b)
fin = has[b]
l = 0
r = 100000
while l <= r:
mid = l + (r - l) // 2
if tmp[mid] < fin:
r = mid - 1
else:
l = mid + 1
has[b] -= 1
tmp[r] -= 1
if (
tmp[0] >= 8
or tmp[0] >= 6
and tmp[1] >= 2
or tmp[0] >= 4
and tmp[1] >= 2
and tmp[2] >= 2
or tmp[0] >= 4
and tmp[1] >= 4
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
x = input()
a = []
a = x.split(" ")
c = {}
for i in range(n):
a[i] = int(a[i])
if a[i] not in c:
c[a[i]] = 1
else:
c[a[i]] += 1
c4, c2, c8, c6 = 0, 0, 0, 0
for k in c.keys():
if c[k] >= 8:
c8 += 1
elif c[k] >= 6:
c6 += 1
elif c[k] >= 4:
c4 += 1
elif c[k] >= 2:
c2 += 1
q = int(input())
for i in range(q):
z = input()
s, x = z.split(" ")
x = int(x)
if s == "+":
if x not in c:
c[x] = 1
else:
c[x] += 1
if c[x] == 8:
c8 += 1
c6 -= 1
if c6 == -1:
c6 += 1
elif c[x] == 6:
c6 += 1
c4 -= 1
if c4 == -1:
c4 += 1
elif c[x] == 4:
c4 += 1
c2 -= 1
if c2 == -1:
c2 += 1
elif c[x] == 2:
c2 += 1
else:
c[x] -= 1
if c[x] == -1:
c[x] += 1
if c[x] == 1:
c2 -= 1
if c2 == -1:
c2 += 1
elif c[x] == 3:
c4 -= 1
c2 += 1
if c4 == -1:
c4 += 1
elif c[x] == 5:
c6 -= 1
c4 += 1
if c6 == -1:
c6 += 1
elif c[x] == 7:
c8 -= 1
c6 += 1
if c8 == -1:
c8 += 1
if (
c8 >= 1
or c4 >= 1
and c2 >= 2
or c6 >= 1
and c2 >= 1
or c6 >= 1
and c4 >= 1
or c4 >= 2
or c6 >= 1
and c2 >= 2
or c6 >= 2
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | N = int(input())
A = {}
sq = set()
rec = set()
for a in map(int, input().split()):
c = A.setdefault(a, 0) + 1
A[a] = c
if c > 3:
sq.add(a)
if c > 1:
rec.add(a)
Q = int(input())
for _ in range(Q):
op, x = input().split()
a = int(x)
if op == "+":
c = A.setdefault(a, 0) + 1
else:
c = A.setdefault(a, 0) - 1
A[a] = c
if c > 3:
sq.add(a)
else:
sq.discard(a)
if c > 1:
rec.add(a)
else:
rec.discard(a)
if len(sq) > 1:
print("Yes")
elif len(sq) == 1:
if len(rec) > 2:
print("Yes")
elif len(rec) == 2:
if sq and rec:
t = list(rec)
c1 = A[t[0]]
c2 = A[t[1]]
if c1 > 5 or c2 > 5:
print("Yes")
else:
print("No")
else:
print("Yes")
else:
t = list(rec)
c1 = A[t[0]]
if c1 > 7:
print("Yes")
else:
print("No")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = []
lengths = [0] * (10**5 + 1)
counter4 = 0
counter6 = 0
counter8 = 0
counter2 = 0
for i in a:
lengths[i] += 1
for i in lengths:
if i >= 8:
counter8 += 1
elif i >= 6:
counter6 += 1
elif i >= 4:
counter4 += 1
elif i >= 2:
counter2 += 1
for i in range(q):
inf = list(input().split())
if inf[0] == "+":
if lengths[int(inf[1])] == 3:
counter4 += 1
counter2 -= 1
elif lengths[int(inf[1])] == 1:
counter2 += 1
elif lengths[int(inf[1])] == 7:
counter8 += 1
counter6 -= 1
elif lengths[int(inf[1])] == 5:
counter6 += 1
counter4 -= 1
lengths[int(inf[1])] += 1
else:
if lengths[int(inf[1])] == 4:
counter4 -= 1
counter2 += 1
elif lengths[int(inf[1])] == 2:
counter2 -= 1
elif lengths[int(inf[1])] == 6:
counter6 -= 1
counter4 += 1
elif lengths[int(inf[1])] == 8:
counter8 -= 1
counter6 += 1
lengths[int(inf[1])] -= 1
if (
counter8 >= 1
or counter6 >= 2
or counter6 >= 1
and (counter2 >= 1 or counter4 >= 1)
or counter4 >= 2
or counter4 >= 1
and counter2 >= 2
):
ans.append("YES")
else:
ans.append("NO")
for i in ans:
print(i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
cnt = [0] * (10**5 + 1)
cnt2 = 0
cnt4 = 0
for x in map(int, input().split()):
cnt2 -= cnt[x] // 2
cnt4 -= cnt[x] // 4
cnt[x] += 1
cnt2 += cnt[x] // 2
cnt4 += cnt[x] // 4
for _ in range(int(input())):
sign, x = input().split()
x = int(x)
cnt2 -= cnt[x] // 2
cnt4 -= cnt[x] // 4
if sign == "+":
cnt[x] += 1
else:
cnt[x] -= 1
cnt2 += cnt[x] // 2
cnt4 += cnt[x] // 4
if cnt4 >= 1 and cnt2 >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = {}
l = {(2): set(), (4): set()}
for i in range(n):
if a[i] not in d:
d[a[i]] = 1
else:
d[a[i]] += 1
if d[a[i]] == 2:
l[2].add(a[i])
if d[a[i]] == 4:
l[4].add(a[i])
l[2].remove(a[i])
l2, l4 = len(l[2]), len(l[4])
for _ in range(int(input())):
ch, x = input().strip().split()
x = int(x)
if ch == "+":
if x not in d:
d[x] = 1
else:
d[x] += 1
if d[x] == 2:
l[2].add(x)
l2 += 1
if d[x] == 4:
l[4].add(x)
l4 += 1
l[2].remove(x)
l2 -= 1
f = 0
if l4 > 1:
f = 1
if l4 == 1:
e = l[4].pop()
if d[e] // 4 > 1:
f = 1
if 5 < d[e] < 8 and l2 > 0:
f = 1
if l2 > 1:
f = 1
l[4].add(e)
if f:
print("YES")
else:
print("NO")
else:
d[x] -= 1
if d[x] == 1:
l[2].remove(x)
l2 -= 1
if d[x] == 3:
l[4].remove(x)
l4 -= 1
l[2].add(x)
l2 += 1
f = 0
if l4 > 1:
f = 1
if l4 == 1:
e = l[4].pop()
if d[e] // 4 > 1:
f = 1
if 5 < d[e] < 8 and l2 > 0:
f = 1
if l2 > 1:
f = 1
l[4].add(e)
if f:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
t = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
a = [(0) for i in range(100001)]
cnt2, cnt4 = 0, 0
for i in l:
a[i] += 1
for i in range(100001):
cnt2 += a[i] // 2
cnt4 += a[i] // 4
t = int(sys.stdin.readline())
for _ in range(t):
sign, amt = sys.stdin.readline().split()
amt = int(amt)
cnt2 -= a[amt] // 2
cnt4 -= a[amt] // 4
if sign == "+":
a[amt] += 1
else:
a[amt] -= 1
cnt2 += a[amt] // 2
cnt4 += a[amt] // 4
if cnt2 - 2 >= 2 and cnt4 >= 1:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
q = int(stdin.readline())
lis = [0] * (10**5 + 10)
four = 0
two = 0
for i in a:
lis[i] += 1
if lis[i] % 2 == 0:
two += 1
if lis[i] % 4 == 0:
four += 1
for loop in range(q):
c, l = stdin.readline().split()
l = int(l)
if c == "+":
lis[l] += 1
if lis[l] % 2 == 0:
two += 1
if lis[l] % 4 == 0:
four += 1
else:
if lis[l] % 2 == 0:
two -= 1
if lis[l] % 4 == 0:
four -= 1
lis[l] -= 1
if four >= 1 and two >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
l = list(map(int, input().split()))
q = int(input())
cnt = {}
for i in range(1, 10**5 + 1):
cnt[i] = 0
cnt2 = 0
cnt4 = 0
for x in l:
cnt2 -= cnt[x] // 2
cnt4 -= cnt[x] // 4
cnt[x] += 1
cnt2 += cnt[x] // 2
cnt4 += cnt[x] // 4
for _ in range(q):
s = input()
e1 = s[0]
e2 = int(s[2:])
cnt2 -= cnt[e2] // 2
cnt4 -= cnt[e2] // 4
if e1 == "+":
cnt[e2] += 1
else:
cnt[e2] -= 1
cnt2 += cnt[e2] // 2
cnt4 += cnt[e2] // 4
if cnt2 >= 4 and cnt4 >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = [int(i) for i in input().split()]
eight = {}
six = {}
four = {}
two = {}
one = {}
for i in a:
if i not in eight:
eight[i] = 1
else:
eight[i] += 1
st = set()
for i in eight:
if eight[i] >= 8:
continue
elif eight[i] >= 6:
six[i] = eight[i]
elif eight[i] >= 4:
four[i] = eight[i]
elif eight[i] >= 2:
two[i] = eight[i]
else:
one[i] = eight[i]
st.add(i)
for i in st:
del eight[i]
var = [eight, six, four, two, one]
chk = [8, 6, 4, 2, 1]
for i in range(int(input())):
x, y = map(str, input().split())
y = int(y)
do = 1
if x == "-":
do *= -1
flag = 0
for j in range(5):
if y in var[j]:
flag = 1
var[j][y] += do
it = [var[j][y], j]
for i in range(5):
if it[0] >= chk[i]:
var[i][y] = var[it[1]][y]
if it[1] != i:
del var[it[1]][y]
break
if flag == 1:
break
if flag == 0:
if y not in var[-1]:
var[-1][y] = do
else:
var[-1][y] += 1
if len(var[0]) >= 1:
print("YES")
elif len(var[1]) >= 1 and len(var[1]) - 1 + len(var[2]) + len(var[3]) >= 1:
print("YES")
elif len(var[2]) > 1 or len(var[2]) == 1 and len(var[3]) >= 2:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().rstrip().split(" ")))
m = int(stdin.readline().rstrip())
d = {}
for i in range(n):
if not d.get(str(l[i]), 0):
d[str(l[i])] = 0
d[str(l[i])] += 1
c_2 = 0
c_4 = 0
c_6 = 0
c_8 = 0
for k, v in d.items():
if v >= 8:
c_8 += 1
elif v >= 6:
c_6 += 1
elif v > 3:
c_4 += 1
elif v >= 2:
c_2 += 1
for i in range(m):
s, val = stdin.readline().rstrip().split(" ")
if not d.get(val, 0):
d[val] = 0
if s == "-":
d[str(val)] -= 1
if d[val] == 7:
c_8 -= 1
c_6 += 1
elif d[val] == 5:
c_6 -= 1
c_4 += 1
elif d[val] == 3:
c_2 += 1
c_4 -= 1
elif d[val] == 1:
c_2 -= 1
elif s == "+":
d[val] += 1
if d[val] == 8:
c_6 -= 1
c_8 += 1
elif d[val] == 6:
c_4 -= 1
c_6 += 1
elif d[val] == 4:
c_2 -= 1
c_4 += 1
elif d[val] == 2:
c_2 += 1
if c_8 >= 1 or c_4 >= 2 or c_6 >= 2:
print("YES")
elif c_6 >= 1 and c_4 >= 1:
print("YES")
elif c_6 >= 1 and c_2 >= 1:
print("YES")
elif c_4 >= 1 and c_2 > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
input = stdin.readline
dicti = {}
n = int(input())
arr = list(map(int, input().split(" ")))
for i in range(n):
dicti[arr[i]] = dicti.get(arr[i], 0) + 1
twothree = set()
fourfive = set()
sixseven = set()
eightover = set()
for i in dicti:
if dicti[i] == 2 or dicti[i] == 3:
twothree.add(i)
elif dicti[i] == 4 or dicti[i] == 5:
fourfive.add(i)
elif dicti[i] == 6 or dicti[i] == 7:
sixseven.add(i)
elif dicti[i] >= 8:
eightover.add(i)
for i in range(int(input())):
a, b = input().strip().split(" ")
b = int(b)
if a == "+":
dicti[b] = dicti.get(b, 0) + 1
if dicti[b] == 2:
twothree.add(b)
elif dicti[b] == 4:
twothree.remove(b)
fourfive.add(b)
elif dicti[b] == 6:
fourfive.remove(b)
sixseven.add(b)
elif dicti[b] == 8:
sixseven.remove(b)
eightover.add(b)
else:
dicti[b] = dicti.get(b, 0) - 1
if dicti[b] == 1:
twothree.remove(b)
elif dicti[b] == 3:
fourfive.remove(b)
twothree.add(b)
elif dicti[b] == 5:
sixseven.remove(b)
fourfive.add(b)
elif dicti[b] == 7:
eightover.remove(b)
sixseven.add(b)
if len(eightover) > 0:
print("YES")
elif len(sixseven) > 0 and (
len(sixseven) > 1 or len(fourfive) > 0 or len(twothree) > 0
):
print("YES")
elif len(fourfive) > 1:
print("YES")
elif len(fourfive) > 0 and len(twothree) > 1:
print("YES")
else:
print("NO") | ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
l = list(map(int, input().split()))
count = [(0) for x in range(100002)]
a = 0
b = 0
for i in range(n):
a -= count[l[i]] // 2
b -= count[l[i]] // 4
count[l[i]] += 1
a += count[l[i]] // 2
b += count[l[i]] // 4
for i in range(int(input())):
x, y = input().split()
a -= count[int(y)] // 2
b -= count[int(y)] // 4
if x == "+":
count[int(y)] += 1
else:
count[int(y)] -= 1
a += count[int(y)] // 2
b += count[int(y)] // 4
if a >= 4 and b >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | t = 1
while t:
t = t - 1
n = int(input())
a = list(map(int, input().split()))
d = dict()
cnt2 = 0
cnt4 = 0
for i in a:
d[i] = d.get(i, 0) + 1
for i in d.values():
cnt2 += i // 2
cnt4 += i // 4
q = int(input())
for i in range(q):
s, g = input().split()
g = int(g)
if s == "+":
pre = d.get(g, 0)
if pre == 0:
d[g] = 1
else:
d[g] += 1
if pre % 2 and d[g] % 2 == 0:
cnt2 += 1
if pre % 4 and d[g] % 4 == 0:
cnt4 += 1
if s == "-":
pre = d.get(g, 0)
if pre == 0:
d[g] = 0
else:
d[g] -= 1
if pre % 2 == 0 and d[g] % 2 == 1:
cnt2 -= 1
if pre % 4 == 0 and d[g] % 4 == 3:
cnt4 -= 1
if cnt4 >= 2:
print("YES")
elif cnt4 == 1 and cnt2 >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
q = int(input())
dic = {}
two = 0
four = 0
for i in arr:
try:
dic[i] += 1
if dic[i] >= 4 and dic[i] % 4 == 0:
four += 1
two -= 1
elif dic[i] % 4 >= 2 and dic[i] % 2 == 0:
two += 1
except:
dic[i] = 1
while q:
l = list(input().split())
if l[0] == "+":
try:
i = int(l[1])
dic[i] += 1
if dic[i] % 4 == 0:
four += 1
two -= 1
elif dic[i] % 4 >= 2 and dic[i] % 2 == 0:
two += 1
except:
dic[int(l[1])] = 1
else:
try:
i = int(l[1])
if dic[i] > 1:
if dic[i] % 4 == 0:
four -= 1
two += 1
dic[i] -= 1
elif dic[i] % 4 >= 2 and dic[i] % 2 == 0:
two -= 1
dic[i] -= 1
elif dic[i] % 4 in [1, 3]:
dic[i] -= 1
else:
dic[i] -= 1
except:
dic[int(l[1])] = 1
if four >= 2 or four >= 1 and two >= 2:
print("YES")
else:
print("NO")
q -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER LIST NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | x = int(input())
d = [int(i) for i in input().split()]
dict1 = {}
for i in d:
if dict1.get(i) == None:
dict1[i] = 1
else:
dict1[i] += 1
count = 0
count1 = 0
for i in dict1:
count += dict1[i] // 2
count1 += dict1[i] // 4
for i in range(int(input())):
g = [j for j in input().split()]
if dict1.get(int(g[1])) == None:
dict1[int(g[1])] = 1
else:
count -= dict1[int(g[1])] // 2
count1 -= dict1[int(g[1])] // 4
if g[0] == "+":
dict1[int(g[1])] += 1
else:
dict1[int(g[1])] -= 1
count += dict1[int(g[1])] // 2
count1 += dict1[int(g[1])] // 4
if count >= 4 and count1 >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | mod = 998244353
n = int(input())
a = list(map(int, input().split()))
d = dict()
two = 0
four = 0
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
for i in d:
two += d[i] // 2
four += d[i] // 4
m = int(input())
for i in range(m):
s = input().split()
if s[0] == "+":
l = int(s[1])
if l in d:
d[l] += 1
else:
d[l] = 1
if d[l] % 2 == 0:
two += 1
if d[l] % 4 == 0:
four += 1
else:
l = int(s[1])
d[l] -= 1
if d[l] % 2 == 1:
two -= 1
if d[l] % 4 == 3:
four -= 1
if four > 0 and two > 3:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
t = int(input())
s = [0] * (10**5 + 5)
two = 0
four = 0
lol = 0
for i in a:
s[i] += 1
lol = s[i]
if lol == 2:
two += 1
elif lol == 4:
two -= 1
four += 1
elif lol == 6:
two += 1
elif lol == 8:
two += 1
for _ in range(t):
d, q = input().split()
q = int(q)
if d == "-":
s[q] -= 1
lol = s[q]
if lol == 1:
two -= 1
elif lol == 3:
two += 1
four -= 1
elif lol == 5:
two -= 1
elif lol == 7:
two -= 1
else:
s[q] += 1
lol = s[q]
if lol == 2:
two += 1
elif lol == 4:
two -= 1
four += 1
elif lol == 6:
two += 1
elif lol == 8:
two += 1
if four == 1 and two >= 2 or four > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | MAX = 100001
n = int(input())
l = list(map(int, input().split()))
eight, six, four, two = 0, 0, 0, 0
num = [0] * MAX
for i in range(n):
num[l[i]] += 1
if num[l[i]] == 8:
eight += 1
if num[l[i]] == 6:
six += 1
if num[l[i]] == 4:
four += 1
if num[l[i]] == 2:
two += 1
for _ in range(int(input())):
s = input().split()
if s[0] == "+":
num[int(s[1])] += 1
if num[int(s[1])] == 8:
eight += 1
if num[int(s[1])] == 6:
six += 1
if num[int(s[1])] == 4:
four += 1
if num[int(s[1])] == 2:
two += 1
else:
if num[int(s[1])] == 8:
eight -= 1
if num[int(s[1])] == 6:
six -= 1
if num[int(s[1])] == 4:
four -= 1
if num[int(s[1])] == 2:
two -= 1
num[int(s[1])] -= 1
if eight > 0 or six > 0 and two > 1 or four > 0 and two > 2 or four > 1:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
def lower_bound(self, x):
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
def get_less_than_x_cnt(self, x):
lb_pos, lb_sum = self.lower_bound(x)
return lb_pos - 1
def get_less_than_and_x_cnt(self, x):
lb_pos, lb_sum = self.lower_bound(x + 1)
return lb_pos - 1
def get_more_than_x_cnt(self, x):
return self.size - self.get_less_than_and_x_cnt(x)
n = int(input())
al = list(map(int, input().split()))
bit23 = Bit(10**5)
bit45 = Bit(10**5)
bit67 = Bit(10**5)
bit8 = Bit(10**5)
cnts = [0] * (10**5 + 1)
for a in al:
cnts[a] += 1
if cnts[a] == 2:
bit23.add(a, 1)
elif cnts[a] == 4:
bit45.add(a, 1)
bit23.add(a, -1)
elif cnts[a] == 6:
bit67.add(a, 1)
bit45.add(a, -1)
elif cnts[a] == 8:
bit8.add(a, 1)
bit67.add(a, -1)
for _ in range(int(input())):
sig, a = map(str, input().split())
a = int(a)
if sig == "+":
cnts[a] += 1
if cnts[a] == 2:
bit23.add(a, 1)
elif cnts[a] == 4:
bit45.add(a, 1)
bit23.add(a, -1)
elif cnts[a] == 6:
bit67.add(a, 1)
bit45.add(a, -1)
elif cnts[a] == 8:
bit8.add(a, 1)
bit67.add(a, -1)
else:
cnts[a] -= 1
if cnts[a] == 1:
bit23.add(a, -1)
elif cnts[a] == 3:
bit45.add(a, -1)
bit23.add(a, 1)
elif cnts[a] == 5:
bit67.add(a, -1)
bit45.add(a, 1)
elif cnts[a] == 7:
bit8.add(a, -1)
bit67.add(a, 1)
cnt8 = bit8.sum(10**5)
cnt6 = bit67.sum(10**5)
cnt4 = bit45.sum(10**5)
cnt2 = bit23.sum(10**5)
if cnt8 >= 1:
print("YES")
elif cnt6 >= 2:
print("YES")
elif cnt6 == 1 and cnt2 + cnt4 >= 1:
print("YES")
elif cnt4 >= 2:
print("YES")
elif cnt4 == 1 and cnt2 >= 2:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
d = {}
ans = 0
count = 0
a = [*map(int, input().split())]
for i in a:
if d.get(i) == None:
d[i] = 1
else:
d[i] += 1
for i in d:
if d[i] != 0:
ans += d[i] // 4
count += d[i] // 2
s = int(input())
for _ in range(s):
st = input()
p = ""
for i in range(2, len(st)):
p += st[i]
p = int(p)
if st[0] == "+":
if d.get(p) == None:
d[p] = 1
else:
ans -= d[p] // 4
count -= d[p] // 2
d[p] += 1
ans += d[p] // 4
count += d[p] // 2
else:
ans -= d[p] // 4
count -= d[p] // 2
d[p] -= 1
ans += d[p] // 4
count += d[p] // 2
if ans >= 1 and count >= 4:
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
score = list(map(int, input().split(" ")))
res = []
coun = [0] * 100001
for i in score:
coun[i] += 1
div2 = 0
div4 = 0
for i in coun:
div2 += i // 2
div4 += i // 4
for i in range(int(input())):
s = input()
new = int(s[2:])
div2 -= coun[new] // 2
div4 -= coun[new] // 4
if s[0] == "+":
coun[new] += 1
else:
coun[new] -= 1
div2 += coun[new] // 2
div4 += coun[new] // 4
print("YES" if div4 >= 1 and div2 >= 4 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
hashmap = {}
count = {}
for i in range(1, 100000):
count[i] = 0
for i in range(n):
if a[i] in hashmap:
hashmap[a[i]] += 1
count[hashmap[a[i]]] += 1
if a[i] not in hashmap:
hashmap[a[i]] = 1
count[hashmap[a[i]]] += 1
for item in [0] * int(input()):
b, c = input().split()
c = int(c)
if b == "+":
if c in hashmap:
hashmap[c] += 1
count[hashmap[c]] += 1
if c not in hashmap:
hashmap[c] = 1
count[hashmap[c]] += 1
if b == "-":
count[hashmap[c]] -= 1
hashmap[c] -= 1
if (
count[8] > 0
or count[4] >= 2
or count[6] > 0
and count[2] >= 2
or count[4] > 0
and count[2] >= 3
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR STRING VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
ware = {}
t = set()
f = set()
for i in range(n):
ware[arr[i]] = ware.get(arr[i], 0) + 1
if ware[arr[i]] == 4:
f.add(arr[i])
t.remove(arr[i])
elif ware[arr[i]] == 2:
t.add(arr[i])
q = int(input())
for _ in range(q):
s, a = input().split()
a = int(a)
if s == "+":
ware[a] = ware.get(a, 0) + 1
if ware[a] == 4:
f.add(a)
t.remove(a)
elif ware[a] == 2:
t.add(a)
else:
if ware[a] == 4:
f.remove(a)
t.add(a)
elif ware[a] == 2:
t.remove(a)
ware[a] -= 1
if len(f) == 1:
a = list(f)[0]
if ware[a] >= 6:
if ware[a] >= 8:
print("YES")
elif len(t) > 0:
print("YES")
else:
print("NO")
elif ware[a] >= 4:
if len(t) < 2:
print("NO")
else:
print("YES")
else:
print("NO")
elif len(f) >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
planks = list(map(int, input().split()))
s1 = 0
s2 = 0
cnts = [(0) for x in range(100005)]
for i in range(n):
cnts[planks[i]] += 1
for i in range(100005):
s1 += cnts[i] // 2
s2 += cnts[i] // 4
q = int(input())
for i in range(q):
op, cnt = input().split()
cnt = int(cnt)
if op == "+":
s1 -= cnts[cnt] // 2
s2 -= cnts[cnt] // 4
cnts[cnt] += 1
s1 += cnts[cnt] // 2
s2 += cnts[cnt] // 4
else:
s1 -= cnts[cnt] // 2
s2 -= cnts[cnt] // 4
cnts[cnt] -= 1
s1 += cnts[cnt] // 2
s2 += cnts[cnt] // 4
if s2 >= 1 and s1 >= 4:
print("yes")
else:
print("no") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
ca = [0] * (10**5 + 1)
d = {(4): 0, (2): 0}
for i in a:
ca[i] += 1
for i in ca:
t = i
d[4] += t // 4
t %= 4
d[2] += t // 2
for _ in range(int(input())):
q = input().strip().split()
i = int(q[1])
t = ca[i]
d[4] -= t // 4
t %= 4
d[2] -= t // 2
if q[0] == "+":
ca[i] += 1
else:
ca[i] -= 1
t = ca[i]
d[4] += t // 4
t %= 4
d[2] += t // 2
if d[4] > 1 or d[4] == 1 and d[2] > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
planks = [0] * 100000
pairs = 0
squares = 0
for x in a:
planks[x - 1] += 1
if planks[x - 1] % 2 == 0:
pairs += 1
if planks[x - 1] % 4 == 0:
squares += 1
for f in range(int(input())):
inp = list(input().split())
p = inp[0]
i = int(inp[1])
i -= 1
if p == "+":
planks[i] += 1
if planks[i] % 2 == 0:
pairs += 1
if planks[i] % 4 == 0:
squares += 1
else:
if planks[i] % 2 == 0:
pairs -= 1
if planks[i] % 4 == 0:
squares -= 1
planks[i] -= 1
if squares > 0 and pairs > 3:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def typ(x):
global dic
if dic[x] == 2 or dic[x] == 3:
return 2
elif dic[x] >= 4:
return 4
else:
return 0
def rep(x):
global dic, two, four, c1, c2
if typ(x) == 2:
if not x in two:
if x in four:
c1 += 1
c2 -= 1
four.remove(x)
two.add(x)
else:
two.add(x)
c1 += 1
elif typ(x) == 4:
if not x in four:
if x in two:
c1 -= 1
c2 += 1
four.add(x)
two.remove(x)
else:
c2 += 1
four.add(x)
elif x in two:
c1 -= 1
two.remove(x)
n = int(input())
ar = list(map(int, input().split()))
dic = {}
for i in range(n):
if ar[i] in dic:
dic[ar[i]] += 1
else:
dic[ar[i]] = 1
two = set({})
c1 = 0
four = set({})
c2 = 0
for i in dic:
rep(i)
for _ in range(int(input())):
si, el = map(str, input().split())
el = int(el)
if si == "+":
dic[el] = dic.get(el, 0) + 1
rep(el)
elif si == "-":
dic[el] -= 1
rep(el)
if c2 >= 2:
print("YES")
elif c2 == 0:
print("NO")
else:
for k in four:
break
if dic[k] >= 8:
print("YES")
elif dic[k] >= 6:
if c1 >= 1:
print("YES")
else:
print("NO")
elif c1 >= 2:
print("YES")
else:
print("NO") | FUNC_DEF IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR DICT ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def est(sz):
s = list(map(len, sz))
if s[4] > 0:
return True
if s[3] > 0 and (s[1] > 0 or s[2] > 0):
return True
if s[2] > 1:
return True
if s[2] and s[1] > 1:
return True
return False
def idx(count):
if count >= 8:
return 4
return count // 2
def main():
(n,) = map(int, input().split(" "))
cnt = {}
for _ in input().split(" "):
a = int(_)
if a in cnt:
cnt[a] += 1
else:
cnt[a] = 1
sz = [set(), set(), set(), set(), set()]
for a, count in cnt.items():
sz[idx(count)].add(a)
pred = est(sz)
for _ in range(int(input())):
op, a = input().split(" ")
a = int(a)
count = cnt.get(a, 0)
sz[idx(count)].discard(a)
need_est = False
if op == "-":
count -= 1
if pred == False:
pass
else:
need_est = True
if op == "+":
count += 1
if a in cnt:
if pred == False:
need_est = True
else:
pass
sz[idx(count)].add(a)
cnt[a] = count
if need_est:
pred = est(sz)
print("YES" if pred else "NO")
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | num = int(input())
dic = {}
sq = 0
rec = 0
for x in input().split():
if int(x) in dic:
dic[int(x)] += 1
key = dic[int(x)]
if key == 2:
rec += 1
elif key == 4:
sq += 1
rec -= 1
elif key == 6:
rec += 1
elif key == 8:
rec += 1
else:
dic[int(x)] = 1
eve = int(input())
temp = 0
for i in range(eve):
c, d = input().split()
if c == "+":
if int(d) in dic:
dic[int(d)] += 1
key = dic[int(d)]
if key == 2:
rec += 1
elif key == 4:
sq += 1
rec -= 1
elif key == 6:
rec += 1
elif key == 8:
rec += 1
else:
dic[int(d)] = 1
else:
key = dic[int(d)]
if key == 2:
rec -= 1
elif key == 4:
sq -= 1
rec += 1
elif key == 6:
rec -= 1
elif key == 8:
rec -= 1
dic[int(d)] -= 1
if sq > 1:
print("YES")
elif sq > 0 and rec > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
count1 = 0
count2 = 0
d = {}
for x in range(n):
try:
d[a[x]] += 1
except:
d[a[x]] = 1
for x in d.keys():
count1 += d[x] // 4
count2 += d[x] % 4 // 2
for x in range(q):
b, c = input().split()
c = int(c)
if b == "+":
try:
count1 -= d[c] // 4
count2 -= d[c] % 4 // 2
d[c] += 1
except:
d[c] = 1
if b == "-":
count1 -= d[c] // 4
count2 -= d[c] % 4 // 2
d[c] -= 1
count1 += d[c] // 4
count2 += d[c] % 4 // 2
if count1 >= 2:
print("YES")
elif count1 == 1 and count2 >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
s1 = set()
s2 = set()
s3 = set()
d = dict()
for x in [int(s) for s in input().split()]:
if x in s1:
s1.remove(x)
s2.add(x)
elif x in s2:
s2.remove(x)
s3.add(x)
elif x in s3:
s3.remove(x)
d[x] = 4
elif d.get(x, 0) != 0:
d[x] += 1
else:
s1.add(x)
for q in range(int(input())):
s, x = input().split()
x = int(x)
if s == "+":
if x in s1:
s1.remove(x)
s2.add(x)
elif x in s2:
s2.remove(x)
s3.add(x)
elif x in s3:
s3.remove(x)
d[x] = 4
elif d.get(x, 0) != 0:
d[x] += 1
else:
s1.add(x)
elif x in s1:
s1.remove(x)
elif x in s2:
s2.remove(x)
s1.add(x)
elif x in s3:
s3.remove(x)
s2.add(x)
elif d.get(x, 0) != 0:
if d[x] == 4:
d.pop(x)
s3.add(x)
else:
d[x] -= 1
if len(d) == 0:
print("NO")
continue
if len(d) > 1:
print("YES")
continue
p = d.popitem()
d[p[0]] = p[1]
if p[1] >= 8:
print("YES")
continue
if p[1] >= 6:
if len(s2) + len(s3) > 0:
print("YES")
continue
else:
print("NO")
continue
if len(s2) + len(s3) > 1:
print("YES")
continue
else:
print("NO")
continue | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | t = int(input())
arr = [int(item) for item in input().split()]
d = dict()
for i in range(10**5 + 1):
d[i] = 0
for i in arr:
d[i] = d[i] + 1
count2 = 0
count4 = 0
count6 = 0
count8 = 0
for j in d:
if d[j] == 2 or d[j] == 3:
count2 = count2 + 1
if d[j] == 4 or d[j] == 5:
count4 = count4 + 1
if d[j] == 6 or d[j] == 7:
count6 = count6 + 1
if d[j] == 8 or d[j] > 8:
count8 = count8 + 1
for i in range(int(input())):
brr = [item for item in input().split()]
a = brr[0]
b = int(brr[1])
if a == "+":
start = d[b]
d[b] = d[b] + 1
if start == 1:
count2 = count2 + 1
if start == 3:
count4 = count4 + 1
count2 = count2 - 1
if start == 5:
count6 = count6 + 1
count4 = count4 - 1
if start == 7:
count8 = count8 + 1
count6 = count6 - 1
if a == "-":
start = d[b]
d[b] = d[b] - 1
if start == 2:
count2 = count2 - 1
if start == 4:
count4 = count4 - 1
count2 = count2 + 1
if start == 6:
count6 = count6 - 1
count4 = count4 + 1
if start == 8:
count8 = count8 - 1
count6 = count6 + 1
flag = 0
if count8 > 0:
print("YES")
flag = 1
if count6 > 0 and (count2 > 0 or count4 > 0 or count6 - 1 > 0) and flag == 0:
print("YES")
flag = 1
if count4 - 1 > 0 and flag == 0:
print("YES")
flag = 1
if count4 > 0 and count2 > 1 and flag == 0:
print("YES")
flag = 1
if flag == 0:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = [(0) for i in range(10**5)]
l = input().split()
li = [int(i) for i in l]
for i in li:
arr[i - 1] += 1
rec = 0
square = 0
for i in arr:
square += i // 4
rec = rec + i % 4 // 2
q = int(input())
for you in range(q):
s = input().split()
x = s[0]
y = int(s[1])
if x == "-":
z = arr[y - 1] // 4
alp = arr[y - 1] % 4 // 2
square -= z
rec -= alp
arr[y - 1] -= 1
square += arr[y - 1] // 4
rec = rec + arr[y - 1] % 4 // 2
else:
z = arr[y - 1] // 4
alp = arr[y - 1] % 4 // 2
square -= z
rec -= alp
arr[y - 1] += 1
square += arr[y - 1] // 4
rec = rec + arr[y - 1] % 4 // 2
if square >= 2 or square >= 1 and rec >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = dict()
two, four, six, eig = 0, 0, 0, 0
for e in a:
if e in d:
d[e] += 1
if d[e] == 2:
two += 1
elif d[e] == 4:
four += 1
two -= 1
elif d[e] == 6:
six += 1
four -= 1
elif d[e] == 8:
eig += 1
six -= 1
else:
d[e] = 1
Q = int(input())
q = []
for _ in range(Q):
inp, val = map(str, input().split())
val = int(val)
if inp == "+":
if val in d:
d[val] += 1
if d[val] == 2:
two += 1
elif d[val] == 4:
four += 1
two -= 1
elif d[val] == 6:
six += 1
four -= 1
elif d[val] == 8:
eig += 1
six -= 1
else:
d[val] = 1
else:
d[val] -= 1
if d[val] == 1:
two -= 1
elif d[val] == 3:
four -= 1
two += 1
elif d[val] == 5:
six -= 1
four += 1
elif d[val] == 7:
eig -= 1
six += 1
if eig > 0:
print("YES")
elif six > 0:
if six > 1 or two > 0 or four > 0:
print("YES")
else:
print("NO")
elif four > 0:
if four > 1:
print("YES")
elif two > 1:
print("YES")
else:
print("NO")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | for _ in range(1):
n = int(input())
arr = [0] * (10**5 + 1)
ma = [0, 0, 0, 0, 0]
a = list(map(int, input().split()))
cnt = [0] * (10**5 + 1)
for i in a:
arr[i] += 1
cnt[arr[i]] += 1
for i in range(int(input())):
s, k = map(str, input().split())
k = int(k)
if s == "+":
arr[k] += 1
cnt[arr[k]] += 1
else:
cnt[arr[k]] -= 1
arr[k] -= 1
if (
cnt[8] >= 1
or cnt[6] >= 1
and cnt[2] > 1
or cnt[4] >= 2
or cnt[4] == 1
and cnt[2] > 2
):
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
input = stdin.readline
input()
(*a,) = list(map(int, input().split()))
s, r = [0] * 2
cnt = [0] * 100002
for i in a:
cnt[i] += 1
if cnt[i] % 4 == 0:
s += 1
if cnt[i] % 2 == 0:
r += 1
q = int(input())
for i in range(q):
sign, n = input().split()
n = int(n)
if sign == "+":
cnt[n] += 1
if cnt[n] % 4 == 0:
s += 1
if cnt[n] % 2 == 0:
r += 1
elif sign == "-":
if cnt[n] % 4 == 0:
s -= 1
if cnt[n] % 2 == 0:
r -= 1
cnt[n] -= 1
print("YES" if s > 1 or s == 1 and r > 3 else "NO") | ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR STRING IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | mod = 10**9 + 7
def solve():
n = int(input())
a = list(map(int, input().split()))
d = {}
cnt8 = 0
cnt6 = 0
cnt4 = 0
cnt2 = 0
for x in a:
if x in d:
d[x] += 1
else:
d[x] = 1
for x in d:
if d[x] >= 8:
cnt8 += 1
elif d[x] >= 6:
cnt6 += 1
elif d[x] >= 4:
cnt4 += 1
elif d[x] >= 2:
cnt2 += 1
q = int(input())
while q > 0:
c, x = input().split()
x = int(x)
val = 0
if c == "+":
if x in d:
val = d[x]
d[x] += 1
else:
d[x] = 1
if val == 1:
cnt2 += 1
elif val == 3:
cnt4 += 1
cnt2 -= 1
elif val == 5:
cnt6 += 1
cnt4 -= 1
elif val == 7:
cnt8 += 1
cnt6 -= 1
else:
val = d[x]
d[x] -= 1
if val == 8:
cnt8 -= 1
cnt6 += 1
elif val == 6:
cnt6 -= 1
cnt4 += 1
elif val == 4:
cnt4 -= 1
cnt2 += 1
elif val == 2:
cnt2 -= 1
if (
cnt8 > 0
or cnt6 > 0
and (cnt2 > 0 or cnt4 > 0 or cnt6 > 1)
or cnt4 > 1
or cnt4 > 0
and cnt2 > 1
):
print("YES")
else:
print("NO")
q -= 1
t = 1
for _ in range(t):
solve() | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
b = [0] * 100001
c = [0] * 100001
for i in a:
b[i] += 1
c[b[i]] += 1
q = int(input())
for _ in range(q):
e, z = input().split()
z = int(z)
if e == "+":
b[z] += 1
c[b[z]] += 1
elif e == "-":
c[b[z]] -= 1
b[z] -= 1
if c[8] > 0 or c[4] > 1 or c[6] > 0 and c[2] > 1 or c[4] > 0 and c[2] > 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR STRING VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
ai = list(map(int, input().split()))
q = int(input())
n2 = 10**5 + 1
board = [0] * n2
for i in range(n):
board[ai[i]] += 1
num2 = 0
num4 = 0
num6 = 0
num8 = 0
for i in board:
if i >= 2:
num2 += 1
if i >= 4:
num4 += 1
if i >= 6:
num6 += 1
if i >= 8:
num8 += 1
for i in range(q):
action = input().split()
action[1] = int(action[1])
if action[0] == "+":
board[action[1]] += 1
if board[action[1]] == 2:
num2 += 1
elif board[action[1]] == 4:
num4 += 1
elif board[action[1]] == 6:
num6 += 1
elif board[action[1]] == 8:
num8 += 1
else:
if board[action[1]] == 2:
num2 -= 1
elif board[action[1]] == 4:
num4 -= 1
elif board[action[1]] == 6:
num6 -= 1
elif board[action[1]] == 8:
num8 -= 1
board[action[1]] -= 1
if num4 >= 2 or num4 >= 1 and num2 >= 3 or num6 >= 1 and num2 >= 2 or num8 >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
cnt = [0] * (pow(10, 5) + 5)
cnt2 = cnt4 = 0
l = list(map(int, input().split()))
for i in range(n):
a = l[i]
cnt2 -= cnt[a] // 2
cnt4 -= cnt[a] // 4
cnt[a] += 1
cnt2 += cnt[a] // 2
cnt4 += cnt[a] // 4
for i in range(int(input())):
sign, x = input().split()
cnt2 -= cnt[int(x)] // 2
cnt4 -= cnt[int(x)] // 4
if sign == "+":
cnt[int(x)] += 1
else:
cnt[int(x)] -= 1
cnt2 += cnt[int(x)] // 2
cnt4 += cnt[int(x)] // 4
if cnt4 >= 1 and cnt2 >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = [int(x) for x in input().split(" ")]
q = int(input())
ops = []
freq = {}
for aa in a:
if aa not in freq:
freq[aa] = 1
else:
freq[aa] += 1
freq_count = {}
for i in range(100001):
freq_count[i] = 0
for f in freq.values():
freq_count[f] += 1
total = len(a)
for i in range(q):
x = input()
num = int(x[2:])
if x[0] == "+":
total += 1
if num not in freq:
freq[num] = 1
freq_count[1] += 1
else:
freq_count[freq[num]] -= 1
freq[num] += 1
freq_count[freq[num]] += 1
else:
total -= 1
freq_count[freq[num]] -= 1
freq[num] -= 1
freq_count[freq[num]] += 1
total_till_7 = 0
for k in [1, 2, 3, 4, 5, 6, 7]:
total_till_7 += k * freq_count[k]
total_till_3 = 0
for k in [1, 2, 3]:
total_till_3 += k * freq_count[k]
if total > total_till_7:
print("YES")
continue
if total > total_till_3:
c1 = freq_count[2] + freq_count[3]
c2 = freq_count[4] + freq_count[5]
c3 = freq_count[6] + freq_count[7]
if c3 + c2 >= 2 or c3 >= 1 and c1 + c2 >= 1 or c1 >= 2:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
d1 = {}
left = {}
for i in a:
if i in d1.keys():
d1[i] = d1[i] + 1
left[i] = left[i] + 1
else:
d1[i] = 1
left[i] = 1
ans = "NO"
sqd = set()
sqrec = set()
sq = set()
rec = set()
for i in list(d1.keys()):
if left[i] >= 8:
left[i] = left[i] - 8
sqd.add(i)
elif left[i] >= 6:
left[i] = left[i] - 6
sqrec.add(i)
elif left[i] >= 4:
left[i] = left[i] - 4
sq.add(i)
elif left[i] >= 2:
left[i] = left[i] - 2
rec.add(i)
if (
len(sqd) >= 1
or len(sqrec) >= 2
or len(sqrec) >= 1
and (len(rec) >= 1 or len(sq) >= 1)
or len(sq) >= 1
and len(rec) >= 2
or len(sq) >= 2
):
ans = "YES"
m = int(input())
for j in range(0, m):
q = input()
if q[0] == "+":
k = int(q[2:])
if k in left.keys():
left[k] = left[k] + 1
d1[k] = d1[k] + 1
else:
left[k] = 1
d1[k] = 1
if d1[k] == 8:
left[k] = left[k] - 2
sqd.add(k)
sqrec.remove(k)
elif d1[k] == 6:
left[k] = left[k] - 2
sq.remove(k)
sqrec.add(k)
elif d1[k] == 4:
left[k] = left[k] - 2
sq.add(k)
rec.remove(k)
elif d1[k] == 2:
left[k] = left[k] - 2
rec.add(k)
if (
len(sqd) >= 1
or len(sqrec) >= 2
or len(sqrec) >= 1
and (len(rec) >= 1 or len(sq) >= 1)
or len(sq) >= 1
and len(rec) >= 2
or len(sq) >= 2
):
ans = "YES"
else:
ans = "NO"
print(ans)
else:
k = int(q[2:])
if k in left.keys():
left[k] = left[k] - 1
d1[k] = d1[k] - 1
if left[k] == -1:
if d1[k] == 7:
left[k] = left[k] + 2
sqd.remove(k)
sqrec.add(k)
elif d1[k] == 5:
left[k] = left[k] + 2
sq.add(k)
sqrec.remove(k)
elif d1[k] == 3:
left[k] = left[k] + 2
sq.remove(k)
rec.add(k)
elif d1[k] == 1:
left[k] = left[k] + 2
rec.remove(k)
if (
len(sqd) >= 1
or len(sqrec) >= 2
or len(sqrec) >= 1
and (len(rec) >= 1 or len(sq) >= 1)
or len(sq) >= 1
and len(rec) >= 2
or len(sq) >= 2
):
ans = "YES"
else:
ans = "NO"
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
lengths = list(map(int, input().strip().split()))
events = int(input())
ele = [0] * (2 * pow(10, 5))
count = [0] * (2 * pow(10, 5))
for i in lengths:
ele[i] += 1
count[ele[i]] += 1
for _ in range(events):
eventA = input().strip().split()
sign = eventA[0]
event = int(eventA[1])
if sign == "+":
ele[event] += 1
count[ele[event]] += 1
if sign == "-":
count[ele[event]] -= 1
ele[event] -= 1
if (
count[8] >= 1
or count[4] >= 2
or count[6] >= 1
and count[2] >= 2
or count[4] >= 1
and count[2] >= 3
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR STRING VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
two = set()
four = set()
six = set()
eight = set()
count = [(0) for i in range(10**5 + 1)]
for i in range(n):
count[a[i]] += 1
if count[a[i]] == 2:
two.add(a[i])
if count[a[i]] == 4:
four.add(a[i])
two.remove(a[i])
if count[a[i]] == 6:
six.add(a[i])
four.remove(a[i])
if count[a[i]] == 8:
eight.add(a[i])
six.remove(a[i])
q = int(input())
for i in range(q):
c, m = input().split()
m = int(m)
if c == "+":
count[m] += 1
if count[m] == 4:
four.add(m)
two.remove(m)
if count[m] == 2:
two.add(m)
if count[m] == 6:
six.add(m)
four.remove(m)
if count[m] == 8:
eight.add(m)
six.remove(m)
else:
count[m] -= 1
if count[m] == 7:
eight.remove(m)
six.add(m)
if count[m] == 5:
six.remove(m)
four.add(m)
if count[m] == 3:
four.remove(m)
two.add(m)
if count[m] == 1:
two.remove(m)
if len(eight) >= 1:
print("YES")
elif len(six) >= 1 and (len(four) >= 1 or len(two) >= 1):
print("YES")
elif len(four) >= 2:
print("YES")
elif len(four) >= 1 and len(two) >= 2:
print("YES")
elif len(six) >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = [int(i) for i in input().split()]
q = int(input())
dic = {}
set2 = set()
set4 = set()
rem = {}
rem2 = 0
numSq = 0
for i in range(n):
if arr[i] in dic:
dic[arr[i]] += 1
else:
dic[arr[i]] = 1
for key in dic.keys():
if dic[key] >= 4:
set4.add(key)
numSq += dic[key] // 4
if dic[key] % 4 in rem:
rem[dic[key] % 4] += 1
else:
rem[dic[key] % 4] = 1
elif dic[key] >= 2:
set2.add(key)
if dic[key] == 3:
rem2 += 1
for i in range(q):
inp = input()
num = int(inp[1:])
if inp[0] == "+":
if num in dic:
dic[num] += 1
else:
dic[num] = 1
else:
dic[num] -= 1
if num in set2:
if dic[num] == 2:
rem2 -= 1
elif dic[num] == 3:
rem2 += 1
elif dic[num] < 2:
set2.remove(num)
elif dic[num] > 3:
set2.remove(num)
set4.add(num)
numSq += 1
if 0 in rem:
rem[0] += 1
else:
rem[0] = 1
elif num in set4:
if dic[num] < 4:
numSq -= 1
set4.remove(num)
set2.add(num)
rem2 += 1
elif dic[num] % 4 == 0:
if inp[0] == "+":
rem[3] -= 1
if 0 in rem:
rem[0] += 1
else:
rem[0] = 1
numSq += 1
else:
rem[1] -= 1
if 0 in rem:
rem[0] += 1
else:
rem[0] = 1
elif inp[0] == "+":
reqVal = dic[num] % 4 - 1
if reqVal == -1:
numSq += 1
reqVal = 3
rem[reqVal] -= 1
if dic[num] % 4 in rem:
rem[dic[num] % 4] += 1
else:
rem[dic[num] % 4] = 1
else:
reqVal = dic[num] % 4 + 1
if reqVal == 4:
numSq -= 1
reqVal = 0
rem[reqVal] -= 1
if dic[num] % 4 in rem:
rem[dic[num] % 4] += 1
else:
rem[dic[num] % 4] = 1
elif dic[num] == 2:
set2.add(num)
if numSq == 0:
print("NO")
elif numSq == 1:
if len(set2) == 0:
print("NO")
elif len(set2) == 1:
if 2 in rem and rem[2] >= 1 or 3 in rem and rem[3] >= 1:
print("YES")
else:
print("NO")
else:
print("YES")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def solve(n, q, p, changes):
count = {}
for i in p:
if i not in count:
count[i] = 1
else:
count[i] += 1
countP = [0] * 4
for planks in count:
if count[planks] >= 8:
countP[3] += 1
elif count[planks] >= 6:
countP[2] += 1
elif count[planks] >= 4:
countP[1] += 1
elif count[planks] >= 2:
countP[0] += 1
for event in changes:
i = int(event[1:])
if event[0] == "+":
if i not in count:
count[i] = 1
else:
count[i] += 1
if count[i] == 8:
countP[3] += 1
countP[2] -= 1
elif count[i] == 6:
countP[2] += 1
countP[1] -= 1
elif count[i] == 4:
countP[1] += 1
countP[0] -= 1
elif count[i] == 2:
countP[0] += 1
else:
count[i] -= 1
if count[i] == 7:
countP[3] -= 1
countP[2] += 1
elif count[i] == 5:
countP[2] -= 1
countP[1] += 1
elif count[i] == 3:
countP[1] -= 1
countP[0] += 1
elif count[i] == 1:
countP[0] -= 1
if (
countP[3] >= 1
or countP[1] >= 2
or countP[2] >= 2
or countP[1] == 1
and countP[0] >= 2
or countP[2] >= 1
and (countP[0] >= 1 or countP[1] >= 1)
):
print("YES")
else:
print("NO")
n = int(input())
p = list(map(int, input().split()))
q = int(input())
changes = []
for i in range(q):
changes.append(input())
solve(n, q, p, changes) | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
l = list(map(int, input().strip().split()))
q = int(input())
count = {}
overTwo = 0
overFour = 0
overSix = 0
overEight = 0
for i in range(len(l)):
if l[i] not in count:
count[l[i]] = 1
else:
count[l[i]] += 1
for key in count.keys():
if count[key] >= 8:
overEight += 1
overSix += 1
overFour += 1
overTwo += 1
elif count[key] >= 6:
overSix += 1
overFour += 1
overTwo += 1
elif count[key] >= 4:
overFour += 1
overTwo += 1
elif count[key] >= 2:
overTwo += 1
for i in range(q):
a, b = map(str, input().strip().split())
b = int(b)
if a == "+":
if b not in count:
count[b] = 0
count[b] += 1
if count[b] == 2:
overTwo += 1
if count[b] == 4:
overFour += 1
if count[b] == 6:
overSix += 1
if count[b] == 8:
overEight += 1
else:
count[b] -= 1
if count[b] == 1:
overTwo -= 1
if count[b] == 3:
overFour -= 1
if count[b] == 5:
overSix -= 1
if count[b] == 7:
overEight -= 1
if overEight > 0:
print("YES")
elif overSix > 0 and overTwo > 1:
print("YES")
elif overFour > 0 and overTwo > 2:
print("YES")
elif overFour > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | cnt = [(0) for x in range(111111)]
numOfSet4 = numOfSet2 = 0
def runn(method, value):
global numOfSet2, numOfSet4
oldCnt = cnt[value]
if method == "+":
if oldCnt % 4 == 1:
numOfSet2 += 1
elif oldCnt % 4 == 3:
numOfSet2 -= 1
numOfSet4 += 1
cnt[value] = oldCnt + 1
elif method == "-":
if oldCnt % 4 == 2:
numOfSet2 -= 1
if oldCnt % 4 == 0 and oldCnt / 4 > 0:
numOfSet2 += 1
numOfSet4 -= 1
cnt[value] = oldCnt - 1
if numOfSet4 >= 2 or numOfSet4 == 1 and numOfSet2 >= 2:
return True
return False
n = int(input())
ar = list(map(int, input().split()))
for x in ar:
tmp = runn("+", x)
q = int(input())
for i in range(q):
mthd, val = input().split()
val = int(val)
tmp = runn(mthd, val)
res = tmp and "YES" or "NO"
print(res) | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
squares = 0
rectangles = 0
shapes = [(0) for i in range(100001)]
for i in input().split():
i = int(i)
shapes[i] += 1
if shapes[i] % 2 == 0:
rectangles += 1
if shapes[i] % 4 == 0:
squares += 1
for i in range(int(input())):
action = input()
i = int(action[1:])
if action[0] == "+":
shapes[i] += 1
if shapes[i] % 2 == 0:
rectangles += 1
if shapes[i] % 4 == 0:
squares += 1
else:
shapes[i] -= 1
if shapes[i] % 2:
rectangles -= 1
if shapes[i] % 4 == 3:
squares -= 1
if rectangles >= 4 and squares >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | t = input()
vals = [[i, 0] for i in range(10**5 + 1)]
twos = 0
fours = 0
for i in input().split():
val = int(i)
vals[val][1] += 1
if vals[val][1] == 2:
twos += 1
if vals[val][1] == 4:
twos -= 1
fours += 1
if vals[val][1] == 6 or vals[val][1] == 8:
twos += 1
n = int(input())
for i in range(n):
buf = input().split()
val = int(buf[1])
if buf[0] == "-":
if vals[val][1] == 4:
fours -= 1
twos += 1
elif vals[val][1] == 2:
twos -= 1
elif vals[val][1] == 6 or vals[val][1] == 8:
twos -= 1
vals[val][1] -= 1
else:
if vals[val][1] == 1:
twos += 1
elif vals[val][1] == 3:
twos -= 1
fours += 1
elif vals[val][1] == 5 or vals[val][1] == 7:
twos += 1
vals[val][1] += 1
if twos >= 2 and fours >= 1 or fours >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
count = [0] * (10**5 + 1)
fours = {}
twos = {}
for x in arr:
count[x] += 1
if count[x] >= 4:
fours[x] = count[x]
if x in twos:
del twos[x]
if 2 <= count[x] <= 3:
twos[x] = count[x]
for i in range(int(input())):
query, length = list(input().split())
length = int(length)
if query == "+":
count[length] += 1
if length in fours:
fours[length] += 1
elif length in twos:
twos[length] += 1
if twos[length] == 4:
del twos[length]
fours[length] = 4
elif count[length] == 2:
twos[length] = 2
else:
count[length] -= 1
if length in fours:
fours[length] -= 1
if fours[length] < 4:
del fours[length]
twos[length] = count[length]
elif length in twos:
twos[length] -= 1
if twos[length] < 2:
del twos[length]
temp1 = 0
temp2 = 0
for k in fours:
temp1 += fours[k] // 4
temp2 += fours[k] % 4 // 2
if temp1 > 1 or temp1 >= 1 and temp2 >= 2:
break
temp2 += len(twos)
if temp1 > 1 or temp1 >= 1 and temp2 >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR IF NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | N = int(input())
planks = [int(x) for x in input().split()]
d = {}
anything_num = 0
two_num = 0
for p in planks:
d[p] = d.get(p, 0) + 1
if d[p] == 8:
anything_num += 1
two_num -= 1
if d[p] == 6:
two_num += 1
if d[p] == 4:
anything_num += 1
two_num -= 1
if d[p] == 2:
two_num += 1
Q = int(input())
for _ in range(Q):
ev, plank = input().split()
plank = int(plank)
if ev == "+":
d[plank] = d.get(plank, 0) + 1
if d[plank] == 8:
anything_num += 1
two_num -= 1
if d[plank] == 6:
two_num += 1
if d[plank] == 4:
anything_num += 1
two_num -= 1
if d[plank] == 2:
two_num += 1
else:
d[plank] -= 1
if d[plank] == 7:
anything_num -= 1
two_num += 1
if d[plank] == 5:
two_num -= 1
if d[plank] == 3:
anything_num -= 1
two_num += 1
if d[plank] == 1:
two_num -= 1
ans = anything_num >= 2 or anything_num == 1 and two_num >= 2
if ans:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = map(int, input().split())
a = [*map(int, input().split())]
datastore = [set() for x in range(9)]
inpres = set()
count = dict()
for plank in a:
if plank in inpres:
datastore[count[plank] if count[plank] <= 8 else 8].remove(plank)
count[plank] += 1
datastore[count[plank] if count[plank] <= 8 else 8].add(plank)
else:
count[plank] = 1
inpres.add(plank)
datastore[1].add(plank)
for q in range(int(input())):
sign, value = input().split()
plank = int(value)
if sign == "+":
if plank in inpres:
datastore[count[plank] if count[plank] <= 8 else 8].remove(plank)
count[plank] += 1
datastore[count[plank] if count[plank] <= 8 else 8].add(plank)
else:
count[plank] = 1
inpres.add(plank)
datastore[1].add(plank)
else:
datastore[count[plank] if count[plank] <= 8 else 8].remove(plank)
count[plank] -= 1
if count[plank] == 0:
inpres.remove(plank)
else:
datastore[count[plank] if count[plank] <= 8 else 8].add(plank)
answer = "NO"
if len(datastore[8]) > 0:
answer = "YES"
elif (
len(datastore[7]) + len(datastore[6]) + len(datastore[5]) + len(datastore[4])
>= 2
):
answer = "YES"
elif (
len(datastore[7]) + len(datastore[6]) + len(datastore[5]) + len(datastore[4])
== 0
):
pass
elif len(datastore[4]) + len(datastore[5]) == 1:
if len(datastore[3]) + len(datastore[2]) >= 2:
answer = "YES"
elif len(datastore[3]) + len(datastore[2]) >= 1:
answer = "YES"
print(answer) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | mxn = 10**5 + 5
n = int(input())
arr = [0] * mxn
nums = list(map(int, input().split()))
sm2 = 0
sm4 = 0
for num in nums:
sm2 -= arr[num] // 2
sm4 -= arr[num] // 4
arr[num] += 1
sm2 += arr[num] // 2
sm4 += arr[num] // 4
for q in range(int(input())):
s = input().split()
num = int(s[1])
sm2 -= arr[num] // 2
sm4 -= arr[num] // 4
if s[0] == "+":
arr[num] += 1
else:
arr[num] -= 1
sm2 += arr[num] // 2
sm4 += arr[num] // 4
if sm2 >= 4 and sm4 >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | q = [(0) for i in range(100000)]
co8, co6, co4, co2 = 0, 0, 0, 0
input()
for z in map(int, input().split()):
if q[z - 1] == 3:
co2 -= 1
if q[z - 1] == 5:
co4 -= 1
if q[z - 1] == 7:
co6 -= 1
q[z - 1] += 1
if q[z - 1] == 2:
co2 += 1
if q[z - 1] == 4:
co4 += 1
if q[z - 1] == 6:
co6 += 1
if q[z - 1] == 8:
co8 += 1
for t in range(int(input())):
c, z = input().split()
z = int(z)
if c == "+":
q[z - 1] += 1
if q[z - 1] == 2:
co2 += 1
if q[z - 1] == 4:
co2 -= 1
co4 += 1
if q[z - 1] == 6:
co4 -= 1
co6 += 1
if q[z - 1] == 8:
co6 -= 1
co8 += 1
else:
if q[z - 1] == 2:
co2 -= 1
if q[z - 1] == 4:
co2 += 1
co4 -= 1
if q[z - 1] == 6:
co4 += 1
co6 -= 1
if q[z - 1] == 8:
co6 += 1
co8 -= 1
q[z - 1] -= 1
if co8 or co6 and (co6 >= 2 or co4 or co2) or co4 and (co4 >= 2 or co2 >= 2):
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def check(n2, n4, n6, n8):
if n8 >= 1:
return True
if n6 >= 1 and n2 >= 2:
return True
if n4 >= 2:
return True
if n4 >= 1 and n2 >= 3:
return True
return False
n = int(input())
a = list(map(int, input().split()))
n8 = 0
n6 = 0
n4 = 0
n2 = 0
freq = [(0) for i in range(100005)]
for i in a:
freq[i] += 1
if freq[i] == 2:
n2 += 1
if freq[i] == 4:
n4 += 1
if freq[i] == 6:
n6 += 1
if freq[i] == 8:
n8 += 1
q = int(input())
for i in range(q):
query = input()
x = int(query[2:])
if query[0] == "+":
freq[x] += 1
if freq[x] == 2:
n2 += 1
if freq[x] == 4:
n4 += 1
if freq[x] == 6:
n6 += 1
if freq[x] == 8:
n8 += 1
else:
if freq[x] == 2:
n2 -= 1
if freq[x] == 4:
n4 -= 1
if freq[x] == 6:
n6 -= 1
if freq[x] == 8:
n8 -= 1
freq[x] -= 1
if check(n2, n4, n6, n8):
print("YES")
else:
print("NO") | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin, stdout
a = int(stdin.readline())
st = [0] * 9
pl = [0] * 100001
def inc(x):
global pl, st
if pl[x] < 8:
st[pl[x]] -= 1
st[pl[x] + 1] += 1
pl[x] += 1
def dec(x):
global pl, st
if pl[x] <= 8:
st[pl[x]] -= 1
st[pl[x] - 1] += 1
pl[x] -= 1
for i in map(int, input().split()):
inc(i)
k = int(stdin.readline())
for _ in " " * k:
u, v = input().split()
if u == "+":
inc(int(v))
else:
dec(int(v))
if (
st[8]
or sum(st[4:8]) > 1
or sum(st[2:4]) > 1
and sum(st[4:6])
or sum(st[2:4])
and sum(st[6:8])
or sum(st[4:8]) > 2
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FUNC_DEF IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
m = 10**5
count = [(0) for i in range(m + 1)]
for i in range(n):
count[a[i]] += 1
d2, d4, d6, d8 = 0, 0, 0, 0
for i in range(m + 1):
k = count[i]
if k >= 8:
d8 += 1
elif k >= 6:
d6 += 1
elif k >= 4:
d4 += 1
elif k >= 2:
d2 += 1
q = int(input())
for i in range(q):
s = input()
x = int(s[2:])
if s[0] == "+":
count[x] += 1
k = count[x]
if k == 2:
d2 += 1
elif k == 4:
d2 -= 1
d4 += 1
elif k == 6:
d4 -= 1
d6 += 1
elif k == 8:
d6 -= 1
d8 += 1
else:
count[x] -= 1
k = count[x]
if k == 1:
d2 -= 1
elif k == 3:
d4 -= 1
d2 += 1
elif k == 5:
d4 += 1
d6 -= 1
elif k == 7:
d8 -= 1
d6 += 1
if d4 > 1 or d6 > 1 or d8 >= 1:
print("YES")
elif d6 == 1 and (d4 > 0 or d2 > 0):
print("YES")
elif d4 == 1 and d2 > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = [0] + [0] * 10**5
for i in range(n):
d[a[i]] += 1
c2 = 0
c4 = 0
c6 = 0
c8 = 0
for i in range(10**5 + 1):
if d[i] >= 2 and d[i] < 4:
c2 += 1
elif d[i] >= 4 and d[i] < 6:
c4 += 1
elif d[i] >= 6 and d[i] < 8:
c6 += 1
elif d[i] >= 8:
c8 += 1
for _ in range(q):
s = input().split()
x = int(s[1])
if s[0] == "+":
d[int(s[1])] += 1
if d[x] == 2:
c2 += 1
elif d[x] == 4:
c4 += 1
c2 -= 1
elif d[x] == 6:
c6 += 1
c4 -= 1
elif d[x] == 8:
c8 += 1
c6 -= 1
else:
temp = d[x]
d[int(s[1])] -= 1
if temp == 2:
c2 -= 1
elif temp == 4:
c4 -= 1
c2 += 1
elif temp == 6:
c6 -= 1
c4 += 1
elif temp == 8:
c8 -= 1
c6 += 1
if c6 != 0 and c2 != 0:
print("yes")
elif c6 >= 2:
print("yes")
elif c4 != 0 and c2 >= 2:
print("yes")
elif c6 != 0 and c4 != 0:
print("yes")
elif c4 >= 2:
print("yes")
elif c8:
print("yes")
else:
print("no") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [(0) for i in range(10**5 + 1)]
cnt = [(0) for i in range(10**5 + 1)]
for i in a:
i = int(i)
l[i] += 1
cnt[l[i]] += 1
for _ in range(q):
sign, num = input().split()
num = int(num)
f = 0
if sign == "+":
l[num] += 1
cnt[l[num]] += 1
else:
cnt[l[num]] -= 1
l[num] -= 1
if cnt[8] > 0:
f = 1
elif cnt[4] >= 2:
f = 1
elif cnt[4] > 0 and cnt[2] >= 3:
f = 1
elif cnt[6] > 0 and cnt[2] >= 2:
f = 1
if f:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
l = get_list()
a = [0] * 100002
b = [0] * 100002
for item in l:
a[item] += 1
b[a[item]] += 1
q = iinput()
for _ in range(q):
s = input()
k = int(s[2:])
if s[0] == "+":
a[k] += 1
b[a[k]] += 1
else:
b[a[k]] -= 1
a[k] -= 1
if b[2] > 1 and b[6] > 0 or b[4] > 1 or b[4] > 0 and b[2] > 2 or b[8] > 0:
print("YES")
else:
print("NO") | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = [int(x) for x in input().split()]
hash_table = {(1): 0, (2): 0, (4): 0, (6): 0, (8): 0}
freq = {}
for i in range(n):
if a[i] not in freq:
freq[a[i]] = 0
freq[a[i]] += 1
for key in freq:
border = 8
while freq[key] < border:
border -= 2 if border > 2 else 1
hash_table[border] += 1
q = int(input())
for _ in range(q):
action, x = [x for x in input().split()]
x = int(x)
if action == "+":
if x not in freq:
freq[x] = 0
freq[x] += 1
if freq[x] in hash_table:
hash_table[freq[x]] += 1
if freq[x] > 1:
hash_table[freq[x] - (2 if freq[x] > 2 else 1)] -= 1
else:
freq[x] -= 1
if freq[x] < 8 and (freq[x] & 1 or freq[x] == 0):
hash_table[freq[x] + 1] -= 1
if freq[x] != 0:
hash_table[freq[x] - (1 if freq[x] != 1 else 0)] += 1
if (
hash_table[8] >= 1
or hash_table[6] >= 1
and (hash_table[6] >= 2 or hash_table[4] >= 1 or hash_table[2] >= 1)
or hash_table[4] >= 1
and (hash_table[4] >= 2 or hash_table[2] >= 2)
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
d[i] = d.get(i, 0) + 1
four_s = 0
two_s = 0
for i in d:
if d[i] >= 4:
four_s += d[i] // 4
two_s += d[i] % 4 // 2
else:
two_s += d[i] // 2
q = int(input())
for _ in range(q):
t, l = input().split()
l = int(l)
if t == "+":
d[l] = d.get(l, 0) + 1
if d[l] % 4 == 0:
two_s -= 1
four_s += 1
elif d[l] % 2 == 0:
two_s += 1
else:
d[l] -= 1
if (d[l] + 1) % 4 == 0:
four_s -= 1
two_s += 1
elif (d[l] + 1) % 2 == 0:
two_s -= 1
if four_s >= 2 or four_s >= 1 and two_s >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
q = int(input())
num = [0] * 100000
num1 = [0] * 100000
num2 = [0] * 100000
s = 0
t = 0
for i in range(n):
num[arr[i] - 1] += 1
for i in range(100000):
if 0 == 0:
if num[i] > 0 and num[i] % 2 == 0:
s += num[i] // 2
elif num[i] % 2 == 1:
num1[i] = 1
s += num[i] // 2
if 0 == 0:
if num[i] > 0 and num[i] % 4 == 0:
t += num[i] // 4
elif num[i] % 4 > 0:
num2[i] = num[i] % 4
t += num[i] // 4
for i in range(q):
lis = list(map(str, input().split()))
if lis[0] == "+":
num[int(lis[1]) - 1] += 1
if lis[0] == "+":
if num1[int(lis[1]) - 1] == 0:
num1[int(lis[1]) - 1] = 1
elif num1[int(lis[1]) - 1] == 1:
s += 1
num1[int(lis[1]) - 1] = 0
if lis[0] == "+":
if num2[int(lis[1]) - 1] == 3:
t += 1
num2[int(lis[1]) - 1] = 0
elif num2[int(lis[1]) - 1] < 3:
num2[int(lis[1]) - 1] += 1
if s >= 4 and t >= 1:
print("YES")
else:
print("NO")
else:
num[int(lis[1]) - 1] -= 1
if lis[0] == "-":
if num1[int(lis[1]) - 1] == 0:
num1[int(lis[1]) - 1] = 1
s -= 1
elif num1[int(lis[1]) - 1] == 1:
num1[int(lis[1]) - 1] = 0
if lis[0] == "-":
if num2[int(lis[1]) - 1] == 0:
t -= 1
num2[int(lis[1]) - 1] = 3
elif num2[int(lis[1]) - 1] > 0:
num2[int(lis[1]) - 1] -= 1
if s >= 4 and t >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
li = list(map(int, input().split()))
sum2 = 0
sum4 = 0
val = int(pow(10, 5) + 1)
ans = [0] * val
for i in range(n):
ans[li[i]] += 1
for i in range(1, val):
sum2 += ans[i] // 2
sum4 += ans[i] // 4
q = int(input())
for i in range(q):
case = list(input().split())
if case[0] == "+":
sum4 -= ans[int(case[1])] // 4
sum2 -= ans[int(case[1])] // 2
ans[int(case[1])] += 1
sum2 += ans[int(case[1])] // 2
sum4 += ans[int(case[1])] // 4
else:
sum4 -= ans[int(case[1])] // 4
sum2 -= ans[int(case[1])] // 2
ans[int(case[1])] -= 1
sum2 += ans[int(case[1])] // 2
sum4 += ans[int(case[1])] // 4
print("YES" if sum4 >= 1 and sum2 >= 4 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n, s, _, *l = open(0)
n = int(n)
d = [0] * 7**6
a = b = 0
for s in s.split() + l:
n -= 1
e = n < 0
t = int(s[2 * e :])
e &= s[0] > "+"
k = 1 - 2 * e
m = d[t] - e
d[t] += k
a += m % 2 * k
b += (m % 4 > 2) * k
if n < 0:
print("NYOE S"[a - 3 > 0 < b :: 2]) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
input = sys.stdin.readline
n = int(input())
L = [*map(int, input().split())]
q = int(input())
events = []
for _ in range(q):
sym, num = input().rstrip().split()
events.append([sym, int(num)])
L_dict = {}
for l in L:
try:
L_dict[l] += 1
except KeyError:
L_dict[l] = 1
double, quatro = 0, 0
for lth, cnt in L_dict.items():
q_made = cnt // 4
d_made = cnt % 4 // 2
quatro += q_made
double += d_made
L_dict[lth] = [cnt, q_made, d_made]
for sym, num in events:
if sym == "+":
try:
L_dict[num][0] += 1
if L_dict[num][0] // 4 > L_dict[num][1]:
L_dict[num][1] += 1
L_dict[num][2] = 0
quatro += 1
double -= 1
elif L_dict[num][0] % 4 // 2 > L_dict[num][2]:
L_dict[num][2] += 1
double += 1
except KeyError:
L_dict[num] = [1, 0, 0]
else:
L_dict[num][0] = max(0, L_dict[num][0] - 1)
if L_dict[num][0] // 4 < L_dict[num][1]:
L_dict[num][1] -= 1
L_dict[num][2] += 1
quatro -= 1
double += 1
elif L_dict[num][0] % 4 // 2 < L_dict[num][2]:
L_dict[num][2] -= 1
double -= 1
if quatro >= 2 or quatro >= 1 and double >= 2:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR FOR VAR VAR VAR IF VAR STRING VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def check(c, cc, ccc, cccc):
if (
cc >= 2
or ccc > 0
and c > 0
or cc > 0
and c > 1
or cccc >= 1
or ccc > 0
and cc > 0
or ccc >= 2
):
print("YES")
return
elif cc >= 1 and ccc >= 1:
print("YES")
return
else:
print("NO")
return
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
c1, c2, c3, c4 = 0, 0, 0, 0
for i in d:
if d[i] >= 8:
c4 += 1
elif d[i] >= 6:
c3 += 1
elif d[i] >= 4:
c2 += 1
elif d[i] >= 2:
c1 += 1
dd = d.copy()
for i in range(q):
x, y = input().split()
y = int(y)
if x == "+":
if d.get(y) != None:
d[y] += 1
else:
d[y] = 1
if d[y] == 2:
c1 += 1
elif d[y] == 4:
c2 += 1
c1 -= 1
elif d[y] == 6:
c3 += 1
c2 -= 1
elif d[y] == 8:
c4 += 1
c3 -= 1
elif x == "-":
d[y] -= 1
if d[y] == 1:
c1 -= 1
elif d[y] == 3:
c2 -= 1
c1 += 1
elif d[y] == 5:
c3 -= 1
c2 += 1
elif d[y] == 7:
c4 -= 1
c3 += 1
check(c1, c2, c3, c4) | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NONE VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | number_of = [0] * 100001
n = int(input())
P = list(map(int, input().split()))
for p in P:
number_of[p - 1] += 1
four_plus = 0
two_plus = 0
for n in number_of:
four_plus += n // 4
two_plus += n // 2
q = int(input())
for i in range(q):
s = input()
lumber_size = int(s.split()[-1]) - 1
if s.split()[0] == "-":
number_of[lumber_size] -= 1
n = number_of[lumber_size]
if n % 4 == 3:
four_plus -= 1
if n % 2 == 1:
two_plus -= 1
elif s.split()[0] == "+":
number_of[lumber_size] += 1
n = number_of[lumber_size]
if n % 4 == 0:
four_plus += 1
if n % 2 == 0:
two_plus += 1
if four_plus >= 1 and two_plus >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = list(map(int, input().split()))
counter = dict()
n2 = 0
n4 = 0
for i in range(n):
if arr[i] not in counter.keys():
counter[arr[i]] = 1
n2 += counter[arr[i]] // 2
n4 += counter[arr[i]] // 4
else:
n2 -= counter[arr[i]] // 2
n4 -= counter[arr[i]] // 4
counter[arr[i]] += 1
n2 += counter[arr[i]] // 2
n4 += counter[arr[i]] // 4
m = int(input())
for i in range(m):
sign, diff = input().split()
if sign == "+":
num = int(diff)
if num not in counter.keys():
counter[num] = 1
n2 += counter[num] // 2
n4 += counter[num] // 4
else:
n2 -= counter[num] // 2
n4 -= counter[num] // 4
counter[num] += 1
n2 += counter[num] // 2
n4 += counter[num] // 4
n += 1
if sign == "-":
num = int(diff)
n2 -= counter[num] // 2
n4 -= counter[num] // 4
counter[num] -= 1
n2 += counter[num] // 2
n4 += counter[num] // 4
n -= 1
if n < 8:
print("NO")
elif n4 >= 1 and n2 >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
lenghts = [int(x) for x in input().split()]
counter = {}
for x in lenghts:
counter[x] = counter.get(x, 0) + 1
q = int(input())
sets = {(2): set(), (4): set(), (6): set(), (8): set()}
for item, count in counter.items():
for x, s in sets.items():
if count >= x:
s.add(item)
for x in range(q):
line = input().split()
sign, item = line[0], int(line[1])
if sign == "+":
counter[item] = counter.get(item, 0) + 1
count = counter[item]
for x, s in sets.items():
if count >= x:
s.add(item)
else:
counter[item] -= 1
count = counter[item]
for x, s in sets.items():
if count < x:
s.discard(item)
if (
sets[8]
or sets[6]
and sets[2]
and len(sets[6] | sets[2]) >= 2
or len(sets[4]) >= 2
or sets[4]
and len(sets[2]) >= 2
and len(sets[2] | sets[4]) >= 3
):
print("yes")
else:
print("no") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
event = int(input())
cnt4 = set()
cnt2 = []
cnt = [(0) for x in range(100001)]
for e in a:
cnt[e] += 1
if cnt[e] % 2 == 0:
cnt2.append(e)
if cnt[e] >= 4:
cnt4.add(e)
for i in range(event):
sign, number = input().split()
number = int(number)
if sign == "-":
cnt[number] -= 1
if cnt[number] % 2:
cnt2.remove(number)
if cnt[number] < 4 and cnt[number] == 3:
cnt4.remove(number)
else:
cnt[number] += 1
if cnt[number] % 2 == 0:
cnt2.append(number)
if cnt[number] >= 4:
cnt4.add(number)
if len(cnt4) and len(cnt2) >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def check(count):
cond = count[7] >= 1
cond1 = count[3] + count[4] + count[5] + count[6] > 1
cond_sq = count[3] + count[4] + count[5] + count[6] == 1
cond_rect = count[5] + count[1] + count[2] + count[6] > 1
if cond or cond1 or cond_sq and cond_rect:
return 1
return 0
n = int(input())
planks = list(map(int, input().split()))
dct = {}
for size in planks:
val = dct.get(size, 0)
val += 1
dct[size] = val
count = [(0) for _ in range(8)]
for size in dct:
val = dct[size]
idx = [val - 1, 7][int(val >= 8)]
count[idx] += 1
q = int(input())
ans = []
for _ in range(q):
s = input()
size = int(s[2:])
val = dct.get(size, 0)
if s[0] == "+":
if val:
if val < 8:
count[val - 1] -= 1
count[val] += 1
else:
count[0] += 1
dct[size] = val + 1
else:
if 1 < val <= 8:
count[val - 1] -= 1
count[val - 2] += 1
elif val == 1:
count[0] -= 1
dct[size] = val - 1
ans.append(["NO", "YES"][check(count)])
for x in ans:
print(x) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | t = int(input())
planks = dict()
for size in (int(i) for i in input().split()):
if size in planks:
planks[size] += 1
else:
planks[size] = 1
twos = set()
fours = set()
sixes = set()
eights = set()
for size, amount in planks.items():
if amount >= 2:
twos.add(size)
if amount >= 4:
fours.add(size)
if amount >= 6:
sixes.add(size)
if amount >= 8:
eights.add(size)
for _ in range(int(input())):
event, size = input().split()
size = int(size)
if event == "+":
if size in planks:
planks[size] += 1
else:
planks[size] = 1
if planks[size] == 2:
twos.add(size)
elif planks[size] == 4:
fours.add(size)
elif planks[size] == 6:
sixes.add(size)
elif planks[size] == 8:
eights.add(size)
else:
planks[size] -= 1
if planks[size] == 1:
twos.remove(size)
elif planks[size] == 3:
fours.remove(size)
elif planks[size] == 5:
sixes.remove(size)
elif planks[size] == 7:
eights.remove(size)
suitable = (
len(fours) >= 1
and len(twos) >= 3
or len(fours) >= 2
or len(sixes) >= 1
and len(twos) >= 2
or len(eights) >= 1
)
if suitable:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
numcnt = [0] * (10**5 + 1)
o, e = 0, 0
b = 0
for i in a:
numcnt[i] += 1
for i in numcnt:
b += i // 4
e += i // 2
q = int(input())
for _ in range(q):
x, y = input().split()
y = int(y)
if x == "+":
numcnt[y] += 1
if numcnt[y] % 4 == 0:
b += 1
if numcnt[y] % 2 == 0:
e += 1
else:
numcnt[y] -= 1
if numcnt[y] % 4 == 3:
b -= 1
if numcnt[y] % 2 == 1:
e -= 1
print("YES" if b >= 2 or b == 1 and e >= 4 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
dic = {}
arr = list(map(int, input().split()))
dicf = {(8): 0, (6): 0, (4): 0, (2): 0}
for i in arr:
try:
if dic[i] == 7:
dicf[8] += 1
elif dic[i] == 5:
dicf[6] += 1
elif dic[i] == 3:
dicf[4] += 1
elif dic[i] == 1:
dicf[2] += 1
dic[i] += 1
except:
dic[i] = 1
for _ in range(int(input())):
v, x = map(str, input().split())
x = int(x)
if v == "+":
try:
if dic[x] == 7:
dicf[8] += 1
elif dic[x] == 5:
dicf[6] += 1
elif dic[x] == 3:
dicf[4] += 1
elif dic[x] == 1:
dicf[2] += 1
dic[int(x)] += 1
except:
dic[int(x)] = 1
else:
if dic[x] == 8:
dicf[8] -= 1
elif dic[x] == 6:
dicf[6] -= 1
elif dic[x] == 4:
dicf[4] -= 1
elif dic[x] == 2:
dicf[2] -= 1
dic[int(x)] -= 1
s = False
r = False
rs = 0
if dicf[8] > 0:
s = True
r = True
elif dicf[6] > 0 and dicf[2] > 1:
s = True
r = True
elif dicf[4] > 1:
s = True
r = True
elif dicf[4] > 0 and dicf[2] > 2:
s = True
r = True
if r and s:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
arr = [int(x) for x in input().split()]
dic = {}
sqSet, recSet, bothSet = set(), set(), set()
for i in arr:
dic[i] = dic.get(i, 0) + 1
val = dic[i]
if i in sqSet:
sqSet.remove(i)
if i in recSet:
recSet.remove(i)
if i in bothSet:
bothSet.remove(i)
if val >= 8:
bothSet.add(i)
elif val >= 6:
sqSet.add(i)
recSet.add(i)
elif val >= 4:
sqSet.add(i)
elif val >= 2:
recSet.add(i)
q = int(input())
for i in range(q):
sym, i = [x for x in input().split()]
i = int(i)
if i in sqSet:
sqSet.remove(i)
if i in recSet:
recSet.remove(i)
if i in bothSet:
bothSet.remove(i)
if sym == "+":
dic[i] = dic.get(i, 0) + 1
else:
dic[i] -= 1
val = dic[i]
if val >= 8:
bothSet.add(i)
elif val >= 6:
sqSet.add(i)
recSet.add(i)
elif val >= 4:
sqSet.add(i)
elif val >= 2:
recSet.add(i)
if len(bothSet) > 0 or len(sqSet) > 1 or len(sqSet) > 0 and len(recSet) > 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
s = [int(x) for x in input().split()]
pos = [0] * 100005
c4, c2 = 0, 0
for i in range(len(s)):
pos[s[i]] += 1
if pos[s[i]] % 4 == 0:
c4 += 1
c2 -= 1
elif pos[s[i]] % 2 == 0:
c2 += 1
for _ in range(int(input())):
L = input().split()
h1, h2 = str(L[0]), int(L[1])
if h1 == "+":
pos[h2] += 1
tt = pos[h2]
if tt % 4 == 0:
c4 += 1
c2 -= 1
elif tt % 2 == 0:
c2 += 1
else:
tt = pos[h2]
if tt % 4 == 0:
c4 -= 1
c2 += 1
elif tt % 2 == 0:
c2 -= 1
pos[h2] -= 1
print("YES" if c4 > 1 or c4 == 1 and c2 > 1 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | I = input
n = int(I())
d = {}
a = b = 0
for s in I().split() + [I() for _ in [0] * int(I())]:
e = 1
n -= 1
if n < 0:
e = s[0] < "-"
s = s[2:]
k = 2 * e - 1
m = d.get(s, 0)
d[s] = m + k
m += e
a += (m % 2 < 1) * k
b += (m % 4 < 1) * k
if n < 0:
print("NYOE S"[a - 3 > 0 < b :: 2]) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
l = list(map(int, input().split()))
set2 = set()
set4 = set()
allplanks = {}
for i in l:
if i in allplanks:
allplanks[i] += 1
else:
allplanks[i] = 1
for i in allplanks:
if allplanks[i] >= 4:
set4.add(i)
elif allplanks[i] >= 2:
set2.add(i)
q = int(input())
for i in range(q):
a, b = input().split()
b = int(b)
if a == "+":
if b in allplanks:
allplanks[b] += 1
else:
allplanks[b] = 1
if b in set2:
set2.remove(b)
if b in set4:
set4.remove(b)
if allplanks[b] >= 4:
set4.add(b)
elif allplanks[b] >= 2:
set2.add(b)
else:
if b in allplanks:
allplanks[b] -= 1
if b in set2:
set2.remove(b)
if b in set4:
set4.remove(b)
if allplanks[b] >= 4:
set4.add(b)
elif allplanks[b] >= 2:
set2.add(b)
if len(set4) >= 2:
print("YES")
elif len(set4) == 1 and len(set2) >= 2:
print("YES")
elif len(set4) == 1:
elem = set4.pop()
set4.add(elem)
cnt = allplanks[elem]
if cnt >= 8:
print("YES")
elif cnt >= 6:
if len(set2) >= 1:
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | def is_good(eights, sixes, fours, twos):
if eights > 0:
return True
if sixes > 0 and sixes + fours + twos >= 2:
return True
if fours >= 2:
return True
if fours == 1 and twos >= 2:
return True
return False
def main():
n = int(input())
a = list(map(int, input().split()))
d = {}
eights = sixes = fours = twos = 0
for i in a:
if i not in d:
d[i] = 1
else:
d[i] += 1
for k in d:
v = d[k]
if v >= 8:
eights += 1
elif v == 6 or v == 7:
sixes += 1
elif v == 4 or v == 5:
fours += 1
elif v == 2 or v == 3:
twos += 1
q = int(input())
for _ in range(q):
sign, x = input().split()
x = int(x)
if sign == "+":
if x in d:
if d[x] == 7:
eights += 1
sixes -= 1
elif d[x] == 5:
sixes += 1
fours -= 1
elif d[x] == 3:
fours += 1
twos -= 1
elif d[x] == 1:
twos += 1
d[x] += 1
else:
d[x] = 1
elif d[x] == 1:
del d[x]
else:
if d[x] == 8:
eights -= 1
sixes += 1
elif d[x] == 6:
sixes -= 1
fours += 1
elif d[x] == 4:
fours -= 1
twos += 1
elif d[x] == 2:
twos -= 1
d[x] -= 1
if is_good(eights, sixes, fours, twos):
print("YES")
else:
print("NO")
main() | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
p_ls = list(map(int, input().split()))
p_dict = {}
square_set = 0
rectangle_set = 0
p_dict = {}
for p in p_ls:
if p in p_dict:
p_dict[p] += 1
else:
p_dict[p] = 1
if p_dict[p] % 4 == 0:
square_set += 1
if p_dict[p] % 2 == 0:
rectangle_set += 1
events = int(input())
for e in range(events):
action, p = input().split()
p = int(p)
if action == "-":
if p_dict[p] % 4 == 0:
square_set -= 1
if p_dict[p] % 2 == 0:
rectangle_set -= 1
p_dict[p] -= 1
elif action == "+":
if p in p_dict:
p_dict[p] += 1
else:
p_dict[p] = 1
if p_dict[p] % 4 == 0:
square_set += 1
if p_dict[p] % 2 == 0:
rectangle_set += 1
if square_set >= 2:
print("YES")
elif square_set == 0:
print("NO")
elif rectangle_set >= 4:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
maxn = 101010
n = int(stdin.readline())
cnt = [0] * maxn
has = [0] * 10
has[0] = maxn
def upd_has(pos, val):
pos = min(pos, 8)
for i in range(pos, -1, -1):
has[i] += val
for i in map(int, stdin.readline().split()):
upd_has(cnt[i], -1)
cnt[i] += 1
upd_has(cnt[i], 1)
q = int(stdin.readline())
for query in range(q):
ch, num = stdin.readline().strip().split()
num = int(num)
sign = 1 if ch == "+" else -1
upd_has(cnt[num], -1)
cnt[num] += sign
upd_has(cnt[num], 1)
if has[8] > 0:
print("YES")
continue
if has[6] > 0 and has[2] >= 2:
print("YES")
continue
if has[4] > 0 and has[2] >= 3:
print("YES")
continue
if has[4] >= 2:
print("YES")
continue
print("NO") | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | from sys import stdin
def r():
return stdin.readline().strip()
def r_t(tp):
return map(tp, r().strip().split())
def r_l(tp):
return list(r_t(tp))
def update(A, B, C, addition, x):
if not addition:
in_4, in_2 = x in B, x in C
new_val = A[x] - 1
if new_val < 4 and in_4:
del B[x]
elif in_4:
B[x] -= 1
if new_val < 2 and in_2:
del C[x]
elif in_2:
C[x] -= 1
A[x] -= 1
elif x in A:
A[x] += 1
if A[x] >= 4:
B[x] = A[x]
if A[x] >= 2:
C[x] = A[x]
else:
A[x] = 1
def decide(A, B, C):
ans = "NO"
if B:
key = int()
for k in B:
key = k
break
update(A, B, C, 0, key)
update(A, B, C, 0, key)
update(A, B, C, 0, key)
update(A, B, C, 0, key)
if C:
key1 = int()
for k in C:
key1 = k
break
update(A, B, C, 0, key1)
update(A, B, C, 0, key1)
if C:
ans = "YES"
update(A, B, C, 1, key1)
update(A, B, C, 1, key1)
update(A, B, C, 1, key)
update(A, B, C, 1, key)
update(A, B, C, 1, key)
update(A, B, C, 1, key)
return ans
def main():
n = int(r())
nums = r_l(int)
A = dict()
for x in nums:
if x not in A:
A[x] = 1
else:
A[x] += 1
B, C = dict(), dict()
for x in A:
if A[x] >= 4:
B[x] = A[x]
if A[x] >= 2:
C[x] = A[x]
q = int(r())
for _ in range(q):
addition, x = r().split()
x = int(x)
update(A, B, C, 1 if addition == "+" else 0, x)
print(decide(A, B, C))
main() | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR IF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR IF VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | import sys
class SegTree:
def __init__(self, init_val, n, ide_ele, seg_func):
self.segfunc = seg_func
self.num = 2 ** (n - 1).bit_length()
self.ide_ele = ide_ele
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = self.seg[k][0], self.seg[k][1] + x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def maxt(a, b):
if a[1] > b[1]:
return a
else:
return b
input = sys.stdin.readline
(N,) = map(int, input().split())
X = list(map(int, input().split()))
nn = 10**5 + 1
ss = SegTree([(i, 0) for i in range(nn)], nn, (-1, -1), maxt)
for x in X:
ss.update(x, 1)
(Q,) = map(int, input().split())
for _ in range(Q):
t, x = input().strip().split()
x = int(x)
if t == "+":
ss.update(x, 1)
else:
ss.update(x, -1)
c, x = ss.query(0, nn)
if x >= 8:
print("YES")
elif x >= 6:
ss.update(c, -6)
c2, x2 = ss.query(0, nn)
if x2 >= 2:
print("YES")
else:
print("NO")
ss.update(c, 6)
elif x >= 4:
ss.update(c, -4)
c2, x2 = ss.query(0, nn)
if x2 >= 4:
print("YES")
elif x2 >= 2:
ss.update(c2, -2)
c3, x3 = ss.query(0, nn)
if x3 >= 2:
print("YES")
else:
print("NO")
ss.update(c2, 2)
else:
print("NO")
ss.update(c, 4)
else:
print("NO") | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
c = [0] * 100001
m2 = set()
m4 = set()
m6 = set()
m8 = set()
for i in range(n):
k = a[i]
c[k] += 1
if c[k] == 2:
m2.add(k)
elif c[k] == 4:
m4.add(k)
elif c[k] == 6:
m6.add(k)
elif c[k] == 8:
m8.add(k)
for i in range(q):
s, b = input().split()
k = int(b)
if s == "+":
c[k] += 1
if c[k] == 2:
m2.add(k)
elif c[k] == 4:
m4.add(k)
elif c[k] == 6:
m6.add(k)
elif c[k] == 8:
m8.add(k)
n += 1
else:
n -= 1
c[k] -= 1
if c[k] == 1:
m2.remove(k)
elif c[k] == 3:
m4.remove(k)
elif c[k] == 5:
m6.remove(k)
elif c[k] == 7:
m8.remove(k)
if n < 8 or len(m4) == 0:
print("NO")
elif len(m8) > 0 or len(m6) > 0 and len(m2) > 1 or len(m4) > 1 or len(m2) > 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = [int(x) for x in input().split()]
s2, s4, s6, s8 = 0, 0, 0, 0
d = dict()
for x in a:
if x in d:
d[x] += 1
else:
d[x] = 1
for x in d:
if d[x] >= 2:
s2 += 1
if d[x] >= 4:
s4 += 1
if d[x] >= 6:
s6 += 1
if d[x] >= 8:
s8 += 1
q = int(input())
for _ in range(q):
s, t = input().split()
t = int(t)
if s == "-":
if d[t] == 2:
s2 -= 1
elif d[t] == 4:
s4 -= 1
elif d[t] == 6:
s6 -= 1
elif d[t] == 8:
s8 -= 1
d[t] -= 1
else:
if t in d:
d[t] += 1
else:
d[t] = 1
if d[t] == 2:
s2 += 1
elif d[t] == 4:
s4 += 1
elif d[t] == 6:
s6 += 1
elif d[t] == 8:
s8 += 1
if s8 > 0:
print("Yes")
elif s6 > 0 and s2 > 1:
print("Yes")
elif s4 > 1:
print("Yes")
elif s4 > 0 and s2 > 2:
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
d = {}
n2 = n4 = 0
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
if d[i] % 2 == 0:
n2 += 1
if d[i] == 4:
n4 += 1
while q:
b1 = input().split()
ch = b1[0]
x = int(b1[1])
if ch == "+":
if x in d:
d[x] += 1
else:
d[x] = 1
if d[x] % 2 == 0:
n2 += 1
if d[x] == 4:
n4 += 1
else:
d[x] -= 1
if d[x] % 2 != 0:
n2 -= 1
if d[x] == 3:
n4 -= 1
if n4 > 0 and n2 >= 4:
print("YES")
else:
print("NO")
q -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
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 $n$ 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:
$+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$).
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-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks.
The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ 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 $x$ ($1 \le x \le 10^5$).
-----Output-----
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).
-----Example-----
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
-----Note-----
After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. | n = int(input())
a = {}
twos = 0
fours = 0
for i in list(map(int, input().split())):
a[i] = a.get(i, 0) + 1
if a[i] % 4 == 0:
fours += 1
twos -= 1
elif a[i] % 2 == 0:
twos += 1
for q in range(int(input())):
c, x = input().split()
x = int(x)
if c == "+":
a[x] = a.get(x, 0) + 1
if a[x] % 4 == 0:
fours += 1
twos -= 1
elif a[x] % 2 == 0:
twos += 1
else:
c4 = a[x] // 4
c2 = a[x] // 2 - 2 * c4
fours -= c4
twos -= c2
a[x] -= 1
if a[x] == 0:
a.pop(x)
available = a.get(x, 0)
contrib4 = available // 4
contrib2 = available // 2 - 2 * contrib4
fours += contrib4
twos += contrib2
able = False
if fours >= 2:
able = True
elif fours == 1 and twos >= 2:
able = True
if able:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.