message stringlengths 2 19.9k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 322 108k | cluster float64 15 15 | __index_level_0__ int64 644 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | instruction | 0 | 94,841 | 15 | 189,682 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = input()
p = 0
k = 0
a = list(map(int, input().split()))
for i in range(2 * n):
if s[p] == '>':
p += a[p]
else:
p -= a[p]
if (p > n - 1) or (p < 0):
print("FINITE")
k = 1
break
if not k:
print("INFINITE")
``` | output | 1 | 94,841 | 15 | 189,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | instruction | 0 | 94,842 | 15 | 189,684 |
Tags: implementation
Correct Solution:
```
def main():
n = int(input())
arrows = input()
cells = [int(x) for x in input().split()]
print(solver(arrows, cells))
def solver(arrows, cells):
for i in range(len(arrows)):
if arrows[i] == '<':
cells[i] = - cells[i]
visited = [False] * len(cells)
index = 0
while True:
if index >= len(cells) or index < 0:
return "FINITE"
elif visited[index] == True:
return "INFINITE"
else:
visited[index] = True
index = index + cells[index]
#print(solver(">><", [2, 1, 1]))
#print(solver("><", [1, 2]))
main()
``` | output | 1 | 94,842 | 15 | 189,685 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | instruction | 0 | 94,843 | 15 | 189,686 |
Tags: implementation
Correct Solution:
```
n = int(input())-1
s = input()
d = [int(i) for i in input().split()]
c = True
cnt = 0
i = 0
z = 0
while i<=n and i>=0:
if s[i]:
if s[i]==">":
i+=d[i]
z+=1
elif s[i]=="<":
i-=d[i]
z+=1
else:
break
if z>=2*n:c=False;break
if i>n or i<0:
print("FINITE")
else:
print("INFINITE")
``` | output | 1 | 94,843 | 15 | 189,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | instruction | 0 | 94,844 | 15 | 189,688 |
Tags: implementation
Correct Solution:
```
if __name__ == '__main__':
Y = lambda: list(map(int, input().split()))
N = lambda: int(input())
n = N()
s = input()
a = Y()
nxt, ans = 0, 0
for i in range(n):
nxt += [a[nxt], -a[nxt]][s[nxt] == '<']
if nxt >= n or nxt < 0:
ans = 2
break
print("INFINITE"[ans:])
``` | output | 1 | 94,844 | 15 | 189,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | instruction | 0 | 94,845 | 15 | 189,690 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()
a=list(map(int,input().split()))
f=n*[False]
i,j=0,0
while True:
# print(i,f[i])
if i<0 or i>=n or n==1:
print("FINITE")
break
elif f[i]==True:
print("INFINITE")
break
else:
f[i]=True
if s[i]=='>':
i+=a[i]
else:
i-=a[i]
``` | output | 1 | 94,845 | 15 | 189,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
import math
def main_function():
n = int(input())
s = input()
a = [int(i) for i in input().split(" ")]
current_position = 0
hash = [0 for i in range(100000)]
while True:
if current_position < 0 or current_position > n - 1:
print("FINITE")
break
else:
if hash[current_position] == 1:
print("INFINITE")
break
else:
hash[current_position] = 1
if s[current_position] == ">":
current_position += a[current_position]
else:
current_position -= a[current_position]
main_function()
``` | instruction | 0 | 94,846 | 15 | 189,692 |
Yes | output | 1 | 94,846 | 15 | 189,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
D = [d if ch=='>' else -d for ch,d in zip(input(), map(int, input().split()))]
i = 0
visited = {0}
while True:
i += D[i]
if i < 0 or i >= n:
print('FINITE')
break
if i in visited:
print('INFINITE')
break
visited.add(i)
``` | instruction | 0 | 94,847 | 15 | 189,694 |
Yes | output | 1 | 94,847 | 15 | 189,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
def main():
n = int(input())
d = input()
l = [int(c) for c in input().split()]
visited = {0}
i = 0
while 0 <= i < n:
di, li = d[i], l[i]
i = i + li if di == '>' else i - li
if i in visited:
print('INFINITE')
return
visited.add(i)
print('FINITE')
if __name__ == '__main__':
main()
``` | instruction | 0 | 94,848 | 15 | 189,696 |
Yes | output | 1 | 94,848 | 15 | 189,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
s = input()
a = list(map(int, input().split()))
WAS = False
pos = 1
for i in range(0, n) :
if s[pos - 1] == '<' : pos -= a[pos - 1]
else : pos += a[pos - 1]
if pos < 1 or pos > n : WAS = True
if WAS : break
if WAS : print("FINITE")
else : print("INFINITE")
``` | instruction | 0 | 94,849 | 15 | 189,698 |
Yes | output | 1 | 94,849 | 15 | 189,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n=int(input())
S=input()
l=list(map(int,input().split()))
i=0
c=1
while i>=0 or i>=n-1 :
if S[i]=='>' and i+l[i]>n-1 :
c=1
break
if S[i]=='<' and i-l[i]<0 :
c=1
break
if l[i]==0 :
c=0
break
if S[i]=='>' :
i=i+l[i]
else :
i=i-l[i]
l[i]=0
if c==1 :
print('FINITE')
else :
print('INFINITE')
``` | instruction | 0 | 94,850 | 15 | 189,700 |
No | output | 1 | 94,850 | 15 | 189,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n=int(input())
s=input()
l=list(map(int,input().split()))
c=0
for i in range(len(s)):
if s[i]=='>':
c+=l[i]
if c>n:
print('FINITE')
exit()
else:
c-=l[i]
if c<0:
print('FINITE')
exit()
print('INFINITE')
``` | instruction | 0 | 94,851 | 15 | 189,702 |
No | output | 1 | 94,851 | 15 | 189,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n=int(input())
s=input()
l=list(map(int,input().split()))
c=0
for i in range(len(s)):
if s[i]=='>':
c+=l[i]
else:
c-=l[i]
if c>n or c<0:
break
print(['FINITE','INFINITE'][n>c>=0])
``` | instruction | 0 | 94,852 | 15 | 189,704 |
No | output | 1 | 94,852 | 15 | 189,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
t = input()
cord = 0
l = list(map(int,input().split()))
i = 0
d = set({})
while cord < len(t):
d.add(cord)
if t[cord] == ">":
cord = cord + l[i]
else:
cord = cord - l[i]
if cord < 0 or cord > n-1:
print("FINITE")
exit()
if cord in d:
print("INFINITE")
exit()
``` | instruction | 0 | 94,853 | 15 | 189,706 |
No | output | 1 | 94,853 | 15 | 189,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
1. Value x and some direction are announced, and all boys move x positions in the corresponding direction.
2. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.
Your task is to determine the final position of each boy.
Input
The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.
Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.
Output
Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.
Examples
Input
6 3
1 2
2
1 2
Output
4 3 6 5 2 1
Input
2 3
1 1
2
1 -2
Output
1 2
Input
4 2
2
1 3
Output
1 4 3 2
Submitted Solution:
```
# You lost the game.
n,q = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
impair = 0
pair = 0
pos = 1
for i in range(q):
if Q[i][0] == 1:
d = Q[i][1]
impair += d
pair += d
if pos == 1 and d % 2:
pos = -1
elif pos == -1 and d % 2 == 0:
pos = 1
else:
impair += pos
pair += -pos
pos = -pos
for i in range(1,n+1):
j = i-1
if pair % 2:
if i % 2:
print(1+(j-pair) % n,end=" ")
else:
print(1+(j-impair) % n,end=" ")
else:
if i % 2:
print(1+(j-impair) % n,end=" ")
else:
print(1+(j-pair) % n,end=" ")
``` | instruction | 0 | 94,855 | 15 | 189,710 |
No | output | 1 | 94,855 | 15 | 189,711 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,031 | 15 | 190,062 |
"Correct Solution:
```
import collections
H,W,K = map(int,input().split())
s1,e1,s2,e2 = map(int,input().split())
s1-=1
e1-=1
s2-=1
e2-=1
L = []
board = []
for _ in range(H):
a = input()
L.append(a)
for i in range(H):
l = L[i]
tmp = []
for j in range(len(l)):
tmp.append(l[j])
board.append(tmp)
queue = collections.deque()
queue.append([0,s1,e1])
seen = [[float('inf')]*(W) for _ in range(H)]
destination = [(1,0),(-1,0),(0,1),(0,-1)]
while queue:
cost,x,y = queue.popleft()
seen[x][y] = cost
if x==s2 and y ==e2:
print(cost);exit()
break
for dx,dy in destination:
X,Y = x,y
for i in range(1,K+1):
NX = X +i*dx
NY = Y + i*dy
if 0>NX or NX>=H or 0>NY or NY>=W or seen[NX][NY] < seen[X][Y]+1: break
else:
if board[NX][NY]=='@':
break
elif seen[NX][NY] ==float('inf'):
queue.append([cost+1,NX,NY])
seen[NX][NY] = cost+1
print(-1)
``` | output | 1 | 95,031 | 15 | 190,063 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,032 | 15 | 190,064 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
def LI(): return [int(x) for x in sys.stdin.readline().split()]
dd = [(1,0),(-1,0),(0,1),(0,-1)]
def solve():
h,w,k = LI()
y,x,s,t = LI()
y -= 1
x -= 1
s -= 1
t -= 1
c = [input() for i in range(h)]
q = deque([(y,x)])
d = [[float("inf")]*w for i in range(h)]
d[y][x] = 0
while q:
y,x = q.popleft()
if (y,x) == (s,t):
print(d[s][t])
return
nd = d[y][x] + 1
for dy,dx in dd:
ny,nx = y,x
for _ in range(k):
ny += dy
nx += dx
if 0 <= ny < h and 0 <= nx < w and c[ny][nx] != "@" and nd <= d[ny][nx]:
if nd < d[ny][nx]:
d[ny][nx] = nd
q.append((ny,nx))
continue
break
print(-1)
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 95,032 | 15 | 190,065 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,033 | 15 | 190,066 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
H,W,K = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())
C = [input() for _ in range(H)]
T = [[-1 for _ in range(W)] for _ in range(H)]
T[x1-1][y1-1] = 0
que = {(x1-1,y1-1):0}
step = 1
while len(que)>0:
que_next = {}
for q in que.keys():
x,y = q[0],q[1]
for i in range(1,K+1):
if x-i<0:
break
if C[x-i][y]=='@' or T[x-i][y]==1:
break
if x-i==x2-1 and y==y2-1:
print(step)
exit()
que_next[(x-i,y)] = 0
for i in range(1,K+1):
if x+i>H-1:
break
if C[x+i][y]=='@' or T[x+i][y]==1:
break
if x+i==x2-1 and y==y2-1:
print(step)
exit()
que_next[(x+i,y)] = 0
for i in range(1,K+1):
if y-i<0:
break
if C[x][y-i]=='@' or T[x][y-i]==1:
break
if x==x2-1 and y-i==y2-1:
print(step)
exit()
que_next[(x,y-i)] = 0
for i in range(1,K+1):
if y+i>W-1:
break
if C[x][y+i]=='@' or T[x][y+i]==1:
break
if x==x2-1 and y+i==y2-1:
print(step)
exit()
que_next[(x,y+i)] = 0
que = que_next
for q in que.keys():
T[q[0]][q[1]] = 1
step += 1
print(-1)
``` | output | 1 | 95,033 | 15 | 190,067 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,034 | 15 | 190,068 |
"Correct Solution:
```
#
import sys
from collections import deque
input=sys.stdin.readline
def main():
H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
x1-=1
y1-=1
x2-=1
y2-=1
mas=[list(input()) for i in range(H)]
dist=[[-1]*W for i in range(H)]
dist[x1][y1]=0
qu=deque([(x1,y1)])
qup=qu.popleft
qua=qu.append
d=((-1,0),(1,0),(0,-1),(0,1))
while(len(qu)>0):
v=qup()
for di in d:
for i in range(1,K+1):
nvh=v[0]+i*di[0]
nvw=v[1]+i*di[1]
if nvh<0 or nvh>=H or nvw<0 or nvw>=W or mas[nvh][nvw]=="@":
break
if dist[nvh][nvw]!=-1 and dist[nvh][nvw]<=dist[v[0]][v[1]]:
break
if dist[nvh][nvw]==-1:
dist[nvh][nvw]=dist[v[0]][v[1]]+1
qua((nvh,nvw))
print(dist[x2][y2])
if __name__=="__main__":
main()
``` | output | 1 | 95,034 | 15 | 190,069 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,035 | 15 | 190,070 |
"Correct Solution:
```
#16:41
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(lambda x:int(x)-1, input().split())
raw = []
for _ in range(h):
raw.append(input())
inf = 10**6
seen = [[inf for _ in range(w)] for _ in range(h)]
seen[x1][y1] = 0
from heapq import heappush as push
from heapq import heappop as pop
now = [[0,x1,y1]]
while now:
s,x,y = pop(now)
if x == x2 and y == y2:
print(s)
exit()
for i in range(1,k+1):
if x-i == -1 or raw[x-i][y] == '@' or seen[x-i][y] < s+1:
break
if seen[x-i][y] != s+1:
seen[x-i][y] = s+1
push(now,[s+1,x-i,y])
for i in range(1,k+1):
if y-i == -1 or raw[x][y-i] == '@' or seen[x][y-i] < s+1:
break
if seen[x][y-i] != s+1:
seen[x][y-i] = s+1
push(now,[s+1,x,y-i])
for i in range(1,k+1):
if x+i == h or raw[x+i][y] == '@' or seen[x+i][y] < s+1:
break
if seen[x+i][y] != s+1:
seen[x+i][y] = s+1
push(now,[s+1,x+i,y])
for i in range(1,k+1):
if y+i == w or raw[x][y+i] == '@' or seen[x][y+i] < s+1:
break
if seen[x][y+i] != s+1:
seen[x][y+i] = s+1
push(now,[s+1,x,y+i])
print(-1)
``` | output | 1 | 95,035 | 15 | 190,071 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,036 | 15 | 190,072 |
"Correct Solution:
```
from heapq import heappop, heappush
from collections import deque
def dijkstra(xs, ys, xg, yg,h,w,k,field):
# que->(cost, x, y, direction)
inf = 1e18
dist = [[inf]*w for _ in range(h)]
dist[xs][ys] = 0
que = deque([(0, xs, ys)])
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
while que:
cost, x, y = que.popleft()
if cost > dist[x][y]:
continue
for v in range(4):
nx, ny = x, y
for _ in range(k):
nx += dx[v]
ny += dy[v]
if not field[nx][ny]:
break
if dist[nx][ny]<=dist[x][y]:
break
if dist[nx][ny] > dist[x][y]+1:
dist[nx][ny] = dist[x][y]+1
que.append((dist[nx][ny], nx, ny))
if dist[xg][yg] == inf:
print(-1)
else:
print(dist[xg][yg])
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
h, w, k = map(int, input().split())
xs, ys, xg, yg = map(int, input().split())
field = [[False]*(w+2) for _ in range(h+2)]
for i in range(h):
# False で覆うことでx,yの制限をなくす。
s = [True if _ == '.' else False for _ in input()]
field[i+1] = [False]+s+[False]
h += 2
w += 2
dijkstra(xs, ys, xg, yg, h, w, k, field)
if __name__ == '__main__':
main()
``` | output | 1 | 95,036 | 15 | 190,073 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,037 | 15 | 190,074 |
"Correct Solution:
```
from collections import deque
H,W,K = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
maze = []
maze.append(["@"]*(W+2))
for _ in range(H):
row = list(input())
maze.append(["@"]+row+["@"])
maze.append(["@"]*(W+2))
q = deque([(x1,y1)])
depth = 0
while q:
for i,j in q:
maze[i][j] = "@"
new_q = set()
l = len(q)
for _ in range(l):
x,y = q.pop()
if (x,y) == (x2,y2):
print(depth)
exit()
# Up
for i in range(1, K+1):
if maze[x-i][y] == "@": break
new_q.add((x-i, y))
# Down
for i in range(1, K+1):
if maze[x+i][y] == "@": break
new_q.add((x+i, y))
# Left
for i in range(1, K+1):
if maze[x][y-i] == "@": break
new_q.add((x, y-i))
# Right
for i in range(1, K+1):
if maze[x][y+i] == "@": break
new_q.add((x, y+i))
q = deque(list(new_q))
depth += 1
print(-1)
``` | output | 1 | 95,037 | 15 | 190,075 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1 | instruction | 0 | 95,038 | 15 | 190,076 |
"Correct Solution:
```
#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]
#que = []
que = deque()
c = [input() for _ in range(h)]
dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
x,y=que.popleft()
if x==x2 and y==y2:
exit(print(dp[x][y]))
for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
for i in range(1,k+1):
xx=x+dx*i
yy=y+dy*i
if not(0<=xx<h and 0<=yy<w) or c[xx][yy]=="@":break
if 0<=dp[xx][yy]<=dp[x][y]:break
if dp[xx][yy]==-1:que.append((xx,yy))
dp[xx][yy]=dp[x][y]+1
print(-1)
``` | output | 1 | 95,038 | 15 | 190,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,335 | 15 | 190,670 |
Tags: constructive algorithms
Correct Solution:
```
#------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now----------------------------------------------------
n,m=map(int,input().split())
s=0
e=n-1
for i in range(n//2):
for j in range(m):
print(s+1,j+1)
print(e+1,m-j)
s+=1
e-=1
if n%2==1:
s=n//2
for j in range(m//2):
print(s+1,j+1)
print(s+1,m-j)
if m%2==1:
print(s+1,m//2+1)
``` | output | 1 | 95,335 | 15 | 190,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,336 | 15 | 190,672 |
Tags: constructive algorithms
Correct Solution:
```
import sys
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
n, m = list(map(int, sys.stdin.readline().strip().split()))
upr = 1
dwr = n
while(upr < dwr):
upc = 1
dwc = m
for i in range(m):
sys.stdout.write(str(upr) + ' ' + str(upc) + '\n')
sys.stdout.write(str(dwr) + ' ' + str(dwc) + '\n')
upc += 1
dwc -= 1
upr += 1
dwr -= 1
if(upr == dwr):
row = upr
col = 1
rcol = m
for i in range(m):
sys.stdout.write(str(row) + ' ' + str(col) + '\n')
tcol = col
col = rcol
rcol = (tcol + 1 if (tcol < rcol) else tcol - 1)
``` | output | 1 | 95,336 | 15 | 190,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,337 | 15 | 190,674 |
Tags: constructive algorithms
Correct Solution:
```
import sys
import math
from collections import defaultdict
n,m=map(int,sys.stdin.readline().split())
#cur=[1,1]
#ans=[-1 for _ in range(2*n*m)]
up,down=1,n
count=0
while up<=down:
left,right=1,m
#ans.append(cur)
while left<=m and count<n*m:
#ans.append([up,left])
#ans[count]=[up,left]
if count<n*m:
sys.stdout.write((str(up)+" "+str(left)+"\n"))
count+=1
left+=1
#ans[count]=[down,right]
if count<n*m:
sys.stdout.write((str(down)+" "+str(right)+"\n"))
count+=1
#ans.append([down,right])
right-=1
up+=1
down-=1
'''if n==1:
a=len(ans)
#print(a,'a')
for i in range(a//2):
print(ans[i][0],ans[i][1])
else:
a=len(ans)
for i in range(a//2):
print(ans[i][0],ans[i][1])
#print(ans)'''
``` | output | 1 | 95,337 | 15 | 190,675 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,338 | 15 | 190,676 |
Tags: constructive algorithms
Correct Solution:
```
import sys
m, n = [int(i) for i in input().split()]
data = [0] * (m+1)
for i in range((m+1)//2 ):
data[2*i] = i+1
data[2*i+1] = m - i
for x in range(n//2):
for i in range(m):
sys.stdout.write(str(i+1) + ' ' + str(x+1) + '\n')
sys.stdout.write(str(m-i) + ' ' + str(n-x) + '\n')
#print(i+1, x+1)
#print(m - i, n - x)
if n % 2 == 1:
q = (n+1)//2
s = " " + str(q) + '\n'
for i in range(m):
#print(data[i], q)
sys.stdout.write(str(data[i]) + s)
``` | output | 1 | 95,338 | 15 | 190,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,339 | 15 | 190,678 |
Tags: constructive algorithms
Correct Solution:
```
import math
import sys
n,m=[int(x) for x in input().split()]
answer=[]
x=math.ceil(n/2)
y=n%2
for i in range(1,math.ceil(n/2)+1):
if y==1 and i==x:
for j in range(1,m//2+1):
answer.append(str(i)+' '+str(j))
answer.append(str(n-i+1)+' '+str(m-j+1))
answer.append((str(i)+' '+str((math.ceil(m/2)))))
else:
for j in range(1,m+1):
answer.append((str(i)+' '+str(j)))
answer.append(str(n-i+1)+' '+str(m-j+1))
print("\n".join(answer[:n*m]))
``` | output | 1 | 95,339 | 15 | 190,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,340 | 15 | 190,680 |
Tags: constructive algorithms
Correct Solution:
```
if __name__ == "__main__":
n, m = [int(x) for x in input().split()]
#n, m = map(int, input().split())
answer = []
for i in range((n + 1) // 2):
for j in range(m):
if i == n // 2 and j == m // 2:
if m % 2 == 0:
break
answer.append("{} {}".format(i + 1, j + 1))
break
answer.append("{} {}".format(i + 1, j + 1))
answer.append("{} {}".format(n - i, m - j))
print("\n".join(answer))
``` | output | 1 | 95,340 | 15 | 190,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,341 | 15 | 190,682 |
Tags: constructive algorithms
Correct Solution:
```
n, m = tuple(map(int, input().split()))
if n==1 and m==1:
print('1 1')
exit()
def onerow(r, m):
for i in range(1, (m+1)//2 + 1):
# print('Here', i)
print(str(r) + ' ' + str(i))
if m%2 == 0 or i != (m+1)//2:
print(str(r) + ' ' + str(m+1-i))
def tworow(r1, r2, m):
for i in range(1, m+1):
print(str(r1) + ' ' + str(i))
print(str(r2) + ' ' + str(m+1-i))
if n%2 == 0:
for i in range(1, n//2 + 1):
tworow(i, n+1-i, m)
if n%2 == 1:
for i in range(1, n//2 + 1):
tworow(i, n+1-i, m)
onerow(n//2 + 1, m)
``` | output | 1 | 95,341 | 15 | 190,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). | instruction | 0 | 95,342 | 15 | 190,684 |
Tags: constructive algorithms
Correct Solution:
```
import sys
input=sys.stdin.buffer.readline
n,m=map(int,input().split())
for i in range(n//2+n%2):
x1=i+1
x2=n-i
if(x1==x2):
for j in range(m//2+m%2):
if(j+1==m-j):
sys.stdout.write((str(x1)+" "+str(j+1)+"\n"))
else:
sys.stdout.write((str(x1)+" "+str(j+1)+"\n"))
sys.stdout.write((str(x2)+" "+str(m-j)+"\n"))
else:
if(i%2==0):
for j in range(m):
sys.stdout.write((str(x1)+" "+str(j+1)+"\n"))
sys.stdout.write((str(x2)+" "+str(m-j)+"\n"))
else:
for j in range(m):
sys.stdout.write((str(x1)+" "+str(m-j)+"\n"))
sys.stdout.write((str(x2)+" "+str(j+1)+"\n"))
``` | output | 1 | 95,342 | 15 | 190,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
ANS=[]
for i in range(1,n//2+1):
for j in range(1,m+1):
sys.stdout.write("".join((str(i)," ",str(j),"\n")))
sys.stdout.write("".join((str(n-i+1)," ",str(m-j+1),"\n")))
if n%2==1:
for j in range(1,m//2+1):
sys.stdout.write("".join((str(n//2+1)," ",str(j),"\n")))
sys.stdout.write("".join((str(n//2+1)," ",str(m-j+1),"\n")))
if m%2==1:
sys.stdout.write("".join((str(n//2+1)," ",str(m//2+1),"\n")))
``` | instruction | 0 | 95,343 | 15 | 190,686 |
Yes | output | 1 | 95,343 | 15 | 190,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n,m=map(int,input().split())
x1,y1,x2,y2=1,1,n,m
for i in range(n*m):
if(i&1):
print(str(x2)+" "+str(y2))
if x2==1:
x2,y2=n,y2-1
else:
x2-=1
else:
print(str(x1)+" "+str(y1))
if x1==n:
x1,y1=1,y1+1
else:
x1+=1
``` | instruction | 0 | 95,344 | 15 | 190,688 |
Yes | output | 1 | 95,344 | 15 | 190,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = list(map(int,input().split()))
for i in range (0, n * m):
if i % 2 == 0:
c = i // (2 * n)
r = (i % (2 * n)) // 2
else:
c = m - 1 - i // (2 * n)
r = n - 1 - (i % (2 * n)) // 2
print(str(r+1) + " " + str(c + 1))
``` | instruction | 0 | 95,345 | 15 | 190,690 |
Yes | output | 1 | 95,345 | 15 | 190,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = list(map(int,input().split()))
ans = []
for i in range(n // 2):
for j in range(m):
ans.append(str(i + 1) + ' ' + str(j + 1))
ans.append(str(n - i) + ' ' + str(m - j))
if n % 2 == 1:
i = n // 2 + 1
for j in range(m // 2):
ans.append(str(i) + ' ' + str(j + 1))
ans.append(str(i) + ' ' + str(m - j))
if m % 2 == 1:
ans.append(str(i) + ' ' + str(m // 2 + 1))
print ('\n'.join(ans))
``` | instruction | 0 | 95,346 | 15 | 190,692 |
Yes | output | 1 | 95,346 | 15 | 190,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
"""
111
111
11111
11111
11 15 12 14 13
23 24 22 25 21
111111
111111
11 16 12 15 13 14
24
11
11
11
11
11
11 51 21 41 31 32 42 22 52 12
1
1
1
1
1
11 51 21 41 31
"""
n,m=list(map(int,input().split()))
if n>2 and m>2:
print(-1)
exit(0)
if n==1 and m==1:
print(1,1)
elif n==1:
count=0
l=1
r=m
fl=0
while count<m:
if fl==0:
print(1,l)
l+=1
fl=1
else:
print(1,r)
r-=1
fl=0
count+=1
#print(l,r,end="1233")
elif n==2:
res=[]
count=0
l=1
r=m
fl=0
y=0
temp=1
while count<m:
if fl==0:
print(1,l)
res.append(l)
y=l
l+=1
fl=1
else:
print(1,r)
res.append(r)
y=r
r-=1
fl=0
count+=1
while res!=[]:
print(2,res[-1])
res.pop()
elif m==1:
#print("hhh")
count=0
l=1
r=n
fl=0
while count<n:
if fl==0:
print(l,1)
l+=1
fl=1
else:
print(r,1)
r-=1
fl=0
count+=1
elif m==2:
res=[]
count=0
l=1
r=n
fl=0
while count<n:
if fl==0:
print(l,1)
res.append(l)
l+=1
fl=1
else:
print(r,1)
res.append(r)
r-=1
fl=0
count+=1
while res!=[]:
print(res[-1],2)
res.pop()
else:
print(-1)
``` | instruction | 0 | 95,347 | 15 | 190,694 |
No | output | 1 | 95,347 | 15 | 190,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
list=[int(x) for x in input().split()]
n=list[0]
m=list[1]
dif=n*m-1
for i in range(0,dif,2):
print(i//m+1,i%m+1)
print((dif-i)//m+1,(dif-i)%m+1)
if dif %2==0:
print(m/2+1,n/2+1)
``` | instruction | 0 | 95,348 | 15 | 190,696 |
No | output | 1 | 95,348 | 15 | 190,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = [int(x) for x in input().split()]
l = 1
r = n
while l <= r:
t = 1
b = m
if l == r:
while t <= b:
print(l, t)
if t != b:
print(r, b)
t += 1
b -= 1
else:
while t <= m and b >= 0:
print(l, t)
if t != b:
print(r, b)
t += 1
b -= 1
l += 1
r -= 1
``` | instruction | 0 | 95,349 | 15 | 190,698 |
No | output | 1 | 95,349 | 15 | 190,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
import math
inp = input().split(' ')
m = int(inp[0])
n = int(inp[1])
for column in range(1, math.ceil(m/2) + 1):
rowRange = range(1, n + 1)
if column == math.ceil(m / 2) and m % 2 == 1:
rowRange = range(1, math.ceil(n/2) + 1)
for row in rowRange:
print(str(column) + ' ' + str(row))
if row == math.ceil(n/2) and n % 2 == 1:
continue
print(str(m + 1 - column) + ' ' + str(n + 1 - row))
``` | instruction | 0 | 95,350 | 15 | 190,700 |
No | output | 1 | 95,350 | 15 | 190,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,536 | 15 | 191,072 |
Tags: implementation
Correct Solution:
```
n = int(input())
mat = []
for i in range(n):
m_ = input()
m_ = m_.split(' ')
mat.append(m_)
i = 0
s=0
m = int((n-1)/2)
while i<n:
if i != m:
s += int(mat[i][i]) + int(mat[i][n-i-1]) + int(mat[i][m])
else:
pass
i += 1
i=0
while i<n:
s+= int(mat[m][i])
i+=1
print(s)
``` | output | 1 | 95,536 | 15 | 191,073 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,537 | 15 | 191,074 |
Tags: implementation
Correct Solution:
```
import time
import collections
class Time_test:
def __enter__(self):
self.enter_time = time.time()
def __exit__(self, exc_type, exc_val, exc_tb):
print("Command was executed in", time.time()-self.enter_time)
n = int(input())
s = 0
for i in range(n):
ipt = [int(x) for x in input().split()]
if n//2 == i:
s += sum(ipt)
continue
s += ipt[n//2] + ipt[i] + ipt[n-i-1]
print(s)
``` | output | 1 | 95,537 | 15 | 191,075 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,538 | 15 | 191,076 |
Tags: implementation
Correct Solution:
```
n=int(input())
k=[]
sum1=0
sum2=0
sum3=0
sum4=0
for i in range(n):
k.append(list(map(int,input().split())))
for i in range(len(k)):
sum1=sum1+k[i][i]
sum2=sum2+k[i][(len(k)-1)-i]
sum3=sum3+k[int(len(k)/2)][i]
sum4=sum4+k[i][int(len(k)/2)]
j=k[int(len(k)/2)][int(len(k)/2)]
x=sum1+sum2+sum3+sum4-3*j
print(x)
``` | output | 1 | 95,538 | 15 | 191,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,539 | 15 | 191,078 |
Tags: implementation
Correct Solution:
```
import sys
def main():
inp = sys.stdin.read().strip().split('\n')
n = int(inp[0])
m = [[int(x) for x in s.split()] for s in inp[1:]]
s = sum(m[i][i] + m[i][-i-1] + m[i][n//2] + m[n//2][i] for i in range(n))
return s - 3*m[n//2][n//2]
print(main())
``` | output | 1 | 95,539 | 15 | 191,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,540 | 15 | 191,080 |
Tags: implementation
Correct Solution:
```
N = int( input() )
mat = list( list( map( int, input().split() ) ) for i in range( N ) )
ans = 0
for i in range( N ):
ans += mat[ i ][ i ]
ans += mat[ N - 1 - i ][ i ]
ans += mat[ N >> 1 ][ i ]
ans += mat[ i ][ N >> 1 ]
print( ans - mat[ N >> 1 ][ N >> 1 ] * 3 )
``` | output | 1 | 95,540 | 15 | 191,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,541 | 15 | 191,082 |
Tags: implementation
Correct Solution:
```
n = int(input())
grid = []
for i in range(n):
row = [int(i) for i in input().split()]
grid.append(row)
sum = 0
for i in range(n):
for j in range(n):
if i == j or i == n - 1 - j or i == (n - 1) / 2 or j == (n - 1) / 2:
sum += grid[i][j]
print(sum)
``` | output | 1 | 95,541 | 15 | 191,083 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,542 | 15 | 191,084 |
Tags: implementation
Correct Solution:
```
row=int(input())
matrix=[]
for i in range(row):
r=list(map(int, input().split()))
matrix.append(r)
p=row-1
count=0
for i in range(row):
count += matrix[i][i]
count += matrix[p-i][i]
count += matrix[int(((p-1)/2)+1)][i]
count += matrix[i][int(((p - 1) / 2) + 1)]
count -= 3*matrix[int(((p-1)/2)+1)][int(((p-1)/2)+1)]
print(count)
``` | output | 1 | 95,542 | 15 | 191,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | instruction | 0 | 95,543 | 15 | 191,086 |
Tags: implementation
Correct Solution:
```
n = int(input())
matrix = [[int(j) for j in input().split()] for i in range(n)]
summ=0
k=n//2
for i in range(n):
for j in range(n):
if i==j:
summ = summ + matrix[i][j]
elif i+j+1 ==n:
summ = summ + matrix[i][j]
elif i==k:
summ = summ + matrix[i][j]
elif j==k:
summ = summ + matrix[i][j]
print(summ)
``` | output | 1 | 95,543 | 15 | 191,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
n = int(input())
a = []
for i in range(n):
a.append([int(i) for i in input().split()])
goodSum = 0
for i in range(n):
goodSum += a[i][i] + a[i][n-1-i] + a[n//2][i] + a[i][n//2]
print(goodSum - (3 * a[n//2][n//2]))
``` | instruction | 0 | 95,547 | 15 | 191,094 |
Yes | output | 1 | 95,547 | 15 | 191,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
b=int(input())
a= [[int(j) for j in input().split()] for i in range(b)]
print(a)
sum=0
gum=0
rum=0
drum=0
d=int((b-1)/2)
for i in range(b):
sum=sum+a[d][i]
gum=gum+a[i][d]
for j in range(b):
if(i==j):
rum=rum+a[i][j]
if((i+j)==b-1):
drum=drum+a[i][j]
c=int(sum+gum+rum+drum-(3*a[d][d]))
print(c)
``` | instruction | 0 | 95,549 | 15 | 191,098 |
No | output | 1 | 95,549 | 15 | 191,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0 | instruction | 0 | 96,401 | 15 | 192,802 |
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
#start the code from here
n=int(input())
global parent
parent=[i for i in range(n)]
# n is total number of nodes
# finding parent of a node
def find(w):
global parent
if parent[w]==w:
return w
else:
return find(parent[w])
def union(a,b):
global parent
w=find(a)
y=find(b)
if w==y:
return
parent[y]=w
#start the code from here
l=[]
ans=0
for i in range(n):
a,b=map(int,input().split())
for u in range(len(l)):
if l[u][0]==a or l[u][1]==b:
union(u,i)
else:
ans+=1
l.append([a,b])
pset=set()
for i in range(len(l)):
pset.add(find(i))
print(len(pset)-1)
``` | output | 1 | 96,401 | 15 | 192,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0 | instruction | 0 | 96,402 | 15 | 192,804 |
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
def dfs(node):
vis[node]=1
for i in range(n):
if (X[i]==X[node] or Y[i]==Y[node]) and vis[i]==0:
dfs(i)
r=[-1 for i in range(2005)]
n=int(input())
X,Y=[],[]
vis=[0]*101
for i in range(n):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
ans=0
for i in range(n):
if (vis[i]==0):
dfs(i)
ans+=1
print(ans-1)
``` | output | 1 | 96,402 | 15 | 192,805 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.