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.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
n,k,t=map(int,input().split())
total=n*k
t=int(total*(t/100))
for i in range(1,n+1):
if t>k:
print(k,end=" ")
t=t-k
elif 0<t<=k:
print(t,end=" ")
t-=t
else:
print(0,end=" ")
``` | instruction | 0 | 14,666 | 7 | 29,332 |
Yes | output | 1 | 14,666 | 7 | 29,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
def process(n,k,t):
for i in range(1,n+1):
for l in range(0,k+1):
b1,b2 = ((i-1)*k + l)/(n*k),((i-1)*k + 1 + l)/(n*k)
if(b1<=t/100<b2):
for j in range(1,i):
print(k,end= ' ')
print(l,end = ' ')
for j in range(i+1,n+1):
print(0,end= ' ')
return
n, k, t = map(int,input().split())
process(n,k,t)
``` | instruction | 0 | 14,667 | 7 | 29,334 |
Yes | output | 1 | 14,667 | 7 | 29,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
val = list(map(int,input().split()))
eachBar = val[0]
maxeachBar = val[1]
percentValue = val[2]
presentmaxvalue = int(eachBar * maxeachBar * (percentValue/100))
a,b = divmod(presentmaxvalue,maxeachBar)
arr = []
for ans in range(a):
arr.append(maxeachBar)
if b != 0:
arr.append(b)
for y in range(eachBar-a-1):
arr.append(0)
else:
for y in range(eachBar-a):
arr.append(0)
print(*arr)
``` | instruction | 0 | 14,668 | 7 | 29,336 |
Yes | output | 1 | 14,668 | 7 | 29,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
from math import floor
n, k, t = map(int, input().split())
answer = ""
filled = 100/n
for i in range(1,n+1):
if filled <= t:
answer += str(k) + " "
t = t - filled
elif filled > t:
answer += str(floor(t)) + " "
t = 0
else:
answer += str(0) + " "
print(answer)
``` | instruction | 0 | 14,669 | 7 | 29,338 |
No | output | 1 | 14,669 | 7 | 29,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
l=list()
while(1):
n,k,t = [int(i) for i in input().split()]
if n in range(101)and t in range(101)and k in range(101) :
break
for i in range(n+1) :
a=round(n*t*0.01)
if i<a :
l.append(str(k))
elif i==a :
l.append((str(int((t*n)%100)/10))[:len(str(int((t*n)%100)/10))-2])
elif i>a :
l.append(str(0))
print(" ".join(l))
``` | instruction | 0 | 14,670 | 7 | 29,340 |
No | output | 1 | 14,670 | 7 | 29,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
l=list()
while(1):
n,k,t = [int(i) for i in input().split()]
if n in range(101)and t in range(101)and k in range(101) :
break
for i in range(n+2) :
a=round(n*t*0.01)
if i<a :
l.append(str(k))
elif i==a :
l.append((str(int((t*n)%100)/10))[:len(str(int((t*n)%100)/10))-2])
elif i>a :
l.append(str(0))
l.append('0')
print(" ".join(l))
``` | instruction | 0 | 14,671 | 7 | 29,342 |
No | output | 1 | 14,671 | 7 | 29,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.
So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.
The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled:
<image>
An example of such a bar can be seen on the picture.
<image>
For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
Input
We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).
Output
Print n numbers. The i-th of them should be equal to ai.
Examples
Input
10 10 54
Output
10 10 10 10 10 4 0 0 0 0
Input
11 13 37
Output
13 13 13 13 0 0 0 0 0 0 0
Submitted Solution:
```
n,k,t = map(int, input().split())
import math
box_size = 100/n
full = math.floor(t/box_size)
middle = math.floor((t%box_size)*k/box_size)
output = []
for i in range(n):
if i < full:
output.append(str(k))
elif i == full:
output.append(str(middle))
else:
output.append(str(0))
str1 = " "
print(str1.join(output))
``` | instruction | 0 | 14,672 | 7 | 29,344 |
No | output | 1 | 14,672 | 7 | 29,345 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black.
Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of (1, 2, ..., N-1), P, which means that the i-th operated machine is Machine P_i.
Here, the score of a permutation P is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by P. Snuke has not decided what permutation P to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo 10^9+7.
Constraints
* 2 \leq N \leq 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the sum of the scores over all possible permutations, modulo 10^9+7.
Examples
Input
4
Output
16
Input
2
Output
1
Input
5
Output
84
Input
100000
Output
341429644 | instruction | 0 | 14,847 | 7 | 29,694 |
"Correct Solution:
```
n = int(input())
p = 10**9 + 7
def fact(n):
n_ = 1
yield n_
for i in range(1, n+1):
n_ = (n_*i) % p
yield n_
def invfact(n, f, p):
m = pow(f[n], p-2, p)
yield m
for i in range(n, 0, -1):
m = m * i % p
yield m
ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0
for k in range((n+1)//2, n):
b = m - k
a = (m - 1) - (2 * b)
perm_ = f[a+b] * rf[a] %p * f[k] % p
ans += (perm_ - perm) %p * k % p
ans %= p
perm = perm_
print(ans)
``` | output | 1 | 14,847 | 7 | 29,695 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black.
Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of (1, 2, ..., N-1), P, which means that the i-th operated machine is Machine P_i.
Here, the score of a permutation P is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by P. Snuke has not decided what permutation P to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo 10^9+7.
Constraints
* 2 \leq N \leq 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the sum of the scores over all possible permutations, modulo 10^9+7.
Examples
Input
4
Output
16
Input
2
Output
1
Input
5
Output
84
Input
100000
Output
341429644 | instruction | 0 | 14,851 | 7 | 29,702 |
"Correct Solution:
```
n = int(input())
p = 10**9 + 7
def fact(n):
n_ = 1
yield n_
for i in range(1, n+1):
n_ = (n_*i) % p
yield n_
def invfact(n, f, p):
m = pow(f[n], p-2, p)
yield m
for i in range(n, 0, -1):
m = m * i % p
yield m
ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0
for k in range((n+1)//2, n):
perm_ = f[k-1] * rf[2*k-n] %p * f[k] % p
ans += (perm_ - perm) %p * k % p
ans %= p
perm = perm_
print(ans)
``` | output | 1 | 14,851 | 7 | 29,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black.
Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of (1, 2, ..., N-1), P, which means that the i-th operated machine is Machine P_i.
Here, the score of a permutation P is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by P. Snuke has not decided what permutation P to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo 10^9+7.
Constraints
* 2 \leq N \leq 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the sum of the scores over all possible permutations, modulo 10^9+7.
Examples
Input
4
Output
16
Input
2
Output
1
Input
5
Output
84
Input
100000
Output
341429644
Submitted Solution:
```
n = int(input())
p = 10**9 + 7
def fact(n):
n_ = 1
yield n_
for i in range(1, n+1):
n_ = (n_*i) % p
yield n_
ans = 0
m = n - 1
f = list(fact(m))
perm = 0
for k in range((n+1)//2, n):
b = m - k
a = (m - 1) - (2 * b)
perm_ = f[a+b] * pow(f[a], p-2, p) %p * f[k] % p
ans += (perm_ - perm) %p * k % p
ans %= p
perm = perm_
print(ans)
``` | instruction | 0 | 14,858 | 7 | 29,716 |
No | output | 1 | 14,858 | 7 | 29,717 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,876 | 7 | 29,752 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
seta = set(a)
if len(seta) == 1:
if a[0] in (0, N-1) or a[0] <= N // 2:
print("Yes")
else:
print("No")
elif len(seta) == 2:
a1 = min(seta)
a2 = max(seta)
counta1 = a.count(a1)
if a2 != a1 + 1:
print("No")
elif counta1 < a2 and counta1 + 2 * (a2 - counta1) <= N:
print("Yes")
else:
print("No")
else:
print("No")
``` | output | 1 | 14,876 | 7 | 29,753 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,877 | 7 | 29,754 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
Min = min(a)
Max = max(a)
if Max - Min > 1:
print("No")
elif Max == Min:
if a[0] == n - 1 or a[0] <= n // 2:
print("Yes")
else:
print("No")
else:
c_M = a.count(Max)
c_m = n - c_M
if c_m < Max <= c_m + c_M // 2:
print("Yes")
else:
print("No")
``` | output | 1 | 14,877 | 7 | 29,755 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,878 | 7 | 29,756 |
"Correct Solution:
```
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
if A[0]==A[-1] and (A[0]==1 or A[0]==N-1):
print("Yes")
else:
k = A[0]
cnt = A.count(k-1)
n = N-cnt
k -= cnt
if k<=0:
print("No")
else:
n -= 2*k
if n>=0:
print("Yes")
else:
print("No")
``` | output | 1 | 14,878 | 7 | 29,757 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,879 | 7 | 29,758 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
L = len(set(a))
if L ==1:
if a[0] < n//2+1 or a[0]==n-1:
print('Yes')
else:
print('No')
elif L == 2:
M,m =max(a),min(a)
m_c =a.count(m)
if M == m+1 and m_c <= m and n-m_c >= 2*(M-m_c):
print('Yes')
else:
print('No')
else:
print('No')
``` | output | 1 | 14,879 | 7 | 29,759 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,880 | 7 | 29,760 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = 0
for i in range(n):
if a[i] == a[0]:
cnt = i+1
else:
break
if a[-1] - a[0] > 1:
print('No')
exit()
elif a[-1] - a[0] == 1:
actual = a[-1]
if actual >= n:
print('No')
elif cnt <= actual - 1 and actual <= cnt + (n - cnt) // 2:
print('Yes')
else:
print('No')
exit()
elif a[-1] - a[0] == 0:
solve = False
actual = a[0]
if n >= actual * 2 or n-1 == actual:
solve = True
if solve:
print('Yes')
else:
print('No')
exit()
else:
print('No')
``` | output | 1 | 14,880 | 7 | 29,761 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,881 | 7 | 29,762 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
M = max(a)
m = min(a)
if M > m + 1:
print("No")
else:
if M == m:
if M == N-1:
print("Yes")
elif M*2 <= N:
print("Yes")
else:
print("No")
else:
# ai == m ならば、ai以外にその色はない
c = a.count(m)
if (M - c) * 2 <= N-c and c < M: # (M-c) -> 一人だけではない色の種類一人だけではないはずなので*2 したものよりも残りの人数が多いはず
print("Yes")
else:
print("No")
``` | output | 1 | 14,881 | 7 | 29,763 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,882 | 7 | 29,764 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
ma = max(a)
mi = min(a)
if ma - mi >= 2:
print('No')
elif ma == mi:
if a[0] == N - 1:
print('Yes')
elif 2 * a[0] <= N:
print('Yes')
else:
print('No')
else:
al = 0
na = 0
for i in range(N):
if a[i] == ma - 1:
al += 1
else:
na += 1
if al < ma and 2 * (ma - al) <= na:
print('Yes')
else:
print('No')
``` | output | 1 | 14,882 | 7 | 29,765 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No | instruction | 0 | 14,883 | 7 | 29,766 |
"Correct Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
data = [[-1, 0]]
for x in a:
if data[-1][0] == x:
data[-1][1] += 1
else:
data.append([x, 1])
data = data[1:]
if len(data) == 1:
print("Yes" if data[0][0] * 2 <= n or data[0][0] + 1 == n else "No")
elif len(data) == 2:
if data[0][0] + 1 == data[1][0] and data[0][0] >= data[0][1] and data[1][1] >= 2 * (data[1][0] - data[0][1]):
print("Yes")
else:
print("No")
else:
print("No")
``` | output | 1 | 14,883 | 7 | 29,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
s = set(a)
if len(s)>=3:
print('No')
elif len(s)==2:
#頑張る
mx = max(a)
mn = min(a)
y = a.count(mx)
x = a.count(mn)
if mx-mn>1:
print('No')
elif x < mx and 2*(mx-x)<=y:
print('Yes')
else:
print('No')
else:
if a[0]==n-1:
print('Yes')
elif a[0]*2<=n:
print('Yes')
else:
print('No')
``` | instruction | 0 | 14,886 | 7 | 29,772 |
Yes | output | 1 | 14,886 | 7 | 29,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
x = min(a)
y = max(a)
if y - x > 1:
print('No')
elif y == x:
if n == x + 1 or 2 * x <= n:
print('Yes')
else:
print('No')
else:
x_cnt = a.count(x)
y_cnt = a.count(y)
if y > x_cnt and 2 * (y - x_cnt) <= y_cnt:
print('Yes')
else:
print('No')
``` | instruction | 0 | 14,887 | 7 | 29,774 |
Yes | output | 1 | 14,887 | 7 | 29,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No
Submitted Solution:
```
import numpy as np
H,W,h,w = map(int,input().split())
# H,W,h,w = (3,4,2,3)
hrep = H//h +1
wrep = W//w +1
elem = np.ones((h,w),dtype=int)
elem[-1,-1] = -h*w
mat = np.tile(elem, (hrep,wrep))
mat = mat[:H,:W]
if mat.sum() > 0:
print("Yes")
for i in mat:
print(" ".join(map(str,i)))
else:
print("No")
``` | instruction | 0 | 14,888 | 7 | 29,776 |
No | output | 1 | 14,888 | 7 | 29,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No
Submitted Solution:
```
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
a = LIST()
if max(a) - min(a) == 0 and (a[0] == N-1 or a[0] <= N//2):
print("Yes")
elif max(a) - min(a) == 1 and a.count(min(a)) < len(set(a)) and (len(set(a))-a.count(min(a))) <= a.count(max(a))//2:
print("Yes")
else:
print("No")
``` | instruction | 0 | 14,889 | 7 | 29,778 |
No | output | 1 | 14,889 | 7 | 29,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cats. We number them from 1 through N.
Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."
Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N-1
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise.
Examples
Input
3
1 2 2
Output
Yes
Input
3
1 1 2
Output
No
Input
5
4 3 4 3 4
Output
No
Input
3
2 2 2
Output
Yes
Input
4
2 2 2 2
Output
Yes
Input
5
3 3 3 3 3
Output
No
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
ans = "Yes"
L_max = max(L)
L_min = min(L)
if L_max - L_min >= 2:
ans = "No"
else:
num_alone = L.count(L_min)
not_alone_L = [v-num_alone for v in L if v == L_max]
if not_alone_L[0] < 0 or len(not_alone_L) < not_alone_L[0]*2:
ans = "No"
print(ans)
``` | instruction | 0 | 14,891 | 7 | 29,782 |
No | output | 1 | 14,891 | 7 | 29,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,289 | 7 | 30,578 |
Tags: brute force, greedy
Correct Solution:
```
from collections import Counter
# region fastio
import os
import sys
from io import BytesIO, IOBase
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")
# endregion
def func(arr):
freq = Counter(arr)
ans = max(Counter(arr).values())
return ans
def main():
for _ in range(int(input())):
_ = input()
arr = list(map(int, input().split()))
print(func(arr))
return
if __name__ == '__main__':
main()
``` | output | 1 | 15,289 | 7 | 30,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,290 | 7 | 30,580 |
Tags: brute force, greedy
Correct Solution:
```
t = int(input())
while t>0 :
n = int(input())
a = list(map(int,input().strip().split()))[:n]
ans=1
x = 1
for i in range(1,n,1):
if a[i]==a[i-1]:
x+=1
ans = max(x,ans)
else:
x=1
print(ans)
t= t -1
``` | output | 1 | 15,290 | 7 | 30,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,291 | 7 | 30,582 |
Tags: brute force, greedy
Correct Solution:
```
t=int(input())
for j in range(0,t):
n=int(input())
s=list(map(int,input().split()))
p={}
for i in range(0,n):
if(p.get(s[i],-1)==-1): p[s[i]]=1
else: p[s[i]]+=1
zd=0
for i in p:
zd=max(zd,p[i])
print(zd)
``` | output | 1 | 15,291 | 7 | 30,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,292 | 7 | 30,584 |
Tags: brute force, greedy
Correct Solution:
```
ans = []
for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
mx = 1
k = 1
for i in range(1, n):
if u[i] == u[i - 1]:
k += 1
else:
mx = max(mx, k)
k = 1
mx = max(mx, k)
ans.append(mx)
print('\n'.join(map(str, ans)))
``` | output | 1 | 15,292 | 7 | 30,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,293 | 7 | 30,586 |
Tags: brute force, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
def println(val):
sys.stdout.write(str(val) + '\n')
ans = []
def solve():
global ans
n = int(input())
a = list(map(int, input().split()))
import collections
cnt = collections.Counter(a)
res = 0
for key in cnt:
if cnt[key] > res:
res = cnt[key]
ans += [str(res)]
for _ in range(int(input()) if 1 else 1):
solve()
print('\n'.join(ans))
``` | output | 1 | 15,293 | 7 | 30,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,294 | 7 | 30,588 |
Tags: brute force, greedy
Correct Solution:
```
for tt in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
used = [set() for i in range(150)]
ans = 0
for x in a:
for i in range(150):
if x not in used[i]:
ans = max(ans,i+1)
used[i].add(x)
break
print(ans)
``` | output | 1 | 15,294 | 7 | 30,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,295 | 7 | 30,590 |
Tags: brute force, greedy
Correct Solution:
```
from collections import deque, Counter,defaultdict as dft
from heapq import heappop ,heappush
from math import log,sqrt,factorial,cos,tan,sin,radians,log2,ceil,floor
from bisect import bisect,bisect_left,bisect_right
from decimal import *
import sys,threading
from itertools import permutations, combinations
from copy import deepcopy
input = sys.stdin.readline
ii = lambda: int(input())
si = lambda: input().rstrip()
mp = lambda: map(int, input().split())
ms= lambda: map(str,input().strip().split(" "))
ml = lambda: list(mp())
mf = lambda: map(float, input().split())
def solve():
n=ii()
arr=ml()
mx=1
pre=arr[0]
count=1
for i in range(1,n):
#print(pre,count,arr[i])
if arr[i]==pre:
count+=1
mx=max(mx,count)
else:
pre=arr[i]
count=1
print(mx)
if __name__ == "__main__":
#tc=1
tc = ii()
for i in range(tc):
solve()
``` | output | 1 | 15,295 | 7 | 30,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1]. | instruction | 0 | 15,296 | 7 | 30,592 |
Tags: brute force, greedy
Correct Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def prod(a, mod=10**9+7):
ans = 1
for each in a:
ans = (ans * each) % mod
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
n = int(input())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
a=list(map(int, input().split()))
count = [0]*(n+69)
for i in a:count[i]+=1
print(max(count))
``` | output | 1 | 15,296 | 7 | 30,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
l1 = set(l)
a = []
for i in l1:
a.append(l.count(i))
print(max(a))
``` | instruction | 0 | 15,297 | 7 | 30,594 |
Yes | output | 1 | 15,297 | 7 | 30,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for val in c.values():
ans = max(ans, val)
print(ans)
# 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")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 15,298 | 7 | 30,596 |
Yes | output | 1 | 15,298 | 7 | 30,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
for i in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
freq={}
res = 0
for i in l:
if i in freq:
freq[i]+=1
else:
freq[i]=1
if len(freq)==1:
print(list(freq.values())[0])
else:
j = max(freq.values())
print(j)
``` | instruction | 0 | 15,299 | 7 | 30,598 |
Yes | output | 1 | 15,299 | 7 | 30,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
from collections import Counter
def A(a,n):
if(n==1):
return 1
c=Counter(a)
mx=1
for i in c:
if(mx<c[i]):
mx=c[i]
return mx
t=int(input())
for _ in range(t):
n=int(input())
a=[int(i) for i in input().split()]
print(A(a,n))
``` | instruction | 0 | 15,300 | 7 | 30,600 |
Yes | output | 1 | 15,300 | 7 | 30,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
t=int(input())
j=0
while(j<t):
n=int(input())
arr=list(map(int, input().split()))
col=1
for i in range(len(arr)-1):
if arr[i+1]==arr[i]:
col+=1
print(col)
j+=1
``` | instruction | 0 | 15,301 | 7 | 30,602 |
No | output | 1 | 15,301 | 7 | 30,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
result = []
first_input = int(input())
for i in range(first_input):
second_input= int(input())
i = input()
i = [int(i) for i in i.split()]
d = dict()
for a in i:
if a in d:
d[a] += 1
else:
d[a] = 1
f = []
for v in d.values():
f.append(v)
f = sorted(f)
result.append(f[-1])
print(result)
``` | instruction | 0 | 15,302 | 7 | 30,604 |
No | output | 1 | 15,302 | 7 | 30,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
t=int(input())
max=0
for i in range(t):
c=1
max=0
n=int(input())
if n<=1:
print(n)
else:
arr=list(map(int,input().split(" ")))
for j in range(n-1):
if(arr[j]==arr[j+1]):
c+=1
else:
c=1
if(c>max):
max=c
print(max)
max=0
``` | instruction | 0 | 15,303 | 7 | 30,606 |
No | output | 1 | 15,303 | 7 | 30,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
* For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100).
The second line of each test case contains n integers a_1,a_2,…,a_n (1 ≤ a_i ≤ n). It is guaranteed that a_1 ≤ a_2 ≤ … ≤ a_n.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
Note
Let's match each color with some numbers. Then:
In the first test case, one optimal color assignment is [1,2,3,3,2,1].
In the second test case, one optimal color assignment is [1,2,1,2,1].
Submitted Solution:
```
z = int(input(""))
for i in range(0,z):
y = int(input(""))
for j in range(y):
L=[]
max=0
L=input("").split(" ")
print(L)
for K in set(L):
nb=L.count(K)
if nb > max:
max = nb
print(max)
break
``` | instruction | 0 | 15,304 | 7 | 30,608 |
No | output | 1 | 15,304 | 7 | 30,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns, there is one integer in each cell.
It's known that n is an odd number, so let's introduce <image>. Fox Ciel can do the following operation many times: she choose a sub-board with size x rows and x columns, then all numbers in it will be multiplied by -1.
Return the maximal sum of numbers in the board that she can get by these operations.
Input
The first line contains an integer n, (1 ≤ n ≤ 33, and n is an odd integer) — the size of the board.
Each of the next n lines contains n integers — the numbers in the board. Each number doesn't exceed 1000 by its absolute value.
Output
Output a single integer: the maximal sum of numbers in the board that can be accomplished.
Examples
Input
3
-1 -1 1
-1 1 -1
1 -1 -1
Output
9
Input
5
-2 0 0 0 -2
0 -2 0 -2 0
0 0 -2 0 0
0 -2 0 -2 0
-2 0 0 0 -2
Output
18
Note
In the first test, we can apply this operation twice: first on the top left 2 × 2 sub-board, then on the bottom right 2 × 2 sub-board. Then all numbers will become positive.
<image>
Submitted Solution:
```
n = int(input())
x = (n + 1) // 2
a = [list(map(int, input().split())) for _ in range(n)]
ans = -10**19
def solve(mask: int):
b = [x[:] for x in a]
for i in range(x):
if mask >> (i & 1):
for j in range(x):
for k in range(x):
b[x - 1 + j][k + i] *= -1
for i in range(x, n):
for j in range(n):
b[i - x][j] += b[i][j]
ret = 0
for i in range(x - 1):
v1 = 0 # flip the rightmost
v2 = 0 # don't
for j in range(x - 1):
v1 += abs(b[i][j] - b[i][j + x])
v1 += -b[i][x - 1]
for j in range(x - 1):
v2 += abs(b[i][j] + b[i][j + x])
v2 += b[i][x - 1]
ret += max(v1, v2)
for i in range(n):
ret += b[x - 1][i]
return ret
for i in range(1 << x):
ans = max(ans, solve(i))
print(ans)
``` | instruction | 0 | 15,390 | 7 | 30,780 |
No | output | 1 | 15,390 | 7 | 30,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,205 | 7 | 34,410 |
Tags: brute force
Correct Solution:
```
#In the name of Allah
from sys import stdin, stdout
input = stdin.readline
n, m, k = map(int, input().split())
mat = [[False] * (m + 2) for _ in range(n + 2)]
for ans in range(1, k + 1):
i, j = map(int, input().split())
if mat[i - 1][j] and mat[i][j - 1]:
if mat[i - 1][j - 1]:
stdout.write(str(ans))
exit(0)
if mat[i - 1][j] and mat[i][j + 1]:
if mat[i - 1][j + 1]:
stdout.write(str(ans))
exit(0)
if mat[i + 1][j] and mat[i][j - 1]:
if mat[i + 1][j - 1]:
stdout.write(str(ans))
exit(0)
if mat[i + 1][j] and mat[i][j + 1]:
if mat[i + 1][j + 1]:
stdout.write(str(ans))
exit(0)
mat[i][j] = True
stdout.write("0")
``` | output | 1 | 17,205 | 7 | 34,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,206 | 7 | 34,412 |
Tags: brute force
Correct Solution:
```
n,m,k = [int(x) for x in input().split()]
l = [[int(x) for x in input().split()] for i in range(k)]
if n<2 or m<2:
print(0)
else:
a = [[0 for i in range(m+2)] for j in range(n+2)]
f = 1
for i in range(k):
a[l[i][0]][l[i][1]] = 1
b = a[l[i][0]][l[i][1]]+a[l[i][0]+1][l[i][1]]+a[l[i][0]][l[i][1]+1]+a[l[i][0]+1][l[i][1]+1]
c = a[l[i][0]][l[i][1]]+a[l[i][0]-1][l[i][1]]+a[l[i][0]][l[i][1]-1]+a[l[i][0]-1][l[i][1]-1]
d = a[l[i][0]][l[i][1]]+a[l[i][0]+1][l[i][1]]+a[l[i][0]][l[i][1]-1]+a[l[i][0]+1][l[i][1]-1]
e = a[l[i][0]][l[i][1]]+a[l[i][0]-1][l[i][1]]+a[l[i][0]][l[i][1]+1]+a[l[i][0]-1][l[i][1]+1]
if b == 4 or c == 4 or d == 4 or e == 4:
print(i+1)
f = 0
break
if f == 1:
print(0)
``` | output | 1 | 17,206 | 7 | 34,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,207 | 7 | 34,414 |
Tags: brute force
Correct Solution:
```
n, m, k = map(int, input().split())
mx = [(m+2)*[0] for i in range(n+2)]
# if square 2*2 formed from black cells appears, and cell (i, j) will upper-left, upper right, bottom-left or bottom-right of this square.
def square_check(i, j):
if mx[i][j+1] and mx[i+1][j] and mx[i+1][j+1]:
return True
if mx[i][j-1] and mx[i-1][j] and mx[i-1][j-1]:
return True
if mx[i][j-1] and mx[i+1][j] and mx[i+1][j-1]:
return True
if mx[i][j+1] and mx[i-1][j] and mx[i-1][j+1]:
return True
return False
for i in range(k):
x, y = map(int, input().split()); mx[x][y] = 1
if square_check(x, y):
print(i+1)
break
else:
print(0)
``` | output | 1 | 17,207 | 7 | 34,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,208 | 7 | 34,416 |
Tags: brute force
Correct Solution:
```
(n,m,k)=[int(x) for x in input().split()]
l=[[0 for x in range(m+2)] for x in range(n+2)]
h=0
for i in range(k):
(a,b)=[int(x) for x in input().split()]
l[a][b]=1
if l[a-1][b-1]+l[a-1][b]+l[a][b-1]+l[a][b]==4 or l[a+1][b+1]+l[a+1][b]+l[a][b+1]+l[a][b]==4 or l[a-1][b+1]+l[a-1][b]+l[a][b+1]+l[a][b]==4 or l[a+1][b-1]+l[a+1][b]+l[a][b-1]+l[a][b]==4:
print(i+1)
h=1
break
if h==0:
print(0)
``` | output | 1 | 17,208 | 7 | 34,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,209 | 7 | 34,418 |
Tags: brute force
Correct Solution:
```
n,m,k=input().split(" ")
n=int(n)
m=int(m)
k=int(k)
l=[[0 for x in range(m+2)] for x in range(n+2)]
flag=0
for i in range(k):
a,b=input().split(" ")
a=int(a)
b=int(b)
l[a][b]=1;
if l[a][b+1]==1 and l[a-1][b]==1 and l[a-1][b+1]==1: #up right
if flag==0:
flag=i+1
elif l[a-1][b]==1 and l[a-1][b-1]==1 and l[a][b-1]:#up left
if flag==0:
flag=i+1
elif l[a][b-1]==1 and l[a+1][b-1]==1 and l[a+1][b]:#down left
if flag==0:
flag=i+1
elif l[a][b+1]==1 and l[a+1][b] and l[a+1][b+1]:#down right
if flag==0:
flag=i+1
print(flag)
``` | output | 1 | 17,209 | 7 | 34,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,210 | 7 | 34,420 |
Tags: brute force
Correct Solution:
```
def formed(w,e):
if w+1 < n and mat[w+1][e] == 'B':
if e+1 < m and mat[w+1][e+1] == 'B' and mat[w][e+1] == 'B' or e-1 >= 0 and mat[w+1][e-1] == 'B' and mat[w][e-1] == 'B':
return True
elif w-1 >= 0 and mat[w-1][e] == 'B':
if e+1 < m and mat[w-1][e+1] == 'B' and mat[w][e+1] == 'B' or e-1 >= 0 and mat[w-1][e-1] == 'B'and mat[w][e-1] == 'B':
return True
return False
n, m, k = [int(x) for x in input().split()]
mat = [[] for l in range(n)]
outcome = 0
for p in range(n):
for t in range(m):
mat[p].append('W')
for g in range(k):
i, j = [int(x)-1 for x in input().split()]
mat[i][j] = 'B'
if formed(i,j):
outcome = g + 1
break
print(outcome)
``` | output | 1 | 17,210 | 7 | 34,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,211 | 7 | 34,422 |
Tags: brute force
Correct Solution:
```
n, m, k = map(int, input().split())
field = [[0] * 1024 for _ in range(1024)]
for i in range(1, k + 1):
r, c = map(int, input().split())
field[r][c] = 1
for y, x in ((r - 1, c - 1), (r - 1, c), (r, c - 1), (r, c)):
if all(field[y + dy][x + dx] for dy in (0, 1) for dx in (0, 1)):
print(i)
exit()
print(0)
``` | output | 1 | 17,211 | 7 | 34,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0 | instruction | 0 | 17,212 | 7 | 34,424 |
Tags: brute force
Correct Solution:
```
n, m, k = map(int, input().split())
arr = [[0 for _ in range(m)] for _ in range(n)]
for i in range(1,k+1):
a, b = map(int, input().split())
a = a - 1
b = b - 1
if arr[a][b] == 0:
arr[a][b] = i
ans = 100000000000
for i in range(n-1):
for j in range(m-1):
if arr[i][j] > 0 and arr[i+1][j] > 0 and arr[i][j+1] > 0 and arr[i+1][j+1] > 0:
maxval = max(arr[i][j], max(arr[i][j+1], max(arr[i+1][j], arr[i+1][j+1])))
ans = min(ans, maxval)
print(ans if ans != 100000000000 else 0)
``` | output | 1 | 17,212 | 7 | 34,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0
Submitted Solution:
```
firstLine = [int(n) for n in input().split()];
matrix = [];
for i in range(0, firstLine[0]):
matrix.append([]);
for j in range(0, firstLine[1]):
matrix[i].append(0);
for i in range(0, firstLine[2]):
temp = [int(n) for n in input().split()];
y = temp[0]-1;
x = temp[1]-1;
matrix[y][x]=1;
out = True;
if( (y) - 1 >= 0):
if( (x) - 1 >= 0):
if(matrix[y-1][x-1] + matrix[y][x-1] + matrix[y-1][x] + matrix[y][x] == 4 and out == True):
print(i+1);
out = False;
break;
if( (x) + 1 < len(matrix[0])):
if(matrix[y-1][x+1] + matrix[y][x+1] + matrix[y-1][x] + matrix[y][x] == 4 and out == True):
print(i+1);
out = False;
break;
if( (y) + 1 < len(matrix)):
if( (x) - 1 >= 0):
if(matrix[y+1][x-1] + matrix[y][x-1] + matrix[y+1][x] + matrix[y][x] == 4 and out == True):
print(i+1);
out = False;
break;
if( (x) + 1 < len(matrix[0])):
if(matrix[y+1][x+1] + matrix[y][x+1] + matrix[y+1][x] + matrix[y][x] == 4 and out == True):
print(i+1);
out = False;
break;
if(out==True):
print(0);
``` | instruction | 0 | 17,213 | 7 | 34,426 |
Yes | output | 1 | 17,213 | 7 | 34,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
Output
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
Examples
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0
Submitted Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/508/A
n, m, k = map(int, input().split())
d_x = [0, 0, -1, -1]
d_y = [0, -1, 0, -1]
a_p = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(k):
y_o, x_o= map(int, input().split())
a_p[y_o][x_o] = 1
for j in range(4):
y = y_o + d_y[j]
x = x_o + d_x[j]
if (x > 0 and y > 0) and (y + 1 <= n and x + 1 <= m) and a_p[y][x] + a_p[y][x + 1] + a_p[y + 1][x] + a_p[y + 1][x + 1] == 4:
print(i + 1)
quit()
print(0)
``` | instruction | 0 | 17,214 | 7 | 34,428 |
Yes | output | 1 | 17,214 | 7 | 34,429 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.