message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,300 | 14 | 48,600 |
Tags: greedy, sortings
Correct Solution:
```
n=int(input())
x=[int(z) for z in input().split()]
x.sort()
y=[]
cur=x[0]
curs=1
i=1
y=[]
while i<n:
r=x[i]
if r==cur:
curs+=1
else:
d=[cur]*curs
y+=[d]
curs=1
cur=r
i+=1
y+=[[cur]*curs]
res=0
while len(y)>1:
u=[]
for h in y:
h.pop()
if h!=[]:
u+=[h]
res+=len(y)-1
y=u[:]
print(res)
``` | output | 1 | 24,300 | 14 | 48,601 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,301 | 14 | 48,602 |
Tags: greedy, sortings
Correct Solution:
```
from collections import Counter
def paintings(n, A):
F = Counter(A).most_common()
p = 0
k = 0
while F:
k += (len(F) - 1) * (F[-1][1] - p)
p = F[-1][1]
while F and F[-1][1] == p:
F.pop()
return k
def main():
n = readint()
A = readinti()
print(paintings(n, A))
##########
import sys
def readint():
return int(input())
def readinti():
return map(int, input().split())
def readintl():
return list(readinti())
def readintll(k):
return [readintl() for _ in range(k)]
def log(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
if __name__ == '__main__':
main()
``` | output | 1 | 24,301 | 14 | 48,603 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,302 | 14 | 48,604 |
Tags: greedy, sortings
Correct Solution:
```
import sys
n = int(input())
l = list(map(int, sys.stdin.readline().split()))
s = set(l)
ans = 0
while len(s) >= 2:
ans += len(s)-1
for i in s:
l.remove(i)
s = set(l)
print(ans)
``` | output | 1 | 24,302 | 14 | 48,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,303 | 14 | 48,606 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
last = A[0]
c = 0
aux = 0
for i in range(n):
a = A[i]
if a == last:
aux += 1
else:
aux = 1
last = A[i]
c = max(c, aux)
print(n - c)
``` | output | 1 | 24,303 | 14 | 48,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,304 | 14 | 48,608 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
seq = input().split()
dic = {}
vec = {}
res = 0
for i in seq:
i = int(i)
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for key in dic:
for i in range(dic[key]):
if i < len(vec):
vec[i] += 1
else:
vec[i] = 1
for key in vec:
if vec[key] > 0:
res += vec[key] - 1
print(res)
``` | output | 1 | 24,304 | 14 | 48,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,305 | 14 | 48,610 |
Tags: greedy, sortings
Correct Solution:
```
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
a = dict(Counter(sorted(input().split())))
ans = 0
f = 0
for val in a:
ans += min(f, a[val])
f += max(a[val] - f, 0)
print(ans)
``` | output | 1 | 24,305 | 14 | 48,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
uni = [arr[0]]
unil = 0
count = [0]
for i in arr:
if(i == uni[unil]):
count[unil]+=1
else:
uni.append(i)
count.append(1)
unil+=1
#print(count)
#print(uni)
unil+=1
zero = 0
ans = 0
while(unil>1):
p = min(count)
i = 0
while(i<unil):
if(i!=unil-1): ans+=p
count[i]-=p
if(count[i]==0):
count.pop(i)
unil-=1
else: i+=1
print (ans)
``` | instruction | 0 | 24,306 | 14 | 48,612 |
Yes | output | 1 | 24,306 | 14 | 48,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
l = [0 for i in range(1001)]
for i in input().split():
l[int(i)] += 1
print(n-max(l))
``` | instruction | 0 | 24,307 | 14 | 48,614 |
Yes | output | 1 | 24,307 | 14 | 48,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
import sys
n = sys.stdin.readline()
nums = sys.stdin.readline().rstrip('\n').split()
ans = 0
while len(nums) > 0:
uniq = set(nums)
ans = ans+ len(uniq) -1
new_nums = []
for i in range(len(nums)):
if nums[i] in uniq:
uniq.remove(nums[i])
else:
new_nums.append(nums[i])
nums = new_nums
sys.stdout.write(str(ans)+'\n')
``` | instruction | 0 | 24,308 | 14 | 48,616 |
Yes | output | 1 | 24,308 | 14 | 48,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in l:
temp = l.count(i)
ans = max(temp,ans)
print(n-ans)
``` | instruction | 0 | 24,309 | 14 | 48,618 |
Yes | output | 1 | 24,309 | 14 | 48,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
y = 0
z = 0
for i in range(1):
y = 0
x = ([int(x) for x in input().split()])
a = sorted(x)
for i in range (0, n-1):
if a[i] == a[i+1]:
y = y + 1
if a[0] == a[n-1]:
z = 1
result = n - max(y, 1) - z
print (result)
``` | instruction | 0 | 24,310 | 14 | 48,620 |
No | output | 1 | 24,310 | 14 | 48,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
pics = sorted(list(map(lambda x: int(x), input().split())))
last = pics[0]
joy = 0
while len(pics)!=0:
a = pics.pop(0)
#print(a, end=" ")
if last<a:
joy+=1
else:
eq = True
for i in range(0, len(pics)):
if pics[i]!=a:
eq=False
last=pics.pop(i)
joy+=1
break
#if eq:
# pics=[]
#print(b)
print(joy)
if joy==930:
print(pics)
``` | instruction | 0 | 24,311 | 14 | 48,622 |
No | output | 1 | 24,311 | 14 | 48,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
count=0
for i in range(n):
if a[i]>a[i-1]:
count+=1
print(count)
``` | instruction | 0 | 24,312 | 14 | 48,624 |
No | output | 1 | 24,312 | 14 | 48,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
Submitted Solution:
```
n = int(input())
A = list(map(int, input().split()))
A.sort()
D = [0 for i in range(n + 1)]
D[1] = 1
for i in range(2, n + 1):
d = -100
for j in range(1, i + 1):
if D[j] >= d and A[i - 1] > A[j - 1]:
d = D[j] + 1
elif D[j] > d:
d = D[j]
D[i] = d
print(D[n])
``` | instruction | 0 | 24,313 | 14 | 48,626 |
No | output | 1 | 24,313 | 14 | 48,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Note that girls in Arpaβs land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.
<image>
There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:
* Each person had exactly one type of food,
* No boy had the same type of food as his girlfriend,
* Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive.
Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.
Input
The first line contains an integer n (1 β€ n β€ 105) β the number of pairs of guests.
The i-th of the next n lines contains a pair of integers ai and bi (1 β€ ai, bi β€ 2n) β the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair.
Output
If there is no solution, print -1.
Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.
If there are multiple solutions, print any of them.
Example
Input
3
1 4
2 5
3 6
Output
1 2
2 1
1 2 | instruction | 0 | 24,358 | 14 | 48,716 |
Tags: constructive algorithms, dfs and similar, graphs
Correct Solution:
```
import sys
n = int(input())
A = [0]*(2*n)
B = []
for line in sys.stdin:
x, y = [int(x)-1 for x in line.split()]
A[x] = y
A[y] = x
B.append(x)
C = [0]*(2*n)
for i in range(2*n):
while not C[i]:
C[i] = 1
C[i^1] = 2
i = A[i^1]
for x in B:
print(C[x], C[A[x]])
``` | output | 1 | 24,358 | 14 | 48,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Note that girls in Arpaβs land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.
<image>
There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:
* Each person had exactly one type of food,
* No boy had the same type of food as his girlfriend,
* Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive.
Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.
Input
The first line contains an integer n (1 β€ n β€ 105) β the number of pairs of guests.
The i-th of the next n lines contains a pair of integers ai and bi (1 β€ ai, bi β€ 2n) β the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair.
Output
If there is no solution, print -1.
Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.
If there are multiple solutions, print any of them.
Example
Input
3
1 4
2 5
3 6
Output
1 2
2 1
1 2 | instruction | 0 | 24,359 | 14 | 48,718 |
Tags: constructive algorithms, dfs and similar, graphs
Correct Solution:
```
import sys
def solve():
n = int(input())
partner = [0]*(2*n)
pacani = []
for line in sys.stdin:
pacan, telka = [int(x) - 1 for x in line.split()]
partner[pacan] = telka
partner[telka] = pacan
pacani.append(pacan)
khavka = [None]*(2*n)
for i in range(2*n):
while khavka[i] is None:
khavka[i] = 1
khavka[i^1] = 2
i = partner[i^1]
for pacan in pacani:
print(khavka[pacan], khavka[partner[pacan]])
solve()
``` | output | 1 | 24,359 | 14 | 48,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,415 | 14 | 48,830 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
def get_answer(m, n):
if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]:
return ("NO", [])
elif (m == 1):
mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]]
return ("YES", mat)
elif (n == 1):
mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)]
return ("YES", mat)
elif n == 2:
bs = [[2, 3], [7, 6], [4, 1], [8, 5]]
mat = []
for i in range(m//4):
for u in bs:
if i % 2 == 0:
mat.append([x + 8*i for x in u])
else:
mat.append([x + 8*i for x in reversed(u)])
if m % 4 == 1:
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n
mat[4][1] = m*n-1
elif m % 4 == 2:
if (m//4) % 2 == 1:
mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]]
else:
mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]]
elif m % 4 == 3:
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n-4
mat[4][1] = m*n-5
mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]]
return ("YES", mat)
elif n == 3:
bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]]
mat = []
for i in range(m//3):
for u in bs:
mat.append([x + 9*i for x in u])
if m % 3 == 1:
mat = [[m*n-1, m*n-2, m*n]] + mat
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
elif m % 3 == 2:
mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]]
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1]
return ("YES", mat)
mat = []
for i in range(m):
if i % 2 == 0:
mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)])
else:
if n != 4:
mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)])
else:
mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)])
return ("YES", mat)
m, n = input().split()
m = int(m)
n = int(n)
res = get_answer(m, n)
print(res[0])
# print(m, n)
if res[0] == "YES":
for i in range(m):
for j in range(n):
print(res[1][i][j], end=' ')
print()
``` | output | 1 | 24,415 | 14 | 48,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,416 | 14 | 48,832 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
import bisect
def list_output(s):
print(' '.join(map(str, s)))
def list_input(s='int'):
if s == 'int':
return list(map(int, input().split()))
elif s == 'float':
return list(map(float, input().split()))
return list(map(str, input().split()))
n, m = map(int, input().split())
swapped = False
if n > m:
n, m = m, n
swapped = True
def check(M):
for i in range(n):
for j in range(m):
if i-1 >= 0 and M[i-1][j] + m == M[i][j]:
return False
if i+1 < n and M[i+1][j] == M[i][j] + m:
return False
if j-1 >= 0 and M[i][j-1] + 1 == M[i][j]:
return False
if j+1 < m and M[i][j+1] == M[i][j] + 1:
return False
return True
def transpose(M):
n = len(M)
m = len(M[0])
R = [[0 for i in range(n)] for j in range(m)]
for i in range(n):
for j in range(m):
R[j][i] = M[i][j]
return R
if n == 1 and m == 1:
print('YES')
print('1')
exit(0)
if n <= 2 and m <= 3:
print('NO')
exit(0)
R = list()
if n == 3 and m == 3:
R.append([4, 3, 8])
R.append([9, 1, 6])
R.append([5, 7, 2])
elif m == 4:
if n == 1:
R.append([3, 1, 4, 2])
elif n == 2:
R.append([5, 4, 7, 2])
R.append([3, 6, 1, 8])
elif n == 3:
R.append([5, 4, 7, 2])
R.append([3, 6, 1, 8])
R.append([11, 9, 12, 10])
elif n == 4:
R.append([5, 4, 7, 2])
R.append([3, 6, 1, 8])
R.append([11, 9, 12, 10])
R.append([14, 16, 15, 13])
else:
M = [[(i-1) * m + j for j in range(1, m+1)] for i in range(1, n+1)]
for i in range(n):
row = list()
if i%2 == 0:
for j in range(0, m, 2):
row.append(M[i][j])
for j in range(1, m, 2):
row.append(M[i][j])
else:
for j in range(1, m, 2):
row.append(M[i][j])
for j in range(0, m, 2):
row.append(M[i][j])
R.append(row)
if swapped:
M = [[(i-1) * n + j for j in range(1, n+1)] for i in range(1, m+1)]
M = transpose(M)
S = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
r = (R[i][j]-1) // m
c = (R[i][j]-1) % m
S[i][j] = M[r][c]
R = transpose(S)
n, m = m, n
#print(check(R))
print('YES')
for i in range(n):
print(' '.join(map(str, R[i])))
``` | output | 1 | 24,416 | 14 | 48,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,417 | 14 | 48,834 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
n,m=map(int,input().split())
if n==1and m==1:print('YES\n1')
elif n==3and m==3:
print('YES')
print(6, 1, 8)
print(7,5,3)
print(2,9,4)
elif n<4and m<4:print('NO')
elif n==1 or m==1:
t=max(n,m)
a=[i for i in range(2,t+1,2)]
a+=[i for i in range(1,t+1,2)]
print('YES')
for i in a:print(i,end="");print([' ','\n'][m==1],end='')
else:
a=[]
for j in range(n):
a.append([int(i)+int(m*j) for i in range(1,m+1)])
if n<=m:
for j in range(1,m,2):
t=a[0][j]
for i in range(1,n):
a[i-1][j]=a[i][j]
a[n-1][j]=t
for i in range(1,n,2):
r,s=a[i][0],a[i][1]
for j in range(2,m):
a[i][j-2]=a[i][j]
a[i][m-2],a[i][m-1]=r,s
else:
for j in range(1,m,2):
r,s=a[0][j],a[1][j]
for i in range(2,n):
a[i-2][j]=a[i][j]
a[n-2][j], a[n-1][j] = r, s
for i in range(1,n,2):
t=a[i][0]
for j in range(1,m):
a[i][j-1]=a[i][j]
a[i][m-1]=t
print('YES')
for i in range(n):
print(*a[i])
``` | output | 1 | 24,417 | 14 | 48,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,418 | 14 | 48,836 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
import sys, itertools
#f = open('input', 'r')
f = sys.stdin
def near(i,n,m):
x = i//m
y = i%m
d = [[0, -1], [0, 1], [-1, 0], [1, 0]]
ns = []
for dx, dy in d:
nx=x+dx
ny=y+dy
if nx>=0 and nx<n and ny>=0 and ny<m:
ns.append(nx*m+ny)
return ns
def check(p, n, m):
d = [[0, -1], [0, 1], [-1, 0], [1, 0]]
for x in range(n):
for y in range(m):
ns = near(p[x*m+y],n,m)
for dx, dy in d:
nx=x+dx
ny=y+dy
if nx>=0 and nx<n and ny>=0 and ny<m and p[nx*m+ny] in ns:
return True
return False
n, m = map(int, f.readline().split())
reverse=False
if n>m:
t1 = list(range(n*m))
t2 = []
for i in range(m):
for j in range(n):
t2.append(t1[j*m+i])
t=n;n=m;m=t
reverse=True
def ans(n,m):
if m>=5:
p = []
for i in range(n):
t3 = []
for j in range(m):
if j*2+i%2 >= m:
break
t3.append(j*2+i%2)
for j in range(m-len(t3)):
if j*2+1-i%2 >= m:
break
t3.append(j*2+1-i%2)
p += [x+i*m for x in t3]
return p
if n==1 and m==1:
return [0]
if n==1 and m<=3:
return False
if n==2 and m<=3:
return False
if n==3 and m==4:
return [4,3,6,1,2,5,0,7,9,11,8,10]
if n==4:
return [4, 3, 6, 1, 2, 5, 0, 7, 12, 11, 14, 9, 15, 13, 11, 14]
for p in list(itertools.permutations(list(range(n*m)), n*m)):
failed = check(p,n,m)
if not failed:
return p
return True
p = ans(n,m)
if p:
print('YES')
if reverse:
for j in range(m):
print(' '.join(str(t2[p[i*m+j]]+1) for i in range(n)))
else:
for i in range(n):
print(' '.join(str(p[i*m+j]+1) for j in range(m)))
else:
print('NO')
``` | output | 1 | 24,418 | 14 | 48,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,419 | 14 | 48,838 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
def get_answer(m, n):
if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]:
return ("NO", [])
elif (n == 1):
mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)]
return ("YES", mat)
elif n == 2:
bs = [[2, 3], [7, 6], [4, 1], [8, 5]]
mat = []
for i in range(m//4):
for u in bs:
if i % 2 == 0: # like bs
mat.append([x + 8*i for x in u])
else:
'''
2 3
7 6
4 1
8 5
11 10 (10 11 is invalid -> flip figure)
14 15
9 12
13 16
'''
mat.append([x + 8*i for x in reversed(u)])
if m % 4 == 1:
'''
2 3 m*n 3
7 6 2 6
4 1 -> 7 1
8 5 4 5
(11 10) 8 m*n-1
(...) (11 10)
(...)
'''
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n
mat[4][1] = m*n-1
elif m % 4 == 2:
if (m//4) % 2 == 1:
'''
9 12
2 3 2 3
... -> ...
8 5 8 5
11 10
'''
mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]]
else:
'''
17 20
2 3 2 3
... -> ...
13 16 13 16
18 19
'''
mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]]
elif m % 4 == 3:
'''
13 12
2 3 10 3
7 6 2 6
4 1 7 1
8 5 -> 4 5
8 9
11 14
'''
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n-4
mat[4][1] = m*n-5
mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]]
return ("YES", mat)
elif n == 3:
bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]]
mat = []
for i in range(m//3):
for u in bs:
mat.append([x + 9*i for x in u])
if m % 3 == 1:
'''
11 1 12
6 1 8 6 10 8
7 5 3 -> 7 5 3
2 9 4 2 9 4
'''
mat = [[m*n-1, m*n-2, m*n]] + mat
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
elif m % 3 == 2:
'''
11 1 12
6 1 8 6 10 8
7 5 3 -> 7 5 3
2 9 4 2 13 4
14 9 15
'''
mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]]
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1]
return ("YES", mat)
mat = []
for i in range(m):
if i % 2 == 0:
mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)])
else:
if n != 4:
mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)])
else:
mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)])
return ("YES", mat)
m, n = input().split()
m = int(m)
n = int(n)
res = get_answer(m, n)
print(res[0])
# print(m, n)
if res[0] == "YES":
for i in range(m):
for j in range(n):
print(res[1][i][j], end=' ')
print()
``` | output | 1 | 24,419 | 14 | 48,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,420 | 14 | 48,840 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
def getNumber(x,y):
x %= xsize
y %= ysize
return x+1+y*xsize
ysize,xsize = (int(e) for e in input().split(' '))
if(xsize>3 and ysize>1):
print('YES')
res = ""
for y in range(ysize):
for x in range(xsize):
tx,ty = x,y
ty += x%2
tx += 2*((ty%ysize)%2)
res += str(getNumber(tx,ty))
res += ' '
res += '\n'
print(res)
elif(xsize>1 and ysize>3):
print('YES')
res = ""
for y in range(ysize):
for x in range(xsize):
tx,ty = x,y
tx += y%2
ty += 2*((tx%xsize)%2)
res += str(getNumber(tx,ty))
res += ' '
res += '\n'
print(res)
elif(xsize==1 and ysize==4):
print('YES')
print('3\n1\n4\n2')
elif(xsize==4 and ysize==1):
print('YES')
print('3 1 4 2')
elif(xsize==1 and ysize>4):
print('YES')
res = ""
tsize = ysize-(not ysize%2)
for y in range(tsize):
res += str((y*2)%tsize+1)
res += '\n'
if(not ysize%2):
res += str(ysize)
print(res)
elif(xsize>4 and ysize==1):
print('YES')
res = ""
tsize = xsize-(not xsize%2)
for x in range(tsize):
res += str((x*2)%tsize+1)
res += ' '
if(not xsize%2):
res += str(xsize)
print(res)
elif(xsize==3 and ysize==3):
print('YES')
print('7 2 6\n3 4 8\n5 9 1')
elif(xsize==1 and ysize==1):
print('YES')
print('1')
else:
print('NO')
"""
2 4
YES
5 4 7 2
3 6 1 8
1 2 3
4 5 6
"""
``` | output | 1 | 24,420 | 14 | 48,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,421 | 14 | 48,842 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
import random
n, m = map(int, input().split())
if n < 4 and m < 4 and not((n == 1 and m == 1) or (m == 3 and n == 3)): print("NO"); quit()
pedy = [list() for i in range(n * m + 1)]
for i in range(n * m):
if i % m != 0: pedy[i+1].append(i)
if i % m != m - 1: pedy[i + 1].append(i + 2)
if i >= m: pedy[i + 1].append(i - m + 1)
if i < (n - 1) * m: pedy[i + 1].append(i + m + 1)
Arr = [x for x in range(1, n*m + 1)]; Arr = Arr[::2] + Arr[1::2]; pp = 0; s = ""
while (not pp):
pp = 1;
for i in range(n):
for j in range(m):
if (i + 1 != n and Arr[i * m + m + j] in pedy[Arr[i * m + j]]) or (j + 1 != m and Arr[i * m + 1 + j] in pedy[Arr[i * m + j]]):
pp = 0; break
if not pp: break
if not pp: random.shuffle(Arr)
print("YES")
for i in range(n):
for j in range(m):
s += str(Arr[i * m + j]) + " "
print(s); s = ""
``` | output | 1 | 24,421 | 14 | 48,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | instruction | 0 | 24,422 | 14 | 48,844 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
import random
n, m = map(int, input().split())
if n < 4 and m < 4 and not((n == 1 and m == 1) or (m == 3 and n == 3)): print("NO"); quit()
pedy = [list() for i in range(n * m + 1)]
for i in range(n * m):
if i % m != 0: pedy[i+1].append(i)
if i % m != m - 1: pedy[i + 1].append(i + 2)
if i >= m: pedy[i + 1].append(i - m + 1)
if i < (n - 1) * m: pedy[i + 1].append(i + m + 1)
Arr = [x for x in range(1, n*m + 1)]; Arr = Arr[::2] + Arr[1::2]; pp = 0; s = ""
while (not pp):
pp = 1;
for i in range(n):
for j in range(m):
if (i + 1 != n and Arr[i * m + m + j] in pedy[Arr[i * m + j]]) or (j + 1 != m and Arr[i * m + 1 + j] in pedy[Arr[i * m + j]]):
pp = 0; break
if not pp: break
if not pp: random.shuffle(Arr)
print("YES")
for i in range(n):
for j in range(m):
s += str(Arr[i * m + j]) + " "
print(s); s = ""
# Made By Mostafa_Khaled
``` | output | 1 | 24,422 | 14 | 48,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
def get_answer(m, n):
if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]:
return ("NO", [])
elif (m == 1):
mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]]
return ("YES", mat)
elif (n == 1):
mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)]
return ("YES", mat)
elif n == 2:
bs = [[2, 3], [7, 6], [4, 1], [8, 5]]
mat = []
for i in range(m//4):
for u in bs:
if i % 2 == 0: # like bs
mat.append([x + 8*i for x in u])
else:
'''
2 3
7 6
4 1
8 5
11 10 (10 11 is invalid -> flip figure)
14 15
9 12
13 16
'''
mat.append([x + 8*i for x in reversed(u)])
if m % 4 == 1:
'''
2 3 m*n 3
7 6 2 6
4 1 -> 7 1
8 5 4 5
(11 10) 8 m*n-1
(...) (11 10)
(...)
'''
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n
mat[4][1] = m*n-1
elif m % 4 == 2:
if (m//4) % 2 == 1:
'''
9 12
2 3 2 3
... -> ...
8 5 8 5
11 10
'''
mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]]
else:
'''
17 20
2 3 2 3
... -> ...
13 16 13 16
18 19
'''
mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]]
elif m % 4 == 3:
'''
13 12
2 3 10 3
7 6 2 6
4 1 7 1
8 5 -> 4 5
8 9
11 14
'''
mat.insert(4, [0, 0])
for i in range(4, 0, -1):
mat[i][0] = mat[i-1][0]
mat[0][0] = m*n-4
mat[4][1] = m*n-5
mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]]
return ("YES", mat)
elif n == 3:
bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]]
mat = []
for i in range(m//3):
for u in bs:
mat.append([x + 9*i for x in u])
if m % 3 == 1:
'''
11 1 12
6 1 8 6 10 8
7 5 3 -> 7 5 3
2 9 4 2 9 4
'''
mat = [[m*n-1, m*n-2, m*n]] + mat
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
elif m % 3 == 2:
'''
11 1 12
6 1 8 6 10 8
7 5 3 -> 7 5 3
2 9 4 2 13 4
14 9 15
'''
mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]]
mat[0][1], mat[1][1] = mat[1][1], mat[0][1]
mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1]
return ("YES", mat)
mat = []
for i in range(m):
if i % 2 == 0:
mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)])
else:
if n != 4:
mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)])
else:
mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)])
return ("YES", mat)
m, n = input().split()
m = int(m)
n = int(n)
res = get_answer(m, n)
print(res[0])
# print(m, n)
if res[0] == "YES":
for i in range(m):
for j in range(n):
print(res[1][i][j], end=' ')
print()
``` | instruction | 0 | 24,423 | 14 | 48,846 |
Yes | output | 1 | 24,423 | 14 | 48,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
n,m=map(int,input().strip().split(' '))
arr=[]
cnt=1
if(n*m==1):
print("YES")
print(1)
elif((n==1 and(m==2 or m==3)) or ((n==2) and (m==1 or m==2 or m==3)) or ((n==3) and (m==1 or m==2 )) ):
print("NO")
elif(n==3 and m==3):
print("YES")
print(6,1,8)
print(7,5,3)
print(2,9,4)
else:
print("YES")
if(m>=n):
for i in range(n):
l=[]
for j in range(m):
l.append(cnt)
cnt+=1
arr.append(l)
ans=[]
for i in range(n):
l=arr[i]
odd=[]
even=[]
for j in range(m):
if((j+1)%2==0):
even.append(l[j])
else:
odd.append(l[j])
if(((i+1)%2)==1):
if(n%2==1 and m%2==1):
odd.extend(even)
ans.append(odd)
elif(m%2==1 and n%2==0):
odd.extend(even)
ans.append(odd)
else:
even.extend(odd)
ans.append(even)
else:
if(n%2==1 and m%2==1):
even.extend(odd)
ans.append(even)
elif(m%2==1 and n%2==0):
even.extend(odd)
ans.append(even)
else:
even.reverse()
odd.reverse()
odd.extend(even)
ans.append(odd)
for i in range(n):
for j in range(m):
print(ans[i][j],end=' ')
print()
else:
temp=n
n=m
m=temp
cnt=1
for i in range(n):
l=[]
p=cnt
for j in range(m):
l.append(p)
p+=n
cnt+=1
arr.append(l)
ans=[]
for i in range(n):
l=arr[i]
odd=[]
even=[]
for j in range(m):
if((j+1)%2==0):
even.append(l[j])
else:
odd.append(l[j])
if(((i+1)%2)==1):
if(n%2==1 and m%2==1):
odd.extend(even)
ans.append(odd)
elif(m%2==1 and n%2==0):
odd.extend(even)
ans.append(odd)
else:
even.extend(odd)
ans.append(even)
else:
if(n%2==1 and m%2==1):
even.extend(odd)
ans.append(even)
elif(m%2==1 and n%2==0):
even.extend(odd)
ans.append(even)
else:
even.reverse()
odd.reverse()
odd.extend(even)
ans.append(odd)
for i in range(m):
for j in range(n):
print(ans[j][i],end=' ')
print()
``` | instruction | 0 | 24,424 | 14 | 48,848 |
Yes | output | 1 | 24,424 | 14 | 48,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
arr = [[i*m+j for j in range(1,m+1)] for i in range(n)]
if m >= 4:
print('YES')
for i in range(n):
k,k1 = [],[]
for j in range(0,m,2):
k.append(arr[i][j])
for j in range(1,m,2):
k1.append(arr[i][j])
if not i&1:
if m == 4:
arr[i] = k[::-1]+k1[::-1]
else:
arr[i] = k+k1
else:
arr[i] = k1+k
for i in arr:
print(*i)
elif n >= 4:
print('YES')
for i in range(m):
k,k1 = [],[]
for j in range(0,n,2):
k.append(arr[j][i])
for j in range(1,n,2):
k1.append(arr[j][i])
if not i&1:
if n == 4:
for ind,x in enumerate(k[::-1]+k1[::-1]):
arr[ind][i] = x
else:
for ind,x in enumerate(k+k1):
arr[ind][i] = x
else:
for ind,x in enumerate(k1+k):
arr[ind][i] = x
for i in arr:
print(*i)
elif n == 1 and m == 1:
print('YES')
print(1)
elif n == 3 and m == 3:
print('YES')
print(9,3,5)
print(2,7,1)
print(4,6,8)
else:
print('NO')
#Fast IO Region
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")
if __name__ == '__main__':
main()
``` | instruction | 0 | 24,425 | 14 | 48,850 |
Yes | output | 1 | 24,425 | 14 | 48,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
def transpos(a,n,m):
b = []
for i in range(m):
b.append([a[j][i] for j in range(n)])
return(b)
def printarr(a):
for i in range(len(a)):
for j in range(len(a[i])):
print(a[i][j], end = ' ')
print("")
n,m = [int(i) for i in input().split()]
a = []
for i in range(n):
a.append([i*m + j for j in range(1,m+1)])
#printarr(transpos(a,n,m))
transp_flag = False
if n > m:
tmp = m
m = n
n = tmp
a = transpos(a,m,n)
transp_flag = True
# m >= n
if m < 3 and m != 1:
print("NO")
elif m == 1:
print("YES")
print(1)
else:
if m == 3:
if n < 3: print("NO")
else:
print("YES")
printarr([[5,9,3],[7,2,4],[1,6,8]])
elif m == 4:
for i in range(n):
tmp = a[i][:]
if i%2 == 0:
a[i] = [tmp[1],tmp[3],tmp[0],tmp[2]]
else:
a[i] = [tmp[2],tmp[0],tmp[3],tmp[1]]
else:
for i in range(n):
if i%2 == 0:
tmp1 = [a[i][j] for j in range(m) if j%2 == 0]
tmp2 = [a[i][j] for j in range(m) if j%2 == 1]
if i%2 == 1:
tmp1 = [a[i][j] for j in range(m) if j%2 == 1]
tmp2 = [a[i][j] for j in range(m) if j%2 == 0]
a[i] = tmp1 + tmp2
if m > 3:
if transp_flag: a = transpos(a,n,m)
print("YES")
printarr(a)
``` | instruction | 0 | 24,426 | 14 | 48,852 |
Yes | output | 1 | 24,426 | 14 | 48,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
n,m=map(int,input().split())
if n==1and m==1:print('YES\n1')
elif n==3and m==3:
print('YES')
print(6, 1, 8)
print(7,5,3)
print(2,9,4)
elif n<4and m<4:print('NO')
elif n==1 or m==1:
t=max(n,m)
a=[i for i in range(1,t+1,2)]
a+=[i for i in range(2,t+1,2)]
print('YES')
for i in a:print(i,end="");print([' ','\n'][m==1])
else:
a=[]
for j in range(n):
a.append([int(i)+int(m*j) for i in range(1,m+1)])
for j in range(1,m,2):
t=a[0][j]
for i in range(1,n):
a[i-1][j]=a[i][j]
a[n-1][j]=t
for i in range(1,n,2):
r,s=a[i][0],a[i][1]
for j in range(2,m):
a[i][j-2]=a[i][j]
a[i][m-2],a[i][m-1]=r,s
print('YES')
for i in range(n):
print(*a[i])
``` | instruction | 0 | 24,427 | 14 | 48,854 |
No | output | 1 | 24,427 | 14 | 48,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
x=input()
if x=="2 4":
print("YES")
print("5 4 7 2")
print("3 6 1 8")
elif x=="2 1":
print("NO")
``` | instruction | 0 | 24,428 | 14 | 48,856 |
No | output | 1 | 24,428 | 14 | 48,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
x=input()
if x=="2 4":
print("YES")
print("5 4 7 2")
print("3 6 1 8")
``` | instruction | 0 | 24,429 | 14 | 48,858 |
No | output | 1 | 24,429 | 14 | 48,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to nΒ·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)Β·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to nΒ·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
Input
The only line contains two integers n and m (1 β€ n, m β€ 105; nΒ·m β€ 105) β the number of rows and the number of columns in the required matrix.
Output
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
Examples
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
Note
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Submitted Solution:
```
q,w=map(int,input().split())
if (q==1)&(w==1):
print('YES')
print(1)
elif (q==2):
if w<=3:
print('NO')
elif w%2==1:
a=[i for i in range(1,w+1) if i%2==1]+[i for i in range(1,w+1) if i%2==0]
s=[i for i in range(1,w+1) if i%2==0]+[i for i in range(1,w+1) if i%2==1]
print('YES')
print(*a)
s=[i+w for i in s]
print(*s)
else:
s=[i for i in range(1,w+1) if i%2==0]+[i for i in range(1,w+1) if i%2==1]
print('YES')
print(*s)
s=[i+w for i in s]
print(*s[::-1])
elif w==2:
if q<=3:
print('NO')
elif q%2==1:
a=[i for i in range(1,q+1) if i%2==1]+[i for i in range(1,q+1) if i%2==0]
s=[i for i in range(1,q+1) if i%2==0]+[i for i in range(1,q+1) if i%2==1]
print('YES')
s=[i+q for i in s]
for i in range(0,q):
print(a[i],s[i])
else:
s=[i for i in range(1,q+1) if i%2==0]+[i for i in range(1,q+1) if i%2==1]
print('YES')
s=[i+q for i in s]
a=s[::-1]
for i in range(0,q):
print(a[i],s[i])
elif q==1:
if w<=2:
print('NO')
elif w%2==1:
a=[i for i in range(1,w+1) if i%2==1]+[i for i in range(1,w+1) if i%2==0]
print('YES')
print(*a)
else:
s=[i for i in range(1,w+1) if i%2==0]+[i for i in range(1,w+1) if i%2==1]
print('YES')
print(*s)
elif w==1:
if q<=2:
print('NO')
elif q%2==1:
a=[i for i in range(1,q+1) if i%2==1]+[i for i in range(1,q+1) if i%2==0]
print('YES')
for i in a:
print(i)
else:
s=[i for i in range(1,q+1) if i%2==0]+[i for i in range(1,q+1) if i%2==1]
print('YES')
for i in s:
print(i)
else:
a=[[0 for i in range(0,w)] for j in range(0,q)]
i=1
z,x=0,0
tt=0
if w%q==0:
tt=1
while i<q*w:
#print(a,z,x)
a[z][x]=i
x+=1
z+=1
if z==q:
z=0
x=max(0,x-q)
while a[z][x]!=0:
x+=1
if x>=w:
x=0
while a[z][x]!=0:
x+=1
i+=1
a[z][x]=i
print('YES')
for i in a:
for j in i:
print(j,end = ' ')
print()
``` | instruction | 0 | 24,430 | 14 | 48,860 |
No | output | 1 | 24,430 | 14 | 48,861 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,431 | 14 | 48,862 |
"Correct Solution:
```
n = 6
table = []
ans = []
for i in range(n):
s = input()
table.append(s)
ind = 0
if table[0][3] == '.':
ans.append(table[0][:3] + 'P' + table[0][4:])
ind = 1
elif table[0][4] == '.':
ans.append(table[0][:4] + 'P' + table[0][5:])
ind = 1
elif table[1][3] == '.':
ans.append(table[0])
ans.append(table[1][:3] + 'P' + table[1][4:])
ind = 2
elif table[1][4] == '.':
ans.append(table[0])
ans.append(table[1][:4] + 'P' + table[1][5:])
ind = 2
elif table[0][0] == '.':
ans.append('P' + table[0][1:])
ind = 1
elif table[0][1] == '.':
ans.append(table[0][:1] + 'P' + table[0][2:])
ind = 1
elif table[0][6] == '.':
ans.append(table[0][:6] +'P' + table[0][7:])
ind = 1
elif table[0][7] == '.':
ans.append(table[0][:7] +'P')
ind = 1
elif table[1][0] == '.':
ans.append(table[0])
ans.append('P' + table[1][1:])
ind = 2
elif table[1][1] == '.':
ans.append(table[0])
ans.append(table[1][:1] + 'P' + table[1][2:])
ind = 2
elif table[1][6] == '.':
ans.append(table[0])
ans.append(table[1][:6] +'P' + table[1][7:])
ind = 2
elif table[1][7] == '.':
ans.append(table[0])
ans.append(table[1][:7] +'P')
ind = 2
elif table[2][3] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2][:3] + 'P' + table[2][4:])
ind = 3
elif table[2][4] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2][:4] + 'P' + table[2][5:])
ind = 3
elif table[3][3] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2])
ans.append(table[3][:3] + 'P' + table[3][4:])
ind = 4
elif table[3][4] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2])
ans.append(table[3][:4] + 'P' + table[3][5:])
ind = 4
elif table[2][0] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append('P' + table[2][1:])
ind = 3
elif table[2][1] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2][:1] + 'P' + table[2][2:])
ind = 3
elif table[2][6] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2][:6] +'P' + table[2][7:])
ind = 3
elif table[2][7] == '.':
ans.append(table[0])
ans.append(table[1])
ans.append(table[2][:7] +'P')
ind = 3
elif table[3][0] == '.':
for i in range(0, 3):
ans.append(table[i])
ans.append('P' + table[3][1:])
ind = 4
elif table[3][1] == '.':
for i in range(0, 3):
ans.append(table[i])
ans.append(table[3][:1] + 'P' + table[3][2:])
ind = 4
elif table[3][6] == '.':
for i in range(0, 3):
ans.append(table[i])
ans.append(table[3][:6] +'P' + table[3][7:])
ind = 4
elif table[3][7] == '.':
for i in range(0, 3):
ans.append(table[i])
ans.append(table[3][:7] +'P')
ind = 4
elif table[4][3] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append(table[4][:3] + 'P' + table[4][4:])
ind = 5
elif table[4][4] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append(table[4][:4] + 'P' + table[4][5:])
ind = 5
elif table[5][3] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append(table[5][:3] + 'P' + table[5][4:])
ind = 6
elif table[5][4] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append(table[5][:4] + 'P' + table[5][5:])
ind = 6
elif table[4][0] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append('P' + table[4][1:])
ind = 5
elif table[4][1] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append(table[4][:1] + 'P' + table[4][2:])
ind = 5
elif table[4][6] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append(table[4][:6] +'P' + table[4][7:])
ind = 5
elif table[4][7] == '.':
for i in range(0, 4):
ans.append(table[i])
ans.append(table[4][:7] +'P')
ind = 5
elif table[5][0] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append('P' + table[5][1:])
ind = 6
elif table[5][1] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append(table[5][:1] + 'P' + table[5][2:])
ind = 6
elif table[5][6] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append(table[5][:6] +'P' + table[5][7:])
ind = 6
elif table[5][7] == '.':
for i in range(0, 5):
ans.append(table[i])
ans.append(table[5][:7] +'P')
ind = 6
for i in range(ind, n):
ans.append(table[i])
for i in ans:
print(i)
``` | output | 1 | 24,431 | 14 | 48,863 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,432 | 14 | 48,864 |
"Correct Solution:
```
def pr(u):
for i in range(6):
s = ''
for j in range(8):
s += u[i][j]
print(s)
p = []
for i in range(6):
s = input()
p.append(list(s))
priority = [[0,3],[0,4],[1,3],[1,4],[0,0],[0,1],[0,6],[0,7],[1,0],[1,1],[1,6],[1,7],[2,3],[2,4],[3,3],[3,4],[2,0],[2,1],[2,6],[2,7],[3,0],[3,1],[3,6],[3,7],[4,3],[4,4],[5,3],[5,4],[4,0],[4,1],[4,6],[4,7],[5,0],[5,1],[5,6],[5,7]]
for a in priority:
if p[a[0]][a[1]] == '.':
p[a[0]][a[1]] = 'P'
pr(p)
break
``` | output | 1 | 24,432 | 14 | 48,865 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,433 | 14 | 48,866 |
"Correct Solution:
```
a = [[3, 3, 4, 4, 3, 3], [3, 3, 4, 4, 3, 3], [2, 2, 3, 3, 2, 2], [2, 2, 3, 3, 2, 2], [1, 1, 2, 2, 1, 1], [1, 1, 2, 2, 1, 1]]
b = ["".join(input().split('-')) for i in range(6)]
ans = []
for i in range(6):
for j in range(6):
if b[i][j] == '.':
ans.append([a[i][j], i, j])
ans.sort(reverse=True)
for i in range(6):
for j in range(6):
if i == ans[0][1] and j == ans[0][2]:
print('P', end='')
else:
print(b[i][j], end='')
if j == 1 or j == 3:
print('-', end='')
print('')
``` | output | 1 | 24,433 | 14 | 48,867 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,434 | 14 | 48,868 |
"Correct Solution:
```
cost = [
[3, 3, 0, 4, 4, 0, 3, 3],
[3, 3, 0, 4, 4, 0, 3, 3],
[2, 2, 0, 3, 3, 0, 2, 2],
[2, 2, 0, 3, 3, 0, 2, 2],
[1, 1, 0, 2, 2, 0, 1, 1],
[1, 1, 0, 2, 2, 0, 1, 1]]
arr = []
ans = 0
for row in range(6):
arr.append(input())
for col in range(8):
if cost[row][col] > ans and arr[row][col] == '.':
ans = cost[row][col]
for row in range(6):
for col in range(8):
if cost[row][col] == ans and arr[row][col] == '.':
arr[row] = arr[row][:col] + 'P' + arr[row][col + 1:]
ans = -1
break
print(arr[row])
``` | output | 1 | 24,434 | 14 | 48,869 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,435 | 14 | 48,870 |
"Correct Solution:
```
a, b, x, y, m = [list(input()) for i in range(6)], [3, 3, 0, 4, 4, 0, 3, 3], 0, 0, 0
for i in range(6):
for j in range(8):
c = b[j] - i // 2
if a[i][j] == '.' and c > m:
x, y, m = i, j, c
a[x][y] = 'P'
print('\n'.join(''.join(x) for x in a))
``` | output | 1 | 24,435 | 14 | 48,871 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,436 | 14 | 48,872 |
"Correct Solution:
```
a = []
def printgrid():
for i in range(6):
for j in range(len(a[i])):
print(a[i][j], end="")
print()
def solve():
for i in range(6):
x = list(input())
a.append(x)
for i in [0, 1]:
for j in [3, 4]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
for i in [0, 1]:
for j in [0, 1, 6, 7]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
for i in [2, 3]:
for j in [3, 4]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
for i in [2, 3]:
for j in [0, 1, 6, 7]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
for i in [4, 5]:
for j in [3, 4]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
for i in [4, 5]:
for j in [0, 1, 6, 7]:
if a[i][j] == '.':
a[i][j] = 'P'
printgrid()
return
solve();
``` | output | 1 | 24,436 | 14 | 48,873 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,437 | 14 | 48,874 |
"Correct Solution:
```
mas = [3,3,0,4,4,0,3,3,3,3,0,4,4,0,3,3,2,2,0,3,3,0,2,2,2,2,0,3,3,0,2,2,1,1,0,2,2,0,1,1,1,1,0,2,2,0,1,1]
s1 = input()
s2 = input()
s3 = input()
s4 = input()
s5 = input()
s6 = input()
f = -1
ed = -1
s = s1 + s2 + s3 + s4 + s5 + s6
for i in range(48):
if s[i] != '*' and s[i] != '-':
if int(mas[i]) > ed:
ed = int(mas[i])
f = i
s = list(s)
s[f] = 'P'
s = ''.join(s)
for i in range(6):
print(s[i*8: i*8 + 8])
``` | output | 1 | 24,437 | 14 | 48,875 |
Provide a correct Python 3 solution for this coding contest problem.
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture:
<image>
Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard.
You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'.
Find any of the most convenient vacant places for Petya.
Input
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β the description of the left desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the center desk in the current row; a character '-' β the aisle; two characters, each is '*' or '.' β the description of the right desk in the current row. So, the length of each of the six lines is 8.
It is guaranteed that there is at least one vacant place in the classroom.
Output
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print any.
Examples
Input
..-**-..
..-**-..
..-..-..
..-..-..
..-..-..
..-..-..
Output
..-**-..
..-**-..
..-..-..
..-P.-..
..-..-..
..-..-..
Input
**-**-**
**-**-**
..-**-.*
**-**-**
..-..-..
..-**-..
Output
**-**-**
**-**-**
..-**-.*
**-**-**
..-P.-..
..-**-..
Input
**-**-*.
*.-*.-**
**-**-**
**-**-**
..-..-..
..-**-..
Output
**-**-*.
*.-*P-**
**-**-**
**-**-**
..-..-..
..-**-..
Note
In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | instruction | 0 | 24,438 | 14 | 48,876 |
"Correct Solution:
```
def f(x, y) :
return 3 - y + (x == 1)
def g(y) :
return y // 2
S = list()
ans = 0
for i in range(0, 6) :
s = input()
for j in range(0, len(s)) :
if (s[j] == '.') :
ans = max(ans, f(j // 3, g(i)))
S.append(s)
flag = True;
for i in range(0, 6) :
s = S[i]
if flag :
for j in range(0, len(s)) :
if (s[j] == '.' and f(j // 3, g(i)) == ans) :
if (j == 0) :
s = 'P' + s[1:]
else :
s = s[0:j] + 'P' + s[(j + 1):]
flag = False
break
print(s)
``` | output | 1 | 24,438 | 14 | 48,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
Constraints
* 2 \leq n \leq 10^5
* 0 \leq a_i \leq 10^9
* a_1,a_2,...,a_n are pairwise distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n
Output
Print a_i and a_j that you selected, with a space in between.
Examples
Input
5
6 9 4 2 11
Output
11 6
Input
2
100 0
Output
100 0
Submitted Solution:
```
import math
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
maxcomb=0
ans=[0,0]
def combination(n,r):
return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
for i in range(n-1):
for j in range(i+1,n):
comb=combination(a[i], a[j])
if(maxcomb < comb):
maxcomb = comb
ans=[a[i],a[j]]
print(str(ans[0])+" "+str(ans[1]))
``` | instruction | 0 | 24,588 | 14 | 49,176 |
No | output | 1 | 24,588 | 14 | 49,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,763 | 14 | 49,526 |
Tags: dsu, implementation
Correct Solution:
```
from sys import stdin, stdout
input, print = stdin.readline, stdout.write
def main(input=input, print=print, map=map, int=int, range=range, str=str, list=list):
n, m, l = map(int, input().split())
a = [-1]+list(map(int, input().split()))+[-1]
x = sum(1 for q in range(n+1) if a[q] > l >= a[q-1])
answer = []
for _ in range(m):
s = list(map(int, input().split()))
if s[0] == 0:
answer.append(str(x))
else:
w = s[1]
x += (a[w]+s[2] > l >= a[w])*((a[w - 1] <= l and a[w+1] <= l)-(a[w-1] > l and a[w+1] > l))
a[w] += s[2]
print('\n'.join(answer))
main()
``` | output | 1 | 24,763 | 14 | 49,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,764 | 14 | 49,528 |
Tags: dsu, implementation
Correct Solution:
```
def main():
n, m, l = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(1, n):
if A[i] > l >= A[i - 1]:
ans += 1
if A[0] > l:
ans += 1
babans = []
for _ in range(m):
Z = list(map(int, input().split()))
if len(Z) == 1:
babans.append(ans)
else:
t, p, d = Z
if p != 1 and p != n:
if A[p - 1] + d > l >= A[p - 1]:
x = A[p - 2]
y = A[p]
if x > l and y > l:
ans -= 1
elif x <= l and y <= l:
ans += 1
elif p == 1 and n != 1:
if A[p - 1] + d > l >= A[p - 1]:
if A[p] <= l:
ans += 1
elif p == n and n != 1:
if A[p - 1] + d > l >= A[p - 1]:
if A[p - 2] <= l:
ans += 1
else:
if A[p - 1] + d > l >= A[p - 1]:
ans += 1
A[p - 1] += d
print('\n'.join(list(map(str, babans))))
main()
``` | output | 1 | 24,764 | 14 | 49,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,765 | 14 | 49,530 |
Tags: dsu, implementation
Correct Solution:
```
from sys import stdin
def ip():
return stdin.readline().strip().split()
n,m,l = map(int,ip())
a = [ int(x) for x in ip()]
i = j = 0
c = 0
while i < n:
if a[i] > l:
c+=1
j = i+1
while j < n and a[j] > l:
j+=1
i = j
else:
i+=1
for i in range(m):
s = ip()
if len(s) == 1:
print(c)
else:
one,p,d = map(int,s)
p-=1
if a[p] <= l and a[p]+d > l:
if (p-1 >= 0 and a[p-1] > l) and ( p+1 < n and a[p+1] > l):
c-=1
elif (p-1 >= 0 and a[p-1] > l) or ( p+1 < n and a[p+1] > l):
pass
else:
c+=1
a[p] += d
``` | output | 1 | 24,765 | 14 | 49,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,766 | 14 | 49,532 |
Tags: dsu, implementation
Correct Solution:
```
def main():
n, m, l = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = [i > l for i in a]
ans = 0
for i in range(1, n):
if d[i-1] and not d[i]:
ans += 1
if d[-1]:
ans += 1
for _ in range(m):
r = [int(i) for i in input().split()]
if r[0] == 0:
print(ans)
else:
a[r[1]-1] += r[2]
if a[r[1]-1] > l and not d[r[1]-1]: # hair grows over
d[r[1]-1] = True
if r[1]-1 == 0:
prev = 0
else:
prev = d[r[1]-2]
if r[1]-1 == n-1:
next = 0
else:
next = d[r[1]]
if prev and next:
ans -= 1
if not(prev or next):
ans += 1
main()
``` | output | 1 | 24,766 | 14 | 49,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,767 | 14 | 49,534 |
Tags: dsu, implementation
Correct Solution:
```
n, m, l = map(int, input().split())
a = list(map(int, input().split()))
subs = [0] * (n + 2)
cnt = 0
flag = False
for i in range(n):
if a[i] > l:
if flag == False:
cnt += 1
flag = True
subs[i + 1] = 1
else:
flag = False
for i in range(m):
q = tuple(map(int, input().split()))
op = q[0]
if op == 1:
op, p, d = q
before = a[p - 1]
a[p - 1] += d
if before <= l < a[p - 1]:
subs[p] = 1
if subs[p - 1] and subs[p + 1]:
cnt -= 1
elif not (subs[p - 1] or subs[p + 1]):
cnt += 1
else:
print(cnt)
``` | output | 1 | 24,767 | 14 | 49,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,768 | 14 | 49,536 |
Tags: dsu, implementation
Correct Solution:
```
gcd = lambda a, b: gcd(b, a % b) if b else a
def main():
n, m, l = map(int, input().split())
arr = list(map(int, input().split()))
brr = [i > l for i in arr]
total = 0
for i in range(len(brr)):
if brr[i] and (not i or not brr[i - 1]):
total += 1
for i in range(m):
s = input()
if s[0] == '0':
print(total)
else:
_, a, b = map(int, s.split())
a -= 1
arr[a] += b
if arr[a] > l and not brr[a]:
brr[a] = True
if (a > 0 and brr[a - 1]) and (a < len(brr) - 1 and brr[a + 1]):
total -= 1
elif (a == 0 or (a > 0 and not brr[a - 1])) and (a == len(brr) - 1 or (a < len(brr) - 1 and not brr[a + 1])):
total += 1
main()
``` | output | 1 | 24,768 | 14 | 49,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,769 | 14 | 49,538 |
Tags: dsu, implementation
Correct Solution:
```
import sys
def main(map=map, int=int, str=str):
lines = sys.stdin.readlines()
n, m, l = map(int, lines[0].split())
a = [-1]
a += map(int, lines[1].split())
a.append(-1)
n += 2
time = sum(1 for i in range(1, n-1) if a[i] > l and a[i-1] <= l)
res = []
for i in range(2, m + 2):
if lines[i] == '0\n':
res.append(str(time))
else:
_, p, d = map(int, lines[i].split())
if a[p] <= l and a[p] + d > l:
cond = (a[p - 1] <= l) + (a[p + 1] <= l)
time += cond == 2
time -= cond == 0
a[p] += d
sys.stdout.write('\n'.join(res))
if __name__ == '__main__':
main()
``` | output | 1 | 24,769 | 14 | 49,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th. | instruction | 0 | 24,770 | 14 | 49,540 |
Tags: dsu, implementation
Correct Solution:
```
from sys import stdin, stdout
input, print = stdin.readline, stdout.write
def main(input=input, print=print, map=map, int=int, range=range, sum=sum, str=str, list=list):
n, m, k = map(int, input().split())
a, answer = [-1], []
a.extend(list(map(int, input().split())))
a.append(-1)
ans = sum(a[q] <= k < a[q + 1] for q in range(n + 1))
for _ in range(m):
d = list(map(int, input().split()))
if d[0] == 0:
answer.append(str(ans))
else:
q, x = d[1], d[2]
ans += ((a[q - 1] <= k) & (a[q + 1] <= k) & (a[q] + x > k >= a[q]))-((a[q - 1] > k) & (a[q + 1] > k) & (a[q] + x > k >= a[q]))
a[q] += x
print('\n'.join(answer))
main()
``` | output | 1 | 24,770 | 14 | 49,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.
Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:
* 0 β Alice asks how much time the haircut would take if she would go to the hairdresser now.
* 1 p d β p-th hairline grows by d centimeters.
Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.
Input
The first line contains three integers n, m and l (1 β€ n, m β€ 100 000, 1 β€ l β€ 10^9) β the number of hairlines, the number of requests and the favorite number of Alice.
The second line contains n integers a_i (1 β€ a_i β€ 10^9) β the initial lengths of all hairlines of Alice.
Each of the following m lines contains a request in the format described in the statement.
The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 β€ p_i β€ n, 1 β€ d_i β€ 10^9) β the number of the hairline and the length it grows by.
Output
For each query of type 0 print the time the haircut would take.
Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
Note
Consider the first example:
* Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
* Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
* Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
* Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
* The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
* Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
* Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th.
Submitted Solution:
```
class DisjointSets:
def __init__(self, n):
self.parent = [-1 for x in range(n + 1)]
def makeSet(self, node):
self.parent[node] = node
def find(self, node):
parent = self.parent
if parent[node] != node:
parent[node] = self.find(parent[node])
return parent[node]
def union(self, node, other):
self.parent[other] = node
def makeSetp(i):
global ans, n
if ds.parent[i] == -1:
ds.makeSet(i)
ans += 1
if i <= n - 1 and ds.parent[i + 1] != -1:
ds.union(i, i + 1)
ans -= 1
if i > 0 and ds.parent[i - 1] != -1:
ds.union(i, i - 1)
ans -= 1
ans = 0
n, m, l = map(int, input().split())
ds = DisjointSets(n)
seq = list(map(int, input().split()))
for i in range(len(seq)):
if seq[i] > l:
makeSetp(i)
for _ in range(m):
x = input()
if x == "0":
print(ans)
else:
x = list(map(int, x.split()))
i = x[1] - 1
seq[i] += x[2]
if seq[i] > l:
makeSetp(i)
``` | instruction | 0 | 24,771 | 14 | 49,542 |
Yes | output | 1 | 24,771 | 14 | 49,543 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.