message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
ar=list(map(int,input().split()))
suff=[0]*(m+1)
d=0
for i in range(m-1,-1,-1):
d+=suff[i]+ar[i]
suff[i]=d
z=1
for i in range(m):
if n-ar[i]<i:
print(-1)
z=0
break
if sum(ar)<n and z:
print(-1)
z=0
if z:
for i in range(m): print(max(i+1,n-suff[i]+1),end=' ')
``` | instruction | 0 | 51,490 | 7 | 102,980 |
Yes | output | 1 | 51,490 | 7 | 102,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
L=list(map(int,input().split()))
sL=sum(L)
if not m-1+L[m-1]<=n<=sL:
print(-1)
else:
for i in range(m):
if not n-i>=L[i]:
print(-1)
break
else:
c=sL-n
for i in range(m-1):
d=min(L[i]-1,c)
L[i]-=d
c-=d
if c!=0:
print(-1)
else:
assert sum(L)==n
d=0
for i in range(m):
print(1+d,end=' ')
d+=L[i]
print()
``` | instruction | 0 | 51,491 | 7 | 102,982 |
Yes | output | 1 | 51,491 | 7 | 102,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
if sum(d) < n: print(-1);exit()
pos = [0]*m;ind = n
for i in range(m-1, -1, -1):
ind = min(ind - 1, n - d[i])
pos[i] = ind
if pos[0] < 0: print(-1);exit()
lind = -1
for i in range(m):
if pos[i] <= lind+1:break
pos[i] = lind+1
lind += d[i]
ppos = [ppp+1 for ppp in pos]
print(*ppos)
``` | instruction | 0 | 51,492 | 7 | 102,984 |
Yes | output | 1 | 51,492 | 7 | 102,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
l=list(map(int,input().split()))
p=[]
totalSum=sum(l)
if totalSum<n:
print(-1)
exit(0)
nn=n
p=[n-l[m-1]+1]+p
totalSum-=l[m-1]
n-=l[m-1]
if m-1>n:
print(-1)
exit(0)
flag=False
for i in range(m-2,-1,-1):
totalSum-=l[i]
pp=max(1,n-totalSum)
n-=pp
p=[n+1]+p
for i in p:
print(i, end=" ")
``` | instruction | 0 | 51,493 | 7 | 102,986 |
No | output | 1 | 51,493 | 7 | 102,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n, m = map(int, input().split())
end = n
res = []
right = n
can = True
for i in map(int, input().split()):
bf = end - i + 1
end -= 1
res.append([bf, i])
right = min(bf, right)
if bf <= 0 or end < 0:
can = False
if can:
left = 1
if right != left:
ind = m - 1
while left != right and ind >= 0:
change = min(right - left, res[ind][1])
if change == res[ind][1] and ind != 0:
right = min([res[i][0] for i in range(ind - 1, -1, -1)])
res[ind][0] = left
left += change
ind -= 1
if left == right:
print(*[i[0] for i in res])
else:
print(-1)
else:
print(-1)
``` | instruction | 0 | 51,494 | 7 | 102,988 |
No | output | 1 | 51,494 | 7 | 102,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
def giverange(a,n):
return [1,n - a + 1]
n,m = li()
l = li()
ans = 1
for i in range(m):
if l[i] > n - i:
print(-1)
exit()
l = [[l[i],i] for i in range(m)]
l.sort(key = lambda x:(x[0],x[1]))
color = [0]*(n + 1)
ans = []
currind = 0
for i in range(m):
mi,ma = giverange(l[i][0],n)
currind += 1
while currind < mi:
currind += 1
if currind > ma:
print(-1)
exit()
color[currind] = i + 1
ans.append([currind,l[i][1]])
last = n
# print('last : ',last,currind)
# print(ans)
for i in range(m-1,-1,-1):
mini = i + 1
fulfilllast = last - l[i][0] + 1
ans[i][0] = max(mini,fulfilllast)
last = ans[i][0] - 1
# print(ans)
j = 0
for i in range(1,n+1,1):
if j == m:
print(-1)
exit()
if i < ans[j][0] or i > ans[j][0] + l[j][0] - 1:
print(-1)
exit()
if i == ans[j][0] + l[j][0] - 1:
j += 1
ans.sort(key = lambda x:x[1])
for i in ans:
print(i[0],end = ' ')
``` | instruction | 0 | 51,495 | 7 | 102,990 |
No | output | 1 | 51,495 | 7 | 102,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).
The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).
Output
If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Submitted Solution:
```
n, m = map(int, input().split())
ls = list(map(int, input().split()))
def solve():
if sum(ls) < n:
return '-1'
target = 0
position = 0
for x in ls:
target = max(target, position+x)
position += 1
if target > n:
return '-1'
sol = []
expand = n - target
position = 1
for x in ls:
sol.append(position)
diff = x - 1
position += 1
if diff > 0 and expand > 0:
position += min(diff, expand)
expand -= min(diff, expand)
return ' '.join(map(str, sol))
``` | instruction | 0 | 51,496 | 7 | 102,992 |
No | output | 1 | 51,496 | 7 | 102,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbouring squares situated in one row or one column.
Your task is to calculate the number of painted cells. If a cell was painted more than once, it should be calculated exactly once.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika.
Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are parallel to coordinate axes. Segments may touch, overlap and even completely coincide.
Output
Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.
Examples
Input
3
0 1 2 1
1 4 1 2
0 3 2 3
Output
8
Input
4
-2 -1 2 -1
2 1 -2 1
-1 -2 -1 2
1 2 1 -2
Output
16
Note
In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3). | instruction | 0 | 51,734 | 7 | 103,468 |
Tags: constructive algorithms, data structures, geometry, two pointers
Correct Solution:
```
from sys import stdin
from itertools import repeat
from collections import defaultdict
def main():
n = int(stdin.readline())
h = defaultdict(list)
w = defaultdict(list)
for i in range(n):
a, b, c, d = map(int, input().split())
if a > c:
a, c = c, a
if b > d:
b, d = d, b
if a == c:
h[a].append((b, d))
else:
w[b].append((a, c))
ans = 0
ys = set()
es = defaultdict(list)
qs = defaultdict(list)
for t, l in h.items():
l.sort()
l.append((1001001001, 1001001001))
nl = []
p = r = l[0][0]
for a, b in l:
if a > r:
nl.append((p, r))
ans += r - p + 1
es[p].append((1, t))
es[r+1].append((-1, t))
p = r = a
if r < b:
r = b
l = nl
ys.add(t)
for t, l in w.items():
l.sort()
l.append((1001001001, 1001001001))
nl = []
p = r = l[0][0]
for a, b in l:
if a > r:
nl.append((p, r))
ys.add(p)
ys.add(r)
es[t].append((2, p, r))
ans += r - p + 1
p = r = a
if r < b:
r = b
l = nl
ys = [-1001001001] + list(ys)
ys.sort()
d = {v: i for i, v in enumerate(ys)}
l = len(ys)
bs = [0] * l
for x in sorted(es.keys()):
for q in sorted(es[x]):
if q[0] <= 1:
a, b = q[0], d[q[1]]
while b < l:
bs[b] += a
b += b - (b & (b - 1))
else:
a, b = d[q[1]] - 1, d[q[2]]
while b > 0:
ans -= bs[b]
b = b & (b - 1)
while a > 0:
ans += bs[a]
a = a & (a - 1)
print (ans)
main()
``` | output | 1 | 51,734 | 7 | 103,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbouring squares situated in one row or one column.
Your task is to calculate the number of painted cells. If a cell was painted more than once, it should be calculated exactly once.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika.
Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are parallel to coordinate axes. Segments may touch, overlap and even completely coincide.
Output
Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.
Examples
Input
3
0 1 2 1
1 4 1 2
0 3 2 3
Output
8
Input
4
-2 -1 2 -1
2 1 -2 1
-1 -2 -1 2
1 2 1 -2
Output
16
Note
In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3). | instruction | 0 | 51,735 | 7 | 103,470 |
Tags: constructive algorithms, data structures, geometry, two pointers
Correct Solution:
```
from sys import stdin
from itertools import repeat
from collections import defaultdict
# input = raw_input
# range = xrange
def main():
n = int(stdin.readline())
h = defaultdict(list)
w = defaultdict(list)
for i in range(n):
a, b, c, d = map(int, input().split())
if a > c:
a, c = c, a
if b > d:
b, d = d, b
if a == c:
h[a].append((b, d))
else:
w[b].append((a, c))
ans = 0
ys = set()
es = defaultdict(list)
qs = defaultdict(list)
for t, l in h.items():
l.sort()
l.append((1001001001, 1001001001))
nl = []
p = r = l[0][0]
for a, b in l:
if a > r:
nl.append((p, r))
ans += r - p + 1
es[p].append((1, t))
es[r+1].append((-1, t))
p = r = a
if r < b:
r = b
l = nl
ys.add(t)
for t, l in w.items():
l.sort()
l.append((1001001001, 1001001001))
nl = []
p = r = l[0][0]
for a, b in l:
if a > r:
nl.append((p, r))
ys.add(p)
ys.add(r)
es[t].append((2, p, r))
ans += r - p + 1
p = r = a
if r < b:
r = b
l = nl
ys = [-1001001001] + list(ys)
ys.sort()
d = {v: i for i, v in enumerate(ys)}
l = len(ys)
bs = [0] * l
for x in sorted(es.keys()):
for q in sorted(es[x]):
if q[0] <= 1:
a, b = q[0], d[q[1]]
while b < l:
bs[b] += a
b += b - (b & (b - 1))
else:
a, b = d[q[1]] - 1, d[q[2]]
while b > 0:
ans -= bs[b]
b = b & (b - 1)
while a > 0:
ans += bs[a]
a = a & (a - 1)
print (ans)
main()
``` | output | 1 | 51,735 | 7 | 103,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,858 | 7 | 103,716 |
Tags: brute force, constructive algorithms
Correct Solution:
```
inp = list(map(int, input().split()))
inp.sort()
string = "NO"
if(inp.count(1)>= 1 or inp.count(2)>=2 or inp.count(3)>=3):
string = "YES"
if(inp == [2,4,4]):
string = "YES"
print(string)
``` | output | 1 | 51,858 | 7 | 103,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,859 | 7 | 103,718 |
Tags: brute force, constructive algorithms
Correct Solution:
```
a, b, c = map(int, input().split())
v = [a, b, c]
v.sort()
if v[0] == 1 or v[0] ==2 and v[1] == 2 or v[0] == 2 and v[1] == 4 and v[2] == 4 or v[0] == 3 and v[1] == 3 and v[2] == 3:
print('YES')
else:
print('NO')
``` | output | 1 | 51,859 | 7 | 103,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,860 | 7 | 103,720 |
Tags: brute force, constructive algorithms
Correct Solution:
```
def possible(vals):
if 1 in vals:
return True
if vals.count(2) >= 2:
return True
if vals.count(3) == 3:
return True
if vals.count(2) == 1 and vals.count(4) == 2:
return True
return False
vals = list(map(int, input().split()))
if possible(vals):
print("YES")
else:
print("NO")
``` | output | 1 | 51,860 | 7 | 103,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,861 | 7 | 103,722 |
Tags: brute force, constructive algorithms
Correct Solution:
```
arr = list(map(int,input().split()))
if (1 in arr):
print("YES")
else:
if arr.count(2) >= 2:
print("YES")
else:
if(arr.count(3) == 3) :
print("YES")
else:
if (arr.count(4) == 2 and arr.count(2) == 1):
print("YES")
else:
print("NO")
``` | output | 1 | 51,861 | 7 | 103,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,862 | 7 | 103,724 |
Tags: brute force, constructive algorithms
Correct Solution:
```
k1, k2, k3 = map(int, input().split())
if k1 == 1 or k2 == 1 or k3 == 1 or k1 == 2 and k2 == 2 or k2 == 2 and k3 == 2 or k1 == 2 and k3 == 2 or k1 == 3 and k2 == 3 and k3 == 3:
print('YES')
elif k1 == 2 and k2 == 4 and k3 == 4 or k1 == 4 and k2 == 2 and k3 == 4 or k1 == 4 and k2 == 4 and k3 == 2:
print('YES')
else:
print('NO')
``` | output | 1 | 51,862 | 7 | 103,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,863 | 7 | 103,726 |
Tags: brute force, constructive algorithms
Correct Solution:
```
l=list(map(int,input().split()))
l=sorted(l)
if l[1]<=2 or l[0]==1 or l[0]==2 and l[1]==4 and l[2]==4 or l[1]==3==l[0]==l[2]:
print("YES")
else :
print("NO")
``` | output | 1 | 51,863 | 7 | 103,727 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | instruction | 0 | 51,865 | 7 | 103,730 |
Tags: brute force, constructive algorithms
Correct Solution:
```
a=sorted(list(map(int,input().split())))
if (a[0]==1) or ((a[0]==2) and (a[1]==2)) or ((a[0]==3) and (a[2]==3)) or ((a[0]==2) and (a[1]==4) and (a[2]==4)):
print('YES')
else:
print('NO')
``` | output | 1 | 51,865 | 7 | 103,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
#http://codeforces.com/problemset/problem/911/C
inp = list(map(int, input().split()))
inp.sort()
string = "NO"
if(inp.count(1)>= 1 or inp.count(2)>=2 or inp.count(3)>=3):
string = "YES"
if(inp == [2,4,4]):
string = "YES"
print(string)
``` | instruction | 0 | 51,866 | 7 | 103,732 |
Yes | output | 1 | 51,866 | 7 | 103,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
a = list(map(int, input().split()))
a.sort()
if (a[0] == 1 or (a[0] == 2 and a[1] == 2) or (a[0] == 3 and a[1] == 3 and a[2] == 3) or (a[0] == 2 and a[1] == 4 and a[2] == 4)):
print ("YES")
else:
print ("NO")
``` | instruction | 0 | 51,867 | 7 | 103,734 |
Yes | output | 1 | 51,867 | 7 | 103,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
a = sorted(list(map(int,input().split())))
if a[0] == 1 or a[0] == 2 and a[1] == 2 or a == [2, 4, 4] or a == [3, 3, 3]:
print('YES')
else:
print('NO')
``` | instruction | 0 | 51,868 | 7 | 103,736 |
Yes | output | 1 | 51,868 | 7 | 103,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
a = [int(z) for z in input().split()]
if 1 in a:
print("YES")
elif a.count(2) >= 2:
print("YES")
elif a.count(3) == 3:
print("YES")
elif a.count(2) == 1 and a.count(4) == 2:
print("YES")
else:
print("NO")
``` | instruction | 0 | 51,869 | 7 | 103,738 |
Yes | output | 1 | 51,869 | 7 | 103,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
l = [0,0,0,0,0]
for i in filter(lambda x: x < 5, map(int, input().split(' '))):
l[i] += 1
if any(l[i] == i for i in range(1,4)) or (l[2] == 1 and l[4] == 2):
print("YES")
else:
print("NO")
``` | instruction | 0 | 51,870 | 7 | 103,740 |
No | output | 1 | 51,870 | 7 | 103,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
import sys
#f = open('input', 'r')
f = sys.stdin
k_list = list(map(int, f.readline().split()))
cd = {}
for k in k_list:
if k in cd:
cd[k] += 1
else:
cd[k] = 1
cl = sorted(cd.items(), key=lambda x: -x[0])
for k, c in cl:
for i in range(2, c+1):
if k%i == 0:
nk = k/i
if nk in cd:
cd[nk] += 1
else:
cd[nk] = 1
if 1 in cd:
print('YES')
else:
print('NO')
``` | instruction | 0 | 51,871 | 7 | 103,742 |
No | output | 1 | 51,871 | 7 | 103,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
a,b,c = map(int,input().split())
if a==1 or b==1 or c==1:
print("YES")
elif a==3 and b==3 and c==3:
print("YES")
else:
l={}
l[2] = 0
l[a]=0
l[b]=0
l[c]=0
l[a]+=1
l[b]+=1
l[c]+=1
if l[2]>=2:
print("YES")
else:
print("NO");
``` | instruction | 0 | 51,872 | 7 | 103,744 |
No | output | 1 | 51,872 | 7 | 103,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
Input
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
Output
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
Examples
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
Note
In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
Submitted Solution:
```
a = list(map(int, input().split(' ')))
a.sort()
if (a[0] == 1) or (a[0] == a[1] == 2) or (a[0] == a[1] == a[2] == 3):
print('YES')
else:
print('NO')
``` | instruction | 0 | 51,873 | 7 | 103,746 |
No | output | 1 | 51,873 | 7 | 103,747 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,900 | 7 | 103,800 |
Tags: implementation
Correct Solution:
```
l = ["Power","Space","Soul","Mind","Time","Reality"]
i = int(input())
while i > 0:
s = input()
if( s == "red"):
del l[l.index("Reality")]
elif (s == "purple"):
del l[l.index("Power")]
elif (s == "green"):
del l[l.index("Time")]
elif (s == "blue"):
del l[l.index("Space")]
elif (s == "orange"):
del l[l.index("Soul")]
elif (s == "yellow"):
del l[l.index("Mind")]
i-=1
print(len(l))
for a in l:
print(a)
``` | output | 1 | 51,900 | 7 | 103,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,901 | 7 | 103,802 |
Tags: implementation
Correct Solution:
```
gem_dict = {'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality','yellow':'Mind'}
T = int(input().strip())
seen = []
for i in range(T):
seen.append(input().strip())
print(6-len(seen))
for _key in gem_dict:
if _key not in seen:
print(gem_dict[_key])
``` | output | 1 | 51,901 | 7 | 103,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,902 | 7 | 103,804 |
Tags: implementation
Correct Solution:
```
t = int(input())
power = ["Mind","Power","Reality","Soul","Space","Time"]
color = ["yellow","purple","red","orange","blue","green"]
present = [0]*6
for i in range(t):
col = str(input().strip())
if col in color:
present[color.index(col)] = 1
print(6-sum(present))
for i in range(6):
if not present[i]:
print(power[i])
``` | output | 1 | 51,902 | 7 | 103,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,903 | 7 | 103,806 |
Tags: implementation
Correct Solution:
```
ref={'red':'Reality','green':'Time','blue':'Space',\
'purple':'Power',\
'yellow':'Mind',\
'orange':'Soul'}
n=int(input())
L=[]
for i in range(n):
#L=list(map(int, input().split()))
L.append(input())
print(6-n)
for j in ref:
if j not in L:
print(ref[j])
'''
n=int(input())
s1=list(map(int, input().split()))
c1=list(map(int, input().split()))
'''
``` | output | 1 | 51,903 | 7 | 103,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,904 | 7 | 103,808 |
Tags: implementation
Correct Solution:
```
a={
"purple":"Power",
"green":"Time",
"blue":"Space",
"orange":"Soul",
"red":"Reality",
"yellow":"Mind"
}
b=[]
n=int(input())
for x in range(n):
b.append(input())
s=0
c=[]
for x in a:
if x not in b:
s+=1
c.append(a[x])
print(s)
for x in range(len(c)):
print(c[x])
``` | output | 1 | 51,904 | 7 | 103,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,905 | 7 | 103,810 |
Tags: implementation
Correct Solution:
```
li=["Power",'Time','Space','Soul','Reality','Mind']
gi={'purple':'Power' ,'green':'Time', 'blue':'Space','orange':'Soul','red':'Reality','yellow':'Mind'}
n=int(input())
for i1 in range(n):
li.remove(gi[input()])
print(len(li))
for i in li:
print(i)
``` | output | 1 | 51,905 | 7 | 103,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,906 | 7 | 103,812 |
Tags: implementation
Correct Solution:
```
main=['purple','green','blue','orange','red','yellow']
type_s=['Power','Time','Space','Soul','Reality','Mind']
n=int(input())
col=[]
for i in range(n):
a=input()
col.append(a)
not_present=[]
for i in main:
if i in col:
pass
else:
not_present.append(i)
count=len(not_present)
ss=[]
for i in not_present:
if(i=='purple'):
ss.append('Power')
elif(i=='green'):
ss.append('Time')
elif(i=='blue'):
ss.append('Space')
elif(i=='orange'):
ss.append('Soul')
elif(i=='red'):
ss.append('Reality')
elif(i=='yellow'):
ss.append('Mind')
print(count)
for i in ss:
print(i)
``` | output | 1 | 51,906 | 7 | 103,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | instruction | 0 | 51,907 | 7 | 103,814 |
Tags: implementation
Correct Solution:
```
d = {}
d["purple"] = "Power"
d["green"] = "Time"
d["blue"] = "Space"
d["orange"] = "Soul"
d["red"] = "Reality"
d["yellow"] = "Mind"
n = int(input())
lista = []
for i in d:
lista.append(d[i])
for x in range(n):
s = input()
lista.remove(d[s])
print(len(lista))
for x in lista:
print(x)
# 1534609961022
``` | output | 1 | 51,907 | 7 | 103,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
mp = {
'purple': 'Power',
'green': 'Time',
'blue': 'Space',
'orange': 'Soul',
'red': 'Reality',
'yellow': 'Mind'
}
n = int(input())
have = {input() for _ in range(n)}
need = mp.keys() - have
print(len(need))
print(*(mp[x] for x in need), sep='\n')
``` | instruction | 0 | 51,908 | 7 | 103,816 |
Yes | output | 1 | 51,908 | 7 | 103,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
n = int(input())
a = {'purple':'Power', 'green' : 'Time', 'blue' : 'Space', 'orange' : 'Soul', 'red' : 'Reality', 'yellow' : 'Mind'}
for _ in range(n):
s = input()
a[s] = 1
print (6-n)
for i in a:
if a[i]!=1:
print (a[i])
``` | instruction | 0 | 51,909 | 7 | 103,818 |
Yes | output | 1 | 51,909 | 7 | 103,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
n = int(input())
mat = []
for _ in range(n):
mat.append(input())
c_mat = ["purple", "green", "blue", "orange", "red", "yellow"]
n_mat = ["Power", "Time", "Space", "Soul", "Reality", "Mind"]
print(6-len(mat))
for i in range(6):
if not c_mat[i] in mat:
print(n_mat[i])
``` | instruction | 0 | 51,910 | 7 | 103,820 |
Yes | output | 1 | 51,910 | 7 | 103,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
q = ["Power","Time","Space","Soul","Reality","Mind"]
w = ["purple","green","blue","orange","red","yellow"]
n = int(input())
k=0
for i in range(n):
a = input()
for i in range(len(q)):
if a == w[i]:
q[i] = ""
k+=1
print(6-k)
for i in range(len(q)):
if q[i]!="":
print(q[i])
``` | instruction | 0 | 51,911 | 7 | 103,822 |
Yes | output | 1 | 51,911 | 7 | 103,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
mydict={"purple":["Power",0],"green":["Time",0],"blue":["Space",0],"orange":["Soul",0],"red":["Reality",0],"yellow":["Mind",0]}
n=int(input())
for i in range(0,n):
Key = str(input())
mydict[Key][1] = 1
print(mydict)
count=0
for values in mydict.values():
if(values[1]==0):
count+=1
print(str(count))
for keys in mydict.keys():
if(mydict[keys][1]==0):
print(mydict[keys][0])
``` | instruction | 0 | 51,913 | 7 | 103,826 |
No | output | 1 | 51,913 | 7 | 103,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
c = {'purple':'Power', 'green':'Time', 'bule':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind'}
n = int(input())
d = []
e = []
for i in range(n):
d.append(input())
for i in c:
if i not in d:
e.append(c[i])
print(len(e))
for i in e:
print(i)
``` | instruction | 0 | 51,914 | 7 | 103,828 |
No | output | 1 | 51,914 | 7 | 103,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input
In the first line of input there is one integer n (0 ≤ n ≤ 6) — the number of Gems in Infinity Gauntlet.
In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output
In the first line output one integer m (0 ≤ m ≤ 6) — the number of absent Gems.
Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Examples
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
Submitted Solution:
```
a=['purple','green','blue','orange','red','yellow']
b=['Power','Time','Space','Soul','Reality','Mind']
n=int(input())
c=[]
for i in range(n):
c.append(input())
for i in range(6):
if(a[i] not in c):
print(b[i])
``` | instruction | 0 | 51,915 | 7 | 103,830 |
No | output | 1 | 51,915 | 7 | 103,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,250 | 7 | 104,500 |
Tags: dp
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
# ------------------------------
def main():
n = N()
arr = RLL()
p = 0
for i in range(n):
if arr[i]!=arr[p]:
p += 1
arr[p] = arr[i]
n = p+1
pre = [0 for _ in range(n)]
dp = [n for _ in range(n)]
for i in range(n):
dp[i] = 0
for i in range(2, n+1):
new = [n for _ in range(n-i+1)]
for l in range(n-i+1):
r = l+i-1
if arr[l]==arr[r]:
now = min(new[l], pre[l+1]+1)
new[l] = now
else:
new[l] = min(new[l], min(dp[l+1], dp[l])+1)
pre = dp
dp = new
print(dp[0])
if __name__ == "__main__":
main()
``` | output | 1 | 52,250 | 7 | 104,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,251 | 7 | 104,502 |
Tags: dp
Correct Solution:
```
from itertools import groupby
import math
n, = list(map(int, input().strip().split()))
array = list(map(int, input().strip().split()))
g_array = [k for k, g in groupby(array)]
n = len(g_array)
extend_n = n + 2
sols = [[0]*extend_n for _ in range(extend_n)]
for i in range(1, extend_n-1):
for j in range(extend_n-2, i, -1):
val = max(sols[i-1][j], sols[i][j+1])
if g_array[i-1] == g_array[j-1]:
val = max(val, sols[i-1][j+1] + 1)
sols[i][j] = val
best = 0
for start in range(1, extend_n-1-1):
start_val = sols[start-1][start+1]
if start_val > best:
best = start_val
print(len(g_array) - 1 - best)
``` | output | 1 | 52,251 | 7 | 104,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,252 | 7 | 104,504 |
Tags: dp
Correct Solution:
```
def fill():
global dp
dp = [0] * (n + 2)
for i in range(n + 2):
dp[i] = [0] * (n + 2)
def compress(v):
global n
global c
c = [v[0]]
for i in range(1, n):
if v[i] != v[i - 1]:
c.append(v[i])
n = len(c)
n = int(input())
v = [int(i) for i in input().split()]
c = []
compress(v)
dp = []
fill()
for i in range(n):
dp[i][1] = 0
dp[i][2] = 1
for sz in range(3, n + 1):
for i in range(n):
j = i + sz - 1
if j >= n:
break
if c[i] == c[j]:
dp[i][sz] = dp[i + 1][sz - 2] + 1
else:
dp[i][sz] = min(dp[i + 1][sz - 1], dp[i][sz - 1]) + 1
print(dp[0][n])
``` | output | 1 | 52,252 | 7 | 104,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,253 | 7 | 104,506 |
Tags: dp
Correct Solution:
```
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()
B = [0]
for a in A:
if B[-1] != a:
B.append(a)
B = B[1:]
k = len(B)
dp = [0]*((k*k + k)//2)
for d in range(1, k):
for i in range(k-d):
if B[i] == B[i+d]:
dp[d*(2*k-d+1)//2+i] = dp[(d-2)*(2*k-d+3)//2+i+1] + 1
else:
dp[d*(2*k-d+1)//2+i] = 1 + min(dp[(d-1)*(2*k-d+2)//2+i], dp[(d-1)*(2*k-d+2)//2+i+1])
print(dp[-1])
``` | output | 1 | 52,253 | 7 | 104,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,254 | 7 | 104,508 |
Tags: dp
Correct Solution:
```
n=int(input())
c=list(map(int,input().split()))
c.append(-5)
arr=[0]
for i in range(n):
if(c[i]!=c[i+1]):
arr.append(c[i])
arr_r=[0]+arr[::-1]
l=len(arr)
store=[0]*(l)
up=[0]*(l)
for i in range(1,l):
for j in range(1,l):
if(arr[i]==arr_r[j]):
store[j]=up[j-1]+1
else:
store[j]=max(store[j-1],up[j])
up=store
store=[0]*(l)
print(l-1-1-up[-1]//2)
``` | output | 1 | 52,254 | 7 | 104,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,255 | 7 | 104,510 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = []
p = -1
for e in a:
if e == p:
continue
else:
b.append(e)
p = e
def lcs(a, b):
lengths = [[0 for j in range(len(b)+1)] for i in range(len(a)+1)]
# row 0 and column 0 are initialized to 0 already
for i, x in enumerate(a):
for j, y in enumerate(b):
if x == y:
lengths[i+1][j+1] = lengths[i][j] + 1
else:
lengths[i+1][j+1] = max(lengths[i+1][j], lengths[i][j+1])
# read the substring out from the matrix
x, y = len(a), len(b)
return lengths[x][y]
ans = 0
#print(b)
#for i in range(len(b)//2+1):
#print(list(reversed(b[:i])), b[i:])
#ans = max(ans, lcs(list(reversed(b[:i])), b[i:]))
ans = lcs(list(reversed(b)), b)//2
n = len(b)
#print(ans)
print(n - ans - 1)
``` | output | 1 | 52,255 | 7 | 104,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,256 | 7 | 104,512 |
Tags: dp
Correct Solution:
```
def run_length_compress(string):
string = string + ["."]
n = len(string)
begin = 0
end = 1
cnt = 1
ans = []
while True:
if end >= n:
break
if string[begin] == string[end]:
end += 1
cnt += 1
else:
ans.append(string[begin])
begin = end
end = begin + 1
cnt = 1
return ans
def lps(string):
n = len(string)
dp = [[0]*n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n+1):
for i in range(n-cl+1):
j = i + cl - 1
if string[i] == string[j] and cl == 2:
dp[i][j] = 2
elif string[i] == string[j]:
dp[i][j] = dp[i+1][j-1] + 2
else:
dp[i][j] = max(dp[i][j-1], dp[i+1][j])
return dp[0][n-1]
n = int(input())
a = list(map(int, input().split()))
a = run_length_compress(a)
len_pal = lps(a)
print(len(a) - 1 - len_pal//2)
``` | output | 1 | 52,256 | 7 | 104,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only. | instruction | 0 | 52,257 | 7 | 104,514 |
Tags: dp
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
#from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
#-------------------------------------------------------------------------
def main():
n = int(input())
arr = list(map(int,input().split()))
p = 0
for i in range(n):
if arr[i]!=arr[p]:
p += 1
arr[p] = arr[i]
n = p+1
pre = [0 for _ in range(n)]
dp = [n for _ in range(n)]
for i in range(n):
dp[i] = 0
for i in range(2, n+1):
new = [n for _ in range(n-i+1)]
for l in range(n-i+1):
r = l+i-1
if arr[l]==arr[r]:
now = min(new[l], pre[l+1]+1)
new[l] = now
else:
new[l] = min(new[l], min(dp[l+1], dp[l])+1)
pre = dp
dp = new
print(dp[0])
if __name__ == "__main__":
main()
``` | output | 1 | 52,257 | 7 | 104,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only.
Submitted Solution:
```
n=int(input())
C=[0]+list(map(int,input().split()))
#n=5000
#C=list(range(n+1))
A=[]
for i in range(1,n+1):
if C[i]!=C[i-1]:
A.append(C[i])
L=len(A)
DP=[[[0]*L for i in range(L)] for j in range(2)]
#左の色に揃える or 右の色に揃える,左からi~j番目を
def color(r,i,j):#i<j
if r==1:
if A[i]==A[j]:
DP[r][i][j]=min(DP[0][i][j-1],DP[1][i][j-1]+1)
else:
DP[r][i][j]=min(DP[0][i][j-1]+1,DP[1][i][j-1]+1)
else:
if A[i]==A[j]:
DP[r][i][j]=min(DP[1][i+1][j],DP[0][i+1][j]+1)
else:
DP[r][i][j]=min(DP[1][i+1][j]+1,DP[0][i+1][j]+1)
for i in range(1,L):
for j in range(L-i):
color(0,j,i+j)
color(1,j,i+j)
#print(DP)
print(min(DP[0][0][L-1],DP[1][0][L-1]))
``` | instruction | 0 | 52,258 | 7 | 104,516 |
Yes | output | 1 | 52,258 | 7 | 104,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
from atexit import register
from io import BytesIO, StringIO
from os import fstat, read, write
input = BytesIO(read(0, fstat(0).st_size)).readline
sys.stdout = StringIO()
register(lambda: write(1, sys.stdout.getvalue().encode()))
def main():
n = int(input())
a = input().split()
dp = [[[5000] * n for _ in range(n)] for _ in range(2)]
for i in range(n):
dp[0][i][i], dp[1][i][i] = 0, 0
for r in range(n):
for l in range(r, -1, -1):
for it in range(2):
c = a[l] if it == 0 else a[r]
if l != 0:
dp[0][l - 1][r] = min(dp[0][l - 1][r], dp[it][l][r] + (1 if c != a[l - 1] else 0))
if r != n - 1:
dp[1][l][r + 1] = min(dp[1][l][r + 1], dp[it][l][r] + (1 if c != a[r + 1] else 0))
print(min(dp[0][0][n - 1], dp[1][0][n - 1]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 52,259 | 7 | 104,518 |
Yes | output | 1 | 52,259 | 7 | 104,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.
For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.
The game "flood fill" is played on the given line as follows:
* At the start of the game you pick any starting square (this is not counted as a turn).
* Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Find the minimum number of turns needed for the entire line to be changed into a single color.
Input
The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.
The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.
Output
Print a single integer — the minimum number of the turns needed.
Examples
Input
4
5 2 2 1
Output
2
Input
8
4 5 2 2 1 3 5 5
Output
4
Input
1
4
Output
0
Note
In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:
* [5, 2, 2, 1]
* [5, 5, 5, 1]
* [1, 1, 1, 1]
In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.
In the third example, the line already consists of one color only.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
from atexit import register
from io import BytesIO, StringIO
import os
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue().encode()))
def main():
n = int(input())
a = input().split()
dp = [[[5000] * n for _ in range(n)] for _ in range(2)]
for i in range(n):
dp[0][i][i], dp[1][i][i] = 0, 0
for r in range(n):
for l in range(r, -1, -1):
for it in range(2):
c = a[l] if it == 0 else a[r]
if l != 0:
dp[0][l - 1][r] = min(dp[0][l - 1][r], dp[it][l][r] + (1 if c != a[l - 1] else 0))
if r != n - 1:
dp[1][l][r + 1] = min(dp[1][l][r + 1], dp[it][l][r] + (1 if c != a[r + 1] else 0))
print(min(dp[0][0][n - 1], dp[1][0][n - 1]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 52,260 | 7 | 104,520 |
Yes | output | 1 | 52,260 | 7 | 104,521 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.