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$. | n = int(input())
l = list(map(int, input().split()))
q = int(input())
d = dict()
for i in l:
if i not in d:
d[i] = 1
else:
d[i] += 1
sq = 0
rec = 0
for i in d:
temp = d[i]
sq += temp // 4
temp = temp % 4
rec += temp // 2
while q:
q -= 1
l = input().split()
i = int(l[1])
if i in d:
temp = d[i]
sq -= temp // 4
temp = temp % 4
rec -= temp // 2
else:
d[i] = 0
if l[0] == "+":
d[i] += 1
else:
d[i] -= 1
if d[i] != 0:
temp = d[i]
sq += temp // 4
temp = temp % 4
rec += temp // 2
else:
d.pop(i)
if sq >= 2:
print("YES")
elif sq == 1 and rec >= 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 FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR 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$. | def main():
n = int(input())
a = list(map(int, input().split()))
q = int(input())
que = [tuple(input().split()) for i in range(q)]
duplicated = set([])
pair = 0
count = [0] * (10**5 + 10)
for v in a:
count[v] += 1
for i in range(1, 10**5 + 10):
pair += count[i] // 2
if count[i] >= 4:
duplicated.add(i)
for i in range(q):
command, value = que[i]
value = int(value)
if command == "+":
if count[value] % 2 == 0:
count[value] += 1
else:
count[value] += 1
pair += 1
if count[value] >= 4:
duplicated.add(value)
elif count[value] % 2 == 0:
pair -= 1
count[value] -= 1
if count[value] == 3:
duplicated.remove(value)
else:
count[value] -= 1
if duplicated and pair >= 4:
print("YES")
else:
print("NO")
return
main() | 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN 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())
x = list(map(int, input().split()))
dic = {}
count1, count2, count3, count4 = 0, 0, 0, 0
for i in range(n):
if not x[i] in dic:
dic[x[i]] = 0
dic[x[i]] += 1
for i in dic.keys():
c = dic[i]
if c >= 2:
count1 += 1
if c >= 4:
count2 += 1
if c >= 6:
count3 += 1
if c >= 8:
count4 += 1
t = int(input())
for i in range(t):
s, c = input().split()
flag = True
c = int(c)
x = dic.get(c, 0)
if s == "-":
dic[c] = x - 1
c = x
if c == 8:
count4 -= 1
elif c == 6:
count3 -= 1
elif c == 4:
count2 -= 1
elif c == 2:
count1 -= 1
else:
dic[c] = x + 1
c = x + 1
if c == 8:
count4 += 1
elif c == 6:
count3 += 1
elif c == 4:
count2 += 1
elif c == 2:
count1 += 1
if (
count4 >= 1
or count3 >= 1
and count1 >= 2
or count2 >= 1
and count1 >= 3
or 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 DICT ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR 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())
a = list(map(int, input().split()))
m = int(input())
d = {}
for itr in a:
if itr in d:
d[itr] += 1
else:
d[itr] = 1
x = {(2): 0, (4): 0, (6): 0, (8): 0}
for itr in d:
if d[itr] >= 8:
x[8] += 1
elif d[itr] >= 6:
x[6] += 1
elif d[itr] >= 4:
x[4] += 1
elif d[itr] >= 2:
x[2] += 1
for itr in range(m):
b = list(input().split())
k = int(b[1])
if b[0] == "+":
if k in d:
d[k] += 1
else:
d[k] = 1
if d[k] == 8:
x[8] += 1
x[6] -= 1
elif d[k] == 6:
x[6] += 1
x[4] -= 1
elif d[k] == 4:
x[4] += 1
x[2] -= 1
elif d[k] == 2:
x[2] += 1
else:
d[k] -= 1
if d[k] == 7:
x[8] -= 1
x[6] += 1
elif d[k] == 5:
x[6] -= 1
x[4] += 1
elif d[k] == 3:
x[4] -= 1
x[2] += 1
elif d[k] == 1:
x[2] -= 1
if x[8] >= 1:
print("YES")
elif x[6] >= 2:
print("YES")
elif x[6] >= 1 and x[4] + x[2] >= 1:
print("YES")
elif x[4] >= 2:
print("YES")
elif x[4] >= 1 and x[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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR VAR VAR NUMBER ASSIGN 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 EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF 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(" ")))
count = [0] * int(100000.0 + 1)
fours = 0
twos = 0
def add(num):
global fours, twos
fours -= int(count[num] / 4)
twos -= int(count[num] % 4 / 2)
count[num] += 1
fours += int(count[num] / 4)
twos += int(count[num] % 4 / 2)
def remove(num):
global fours, twos
fours -= int(count[num] / 4)
twos -= int(count[num] % 4 / 2)
count[num] -= 1
fours += int(count[num] / 4)
twos += int(count[num] % 4 / 2)
for num in a:
add(num)
q = int(input())
for i in range(0, q):
sign, num = input().split(" ")
num = int(num)
if sign == "-":
remove(num)
else:
add(num)
if fours >= 1 and (fours - 1) * 2 + twos >= 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 STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP BIN_OP 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$. | n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * (10**5 + 5)
cnt4 = 0
cnt2 = 0
for i in range(n):
b[a[i]] += 1
for elem in b:
cnt4 += elem // 4
cnt2 += elem // 2
for i in range(q):
s = input().split()
x = int(s[1])
cnt4 -= b[x] // 4
cnt2 -= b[x] // 2
if s[0] == "+":
b[x] += 1
else:
b[x] -= 1
cnt4 += b[x] // 4
cnt2 += b[x] // 2
if cnt4 > 0:
cnt = cnt2 - 2
if cnt >= 2:
print("YES")
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 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 VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR 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 ASSIGN VAR BIN_OP 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$. | t = int(input())
x = list(map(int, input().split()))
l = [0] * (10**5 + 1)
cts = [0] * (10**5 + 1)
for each in x:
l[each] += 1
for each in l:
cts[each] += 1
twos = cts[2] + cts[3]
fours = cts[4] + cts[5]
sixes = cts[6] + cts[7]
eights = sum(cts[8:])
for _ in range(int(input())):
s, n = input().split()
r = int(n)
if s == "+":
l[r] += 1
if l[r] == 2:
twos += 1
elif l[r] == 4:
fours += 1
twos -= 1
elif l[r] == 6:
sixes += 1
fours -= 1
elif l[r] == 8:
eights += 1
sixes -= 1
else:
if l[r] == 2:
twos -= 1
elif l[r] == 4:
fours -= 1
twos += 1
elif l[r] == 6:
sixes -= 1
fours += 1
elif l[r] == 8:
sixes += 1
eights -= 1
l[r] -= 1
if (
(eights >= 1 or fours >= 2 or sixes >= 2)
or fours >= 1
and twos >= 2
or sixes >= 1
and twos >= 1
or sixes >= 1
and fours >= 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 BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL 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 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 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 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$. | import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write
def input():
return fast_reader().strip()
def print(*argv):
fast_writer(" ".join(str(i) for i in argv))
fast_writer("\n")
for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
if a[i] in d:
d[a[i]] += 1
else:
d[a[i]] = 1
s2 = 0
s4 = 0
key = list(d.keys())
for i in key:
if d[i] >= 4:
s4 += d[i] // 4
if d[i] % 4 >= 2:
s2 += 1
ans = ""
q = int(input())
for ppp in range(q):
x, y = input().split()
y = int(y)
if x == "+":
if y in d:
ini = d[y]
d[y] += 1
fin = d[y]
if ini // 4 != fin // 4:
s4 += 1
s2 -= 1
if ini % 4 < 2 and fin % 4 >= 2:
s2 += 1
else:
d[y] = 1
else:
ini = d[y]
d[y] -= 1
fin = d[y]
if ini // 4 != fin // 4:
s4 -= 1
if ini % 4 < 2 and fin % 4 >= 2:
s2 += 1
if ini % 4 >= 2 and fin % 4 < 2:
s2 -= 1
if s4 >= 2:
ans = "YES"
elif s4 >= 1 and s2 >= 2:
ans = "YES"
else:
ans = "NO"
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL 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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING 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 ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER 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$. | import sys
n = int(sys.stdin.readline())
arr = list(map(int, input().split()))
di = {}
count2 = 0
count4 = 0
for i in arr:
if i in di:
di[i] += 1
if di[i] % 4 != 0 and di[i] % 2 == 0:
count2 += 1
if di[i] % 4 == 0:
count4 += 1
count2 -= 1
else:
di[i] = 1
arr.clear()
no = int(sys.stdin.readline())
for i in range(no):
s, o = input().split()
o = int(o)
if s == "-":
if di[o] % 4 == 0:
count4 -= 1
count2 += 1
elif di[o] % 2 == 0 and di[o] % 4 != 0:
count2 -= 1
di[o] -= 1
else:
if o not in di:
di[o] = 0
di[o] += 1
if di[o] % 4 != 0 and di[o] % 2 == 0:
count2 += 1
if di[o] % 4 == 0:
count4 += 1
count2 -= 1
if count4 >= 2 or count4 >= 1 and count2 >= 2:
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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL 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 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 VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER 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$. | from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = [0] * 100010
s = [0] * 10
for x in a:
b[x] += 1
if b[x] == 8:
s[6] -= 1
s[8] += 1
elif b[x] == 6:
s[4] -= 1
s[6] += 1
elif b[x] == 4:
s[2] -= 1
s[4] += 1
elif b[x] == 2:
s[0] -= 1
s[2] += 1
elif b[x] == 1:
s[0] += 1
for _ in range(int(input())):
c, x = input().rstrip().split()
x = int(x)
if c == "+":
b[x] += 1
if b[x] == 8:
s[6] -= 1
s[8] += 1
elif b[x] == 6:
s[4] -= 1
s[6] += 1
elif b[x] == 4:
s[2] -= 1
s[4] += 1
elif b[x] == 2:
s[0] -= 1
s[2] += 1
elif b[x] == 1:
s[0] += 1
else:
b[x] -= 1
if b[x] == 7:
s[8] -= 1
s[6] += 1
elif b[x] == 5:
s[6] -= 1
s[4] += 1
elif b[x] == 3:
s[4] -= 1
s[2] += 1
elif b[x] == 1:
s[2] -= 1
s[0] += 1
elif b[x] == 0:
s[0] -= 1
if s[8] or s[6] > 1:
print("YES")
elif s[6] and (s[4] or s[2]):
print("YES")
elif s[4] >= 2:
print("YES")
elif s[4] and s[2] >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR VAR 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 BIN_OP LIST NUMBER NUMBER FOR VAR VAR 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 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING 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 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 VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF 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())
aq = [0] * (10**5 + 1)
a = list(map(int, input().split()))
q2, q4 = 0, 0
for x in a:
aq[x] += 1
for x in aq:
q4 += x // 4
q2 += x % 4 // 2
a = aq
t = int(input())
for _ in range(t):
c, x = input().split()
x = int(x)
if c == "-":
q4 -= a[x] // 4
q2 -= a[x] % 4 // 2
a[x] -= 1
q4 += a[x] // 4
q2 += a[x] % 4 // 2
elif c == "+":
q4 -= a[x] // 4
q2 -= a[x] % 4 // 2
a[x] += 1
q4 += a[x] // 4
q2 += a[x] % 4 // 2
print(("no", "yes")[q4 >= 1 and q2 // 2 + q4 > 1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN 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 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 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 EXPR FUNC_CALL VAR STRING STRING VAR NUMBER BIN_OP BIN_OP VAR 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())
a = input().split()
d = dict()
count = [0] * 100001
for i in a:
if i not in d:
d[i] = 1
count[1] += 1
else:
d[i] += 1
count[d[i]] += 1
q = int(input())
for i in range(q):
s = input().split()
if s[1] in d:
if s[0] == "+":
d[s[1]] += 1
count[d[s[1]]] += 1
else:
count[d[s[1]]] -= 1
d[s[1]] -= 1
else:
d[s[1]] = 1
if (
count[8] > 0
or count[6] > 0
and (count[4] > 1 or count[2] > 1)
or count[4] > 0
and count[2] > 2
or count[4] > 1
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR 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 VAR IF VAR NUMBER STRING VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR 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 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 check():
two, four, six, eight = 0, 0, 0, 0
for i in range(1, 9):
if i == 2 or i == 3:
two += ind[i]
if i == 4 or i == 5:
four += ind[i]
if i == 6 or i == 7:
six += ind[i]
if i >= 8:
eight += ind[i]
if four >= 1:
if four >= 2:
return True
if two >= 2:
return True
if six >= 1:
return True
if six >= 1:
if two >= 1 or four >= 1:
return True
if six >= 2:
return True
if eight >= 1:
return True
return False
n = int(input())
a = [int(i) for i in input().split()]
length = [0] * (100002 + 1)
for i in range(n):
length[a[i]] += 1
ind = [0] * 9
for i in length:
if i > 0:
if i <= 8:
ind[i] += 1
else:
ind[-1] += 1
q = int(input())
for i in range(q):
t = input()
if t[0] == "+":
pq = int(t[2:])
ind[min(8, length[pq])] -= 1
length[pq] += 1
ind[min(8, length[pq])] += 1
else:
pq = int(t[2:])
ind[min(8, length[pq])] -= 1
length[pq] -= 1
ind[min(8, length[pq])] += 1
if check():
sys.stdout.write("YES" + "\n")
else:
sys.stdout.write("NO" + "\n") | IMPORT FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER 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 BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING EXPR FUNC_CALL VAR BIN_OP 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$. | nums = {}
n = int(input())
e = {(2): 0, (4): 0, (6): 0, (8): 0}
for a in map(int, input().split()):
if a in nums:
nums[a] += 1
if nums[a] == 8:
e[8] += 1
e[6] -= 1
continue
if nums[a] == 6:
e[6] += 1
e[4] -= 1
continue
if nums[a] == 4:
e[4] += 1
e[2] -= 1
continue
if nums[a] == 2:
e[2] += 1
else:
nums[a] = 1
q = int(input())
for _ in range(q):
sign, x = input().split()
x = int(x)
if sign == "+":
if x in nums:
nums[x] += 1
if nums[x] == 8:
e[8] += 1
e[6] -= 1
if nums[x] == 6:
e[6] += 1
e[4] -= 1
if nums[x] == 4:
e[4] += 1
e[2] -= 1
if nums[x] == 2:
e[2] += 1
else:
nums[x] = 1
else:
nums[x] -= 1
if nums[x] == 7:
e[8] -= 1
e[6] += 1
elif nums[x] == 5:
e[6] -= 1
e[4] += 1
elif nums[x] == 3:
e[4] -= 1
e[2] += 1
elif nums[x] == 1:
e[2] -= 1
if e[4] + e[6] + e[8] > 0 and e[2] * 2 + e[4] * 4 + e[6] * 6 + e[8] * 8 >= 8:
print("YES")
else:
print("NO") | ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR 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 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 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 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 IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP 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$. | def low_bound(list, item):
low = -1
high = len(list)
while high - low > 1:
mid = (low + high) // 2
if list[mid][0] > item:
low = mid
else:
high = mid
return low
def high_bound(list, item):
low = -1
high = len(list)
while high - low > 1:
mid = (low + high) // 2
if list[mid][0] >= item:
low = mid
else:
high = mid
return high
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = [[0, i] for i in range(100000)]
d_ind = [i for i in range(100000)]
for i in range(n):
d[a[i] - 1][0] += 1
d.sort(reverse=True)
for i in range(100000):
d_ind[d[i][1]] = i
for i in range(q):
sign, leng = list(map(str, input().split()))
leng = int(leng)
ind_swap1 = 0
ind_swap2 = 0
if sign == "+":
ind_swap1 = d_ind[leng - 1]
ind_swap2 = high_bound(d, d[d_ind[leng - 1]][0] + 1)
d[d_ind[leng - 1]][0] += 1
else:
ind_swap1 = d_ind[leng - 1]
ind_swap2 = low_bound(d, d[d_ind[leng - 1]][0] - 1)
d[d_ind[leng - 1]][0] -= 1
d[ind_swap1], d[ind_swap2] = d[ind_swap2], d[ind_swap1]
d_ind[d[ind_swap1][1]], d_ind[d[ind_swap2][1]] = (
d_ind[d[ind_swap2][1]],
d_ind[d[ind_swap1][1]],
)
fl4 = False
fl21 = False
fl22 = False
for j in range(100000):
if d[j][0] >= 8:
fl4 = fl21 = fl22 = True
break
elif d[j][0] >= 6:
if fl4:
fl21 = True
fl22 = True
break
else:
fl4 = True
if fl21:
fl22 = True
break
else:
fl21 = True
elif d[j][0] >= 4:
if fl4:
fl21 = True
fl22 = True
break
else:
fl4 = True
elif d[j][0] >= 2:
if fl21:
fl22 = True
if fl4:
break
else:
fl21 = True
if not fl4:
break
elif not fl4 or not fl21 or not fl22:
break
if fl4 and fl21 and fl22:
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN 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 LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR IF 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$. | mv = 10**5
n = int(input())
A = list(map(int, input().split()))
G = [(0) for i in range(mv + 1)]
ns = 0
nr = 0
for i in A:
G[i] = G[i] + 1
if G[i] % 2 == 0:
nr = nr + 1
if G[i] % 4 == 0:
ns = ns + 1
q = int(input())
for i in range(q):
s = list(input().split())
v = int(s[1])
if s[0] == "+":
G[v] = G[v] + 1
if G[v] % 2 == 0:
nr = nr + 1
if G[v] % 4 == 0:
ns = ns + 1
else:
if G[v] % 2 == 0:
nr = nr - 1
if G[v] % 4 == 0:
ns = ns - 1
G[v] = G[v] - 1
if nr - 2 >= 2 and ns >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP NUMBER 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP 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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR 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$. | import sys
input = sys.stdin.readline
def name(op, h, f):
ele = op.split()
if int(ele[1]) not in h:
h[int(ele[1])] = 1
elif ele[0] == "+":
h[int(ele[1])] += 1
if h[int(ele[1])] % 2 == 0:
f[2] += 1
if h[int(ele[1])] % 4 == 0:
f[4] += 1
if h[int(ele[1])] % 6 == 0:
f[6] += 1
else:
if h[int(ele[1])] % 2 == 0:
f[2] -= 1
if h[int(ele[1])] % 4 == 0:
f[4] -= 1
if h[int(ele[1])] % 6 == 0:
f[6] -= 1
h[int(ele[1])] -= 1
if f[4] >= 2:
print("YES")
elif f[2] - 3 >= 1 and f[6] >= 1:
print("YES")
elif f[4] >= 1 and f[2] - 2 >= 2:
print("YES")
else:
print("NO")
def solution():
l = int(input())
arr = list(map(lambda x: int(x), input().split()))
n = int(input())
h = {}
f = {(2): 0, (6): 0, (4): 0}
for ele in arr:
if ele not in h:
h[ele] = 1
else:
h[ele] += 1
if h[ele] % 2 == 0:
f[2] += 1
if h[ele] % 4 == 0:
f[4] += 1
if h[ele] % 6 == 0:
f[6] += 1
for i in range(0, n):
op = input()
name(op, h, f)
solution() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR 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
n = int(input())
start = [int(x) for x in input().split()]
q = int(input())
planks = [(0) for _ in range(max(start) + 1)]
for s in start:
planks[s] += 1
state = "NO"
square = set()
rectangle = set()
for i in range(len(planks)):
if planks[i] >= 4:
square.add(i)
if planks[i] >= 2:
rectangle.add(i)
def check(planks, square, rectangle):
state = "NO"
if len(square) >= 2:
state = "YES"
elif len(square) == 0:
state = "NO"
else:
for s in square:
if planks[s] >= 8:
state = "YES"
break
if s not in rectangle and len(rectangle) >= 2:
state = "YES"
break
if s in rectangle and len(rectangle) >= 3:
state = "YES"
break
if s in rectangle and len(rectangle) >= 2 and planks[s] >= 6:
state = "YES"
break
print(state)
for line in sys.stdin:
sign, length = (x for x in line.split())
if sign == "+":
if int(length) >= len(planks) - 1:
for j in range(int(length) - (len(planks) - 1)):
planks.append(0)
planks[int(length)] += 1
if planks[int(length)] == 4:
square.add(int(length))
if planks[int(length)] == 2:
rectangle.add(int(length))
if sign == "-":
planks[int(length)] -= 1
if planks[int(length)] == 3:
square.remove(int(length))
if planks[int(length)] == 1:
rectangle.remove(int(length))
check(planks, square, rectangle) | IMPORT 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 NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR STRING IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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$. | def main():
number_plank = int(input())
planks = input().split()
number_events = int(input())
events = [0] * number_events
count = {}
cnt2 = 0
cnt4 = 0
for x in planks:
x = int(x)
if not x in count:
count[x] = 0
cnt2 -= count[x] // 2
cnt4 -= count[x] // 4
count[x] += 1
cnt2 += count[x] // 2
cnt4 += count[x] // 4
for x in range(number_events):
events[x] = int(input().replace(" ", ""))
for x in events:
if not abs(x) in count:
count[abs(x)] = 0
cnt2 -= count[abs(x)] // 2
cnt4 -= count[abs(x)] // 4
if x > 0:
count[abs(x)] += 1
else:
count[abs(x)] -= 1
cnt2 += count[abs(x)] // 2
cnt4 += count[abs(x)] // 4
if cnt4 > 0 and cnt2 > 3:
print("YES")
else:
print("NO")
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN 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 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 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
I = [(0) for i in range(10**5 + 1)]
y2, y4, y6, y8 = 0, 0, 0, 0
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
for i in range(0, n):
I[a[i]] = I[a[i]] + 1
if I[a[i]] == 2:
y2 = y2 + 1
if I[a[i]] == 4:
y4 = y4 + 1
if I[a[i]] == 6:
y6 = y6 + 1
if I[a[i]] == 8:
y8 = y8 + 1
Q = int(sys.stdin.readline().strip())
for q in range(Q):
s, x = sys.stdin.readline().strip().split()
x = int(x)
if s == "+":
I[x] = I[x] + 1
if I[x] == 2:
y2 = y2 + 1
if I[x] == 4:
y4 = y4 + 1
if I[x] == 6:
y6 = y6 + 1
if I[x] == 8:
y8 = y8 + 1
if s == "-":
I[x] = I[x] - 1
if I[x] == 1:
y2 = y2 - 1
if I[x] == 3:
y4 = y4 - 1
if I[x] == 5:
y6 = y6 - 1
if I[x] == 7:
y8 = y8 - 1
if y4 >= 1 and y2 + y4 + y6 + y8 >= 4:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL 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 ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR 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())
num = list(map(int, input().split()))
a, sum2, sum4 = 100001 * [0], 0, 0
def upp(x, v):
global sum2, sum4
sum4 -= int(a[x] / 4)
sum2 -= int(a[x] / 2)
a[x] += v
sum4 += int(a[x] / 4)
sum2 += int(a[x] / 2)
for i in range(n):
upp(num[i], 1)
q = int(input())
while q >= 1:
q -= 1
u = list(input().split())
if u[0] == "+":
upp(int(u[1]), 1)
else:
upp(int(u[1]), -1)
if sum4 >= 1 and sum2 >= 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 VAR VAR BIN_OP NUMBER LIST NUMBER NUMBER NUMBER FUNC_DEF VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL 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$. | n = int(input())
array = list(map(int, input().split(" ")))
count = []
for x in range(100001):
count.append(0)
for x in array:
count[x] += 1
c2 = 0
c4 = 0
c6 = 0
c8 = 0
for x in range(100001):
if count[x] >= 2:
c2 += 1
if count[x] >= 6:
c6 += 1
if count[x] >= 4:
c4 += 1
if count[x] >= 8:
c8 += 1
q = int(input())
def res(a, b, c, d):
if d > 0:
return "YES"
if c > 0 and a > 1:
return "YES"
if b > 1:
return "YES"
if b == 1 and a > 2:
return "YES"
return "NO"
for event in range(q):
c, x = input().split(" ")
x = int(x)
if c == "+":
count[x] += 1
if count[x] == 2:
c2 += 1
if count[x] == 4:
c4 += 1
if count[x] == 8:
c8 += 1
if count[x] == 6:
c6 += 1
else:
count[x] -= 1
if count[x] == 1:
c2 -= 1
if count[x] == 3:
c4 -= 1
if count[x] == 7:
c8 -= 1
if count[x] == 5:
c6 -= 1
print(res(c2, c4, c6, c8)) | 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 FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 FUNC_DEF IF VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING 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 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 EXPR FUNC_CALL VAR 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())
arr = [int(i) for i in input().split()]
q = int(input())
dic1 = {}
dic2 = {}
for i in range(0, 8 + 1):
dic2[i] = 0
for i in range(n):
if arr[i] not in dic1:
dic1[arr[i]] = 1
dic2[1] += 1
else:
if dic1[arr[i]] < 8:
dic2[dic1[arr[i]]] -= 1
dic1[arr[i]] += 1
if dic1[arr[i]] < 8:
dic2[dic1[arr[i]]] += 1
elif dic1[arr[i]] == 8:
dic2[8] += 1
for _ in range(q):
s, a = input().split()
a = int(a)
if s == "+":
if a not in dic1:
dic1[a] = 1
dic2[1] += 1
else:
if dic1[a] < 8:
dic2[dic1[a]] -= 1
dic1[a] += 1
if dic1[a] < 8:
dic2[dic1[a]] += 1
elif dic1[a] == 8:
dic2[8] += 1
else:
if dic1[a] <= 8:
dic2[dic1[a]] -= 1
dic1[a] -= 1
if dic1[a] < 8:
dic2[dic1[a]] += 1
s = 0
for i in range(4, 8):
s += dic2[i]
if dic2[8] >= 1 or s >= 2:
print("YES")
elif s == 0:
print("NO")
elif dic2[6] == 1 or dic2[7] == 1:
if dic2[2] + dic2[3] + 1 >= 2:
print("YES")
else:
print("NO")
elif dic2[2] + dic2[3] >= 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER 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 IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF 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(""))
p = [int(x) for x in input("").split()]
q = int(input(""))
l = [0] * 10**6
c2, c4, c6, c8 = 0, 0, 0, 0
for i in p:
l[i] += 1
if l[i] == 2:
c2 += 1
elif l[i] == 4:
c4 += 1
elif l[i] == 6:
c6 += 1
elif l[i] == 8:
c8 += 1
for i in range(q):
qs = input("").split()
if qs[0] == "+":
l[int(qs[1])] += 1
if l[int(qs[1])] == 2:
c2 += 1
elif l[int(qs[1])] == 4:
c4 += 1
elif l[int(qs[1])] == 6:
c6 += 1
elif l[int(qs[1])] == 8:
c8 += 1
else:
l[int(qs[1])] -= 1
if l[int(qs[1])] == 1:
c2 -= 1
elif l[int(qs[1])] == 3:
c4 -= 1
elif l[int(qs[1])] == 5:
c6 -= 1
elif l[int(qs[1])] == 7:
c8 -= 1
if c8 >= 1 or c6 >= 1 and c2 >= 2 or c4 >= 2 or c4 >= 1 and c2 >= 3:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP 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 IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 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 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$. | def check(tem2, tem4):
if tem4 < 1:
return False
if tem4 >= 2:
return True
if tem2 >= 4:
return True
return False
num = int(input())
init = input().split()
dic = {}
tem4 = 0
tem2 = 0
resultado = []
for i in init:
if i in dic:
tem4 -= int(dic[i] / 4)
tem2 -= int(dic[i] / 2)
dic[i] += 1
tem4 += int(dic[i] / 4)
tem2 += int(dic[i] / 2)
else:
dic[i] = 1
num = int(input())
for i in range(num):
a, b = input().split()
if a == "+":
if b in dic:
tem4 -= int(dic[b] / 4)
tem2 -= int(dic[b] / 2)
dic[b] += 1
tem4 += int(dic[b] / 4)
tem2 += int(dic[b] / 2)
else:
dic[b] = 1
else:
tem4 -= int(dic[b] / 4)
tem2 -= int(dic[b] / 2)
dic[b] -= 1
tem4 += int(dic[b] / 4)
tem2 += int(dic[b] / 2)
if check(tem2, tem4):
resultado.append("YES")
else:
resultado.append("NO")
print("\n".join(resultado)) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR 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 IF VAR STRING IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR 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())
l = list(map(int, input().split()))
changes = int(input())
d = {}
carre = 0
rect = 0
for el in l:
if el in d:
d[el] += 1
else:
d[el] = 1
for qtt in d.values():
carre += qtt // 4
rect += qtt % 4 // 2
for i in range(changes):
op, l = input().split()
l = int(l)
if op == "-":
d[l] -= 1
if not (d[l] + 1) % 4:
carre -= 1
rect += 1
elif not (d[l] + 1) % 2:
rect -= 1
else:
if l in d:
d[l] += 1
else:
d[l] = 1
if not d[l] % 4:
carre += 1
rect -= 1
elif not d[l] % 2:
rect += 1
print(["NO", "YES"][carre >= 1 and rect >= 2 or carre >= 2]) | 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 IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP 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 VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER VAR 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$. | t = int(input())
num = list(map(int, input().split(" ")))
q = int(input())
cum_dict = {}
var0 = 0
var1 = 0
var2 = 0
var3 = 0
var4 = 0
count_dict = {}
for i in num:
if i not in count_dict.keys():
count_dict[i] = 1
var0 += 1
elif count_dict[i] == 1:
var0 -= 1
var1 += 1
count_dict[i] += 1
elif count_dict[i] == 2:
count_dict[i] += 1
elif count_dict[i] == 3:
var1 -= 1
var2 += 1
count_dict[i] += 1
elif count_dict[i] == 4:
count_dict[i] += 1
elif count_dict[i] == 5:
var2 -= 1
var3 += 1
count_dict[i] += 1
elif count_dict[i] == 6:
count_dict[i] += 1
elif count_dict[i] == 7:
var3 -= 1
var4 += 1
count_dict[i] += 1
else:
count_dict[i] += 1
for _ in range(q):
tmp_str = input().split(" ")
i = int(tmp_str[1])
if tmp_str[0] == "+":
if i not in count_dict.keys():
count_dict[i] = 1
var0 += 1
elif count_dict[i] == 1:
var0 -= 1
var1 += 1
count_dict[i] += 1
elif count_dict[i] == 2:
count_dict[i] += 1
elif count_dict[i] == 3:
var1 -= 1
var2 += 1
count_dict[i] += 1
elif count_dict[i] == 4:
count_dict[i] += 1
elif count_dict[i] == 5:
var2 -= 1
var3 += 1
count_dict[i] += 1
elif count_dict[i] == 6:
count_dict[i] += 1
elif count_dict[i] == 7:
var3 -= 1
var4 += 1
count_dict[i] += 1
else:
count_dict[i] += 1
elif count_dict[i] == 1:
count_dict[i] -= 1
elif count_dict[i] == 2:
var0 += 1
var1 -= 1
count_dict[i] -= 1
elif count_dict[i] == 3:
count_dict[i] -= 1
elif count_dict[i] == 4:
var1 += 1
var2 -= 1
count_dict[i] -= 1
elif count_dict[i] == 5:
count_dict[i] -= 1
elif count_dict[i] == 6:
var2 += 1
var3 -= 1
count_dict[i] -= 1
elif count_dict[i] == 7:
count_dict[i] -= 1
elif count_dict[i] == 8:
var3 += 1
var4 -= 1
count_dict[i] -= 1
else:
count_dict[i] -= 1
if var4 >= 1 or var3 >= 2 or var2 >= 2:
print("YES")
elif var3 >= 1 and (var1 >= 1 or var2 >= 1):
print("YES")
elif var2 >= 1 and var1 >= 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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR 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$. | def ans(a, b, n):
length = len(a)
counter = 0
d = {}
sq = 0
rect = 0
i1 = -1
for i in a:
if i not in d:
d[i] = 1
else:
d[i] += 1
for j in d:
if d[j] >= 8:
sq += 2
elif d[j] >= 6:
sq += 1
rect += 1
elif d[j] >= 4:
sq += 1
elif d[j] >= 2:
rect += 1
for i in range(n):
x = b[counter]
counter += 1
if x > 0:
if x not in d:
d[x] = 1
else:
d[x] += 1
if d[x] == 8:
rect -= 1
sq += 1
elif d[x] == 6:
rect += 1
elif d[x] == 4:
sq += 1
rect -= 1
elif d[x] == 2:
rect += 1
length += 1
else:
y = -x
d[y] -= 1
if d[y] == 7:
sq -= 1
rect += 1
elif d[y] == 5:
rect -= 1
elif d[y] == 3:
sq -= 1
rect += 1
elif d[y] == 1:
rect -= 1
length -= 1
if length < 8:
print("NO")
elif sq >= 2:
print("YES")
elif sq == 1 and rect >= 2:
print("YES")
else:
print("NO")
return
m = int(input())
lis = input().split()
n = int(input())
a = []
for i in lis:
a.append(int(i))
b = []
for j in range(n):
x = input().split()
if x[0] == "-":
y = int(x[1]) * -1
else:
y = int(x[1])
b.append(y)
ans(a, b, n) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR 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 VAR NUMBER ASSIGN VAR VAR 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 VAR NUMBER IF 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 RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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$. | from sys import stdin
input = stdin.readline
n = int(input())
(*a,) = map(int, input().split())
cnt = [0] * 100001
t = f = 0
for i in a:
if cnt[i] & 1:
t += 1
if cnt[i] & 3 == 3:
f += 1
cnt[i] += 1
for _ in range(int(input())):
cmd = input().split()
x = int(cmd[1])
if cmd[0] == "+":
if cnt[x] & 1:
t += 1
if cnt[x] & 3 == 3:
f += 1
cnt[x] += 1
else:
if not cnt[x] & 1:
t -= 1
if not cnt[x] & 3:
f -= 1
cnt[x] -= 1
print("YES" if f and t > 3 else "NO") | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER 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 IF VAR NUMBER STRING IF BIN_OP VAR VAR 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 VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR 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$. | import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
storage = [(0) for i in range(10**5 + 1)]
sides = [(0) for i in range(9)]
for i in a:
storage[i] += 1
for i in storage:
if i >= 8:
sides[8] += 1
elif i >= 6:
sides[6] += 1
elif i >= 4:
sides[4] += 1
elif i >= 2:
sides[2] += 1
for _ in range(int(input())):
ps, s = input().split()
size = int(s)
if ps == "+":
storage[size] += 1
if storage[size] == 2:
sides[2] += 1
elif storage[size] == 4:
sides[2] -= 1
sides[4] += 1
elif storage[size] == 6:
sides[4] -= 1
sides[6] += 1
elif storage[size] == 8:
sides[6] -= 1
sides[8] += 1
else:
storage[size] -= 1
if storage[size] == 1:
sides[2] -= 1
elif storage[size] == 3:
sides[2] += 1
sides[4] -= 1
elif storage[size] == 5:
sides[4] += 1
sides[6] -= 1
elif storage[size] == 7:
sides[6] += 1
sides[8] -= 1
if sides[8] != 0:
print("YES")
elif sides[6] != 0 and sides[2] + sides[4] + sides[6] > 1:
print("YES")
elif sides[4] > 1:
print("YES")
elif sides[4] == 1 and sides[2] > 1:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF 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 FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR 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 NUMBER NUMBER VAR VAR NUMBER IF VAR VAR 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 NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF 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()))
q = int(input())
X = [0] * (10**5 + 1)
for a in A:
X[a] += 1
S8 = set()
S6 = set()
S4 = set()
S2 = set()
S0 = set()
for i, x in enumerate(X):
if i == 0:
continue
if x >= 8:
S8.add(i)
elif x >= 6:
S6.add(i)
elif x >= 4:
S4.add(i)
elif x >= 2:
S2.add(i)
else:
S0.add(i)
for i in range(q):
e, x = map(str, input().split())
x = int(x)
if e == "+":
if X[x] == 1:
S0.remove(x)
S2.add(x)
elif X[x] == 3:
S2.remove(x)
S4.add(x)
elif X[x] == 5:
S4.remove(x)
S6.add(x)
elif X[x] == 7:
S6.remove(x)
S8.add(x)
else:
pass
X[x] += 1
else:
if X[x] == 2:
S2.remove(x)
S0.add(x)
elif X[x] == 4:
S4.remove(x)
S2.add(x)
elif X[x] == 6:
S6.remove(x)
S4.add(x)
elif X[x] == 8:
S8.remove(x)
S6.add(x)
else:
pass
X[x] -= 1
if len(S8) >= 1:
print("YES")
elif len(S6) >= 2:
print("YES")
elif len(S6) >= 1 and len(S4) >= 1:
print("YES")
elif len(S6) >= 1 and len(S2) >= 1:
print("YES")
elif len(S4) >= 2:
print("YES")
elif len(S4) >= 1 and len(S2) >= 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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN 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 VAR FUNC_CALL VAR VAR IF VAR NUMBER 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 EXPR FUNC_CALL VAR 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 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 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 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 IF FUNC_CALL VAR VAR NUMBER 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 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$. | def solve():
n = int(input())
colv = [(0) for i in range(8)]
dct = {}
for i in list(map(int, input().split())):
if dct.get(i, False):
if dct[i] < 8:
colv[dct[i]] += 1
if dct[i] < 8:
colv[dct[i] - 1] -= 1
dct[i] += 1
else:
dct[i] = 1
colv[0] += 1
for q in range(int(input())):
a, b = input().split()
b = int(b)
if a == "+":
if dct.get(b, False):
if dct[b] < 8:
colv[dct[b]] += 1
if dct[b] < 8:
colv[dct[b] - 1] -= 1
dct[b] += 1
else:
dct[b] = 1
colv[0] += 1
else:
dct[b] -= 1
if dct[b] < 8:
colv[dct[b]] -= 1
if dct[b]:
if dct[b] < 8:
colv[dct[b] - 1] += 1
s = 0
m4 = False
for i in range(1, 8):
s += colv[i] * (i + i % 2)
if i >= 3 and colv[i]:
m4 = True
if m4 and s >= 8:
print("YES")
else:
print("NO")
for i in range(1):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN 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 FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER 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$. | t = int(input())
list_ = [0] * 100001
a = list(map(int, list(input().split())))
c1 = 0
c2 = 0
for s in a:
list_[s] += 1
if list_[s] % 2 == 0:
c1 += 1
if list_[s] % 4 == 0:
c2 += 1
n = int(input())
for i in range(n):
x, y = input().split()
y = int(y)
if x == "+":
list_[y] += 1
if list_[y] % 2 == 0:
c1 += 1
if list_[y] % 4 == 0:
c2 += 1
else:
list_[y] -= 1
if list_[y] % 2 == 1:
c1 -= 1
if list_[y] % 4 == 3:
c2 -= 1
if c2 == 0 or c1 < 4:
print("NO", "\n")
else:
print("YES", "\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR 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 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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR 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$. | maxN = 100000.0 + 5
a = [0] * int(maxN)
cnt = [0] * int(maxN)
n = int(input())
x = [int(item) for item in input().split()]
for i in range(n):
a[x[i]] += 1
cnt[a[x[i]]] += 1
q = int(input())
for i in range(q):
t = [item for item in input().split()]
c = t[0]
x = int(t[1])
if c == "+":
a[x] += 1
cnt[a[x]] += 1
else:
cnt[a[x]] -= 1
a[x] -= 1
if (
cnt[8] > 0
or cnt[4] >= 2
or cnt[6] > 0
and cnt[2] >= 2
or cnt[4] > 0
and cnt[2] >= 3
):
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR 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 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()))
q = int(input())
have = [0] * 100010
for i in range(n):
have[arr[i]] += 1
haveFour = 0
haveTwo = 0
for i in range(len(have)):
haveFour += have[i] // 4
haveTwo += have[i] % 4 // 2
for i in range(q):
a, b = list(input().split())
b = int(b)
if a == "+":
have[b] += 1
if have[b] % 4 == 0:
haveFour += 1
haveTwo -= 1
elif have[b] % 2 == 0:
haveTwo += 1
else:
have[b] -= 1
if have[b] % 4 == 3:
haveFour -= 1
haveTwo += 1
elif have[b] % 2 == 1:
haveTwo -= 1
if haveFour >= 1 and haveTwo >= 2 or haveFour >= 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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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 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 VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER 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 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())
l = list(map(int, input().split()))
d = {}
for i in l:
if i in d:
d[i] += 1
else:
d[i] = 1
fours = 0
twos = 0
for i in d.values():
if i >= 4:
fours += i // 4
twos += i % 4 // 2
elif i >= 2:
twos += 1
e = int(input())
for i in range(e):
[m, p] = input().split()
p = int(p)
if m == "+":
if p in d:
if d[p] == 1:
twos += 1
elif d[p] == 3:
fours += 1
twos -= 1
elif d[p] > 4 and d[p] % 4 == 3:
fours += 1
twos -= 1
elif d[p] > 4 and d[p] % 2 == 1:
twos += 1
d[p] += 1
else:
d[p] = 1
else:
if d[p] > 5 and d[p] % 4 == 0:
fours -= 1
twos += 1
elif d[p] > 5 and d[p] % 2 == 0:
twos -= 1
elif d[p] == 4:
fours -= 1
twos += 1
elif d[p] == 2:
twos -= 1
d[p] -= 1
if fours > 0 and 2 * (fours - 1) + twos >= 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 IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST 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 IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP 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 = int(input())
l = list(map(int, input().split()))
d = {}
for i in l:
if d.get(i) == None:
d[i] = [1, 0, False]
else:
d[i][0] += 1
d[i][1] = d[i][0] // 2
if d[i][0] >= 4:
d[i][2] = True
ans = 0
isans = 0
for i in d:
ans += d[i][1]
if d[i][2]:
isans += 1
x = int(input())
count = t
for i in range(x):
s, a = input().split()
a = int(a)
if s == "+":
if d.get(a) == None:
d[a] = [1, 0, False]
else:
d[a][0] += 1
if d[a][0] % 2 == 0:
d[a][1] += 1
ans += 1
if d[a][0] >= 4 and not d[a][2]:
d[a][2] = True
isans += 1
count += 1
else:
count -= 1
d[a][0] -= 1
if d[a][0] % 2 != 0:
d[a][1] -= 1
ans -= 1
if d[a][0] < 4 and d[a][2]:
d[a][2] = False
isans -= 1
if count < 8:
print("NO")
continue
if ans >= 4 and isans > 0:
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 IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN 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$. | t = int(input())
def calculate(main):
if main.get(8, 0) >= 1:
print("YES")
elif main.get(4, 0) >= 2:
print("YES")
elif main.get(6, 0) >= 2:
print("YES")
elif main.get(6, 0) == 1 and (main.get(4, 0) >= 1 or main.get(2, 0) >= 1):
print("YES")
elif main.get(4, 0) == 1 and main.get(2, 0) >= 2:
print("YES")
else:
print("NO")
a = list(map(lambda x: int(x), input().split()))
hashmap = {}
main = {(2): 0, (4): 0, (8): 0, (6): 0}
for i in a:
if i not in hashmap:
hashmap[i] = 0
hashmap[i] += 1
for i in hashmap:
if hashmap[i] >= 8:
main[8] += 1
elif hashmap[i] >= 6:
main[6] += 1
elif hashmap[i] >= 4:
main[4] += 1
elif hashmap[i] >= 2:
main[2] += 1
q = int(input())
for i in range(0, q):
op, num = list(map(lambda x: x, input().split()))
num = int(num)
if op == "+":
if num not in hashmap:
hashmap[num] = 1
calculate(main)
continue
temp = hashmap[num]
hashmap[num] += 1
if hashmap[num] == 2:
main[2] += 1
elif hashmap[num] == 4:
main[2] -= 1
main[4] += 1
elif hashmap[num] == 6:
main[4] -= 1
main[6] += 1
elif hashmap[num] == 8:
main[6] -= 1
main[8] += 1
if op == "-":
if num not in hashmap:
hashmap[num] = 1
calculate(main)
continue
temp = hashmap[num]
hashmap[num] -= 1
if temp == 2:
main[2] -= 1
elif temp == 4:
main[2] += 1
main[4] -= 1
elif temp == 6:
main[6] -= 1
main[4] += 1
elif temp == 8:
main[6] += 1
main[8] -= 1
calculate(main) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL 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 VAR VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR 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 NUMBER NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER 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$. | m = int(input())
a = list(map(int, input().split()))
n = int(input())
c = {}
for i in a:
if i in c:
c[i] += 1
else:
c[i] = 1
t = 0
p = 0
for key, val in c.items():
t += val // 4
val = val - val // 4 * 4
p += val // 2
for i in range(n):
b = list(input().split())
if b[0] == "+":
if int(b[1]) in c:
c[int(b[1])] += 1
else:
c[int(b[1])] = 1
if c[int(b[1])] % 4 == 0:
t += 1
p -= 1
elif c[int(b[1])] % 2 == 0:
p += 1
else:
if int(b[1]) in c:
c[int(b[1])] -= 1
if (c[int(b[1])] + 1) % 4 == 0:
t -= 1
p += 1
elif (c[int(b[1])] + 1) % 2 == 0:
p -= 1
if t >= 2:
print("YES")
elif t == 1 and p >= 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 DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER 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()))
ware = {}
pairs = 0
pair = {}
sq = 0
re = 0
for i in range(n):
ware[arr[i]] = ware.get(arr[i], 0) + 1
if ware[arr[i]] == 2:
ware[arr[i]] = 0
pair[arr[i]] = pair.get(arr[i], 0) + 1
pairs += 1
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] == 2:
ware[a] = 0
pair[a] = pair.get(a, 0) + 1
pairs += 1
elif ware[a] == 0:
ware[a] = 1
pair[a] -= 1
pairs -= 1
if pair[a] == 0:
del pair[a]
else:
ware[a] -= 1
if pairs >= 4 and len(pair) < pairs:
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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL 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 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 ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL 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$. | def increase(num_counter, seconds, fourths):
if num_counter and num_counter % 4 == 0:
fourths += 1
seconds -= 1
elif num_counter and num_counter % 2 == 0:
seconds += 1
return seconds, fourths
def decrease(num_counter, seconds, fourths):
if num_counter and num_counter % 4 == 3:
fourths -= 1
seconds += 1
elif num_counter and num_counter % 2 == 1:
seconds -= 1
return seconds, fourths
input()
arr = input().split()
q = int(input())
counter = dict()
fourths = 0
seconds = 0
for val in arr:
counter[val] = counter.get(val, 0) + 1
seconds, fourths = increase(counter[val], seconds, fourths)
while q > 0:
q -= 1
op, val = input().split()
if op == "+":
num_counter = counter[val] = counter.get(val, 0) + 1
seconds, fourths = increase(num_counter, seconds, fourths)
else:
num_counter = counter[val] = counter[val] - 1
seconds, fourths = decrease(num_counter, seconds, fourths)
if fourths > 1 or fourths == 1 and seconds > 1:
print("YES")
else:
print("NO") | FUNC_DEF IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR 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$. | def main():
n = int(input())
a = list(map(int, input().split()))
l = [(0) for i in range(100001)]
for i in range(n):
l[a[i]] += 1
m2 = set([])
m4 = set([])
m6 = set([])
m8 = set([])
for i in range(100001):
if l[i] == 2 or l[i] == 3:
m2.add(i)
if l[i] == 4 or l[i] == 5:
m4.add(i)
if l[i] == 6 or l[i] == 7:
m6.add(i)
if l[i] >= 8:
m8.add(i)
q = int(input())
for i in range(q):
s, idx = input().split()
idx = int(idx)
if s == "+":
l[idx] += 1
if l[idx] == 2:
m2.add(idx)
elif idx in m2 and l[idx] == 4:
m2.discard(idx)
m4.add(idx)
elif idx in m4 and l[idx] == 6:
m4.discard(idx)
m6.add(idx)
elif idx in m6 and l[idx] == 8:
m6.discard(idx)
m8.add(idx)
else:
l[idx] -= 1
if idx in m2 and l[idx] == 1:
m2.discard(idx)
elif idx in m4 and l[idx] == 3:
m4.discard(idx)
m2.add(idx)
elif idx in m6 and l[idx] == 5:
m6.discard(idx)
m4.add(idx)
elif idx in m8 and l[idx] == 7:
m8.discard(idx)
m6.add(idx)
if (
len(m8) > 0
or len(m6) > 1
or len(m6) > 0
and len(m2) + len(m4) > 0
or len(m4) > 1
or len(m4) > 0
and len(m2) > 1
):
print("YES")
else:
print("NO")
main() | 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 NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER 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 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 IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR 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 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$. | t = int(input())
a = input().split(" ")
a = list(map(int, a))
n = 2 * pow(10, 5)
lis = n * [0]
cnt = n * [0]
for ele in a:
lis[ele] += 1
cnt[lis[ele]] += 1
t2 = int(input())
for i in range(t2):
c = input().split(" ")
if c[0] == "+":
v = int(c[1])
lis[v] += 1
cnt[lis[v]] += 1
else:
v = int(c[1])
cnt[lis[v]] -= 1
lis[v] -= 1
if (
cnt[8] >= 1
or cnt[4] >= 2
or cnt[6] >= 1
and cnt[2] >= 2
or cnt[4] >= 1
and cnt[2] >= 3
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP VAR LIST 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 FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL 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 = list(map(int, input().split()))
k = []
cnt = [0] * 10**6
c2, c4 = 0, 0
for i in range(n):
x = A[i]
c2 -= cnt[x] // 2
c4 -= cnt[x] // 4
cnt[x] += 1
c2 += cnt[x] // 2
c4 += cnt[x] // 4
for i in range(int(input())):
typ, x = map(str, input().split())
x = int(x)
c2 -= cnt[x] // 2
c4 -= cnt[x] // 4
if typ == "+":
cnt[x] += 1
else:
cnt[x] -= 1
c2 += cnt[x] // 2
c4 += cnt[x] // 4
if c4 >= 1 and c2 >= 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 LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER 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 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$. | n = int(input().split()[0])
arr = [0] * 100005
line = input().split()
for i in range(n):
arr[int(line[i])] += 1
eights, sixes, fours, twos = 0, 0, 0, 0
for i in range(100004):
if arr[i] >= 8:
eights += 1
elif arr[i] >= 6:
sixes += 1
elif arr[i] >= 4:
fours += 1
elif arr[i] >= 2:
twos += 1
numQueries = int(input().split()[0])
for i in range(numQueries):
line = input().split()
add = line[0]
q = int(line[1])
if add == "+":
arr[q] += 1
if arr[q] == 2:
twos += 1
elif arr[q] == 4:
fours += 1
twos -= 1
elif arr[q] == 6:
sixes += 1
fours -= 1
elif arr[q] == 8:
eights += 1
sixes -= 1
if add == "-":
arr[q] -= 1
if arr[q] == 1:
twos -= 1
elif arr[q] == 3:
fours -= 1
twos += 1
elif arr[q] == 5:
sixes -= 1
fours += 1
elif arr[q] == 7:
eights -= 1
sixes += 1
if (
fours + sixes + eights >= 2
or fours >= 1
and twos >= 2
or sixes >= 1
and twos >= 1
or eights >= 1
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL 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 FUNC_CALL VAR NUMBER 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 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 IF BIN_OP BIN_OP VAR VAR 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$. | t = 1
for _ in range(t):
n = int(input())
a = list(map(int, input().rstrip().split()))
freq = {}
for i in a:
if i not in freq.keys():
freq[i] = 0
freq[i] += 1
sdg4, sdg2 = 0, 0
check = False
for val in freq.values():
sdg4 += val // 4
sdg2 += val // 2
Q = int(input())
for q in range(Q):
s = list(input().rstrip().split())
num = int(s[1])
if s[0] == "+":
if num not in freq:
freq[num] = 1
else:
if freq[num] % 4 == 3:
sdg4 += 1
if freq[num] % 2 == 1:
sdg2 += 1
freq[num] += 1
n += 1
else:
if freq[num] % 2 == 0:
sdg2 -= 1
if freq[num] % 4 == 0:
sdg4 -= 1
freq[num] -= 1
n -= 1
if n < 8:
print("NO")
continue
if sdg2 >= 4:
chk = True
else:
chk = False
if chk and sdg4 > 0:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER FOR 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 FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF 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())
lst = list(map(int, input().split()))
lenCnt = {}
cnt, items = [], []
if lst[0] == 80140:
hack = True
for i in lst:
if lenCnt.get(i):
lenCnt[i] += 1
else:
lenCnt[i] = 1
items.append(i)
cnt2, cnt4 = 0, 0
for i in items:
if lenCnt[i] >= 4:
cnt4 += lenCnt[i] // 4
if lenCnt[i] % 4 >= 2:
cnt2 += 1
elif lenCnt[i] >= 2:
cnt2 += 1
q = int(input())
for _ in range(q):
val = input()
m = int(val[1:])
if val[0] == "+":
if lenCnt.get(m) == None:
lenCnt[m] = 0
elif lenCnt[m] % 4 == 3:
cnt2 -= 1
cnt4 += 1
elif lenCnt[m] % 4 == 1:
cnt2 += 1
lenCnt[m] += 1
else:
if lenCnt[m] % 4 == 0:
cnt4 -= 1
cnt2 += 1
elif lenCnt[m] % 4 == 2:
cnt2 -= 1
lenCnt[m] -= 1
if cnt4 >= 2:
print("YES")
elif cnt4 == 1 and cnt2 >= 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 VAR LIST LIST IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER 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 IF FUNC_CALL VAR VAR NONE 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 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 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
def input():
return sys.stdin.readline().rstrip()
def input_split():
return [int(i) for i in input().split()]
n = int(input())
answers = []
arr = input_split()
q = int(input())
counts = {a: (0) for a in arr}
for a in arr:
counts[a] += 1
above_4 = set()
above_2 = set()
for k in counts:
if counts[k] >= 4:
above_4.add(k)
above_2.add(k)
elif counts[k] >= 2:
above_2.add(k)
else:
pass
for _ in range(q):
sym, length = input().split()
length = int(length)
if sym == "+":
if length not in counts:
counts[length] = 1
else:
counts[length] += 1
if counts[length] == 2:
above_2.add(length)
elif counts[length] == 4:
above_4.add(length)
else:
pass
else:
counts[length] -= 1
if counts[length] == 1:
above_2.discard(length)
above_4.discard(length)
elif counts[length] == 3:
above_4.discard(length)
else:
pass
ans = None
if len(above_4) >= 1 and len(above_2) >= 3:
ans = "YES"
elif len(above_4) == 1:
amt = counts[list(above_4)[0]]
if amt >= 8 and len(above_2) == 1:
ans = "YES"
elif amt >= 6 and len(above_2) == 2:
ans = "YES"
elif len(above_4) == 2:
ans = "YES"
if ans is None:
ans = "NO"
answers.append(ans)
print(*answers, sep="\n") | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR 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 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 ASSIGN VAR VAR NUMBER VAR VAR NUMBER 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 EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR NONE ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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()))
x = int(input())
b = [0] * 100001
k = 0
t = 0
for i in arr:
b[i] += 1
for e in b:
k = k + e // 2
t = t + e // 4
for j in range(x):
c, d = map(str, input().split())
d = int(d)
k = k - b[d] // 2
t = t - b[d] // 4
if c == "+":
b[d] = b[d] + 1
else:
b[d] = b[d] - 1
k += b[d] // 2
t += b[d] // 4
if t > 0 and k > 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP 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
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
twos = {}
fours = {}
eights = {}
sixs = {}
freq = {}
for num in A:
freq[num] = freq.get(num, 0) + 1
if freq[num] == 2:
twos[num] = True
if freq[num] == 4:
fours[num] = True
del twos[num]
if freq[num] == 6:
sixs[num] = True
del fours[num]
if freq[num] == 8:
eights[num] = True
del sixs[num]
for _ in range(q):
query = sys.stdin.readline().split()
num = int(query[1])
if query[0] == "+":
freq[num] = freq.get(num, 0) + 1
if freq[num] == 2:
twos[num] = True
if freq[num] == 4:
fours[num] = True
del twos[num]
if freq[num] == 6:
sixs[num] = True
del fours[num]
if freq[num] == 8:
eights[num] = True
del sixs[num]
else:
freq[num] = freq.get(num, 0) - 1
if freq[num] == 1:
del twos[num]
if freq[num] == 3:
del fours[num]
twos[num] = True
if freq[num] == 5:
del sixs[num]
fours[num] = True
if freq[num] == 7:
del eights[num]
sixs[num] = True
ans = "NO"
if len(eights) > 0:
ans = "YES"
if len(sixs) > 1:
ans = "YES"
if len(sixs) == 1 and (len(fours) > 0 or len(twos) > 0):
ans = "YES"
if len(fours) > 1:
ans = "YES"
if len(fours) == 1 and len(twos) > 1:
ans = "YES"
print(ans) | 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR 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 ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR 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$. | from sys import stdin
inp = lambda: stdin.readline().strip()
na = int(inp())
a = [0] * (10**5 + 1)
four = set()
six = set()
two = set()
eight = set()
for i in inp().split():
i = int(i)
a[i] += 1
if a[i] == 8:
eight.add(i)
six.remove(i)
if a[i] == 6:
four.remove(i)
six.add(i)
elif a[i] == 4:
four.add(i)
two.remove(i)
elif a[i] == 2:
two.add(i)
t = int(inp())
for _ in range(t):
s, n = inp().split()
n = int(n)
if s == "+":
a[n] += 1
if a[n] == 8:
eight.add(n)
six.remove(n)
if a[n] == 6:
four.remove(n)
six.add(n)
elif a[n] == 4:
four.add(n)
two.remove(n)
elif a[n] == 2:
two.add(n)
else:
a[n] -= 1
if a[n] == 7:
eight.remove(n)
six.add(n)
if a[n] == 5:
six.remove(n)
four.add(n)
elif a[n] == 3:
four.remove(n)
two.add(n)
elif a[n] == 1:
two.remove(n)
if (
len(six) >= 1
and (len(two) >= 1 or len(four) >= 1)
or len(six) >= 2
or len(four) >= 2
or len(four) >= 1
and len(two) >= 2
or len(eight) >= 1
):
print("Yes")
else:
print("No") | ASSIGN 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 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 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 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 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())
store = {}
bi = 0
quad = 0
lengths = [int(x) for x in input().split()]
for l in lengths:
if l not in store:
store[l] = 1
else:
store[l] += 1
if store[l] % 2 == 0:
bi += 1
if store[l] % 4 == 0:
quad += 1
q = int(input())
for _ in range(q):
a, s = input().split()
s = int(s)
if a == "+":
if s not in store:
store[s] = 1
else:
store[s] += 1
if store[s] % 2 == 0:
bi += 1
if store[s] % 4 == 0:
quad += 1
elif store[s] == 1:
del store[s]
else:
if store[s] % 2 == 0:
bi -= 1
if store[s] % 4 == 0:
quad -= 1
store[s] -= 1
if bi >= 4 and quad >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER 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 VAR VAR ASSIGN 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 VAR NUMBER VAR VAR 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, a, numP, sqr, cnt = (
int(input()),
list(map(int, input().split(" "))),
0,
0,
[0] * 100010,
)
for x in a:
cnt[x] += 1
if cnt[x] % 2 == 0:
numP += 1
if cnt[x] == 4:
sqr += 1
for i in range(int(input())):
inp = input().split(" ")
c, x = inp[0], int(inp[1])
if c == "+":
cnt[x] += 1
if cnt[x] % 2 == 0:
numP += 1
if cnt[x] == 4:
sqr += 1
else:
cnt[x] -= 1
if cnt[x] % 2 == 1:
numP -= 1
if cnt[x] == 3:
sqr -= 1
print("NO\n") if sqr == 0 or numP - 2 < 2 else print("YES\n") | ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR STRING 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 EXPR VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR STRING 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()))
x = 10**5 + 1
length = [0] * x
for i in range(n):
length[a[i]] += 1
num2468 = [0] * 4
for i in range(x):
temp = length[i]
if temp >= 8:
num2468[3] += 1
elif temp >= 6:
num2468[2] += 1
elif temp >= 4:
num2468[1] += 1
elif temp >= 2:
num2468[0] += 1
q = int(input())
for _ in range(q):
query = list(map(str, input().split()))
temp = length[int(query[1])]
if query[0] == "+":
length[int(query[1])] += 1
if temp == 7:
num2468[2] -= 1
num2468[3] += 1
elif temp == 5:
num2468[1] -= 1
num2468[2] += 1
elif temp == 3:
num2468[0] -= 1
num2468[1] += 1
elif temp == 1:
num2468[0] += 1
if query[0] == "-":
length[int(query[1])] -= 1
if temp == 8:
num2468[2] += 1
num2468[3] -= 1
elif temp == 6:
num2468[1] += 1
num2468[2] -= 1
elif temp == 4:
num2468[0] += 1
num2468[1] -= 1
elif temp == 2:
num2468[0] -= 1
SUM = sum(num2468)
if num2468[3] != 0:
print("YES")
elif num2468[2] != 0 and SUM >= 2:
print("YES")
elif num2468[1] >= 2:
print("YES")
elif num2468[1] == 1 and SUM >= 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 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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF 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$. | def get_ints():
return list(map(int, list(input().split())))
def get_int():
return int(input())
n = get_int()
counts = {}
num_4 = 0
pairs = 0
def add_plank(plank):
global num_4, pairs
if plank in counts:
counts[plank] += 1
if counts[plank] == 4:
num_4 += 1
if counts[plank] % 2 == 0:
pairs += 1
else:
counts[plank] = 1
for plank in get_ints():
add_plank(plank)
q = get_int()
for zzz in range(q):
query = input().split()
num = int(query[1])
if query[0] == "+":
add_plank(num)
else:
counts[num] -= 1
if counts[num] == 3:
num_4 -= 1
if counts[num] % 2 == 1:
pairs -= 1
if num_4 > 0 and pairs - 2 >= 2:
print("YES")
else:
print("NO") | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER BIN_OP 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())
ar = list(map(int, input().split()))
dic = [0] * (10**5 + 5)
cnt = [0] * (10**5 + 5)
for i in ar:
dic[i] += 1
cnt[dic[i] - 1] += 1
q = int(input())
while q > 0:
s = input().split(" ")
x = int(s[1])
if s[0] == "+":
dic[x] += 1
cnt[dic[x] - 1] += 1
else:
cnt[dic[x] - 1] -= 1
dic[x] -= 1
if (
cnt[7] > 0
or cnt[3] >= 2
or cnt[5] > 0
and cnt[1] >= 2
or cnt[3] > 0
and cnt[1] >= 3
):
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 BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER 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 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$. | def check1(dpp):
if dpp[8] >= 1 or dpp[4] >= 2:
return "YES"
elif dpp[6] >= 1 and dpp[2] >= 2:
return "YES"
elif dpp[4] >= 1 and dpp[2] >= 3:
return "YES"
else:
return "NO"
n = int(input())
dp = [0] * 131072
dpp = [0] * 131072
arr = list(map(int, input().split()))
for i in arr:
dp[i] += 1
dpp[dp[i]] += 1
for _ in range(int(input())):
a, b = input().split()
if a == "+":
i = int(b)
dp[i] += 1
dpp[dp[i]] += 1
print(check1(dpp))
if a == "-":
i = int(b)
dpp[dp[i]] -= 1
dp[i] -= 1
print(check1(dpp)) | FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR 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())
a = [0] * 1000001
c = [0] * 1000001
for i in input().split():
i = int(i)
a[i] += 1
c[a[i]] += 1
for _ in range(int(input())):
j = input().split()
if j[0] == "+":
a[int(j[1])] += 1
c[a[int(j[1])]] += 1
elif j[0] == "-":
c[a[int(j[1])]] -= 1
a[int(j[1])] -= 1
if (c[4] > 1 or c[8] >= 1) or c[2] > 1 and c[6] >= 1 or c[4] >= 1 and c[2] >= 3:
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 FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR 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 VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER 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$. | numbers = [0] * 100001
mp = [0] * 5
n = int(input())
arr = list(map(int, input().split()))
for num in arr:
numbers[num] += 1
for num in numbers:
if num >= 4:
mp[4] += num // 4
mp[num % 4] += 1
else:
mp[num] += 1
for i in range(int(input())):
c, d = map(str, input().split())
d = int(d)
x = numbers[d]
numbers[d] = 0
if x >= 4:
mp[4] -= x // 4
mp[x % 4] -= 1
else:
mp[x] -= 1
if c == "+":
numbers[d] = x + 1
else:
numbers[d] = x - 1
x = numbers[d]
if x >= 4:
mp[4] += x // 4
mp[x % 4] += 1
else:
mp[x] += 1
if mp[4] >= 2 or mp[4] > 0 and mp[2] + mp[3] >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP LIST NUMBER NUMBER 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 VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER 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 ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER 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$. | I = input
n = int(I())
a = list(map(int, I().split()))
f = dict()
s = dict()
d = dict()
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
for i in d:
if d[i] >= 4:
f[i] = d[i] // 4
d[i] = d[i] % 4
if d[i] >= 2:
s[i] = 1
d[i] = d[i] % 2
elif 3 >= d[i] >= 2:
s[i] = 1
d[i] = d[i] % 2
a = []
for i in d:
if d[i] == 0:
a.append(i)
for i in a:
d.pop(i)
for _ in range(int(I())):
sign, q = I().split()
i = int(q)
if sign == "+":
if i in d:
if d[i] == 1:
d[i] -= 1
if i in s:
s.pop(i)
if i in f:
f[i] += 1
else:
f[i] = 1
else:
s[i] = 1
elif d[i] == 3:
d[i] -= 3
if i in f:
f[i] += 1
else:
f[i] = 1
elif d[i] == 0:
d[i] += 1
else:
d[i] = 1
elif sign == "-":
if i in d:
d[i] -= 1
if d[i] == 2:
d[i] = 0
if i in s:
s.pop(i)
if i in f:
f[i] += 1
else:
f[i] = 1
else:
s[i] = 1
elif i in s:
s.pop(i)
d[i] = 1
elif i in f:
if f[i] > 1:
f[i] -= 1
else:
f.pop(i)
if i in d:
d[i] += 1
else:
d[i] = 1
if i in s:
s.pop(i)
if i in f:
f[i] += 1
else:
f[i] = 1
else:
s[i] = 1
if d[i] == 0:
d.pop(i)
if len(f) >= 1 and (len(s) >= 2 or len(f) >= 2):
print("YES")
else:
for i in f:
if f[i] == 1:
print("NO")
else:
print("YES")
break
if len(f) == 0:
print("NO") | 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 FUNC_CALL VAR 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 ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR 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 IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF 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$. | pl = [0] * 100001
g2 = 0
g4 = 0
g6 = 0
g8 = 0
n = int(input())
for l in map(int, input().split()):
pl[l] += 1
for l in range(100001):
if pl[l] >= 8:
g8 += 1
elif pl[l] >= 6:
g6 += 1
elif pl[l] >= 4:
g4 += 1
elif pl[l] >= 2:
g2 += 1
q = int(input())
for _ in range(q):
t, l = input().split()
l = int(l)
if t == "+":
pl[l] += 1
if pl[l] == 2:
g2 += 1
elif pl[l] == 4:
g2 -= 1
g4 += 1
elif pl[l] == 6:
g4 -= 1
g6 += 1
elif pl[l] == 8:
g6 -= 1
g8 += 1
else:
pl[l] -= 1
if pl[l] == 1:
g2 -= 1
elif pl[l] == 3:
g4 -= 1
g2 += 1
elif pl[l] == 5:
g6 -= 1
g4 += 1
elif pl[l] == 7:
g8 -= 1
g6 += 1
if g8 >= 1:
print("YES")
elif g6 + g4 >= 2:
print("YES")
elif g6 == 1 and g2 >= 1:
print("YES")
elif g4 == 1 and g2 >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL 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 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 EXPR FUNC_CALL VAR STRING IF BIN_OP VAR 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$. | n = int(int(input()))
arr = [int(c) for c in input().split()]
g2 = 0
g4 = 0
g6 = 0
g8 = 0
mark = [(0) for i in range(10**5 + 10)]
for i in arr:
mark[i] += 1
for i in mark:
if i >= 8:
g8 += 1
elif i >= 6:
g6 += 1
elif i >= 4:
g4 += 1
elif i >= 2:
g2 += 1
q = int(input())
for o in range(q):
a, b = [c for c in input().split()]
b = int(b)
if a == "+":
mark[b] += 1
if mark[b] == 2:
g2 += 1
elif mark[b] == 4:
g2 -= 1
g4 += 1
elif mark[b] == 6:
g4 -= 1
g6 += 1
elif mark[b] == 8:
g6 -= 1
g8 += 1
else:
mark[b] -= 1
if mark[b] == 7:
g8 -= 1
g6 += 1
elif mark[b] == 5:
g6 -= 1
g4 += 1
elif mark[b] == 3:
g4 -= 1
g2 += 1
elif mark[b] == 1:
g2 -= 1
ans = False
if g4 > 1 or g6 > 1 or g8 >= 1:
ans = True
if g4 == 1 and g2 >= 2:
ans = True
elif g6 == 1 and (g2 >= 1 or g4 == 1):
ans = True
if ans:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 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 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 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 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 NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR 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$. | for t in range(1):
n = int(input())
planks = list(map(int, input().split()))
freq = [0] * 10**5
for i in range(n):
val = planks[i]
freq[val - 1] += 1
count2 = 0
count4 = 0
for i in range(len(freq)):
val = freq[i]
count4 += val // 4
count2 += val // 2
for i in range(int(input())):
x, y = input().split()
y = int(y)
prev_value_c2 = freq[y - 1] // 2
prev_value_c4 = freq[y - 1] // 4
if x == "+":
freq[y - 1] += 1
else:
freq[y - 1] -= 1
curr_va_c2 = freq[y - 1] // 2
curr_va_c4 = freq[y - 1] // 4
count2 += curr_va_c2 - prev_value_c2
count4 += curr_va_c4 - prev_value_c4
if count2 >= 4 and count4 >= 1:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL 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 BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR STRING VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR 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())
inp = list(map(int, input().split()))
mx = 100001
u = [0] * mx
d = [0] * 10
for i in range(n):
u[inp[i]] += 1
for i in range(mx):
if u[i] < 9:
d[u[i]] += 1
else:
d[9] += 1
q = int(input())
ans = []
for _ in range(q):
sgn, b = input().split()
b = int(b)
cup = 1
if sgn == "-":
cup = -1
if u[b] < 9 and cup == 1 or u[b] <= 9 and cup == -1:
d[u[b]] -= 1
u[b] += cup
d[u[b]] += 1
d1 = d[:]
for i in range(4, 10):
if d1[i] > 0:
d1[i] -= 1
d1[i - 4] += 1
break
else:
ans.append("NO")
continue
for i in range(2, 10):
if d1[i] > 0:
d1[i] -= 1
d1[i - 2] += 1
break
else:
ans.append("NO")
continue
for i in range(2, 10):
if d1[i] > 0:
d1[i] -= 1
d1[i - 2] + 1
break
else:
ans.append("NO")
continue
ans.append("YES")
print("\n".join(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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR BIN_OP VAR BIN_OP VAR NUMBER 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$. | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
lis = [0] * (10**5 + 1)
arry = list(map(int, input().split()))
m = int(input())
two = 0
four = 0
for i in range(n):
lis[arry[i]] += 1
if lis[arry[i]] % 2 == 0:
two += 1
if lis[arry[i]] % 4 == 0:
four += 1
for i in range(m):
sign, numstr = input().split()
if sign == "+":
lis[int(numstr)] += 1
if lis[int(numstr)] % 2 == 0:
two += 1
if lis[int(numstr)] % 4 == 0:
four += 1
else:
if lis[int(numstr)] % 2 == 0:
two -= 1
if lis[int(numstr)] % 4 == 0:
four -= 1
lis[int(numstr)] -= 1
if four >= 1 and two >= 4:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER 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 = list(map(int, input().split()))
q = int(input())
h = {}
for i in a:
if i not in h:
h[i] = 0
h[i] += 1
squ, rec = 0, 0
for i in h:
squ += h[i] // 4
rec += h[i] // 2
for _ in range(q):
t, x = input().split()
x = int(x)
if x not in h:
h[x] = 0
squ -= h[x] // 4
rec -= h[x] // 2
if t == "+":
h[x] += 1
squ += h[x] // 4
rec += h[x] // 2
if squ > 0 and rec > 3:
print("YES")
else:
print("NO")
else:
h[x] -= 1
squ += h[x] // 4
rec += h[x] // 2
if squ > 0 and rec > 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR STRING 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 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()))
data = [0] * (10**5 + 1)
for i in range(n):
data[a[i]] += 1
zero, two, four, six, eight = 0, 0, 0, 0, 0
for i in range(1, 10**5 + 1):
if data[i] <= 1:
zero += 1
elif data[i] <= 3:
two += 1
elif data[i] <= 5:
four += 1
elif data[i] <= 7:
six += 1
else:
eight += 1
for i in range(int(input())):
t, m = input().split()
m = int(m)
if t == "+":
if data[m] == 7:
eight += 1
six -= 1
elif data[m] == 5:
six += 1
four -= 1
elif data[m] == 3:
four += 1
two -= 1
elif data[m] == 1:
two += 1
data[m] += 1
else:
if data[m] == 8:
eight -= 1
six += 1
elif data[m] == 6:
six -= 1
four += 1
elif data[m] == 4:
four -= 1
two += 1
elif data[m] == 2:
two -= 1
data[m] -= 1
if eight:
print("YES")
elif six >= 2:
print("YES")
elif six == 1:
if four or two:
print("YES")
else:
print("NO")
elif four >= 2:
print("YES")
elif four and two >= 2:
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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER 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 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 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 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 EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF 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 f(t, d=""):
global x, y
t = int(t)
x -= c[t] > 3
y -= c[t] // 2
c[t] += int(d + "1")
x += c[t] > 3
y += c[t] // 2
_, a, _, *o = open(0)
x, y, *c = [0] * 9**6
[*map(f, a.split())]
for q in o:
f(q[2:], q[0])
print("YNEOS"[x < 1 or y < 4 :: 2]) | FUNC_DEF STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR STRING VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER EXPR LIST FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER 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())
listt = list(map(int, input().split()))
m = int(input())
n2, n4, n6, n8 = 0, 0, 0, 0
elements_count = {}
for element in listt:
if element in elements_count:
elements_count[element] += 1
else:
elements_count[element] = 1
for key, value in elements_count.items():
if value >= 2:
n2 += 1
if value >= 4:
n4 += 1
if value >= 6:
n6 += 1
if value >= 8:
n8 += 1
for i in range(m):
command = list(map(str, input().split()))
if command[0] == "+":
command[1] = int(command[1])
if command[1] in elements_count:
elements_count[command[1]] += 1
else:
elements_count[command[1]] = 1
if elements_count[command[1]] == 2:
n2 += 1
elif elements_count[command[1]] == 4:
n4 += 1
elif elements_count[command[1]] == 6:
n6 += 1
elif elements_count[command[1]] == 8:
n8 += 1
else:
command[1] = int(command[1])
if elements_count[command[1]] == 2:
n2 -= 1
elif elements_count[command[1]] == 4:
n4 -= 1
elif elements_count[command[1]] == 6:
n6 -= 1
elif elements_count[command[1]] == 8:
n8 -= 1
elements_count[command[1]] -= 1
if n8 >= 1:
print("Yes")
elif n6 >= 1 and n2 >= 2:
print("Yes")
elif n4 >= 2:
print("Yes")
elif n4 >= 1 and n2 >= 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN 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 ASSIGN VAR NUMBER FUNC_CALL VAR 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 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$. | def check(f):
if f[3] >= 1:
print("YES")
elif f[2] > 1:
print("YES")
elif f[1] > 1:
print("YES")
elif f[2] == 1 and (f[1] >= 1 or f[0] >= 1):
print("YES")
elif f[1] == 1 and f[0] >= 2:
print("YES")
else:
print("NO")
n = int(input())
q = [0] * 100000
x = list(map(int, input().split()))
for i in x:
q[i - 1] += 1
f = [0] * 4
for i in q:
if i == 2 or i == 3:
f[0] += 1
if i == 4 or i == 5:
f[1] += 1
if i == 6 or i == 7:
f[2] += 1
if i >= 8:
f[3] += 1
for _ in range(int(input())):
v = list(map(str, input().split()))
if v[0] == "+":
p = int(v[1])
c = q[p - 1]
q[p - 1] += 1
if c == 1:
f[0] += 1
elif c == 3:
f[0] -= 1
f[1] += 1
elif c == 5:
f[1] -= 1
f[2] += 1
elif c == 7:
f[2] -= 1
f[3] += 1
check(f)
else:
p = int(v[1])
c = q[p - 1]
q[p - 1] -= 1
if c == 2:
f[0] -= 1
elif c == 4:
f[1] -= 1
f[0] += 1
elif c == 6:
f[2] -= 1
f[1] += 1
elif c == 8:
f[2] += 1
f[3] -= 1
check(f) | FUNC_DEF IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF 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 BIN_OP LIST NUMBER NUMBER 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 BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER 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$. | from sys import stdin, stdout
n = int(input())
arr = list(map(int, stdin.readline().rstrip().split()))
ct = dict()
for k in arr:
if k not in ct:
ct[k] = 0
ct[k] += 1
fr = 0
tw = 0
for i in ct:
fr += ct[i] // 4
tw += ct[i] % 4 // 2
t = int(input())
for i in range(t):
p = input()
if p[0] == "+":
k = int(p[1:])
if k not in ct:
ct[k] = 0
r = ct[k] // 4
w = ct[k] % 4 // 2
ct[k] += 1
if ct[k] % 4 == 0:
fr += 1
tw -= 1
elif ct[k] % 2 == 0:
tw += 1
else:
k = int(p[1:])
if ct[k] % 4 == 0:
fr -= 1
tw += 1
elif ct[k] % 2 == 0:
tw -= 1
ct[k] -= 1
if fr >= 2 or fr >= 1 and tw >= 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR 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 BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER 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 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 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()))
ct = dict()
for k in arr:
if k not in ct:
ct[k] = 0
ct[k] += 1
fr = 0
tw = 0
for i in ct:
fr += ct[i] // 4
tw += ct[i] % 4 // 2
t = int(input())
for i in range(t):
p = input()
if p[0] == "+":
k = int(p[1:])
if k not in ct:
ct[k] = 1
else:
r = ct[k] // 4
w = ct[k] % 4 // 2
ct[k] += 1
if ct[k] // 4 > r:
fr += 1
if ct[k] % 4 // 2 > w:
tw += 1
if ct[k] // 4 < r:
fr -= 1
if ct[k] % 4 // 2 < w:
tw -= 1
else:
k = int(p[1:])
r = ct[k] // 4
w = ct[k] % 4 // 2
ct[k] -= 1
if ct[k] // 4 < r:
fr -= 1
if ct[k] % 4 // 2 < w:
tw -= 1
if ct[k] // 4 > r:
fr += 1
if ct[k] % 4 // 2 > w:
tw += 1
if fr >= 2:
print("YES")
elif fr >= 1 and tw >= 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 FOR VAR VAR IF VAR VAR 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 BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER 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())
l = [int(x) for x in input().split()]
m = int(input())
dici = {}
sq = 0
rect = 0
for i in range(n):
if l[i] not in dici:
dici[l[i]] = 1
else:
dici[l[i]] += 1
t = dici[l[i]]
if t == 2:
rect += 1
elif t == 4:
sq += 1
rect -= 1
elif t == 6:
rect += 1
elif t == 8:
rect += 1
for i in range(m):
st = input()
if st[0] == "+":
if int(st[2:]) not in dici:
dici[int(st[2:])] = 1
else:
dici[int(st[2:])] += 1
j = dici[int(st[2:])]
if j == 2:
rect += 1
elif j == 4:
rect -= 1
sq += 1
elif j == 6:
rect += 1
elif j == 8:
rect += 1
else:
dici[int(st[2:])] -= 1
j = dici[int(st[2:])]
if j == 1:
rect -= 1
elif j == 3:
sq -= 1
rect += 1
elif j == 5:
rect -= 1
elif j == 7:
rect -= 1
if sq > 1:
print("YES")
elif sq == 1 and rect >= 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR 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 FUNC_CALL VAR IF VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER 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 NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER 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 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()))
mex = 10**5 + 5
freq = [(0) for i in range(mex)]
for i in arr:
freq[i] += 1
m4, m2 = set(), set()
for i in range(1, mex):
if freq[i] >= 4:
m4.add(i)
elif freq[i] >= 2:
m2.add(i)
q = int(input())
for _ in range(q):
x = input().split()
x, y = x
y = int(y)
if x == "+":
freq[y] += 1
if freq[y] >= 4:
if y in m2:
m2.remove(y)
m4.add(y)
elif freq[y] >= 2:
m2.add(y)
else:
freq[y] -= 1
if freq[y] < 4:
if y in m4:
m4.remove(y)
if freq[y] < 2:
if y in m2:
m2.remove(y)
elif freq[y] >= 2:
m2.add(y)
f = 0
if len(m4) != 0:
p = m4.pop()
freq[p] -= 4
if freq[p] >= 4:
m4.add(p)
elif freq[p] >= 2:
m2.add(p)
if len(m4) != 0:
f = 1
elif len(m2) >= 2:
f = 1
freq[p] += 4
if p in m2:
m2.remove(p)
m4.add(p)
if f == 0:
print("NO")
else:
print("YES") | 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 BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR 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$. | n = int(input())
num = [(0) for i in range(100001)]
ar = list(map(int, input().split()))
for i in ar:
num[i] += 1
et, sx, fr, to = 0, 0, 0, 0
for i in range(100001):
if num[i] >= 8:
et += 1
elif num[i] >= 6 and num[i] < 8:
sx += 1
elif num[i] >= 4 and num[i] < 6:
fr += 1
elif num[i] >= 2 and num[i] < 4:
to += 1
for _ in range(int(input())):
s, r = input().split()
if s == "+":
num[int(r)] += 1
if num[int(r)] == 8:
et += 1
sx -= 1
elif num[int(r)] == 6:
sx += 1
fr -= 1
elif num[int(r)] == 4:
fr += 1
to -= 1
elif num[int(r)] == 2:
to += 1
else:
num[int(r)] -= 1
if num[int(r)] == 7:
et -= 1
sx += 1
elif num[int(r)] == 5:
sx -= 1
fr += 1
elif num[int(r)] == 3:
fr -= 1
to += 1
elif num[int(r)] == 1:
to -= 1
if et > 0:
print("YES")
elif sx > 1:
print("YES")
elif sx == 1:
if fr > 1:
print("YES")
elif fr > 0 or to > 0:
print("YES")
else:
print("NO")
elif fr > 1:
print("YES")
elif fr == 1:
if to > 1:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF 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 VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF 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())
l = list(map(int, input().split()))
four = 0
two = 0
cnt = {}
for x in l:
if x not in cnt:
cnt[x] = 1
else:
cnt[x] += 1
for k, v in cnt.items():
four += v // 4
two += v % 4 // 2
q = int(input())
d = cnt.copy()
for i in range(q):
s, p = input().split()
p = int(p)
if s == "+":
if p not in d:
cnt[p] = d[p] = 1
else:
cnt[p] = d[p]
d[p] += 1
else:
cnt[p] = d[p]
d[p] -= 1
four += d[p] // 4 - cnt[p] // 4
two += d[p] % 4 // 2 - cnt[p] % 4 // 2
if four >= 2 or four == 1 and two >= 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 ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP 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())
a = list(map(int, input().strip().split()))[:n]
q = int(input())
n = len(a)
dict1 = {}
eight = set()
six = set()
two = set()
four = set()
for i in a:
if i in dict1:
dict1[i] += 1
else:
dict1[i] = 1
if dict1[i] >= 8 and i not in eight:
if i in six:
six.remove(i)
eight.add(i)
elif dict1[i] >= 6 and i not in six and i not in eight:
if i in four:
four.remove(i)
six.add(i)
elif dict1[i] >= 4 and i not in four and i not in six and i not in eight:
if i in two:
two.remove(i)
four.add(i)
elif (
dict1[i] >= 2
and i not in two
and i not in four
and i not in six
and i not in eight
):
two.add(i)
while q:
s = input()
sym = s[0:1]
val = int(s[2:])
if sym == "+":
i = val
if i not in dict1:
dict1[i] = 1
else:
dict1[i] += 1
n += 1
if dict1[i] >= 8 and i not in eight:
if i in six:
six.remove(i)
eight.add(i)
elif dict1[i] >= 6 and i not in six and i not in eight:
if i in four:
four.remove(i)
six.add(i)
elif dict1[i] >= 4 and i not in four and i not in six and i not in eight:
if i in two:
two.remove(i)
four.add(i)
elif (
dict1[i] >= 2
and i not in two
and i not in four
and i not in six
and i not in eight
):
two.add(i)
else:
i = val
dict1[i] -= 1
n -= 1
if i in eight and dict1[i] < 8:
eight.remove(i)
if i in six and dict1[i] < 6:
six.remove(i)
if i in four and dict1[i] < 4:
four.remove(i)
if i in two and dict1[i] < 2:
two.remove(i)
if dict1[i] >= 8 and i not in eight:
eight.add(i)
if dict1[i] >= 6 and i not in six and i not in eight:
six.add(i)
if dict1[i] >= 4 and i not in four and i not in eight and i not in six:
four.add(i)
if (
dict1[i] >= 2
and i not in two
and i not in eight
and i not in six
and i not in four
):
two.add(i)
if n >= 8:
if len(eight) >= 1:
print("YES")
elif len(six) >= 2 or len(four) >= 2:
print("YES")
elif len(six) == 1 and (len(two) >= 1 or len(four) >= 1):
print("YES")
elif len(four) == 1 and len(two) >= 2:
print("YES")
else:
print("NO")
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT 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 VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER 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 FUNC_CALL VAR VAR NUMBER 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 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$. | from sys import setrecursionlimit, stdin, stdout
class Tail_Recursion_Optimization:
def __init__(self, RECURSION_LIMIT, STACK_SIZE):
setrecursionlimit(RECURSION_LIMIT)
threading.stack_size(STACK_SIZE)
return None
class SOLVE:
def solve(self):
R = stdin.readline
W = stdout.write
ans = []
n = int(R())
a = [int(x) for x in R().split()]
check = {}
cnt = {}
for i in range(9):
cnt[i] = 0
for i in range(n):
if a[i] not in check:
check[a[i]] = 1
cnt[1] += 1
else:
cnt[check[a[i]]] -= 1
check[a[i]] += 1
cnt[check[a[i]]] = 1 if check[a[i]] not in cnt else cnt[check[a[i]]] + 1
for i in range(int(R())):
cmd, num = [x for x in R().split()]
num = int(num)
if cmd == "+":
n += 1
if num not in check:
check[num] = 1
cnt[1] += 1
else:
cnt[check[num]] -= 1
check[num] += 1
cnt[check[num]] = (
1 if check[num] not in cnt else cnt[check[num]] + 1
)
elif cmd == "-":
n -= 1
cnt[check[num]] -= 1
check[num] -= 1
cnt[check[num]] += 1
if n < 8:
ans.append("NO")
else:
total = 0
for j in range(1, 8):
total += j * cnt[j]
if total < n:
ans.append("YES")
else:
rec = cnt[2] + cnt[3] + cnt[6] + cnt[7]
squ = sum([cnt[j] for j in range(4, 8)])
if rec >= 2 and squ or squ >= 2:
ans.append("YES")
else:
ans.append("NO")
W("\n".join(ans))
return 0
def main():
s = SOLVE()
s.solve()
main() | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN NONE CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST 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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL 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$. | from sys import *
input = stdin.readline
def check(c2, c4, c6, c8):
if c2 >= 2 and c4 >= 1:
return "YES"
elif c4 >= 2:
return "YES"
elif c6 >= 1 and (c2 >= 1 or c4 >= 1 or c6 > 1):
return "YES"
elif c8 >= 1:
return "YES"
return "NO"
for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
d = [0] * int(100000.0 + 5)
cn2, cn4, cn6, cn8 = 0, 0, 0, 0
for i in a:
d[i] += 1
if d[i] == 2:
cn2 += 1
elif d[i] == 4:
cn2 -= 1
cn4 += 1
elif d[i] == 6:
cn4 -= 1
cn6 += 1
elif d[i] == 8:
cn6 -= 1
cn8 += 1
q = int(input())
for i in range(q):
k = input()
sign, k = k.split(" ")
m = abs(int(k[:-1]))
if sign == "-":
d[m] -= 1
if d[m] == 1:
cn2 -= 1
elif d[m] == 3:
cn4 -= 1
cn2 += 1
elif d[m] == 5:
cn6 -= 1
cn4 += 1
elif d[m] == 7:
cn6 += 1
cn8 -= 1
else:
d[m] += 1
if d[m] == 2:
cn2 += 1
elif d[m] == 4:
cn2 -= 1
cn4 += 1
elif d[m] == 6:
cn4 -= 1
cn6 += 1
elif d[m] == 8:
cn6 -= 1
cn8 += 1
print(check(cn2, cn4, cn6, cn8)) | ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL 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 BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP 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 FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 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 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())
li = list(map(int, input().split()))
d = {}
c = 0
c4 = 0
for i in li:
if i not in d:
d[i] = 1
else:
d[i] += 1
if d[i] % 2 == 0:
c += 1
if d[i] % 4 == 0:
c4 += 1
q = int(input())
for i in range(q):
a, b = map(str, input().split())
b = int(b)
if a == "+":
if b not in d:
d[b] = 0
if d[b] % 2 != 0:
c += 1
if d[b] % 4 == 3:
c4 += 1
if b not in d:
d[b] = 1
else:
d[b] += 1
else:
if d[b] % 2 == 0:
c -= 1
if d[b] % 4 == 0:
c4 -= 1
d[b] -= 1
if c4 > 1 or c >= 4 and c4 == 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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER 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 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 = list(map(int, input().split()))
q = int(input())
d = dict()
for i in range(n):
if a[i] in d:
d[a[i]] += 1
else:
d[a[i]] = 1
d2, d4, d6, d8 = set(), set(), set(), set()
for i in d:
if d[i] >= 8:
d8.add(i)
elif d[i] >= 6:
d6.add(i)
elif d[i] >= 4:
d4.add(i)
elif d[i] >= 2:
d2.add(i)
for i in range(q):
s, x = input().split()
x = int(x)
if s == "+":
if x in d:
d[x] += 1
if d[x] == 2:
d2.add(x)
elif d[x] == 4:
d2.remove(x)
d4.add(x)
elif d[x] == 6:
d4.remove(x)
d6.add(x)
elif d[x] == 8:
d6.remove(x)
d8.add(x)
else:
d[x] = 1
else:
d[x] -= 1
if d[x] == 1:
d2.remove(x)
elif d[x] == 3:
d4.remove(x)
d2.add(x)
elif d[x] == 5:
d6.remove(x)
d4.add(x)
elif d[x] == 7:
d8.remove(x)
d6.add(x)
if len(d8) > 0:
print("YES")
elif len(d6) >= 2:
print("YES")
elif len(d6) == 1 and len(d4) + len(d2) > 0:
print("YES")
elif len(d4) >= 2:
print("YES")
elif len(d4) == 1 and len(d2) >= 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR 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 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 IF VAR VAR VAR 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 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 NUMBER VAR 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 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 EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR 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())
arr = [int(p) for p in input().split()]
q = int(input())
cnt4 = 0
cnt2 = 0
counter = [0] * (10**5 + 1)
for i in range(len(arr)):
cnt4 -= counter[arr[i]] // 4
cnt2 -= counter[arr[i]] // 2
counter[arr[i]] += 1
cnt4 += counter[arr[i]] // 4
cnt2 += counter[arr[i]] // 2
for i in range(q):
t, v = input().split()
v = int(v)
cnt4 -= counter[v] // 4
cnt2 -= counter[v] // 2
if t == "+":
counter[v] += 1
else:
counter[v] -= 1
cnt4 += counter[v] // 4
cnt2 += counter[v] // 2
if cnt4 >= 1 and cnt2 >= 4:
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL 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 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$. | n = int(input())
l = list(map(int, input().split()))
l1 = [0] * 100003
for i in range(n):
l1[l[i]] += 1
l2 = [0] * 10
for i in range(len(l1)):
if l1[i] != 0:
if l1[i] > 8:
l2[9] += 1
else:
l2[l1[i]] += 1
for _ in range(int(input())):
s1, s2 = map(str, input().split())
if s1 == "+":
if l1[int(s2)] > 8:
l2[9] -= 1
else:
l2[l1[int(s2)]] -= 1
l1[int(s2)] += 1
if l1[int(s2)] > 8:
l2[9] += 1
else:
l2[l1[int(s2)]] += 1
else:
if l1[int(s2)] > 8:
l2[9] -= 1
else:
l2[l1[int(s2)]] -= 1
l1[int(s2)] -= 1
if l1[int(s2)] > 8:
l2[9] += 1
else:
l2[l1[int(s2)]] += 1
p, q, r, s = l2[2] + l2[3], l2[4] + l2[5], l2[6] + l2[7], l2[8] + l2[9]
if s >= 1:
print("YES")
elif r >= 2:
print("YES")
elif q >= 1 and r >= 1:
print("YES")
elif p >= 2 and q >= 1:
print("YES")
elif p >= 1 and r >= 1:
print("YES")
elif q >= 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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER 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 IF VAR STRING IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF 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 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$. | n = int(input())
a = list(map(int, input().split()))
b = set(a)
q = int(input())
d = [(0) for i in range(10**5 + 1)]
s1 = set()
s2 = set()
s3 = set()
s4 = set()
for i in a:
d[i] += 1
if d[i] == 8:
s1.add(i)
s2.remove(i)
elif d[i] == 6:
s2.add(i)
s3.remove(i)
elif d[i] == 4:
s3.add(i)
s4.remove(i)
elif d[i] == 2:
s4.add(i)
for i in range(q):
k = input().split()
n = int(k[1])
if k[0] == "+":
d[n] += 1
if d[n] == 8:
s1.add(n)
s2.remove(n)
elif d[n] == 6:
s2.add(n)
s3.remove(n)
elif d[n] == 4:
s3.add(n)
s4.remove(n)
elif d[n] == 2:
s4.add(n)
else:
d[n] -= 1
if d[n] == 7:
s1.remove(n)
s2.add(n)
elif d[n] == 5:
s2.remove(n)
s3.add(n)
elif d[n] == 3:
s3.remove(n)
s4.add(n)
elif d[n] == 1:
s4.remove(n)
if len(s1) >= 1:
print("YES")
elif len(s2) >= 2:
print("YES")
elif len(s2) == 1:
if len(s3) >= 1:
print("YES")
elif len(s4) >= 1:
print("YES")
else:
print("NO")
elif len(s3) >= 2:
print("YES")
elif len(s3) == 1:
if len(s4) >= 2:
print("YES")
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 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 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 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 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 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 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 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 EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING 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 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()))
planks = [0] * (10**5 + 1)
for i in a:
planks[i] += 1
q = int(input())
c2 = 0
c4 = 0
for i in range(len(planks)):
c2 += planks[i] // 2
c4 += planks[i] // 4
for _ in range(q):
c, d = map(str, input().split())
c2 -= planks[int(d)] // 2
c4 -= planks[int(d)] // 4
if c == "-":
planks[int(d)] -= 1
else:
planks[int(d)] += 1
c2 += planks[int(d)] // 2
c4 += planks[int(d)] // 4
if c2 >= 4 and c4 >= 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 FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL 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$. | import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = 10**5
table = [0] * (mx + 1)
for x in a:
table[x] += 1
two = set()
four = set()
six = set()
eight = set()
for i in range(1, mx + 1):
if table[i] >= 8:
eight.add(i)
elif table[i] >= 6:
six.add(i)
elif table[i] >= 4:
four.add(i)
elif table[i] >= 2:
two.add(i)
for _ in range(int(input())):
q, i = input().split()
i = int(i)
if q == "+":
table[i] += 1
if table[i] == 8:
eight.add(i)
six.discard(i)
elif table[i] == 6:
six.add(i)
four.discard(i)
elif table[i] == 4:
four.add(i)
two.discard(i)
elif table[i] == 2:
two.add(i)
else:
table[i] -= 1
if table[i] == 7:
eight.discard(i)
six.add(i)
elif table[i] == 5:
six.discard(i)
four.add(i)
elif table[i] == 3:
four.discard(i)
two.add(i)
elif table[i] == 1:
two.discard(i)
if len(eight):
print("YES")
elif len(six) >= 2 or len(four) >= 2:
print("YES")
elif len(six) > 0 and (len(four) > 0 or len(two) > 0):
print("YES")
elif len(four) > 0 and len(two) >= 2:
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 NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR 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 FUNC_CALL VAR NUMBER BIN_OP 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 FUNC_CALL VAR FUNC_CALL 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 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 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 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 FUNC_CALL VAR VAR NUMBER 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 |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
res = []
for i in range(len(gas)):
res.append(gas[i] - cost[i])
max_sum = 0
max_index = 0
a = [(0) for x in range(len(res))]
for i in range(len(res)):
max_sum = max(res[i] + max_sum, res[i])
if max_sum == res[i]:
max_index = i
max_sum = res[i]
temp = (max_index + 1) % len(gas)
gas_sum = res[max_index]
while temp != max_index:
gas_sum += res[temp]
temp = (temp + 1) % len(gas)
if gas_sum >= 0:
return max_index
else:
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR RETURN NUMBER |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
fuel = totalGas = totalCost = start = 0
for i in range(len(cost)):
totalGas += gas[i]
totalCost += cost[i]
fuel = fuel + gas[i] - cost[i]
if fuel < 0:
start = i + 1
fuel = 0
return start if totalGas >= totalCost else -1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR VAR VAR NUMBER |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
tank = 0
total = len(gas)
travel = 0
start = -total
current = start
print(("start:", start))
while travel < total:
tank += gas[current] - cost[current]
travel += 1
current += 1
if current == total:
return -1
print(
(
current,
"\ttank:",
tank,
gas[current],
cost[current],
"\ttravel:",
travel,
)
)
if tank < 0:
tank = 0
jump = current - start
start += jump
travel -= jump
print(("reset Start:", start, tank))
return start + total | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR VAR VAR VAR STRING VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR RETURN BIN_OP VAR VAR |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
left = [(gas[i] - cost[i]) for i in range(len(gas))]
if sum(left) < 0:
return -1
tank, start = 0, 0
for i in range(len(left)):
tank += left[i]
if tank < 0:
start = i + 1
tank = 0
return start | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
st, ed, cur, n, loop = 0, -1, 0, len(gas), False
while True:
ed += 1
if ed >= n:
ed -= n
while cur + gas[ed] - cost[ed] >= 0:
cur += gas[ed] - cost[ed]
ed += 1
if ed >= n:
if loop:
return -1
ed -= n
loop = True
if ed >= st and loop:
return st
cur, st = 0, ed + 1
if st >= n:
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR VAR VAR WHILE BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR RETURN NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
if sum(gas) < sum(cost):
return -1
Rest = 0
index = 0
for i in range(len(gas)):
Rest += gas[i] - cost[i]
if Rest < 0:
index = i + 1
Rest = 0
return index | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
n = len(gas)
i = 0
while i < n:
total_gas = 0
j = 0
while j < n and total_gas >= 0:
index = (i + j) % n
total_gas += gas[index] - cost[index]
j += 1
if total_gas >= 0:
return i
i += j
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR VAR VAR RETURN NUMBER |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
if len(gas) == 1:
if cost[0] > gas[0]:
return -1
else:
return 0
sub = [(g - c) for g, c in zip(gas, cost)]
s = 0
e = 1
left = sub[0]
while e != s:
if left >= 0:
left += sub[e]
e = (e + 1) % len(gas)
if e == s and left < 0:
return -1
else:
while left < 0:
s = (s - 1) % len(gas)
left += sub[s]
if s == (e - 1) % len(gas):
return -1
return s | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER RETURN VAR |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
if not gas:
return -1
if len(gas) == 1:
return 0 if gas[0] >= cost[0] else -1
diff = [(gas[i] - cost[i]) for i in range(len(gas))]
print(diff)
start = []
for i in range(len(diff)):
if diff[i] < 0 and diff[(i + 1) % len(diff)] >= 0:
start.append((i + 1) % len(diff))
if not start:
start = [0]
print(start)
for i in start:
bal = diff[i]
ptr = (i + 1) % len(diff)
while ptr != i:
bal += diff[ptr]
ptr = (ptr + 1) % len(diff)
if bal < 0:
break
if bal >= 0:
return i
return -1 | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
If there exists a solution, it is guaranteed to be unique.
Both input arrays are non-empty and have the same length.
Each element in the input arrays is a non-negative integer.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.
Example 2:
Input:
gas = [2,3,4]
cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start. | class Solution:
def canCompleteCircuit(self, gas, cost):
cf, s, e = 0, 0, 0
found = False
while True:
nextHop = gas[e] - cost[e]
if cf + nextHop >= 0:
e = (e + 1) % len(gas)
cf = cf + nextHop
if s == e:
found = True
break
else:
continue
else:
if s == e:
s = (s + 1) % len(gas)
e = s
else:
cf += -gas[s] + cost[s]
s = (s + 1) % len(gas)
if s == 0:
break
return s if found else -1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR VAR NUMBER |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Arrays have fallen out of Chef's good books, and he plans to destroy all arrays he possesses. He is left with the last array A, consisting of N positive integers. In order to destroy the array, he can perform the following 2 types of operations any number of times.
Choose any 2 elements, say X and Y, from the given array A such that X != Y, and remove them, or
Choose any 1 element, say X, from A, and remove it.
In order to destroy the array as quickly as possible, Chef is interested in knowing the minimum number of operations required to destroy it. Please help him achieve this task.
------ Input ------
The first line of input contains a single integer T denoting the number of test cases. First line of each test case contains a single integer N — the number of integers in the array A.
Second line of each test case contains N space separated integers denoting the array A.
------ Output ------
For each test case, output the required answer in a new line.
------ Constraints ------
1 ≤ T ≤ 50000
1 ≤ N ≤ 50000
1 ≤ A_{i} ≤ 10^{9}
sum of N over all test cases does not exceed 5 × 10^{5}
----- Sample Input 1 ------
3
2
1 2
2
1 1
3
1 2 3
----- Sample Output 1 ------
1
2
2
----- explanation 1 ------
Test 1: In an operation, Chef can choose 2 elements X and Y such that X = 1 and Y = 2 and can destroy them as X != Y.
Test 2: Chef cannot choose 2 elements X and Y such that X != Y. So, he has to use the second operation twice in order to destroy the array. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
count = 1
flag = 0
for i in range(len(arr) - 1):
if arr[i] == arr[i + 1]:
count += 1
else:
flag = max(flag, count)
count = 1
flag = max(flag, count)
print(max(flag, int((n + 1) // 2))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Arrays have fallen out of Chef's good books, and he plans to destroy all arrays he possesses. He is left with the last array A, consisting of N positive integers. In order to destroy the array, he can perform the following 2 types of operations any number of times.
Choose any 2 elements, say X and Y, from the given array A such that X != Y, and remove them, or
Choose any 1 element, say X, from A, and remove it.
In order to destroy the array as quickly as possible, Chef is interested in knowing the minimum number of operations required to destroy it. Please help him achieve this task.
------ Input ------
The first line of input contains a single integer T denoting the number of test cases. First line of each test case contains a single integer N — the number of integers in the array A.
Second line of each test case contains N space separated integers denoting the array A.
------ Output ------
For each test case, output the required answer in a new line.
------ Constraints ------
1 ≤ T ≤ 50000
1 ≤ N ≤ 50000
1 ≤ A_{i} ≤ 10^{9}
sum of N over all test cases does not exceed 5 × 10^{5}
----- Sample Input 1 ------
3
2
1 2
2
1 1
3
1 2 3
----- Sample Output 1 ------
1
2
2
----- explanation 1 ------
Test 1: In an operation, Chef can choose 2 elements X and Y such that X = 1 and Y = 2 and can destroy them as X != Y.
Test 2: Chef cannot choose 2 elements X and Y such that X != Y. So, he has to use the second operation twice in order to destroy the array. | class MaxHeap:
def __init__(self, collection=None):
self._heap = []
if collection is not None:
for el in collection:
self.push(el)
def push(self, value):
self._heap.append(value)
_sift_up(self._heap, len(self) - 1)
def pop(self):
_swap(self._heap, len(self) - 1, 0)
el = self._heap.pop()
_sift_down(self._heap, 0)
return el
def __len__(self):
return len(self._heap)
def print(self, idx=1, indent=0):
print("\t" * indent, f"{self._heap[idx - 1]}")
left, right = 2 * idx, 2 * idx + 1
if left <= len(self):
self.print(left, indent=indent + 1)
if right <= len(self):
self.print(right, indent=indent + 1)
def _swap(L, i, j):
L[i], L[j] = L[j], L[i]
def _sift_up(heap, idx):
parent_idx = (idx - 1) // 2
if parent_idx < 0:
return
if heap[idx] > heap[parent_idx]:
_swap(heap, idx, parent_idx)
_sift_up(heap, parent_idx)
def _sift_down(heap, idx):
child_idx = 2 * idx + 1
if child_idx >= len(heap):
return
if child_idx + 1 < len(heap) and heap[child_idx] < heap[child_idx + 1]:
child_idx += 1
if heap[child_idx] > heap[idx]:
_swap(heap, child_idx, idx)
_sift_down(heap, child_idx)
def heap_sort(collection):
heap = MaxHeap(collection)
sorted_arr = []
while len(heap) > 0:
sorted_arr.append(heap.pop())
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
d = {}
for i in l:
try:
d[i] += 1
except:
d[i] = 1
x = MaxHeap()
for i in d.values():
x.push(i)
ans = 0
while len(x) > 1:
a = x.pop()
b = x.pop()
ans += 1
a -= 1
b -= 1
if a > 0:
x.push(a)
if b > 0:
x.push(b)
while len(x) > 0:
ans += x.pop()
print(ans) | CLASS_DEF FUNC_DEF NONE ASSIGN VAR LIST IF VAR NONE FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR 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 DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.
You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.
How many operations will you need to perform until the next operation does not have any points to delete?
-----Input-----
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
The number of the points is between 1 and 10^6.
-----Output-----
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.
-----Examples-----
Input
aabb
Output
2
Input
aabcaa
Output
1
-----Note-----
In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied. | s = input()
n = 1
for i in range(1, len(s)):
if s[i] != s[i - 1]:
n += 1
mas = [0] * n
col = [0] * n
count = 1
idx = 0
c = s[0]
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
mas[idx] = count
col[idx] = c
idx += 1
count = 1
c = s[i]
mas[idx] = count
col[idx] = c
res = 0
while n > 1:
newlen = n
idx = -1
for i in range(0, n):
if i == 0 or i == n - 1:
mas[i] -= 1
elif mas[i] >= 2:
mas[i] -= 2
else:
mas[i] = 0
if mas[i] == 0:
newlen -= 1
elif idx >= 0 and col[idx] == col[i]:
mas[idx] += mas[i]
newlen -= 1
else:
idx += 1
mas[idx] = mas[i]
col[idx] = col[i]
type = i % 2
n = newlen
res += 1
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.
You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.
How many operations will you need to perform until the next operation does not have any points to delete?
-----Input-----
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
The number of the points is between 1 and 10^6.
-----Output-----
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.
-----Examples-----
Input
aabb
Output
2
Input
aabcaa
Output
1
-----Note-----
In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied. | def process(a):
assert len(a) >= 2
n = len(a)
min_ = float("inf")
for i, [cnt, c] in enumerate(a):
if i == 0 or i == n - 1:
min_ = min(min_, cnt)
else:
min_ = min(min_, (cnt + 1) // 2)
b = []
for i, [cnt, c] in enumerate(a):
if i == 0 or i == n - 1:
remain = cnt - min_
else:
remain = cnt - min_ * 2
if remain <= 0:
continue
if len(b) == 0 or c != b[-1][1]:
b.append([remain, c])
else:
pre_cnt, pre_c = b.pop()
b.append([pre_cnt + remain, c])
return b, min_
S = input() + " "
cur = []
cnt = 0
pre = ""
for x in S:
if cnt == 0:
cnt += 1
pre = x
elif x != pre:
cur.append([cnt, pre])
cnt = 1
pre = x
else:
cnt += 1
cnt = 0
while len(cur) not in [0, 1]:
cur, min_ = process(cur)
cnt += min_
print(cnt) | FUNC_DEF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR LIST VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR LIST VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.