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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
data=list(map(int,input().split()))
n=data[0]
m=data[1]
k=data[2]
pos=[1,1]
if k<=n-1:
print(k+1,1)
else:
k-=n-1
ans=k//(m-1)
pos=k%(m-1)
if pos==0 and ans%2 ==0:
print(n-ans+1,2)
elif pos==0 and ans%2 !=0:
print(n-ans+1,m)
elif pos!=0 and ans%2 ==0:
print(n-ans,1+k%(2*m-2))
else:
print(n-ans,2+(2*m-2)-k%(2*m-2))
``` | instruction | 0 | 85,496 | 15 | 170,992 |
Yes | output | 1 | 85,496 | 15 | 170,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
#!/usr/bin/env python3
from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
#lines = stdin.readlines()
n, m, k = rint()
if k < n:
print(k+1, 1)
exit()
moc = (k-n) // (m-1)
res = (k-n) % (m-1)
row = n - moc
if row % 2 == 0: #even
col = 2 + res
else:
col = m - res
print(row, col)
``` | instruction | 0 | 85,497 | 15 | 170,994 |
Yes | output | 1 | 85,497 | 15 | 170,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
n, m, k = [*map(int, input().split())]
if k < n:
print(k + 1, 1)
quit()
k -= n
m -= 1
row = n - k // m
if row % 2 == 1:
col = m + 1 - k % m
else:
col = k % m + 2
print(row, col)
``` | instruction | 0 | 85,498 | 15 | 170,996 |
Yes | output | 1 | 85,498 | 15 | 170,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
data=list(map(int,input().split()))
n=data[0]
m=data[1]
k=data[2]
pos=[1,1]
if k<n-1:
print(k+1,1)
else:
k-=n-1
ans=k//(m-1)
pos=k%(m-1)
if pos==0 and ans%2 ==0:
print(n-ans+1,2)
elif pos==0 and ans%2 !=0:
print(n-ans+1,m)
elif pos!=0 and ans%2 ==0:
print(n-ans,1+k%(2*m-2))
else:
print(n-ans,2+(2*m-2)-k%(2*m-2))
``` | instruction | 0 | 85,499 | 15 | 170,998 |
No | output | 1 | 85,499 | 15 | 170,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
n,m,k=input().split()
import math
n=int(n)
m=int(m)
k=int(k)
if k+1<=n:
print(k+1,1)
else:
n=n+1-int(math.ceil((k-n+1)/(m-1)))
if n%2==0:
m=1+(k-n+1)%(m-1)
else:
m=m-(k-n+1)%(m-1)
print(n,m)
``` | instruction | 0 | 85,500 | 15 | 171,000 |
No | output | 1 | 85,500 | 15 | 171,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
n,m,k = [int(x) for x in input().split()]
def solution(n,m,k):
if 0 <= k < n:
print("{} 1".format(k+1))
return
row = m - (k - n)//(m-1)
if row % 2: #is odd
col = 2 + (k - n)%(m-1)
else:
col = m - (k - n)%(m-1)
print("{} {}".format(row+1, col))
solution(n,m,k)
``` | instruction | 0 | 85,501 | 15 | 171,002 |
No | output | 1 | 85,501 | 15 | 171,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
Input
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Output
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
Examples
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
Note
Here is her path on matrix 4 by 3:
<image>
Submitted Solution:
```
#!/usr/bin/env python3
n, m, k = map(int, input().split(' '))
if k < n:
print(1, k + 1)
else:
k -= n
m -= 1
row = n - k//m
k %= m
if row % 2 == 0:
print(row, 2 + k)
else:
print(row, 1 + (m -k))
``` | instruction | 0 | 85,502 | 15 | 171,004 |
No | output | 1 | 85,502 | 15 | 171,005 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,505 | 15 | 171,010 |
"Correct Solution:
```
a,v=list(map(int,input().split()))
b,w=list(map(int,input().split()))
t=int(input())
if w*t+(abs(a-b))<=v*t:
print("YES")
else:
print("NO")
``` | output | 1 | 85,505 | 15 | 171,011 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,508 | 15 | 171,016 |
"Correct Solution:
```
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
m = abs(A-B)
if V*T >= m+W*T:
print('YES')
else:
print('NO')
``` | output | 1 | 85,508 | 15 | 171,017 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,511 | 15 | 171,022 |
"Correct Solution:
```
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if(abs(a-b)>t*(v-w)):
print("NO")
else:
print("YES")
``` | output | 1 | 85,511 | 15 | 171,023 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to quickly solve popular puzzles and train your instantaneous power. Today's challenge is a puzzle of colorful tiles lined up and erasing them well.
In the initial state, tiles are placed on some squares on the grid. Each tile is colored. After the game starts, the player can perform the operations shown in the following procedure many times.
1. Select one square without tiles and hit that square.
2. Follow from the hit square to the top, and pay attention to the tile when you reach the square where the tile is placed. If you get to the edge of the board without the squares on which the tiles are placed, you will not pay attention to anything.
3. Perform the same operation from the square you hit to the bottom, left, and right. Up to 4 tiles will be the focus of attention.
4. If any of the tiles of interest have the same color, remove those tiles from the board. If there are two pairs of tiles of the same color, remove both.
5. The score will be the same as the number of tiles removed.
6. Stop paying attention.
For example, consider the following situation. The squares without tiles are periods, and the tile colors are represented by uppercase letters.
..A ......
....... B ..
..........
..B ......
..A.CC ....
Now consider the operation of hitting the squares in the second row from the top and the third column from the left. Since there are three tiles of interest, `A`,` B`, and `B`, the two of` B` disappear and the board becomes as follows, and two points are obtained.
..A ......
..........
..........
..........
..A.CC ....
If this puzzle is slow, the time will run out, and you will not be able to see part of the board and you will not know how much training you lacked. Two tiles of each color are placed, but it is not always possible to erase all of them, so let the program calculate the maximum score in advance.
Input
M N
C1,1 C1,2 ... C1, N
C2,1 C2,2 ... C2, N
...
CM, 1CM, 2 ... CM, N
The integers M and N indicate that the board is a grid of vertical M x horizontal N. Ci and j are uppercase letters or periods (`.`), And for the cells in the i-th row from the top and the j-th column from the left, the uppercase letters indicate the color of the tiles placed, and the period indicates the color of the tile. Indicates that no tile is placed on this square.
Satisfy 1 ≤ M ≤ 500 and 1 ≤ N ≤ 500. Each uppercase letter appears as 0 or 2 as you type.
Output
Output the maximum score on one line.
Examples
Input
5 10
..A.......
.......B..
..........
..B.......
..A.CC....
Output
4
Input
3 3
ABC
D.D
CBA
Output
4
Input
5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
Output
34 | instruction | 0 | 85,682 | 15 | 171,364 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
m,n = LI()
a = [[c for c in S()] for _ in range(m)]
ad = collections.defaultdict(list)
for i in range(m):
for j in range(n):
if a[i][j] != '.':
ad[a[i][j]].append((i,j))
ps = set(map(tuple,ad.values()))
f = True
r = 0
while f:
f = False
for pa,pb in list(ps):
i1,j1 = pa
i2,j2 = pb
if i1 == i2:
ff = abs(j1-j2) > 1
for j in range(min(j1,j2)+1,max(j1,j2)):
if a[i1][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
elif j1 == j2:
ff = abs(i1-i2) > 1
for i in range(min(i1,i2)+1,max(i1,i2)):
if a[i][j1] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
else:
i,j = i1,j2
ff = a[i][j] == '.'
for j3 in range(min(j,j1)+1,max(j,j1)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i2)+1,max(i,i2)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
continue
i,j = i2,j1
ff = a[i][j] == '.'
for j3 in range(min(j,j2)+1,max(j,j2)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i1)+1,max(i,i1)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
return r
print(main())
``` | output | 1 | 85,682 | 15 | 171,365 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to quickly solve popular puzzles and train your instantaneous power. Today's challenge is a puzzle of colorful tiles lined up and erasing them well.
In the initial state, tiles are placed on some squares on the grid. Each tile is colored. After the game starts, the player can perform the operations shown in the following procedure many times.
1. Select one square without tiles and hit that square.
2. Follow from the hit square to the top, and pay attention to the tile when you reach the square where the tile is placed. If you get to the edge of the board without the squares on which the tiles are placed, you will not pay attention to anything.
3. Perform the same operation from the square you hit to the bottom, left, and right. Up to 4 tiles will be the focus of attention.
4. If any of the tiles of interest have the same color, remove those tiles from the board. If there are two pairs of tiles of the same color, remove both.
5. The score will be the same as the number of tiles removed.
6. Stop paying attention.
For example, consider the following situation. The squares without tiles are periods, and the tile colors are represented by uppercase letters.
..A ......
....... B ..
..........
..B ......
..A.CC ....
Now consider the operation of hitting the squares in the second row from the top and the third column from the left. Since there are three tiles of interest, `A`,` B`, and `B`, the two of` B` disappear and the board becomes as follows, and two points are obtained.
..A ......
..........
..........
..........
..A.CC ....
If this puzzle is slow, the time will run out, and you will not be able to see part of the board and you will not know how much training you lacked. Two tiles of each color are placed, but it is not always possible to erase all of them, so let the program calculate the maximum score in advance.
Input
M N
C1,1 C1,2 ... C1, N
C2,1 C2,2 ... C2, N
...
CM, 1CM, 2 ... CM, N
The integers M and N indicate that the board is a grid of vertical M x horizontal N. Ci and j are uppercase letters or periods (`.`), And for the cells in the i-th row from the top and the j-th column from the left, the uppercase letters indicate the color of the tiles placed, and the period indicates the color of the tile. Indicates that no tile is placed on this square.
Satisfy 1 ≤ M ≤ 500 and 1 ≤ N ≤ 500. Each uppercase letter appears as 0 or 2 as you type.
Output
Output the maximum score on one line.
Examples
Input
5 10
..A.......
.......B..
..........
..B.......
..A.CC....
Output
4
Input
3 3
ABC
D.D
CBA
Output
4
Input
5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
Output
34 | instruction | 0 | 85,683 | 15 | 171,366 |
"Correct Solution:
```
h, w = map(int, input().split())
mp = [input() for _ in range(h)]
points = {}
for y in range(h):
for x in range(w):
c = mp[y][x]
if c != ".":
if c not in points:
points[c] = [(x, y)]
else:
points[c].append((x, y))
keys = []
preventer = {}
for c, ps in points.items():
keys.append(c)
p1, p2 = ps
x1, y1 = p1
x2, y2 = p2
if x1 == x2:
s = set()
for y in range(y1 + 1, y2):
s.add(mp[y][x1])
preventer[c] = [s]
continue
if y1 == y2:
s = set()
for x in range(x1 + 1, x2):
s.add(mp[y1][x])
preventer[c] = [s]
continue
s1 = set()
s2 = set()
if x1 < x2:
for x in range(x1 + 1, x2):
s1.add(mp[y1][x])
for y in range(y1, y2):
s1.add(mp[y][x2])
for x in range(x1, x2):
s2.add(mp[y2][x])
for y in range(y1 + 1, y2):
s2.add(mp[y][x1])
else:
for x in range(x2, x1):
s1.add(mp[y1][x])
for y in range(y1 + 1, y2):
s1.add(mp[y][x2])
for x in range(x2 + 1, x1):
s2.add(mp[y2][x])
for y in range(y1 + 1, y2 + 1):
s2.add(mp[y][x1])
preventer[c] = [s1, s2]
removal = {".":True}
for key in keys:
removal[key] = False
ans = 0
while True:
remove_lst = []
for key in keys:
for s in preventer[key]:
if not s:
break
for c in s:
if not removal[c]:
break
else:
removal[key] = True
remove_lst.append(key)
ans += 2
break
if not remove_lst:
break
for rem in remove_lst:
keys.remove(rem)
print(ans)
``` | output | 1 | 85,683 | 15 | 171,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to quickly solve popular puzzles and train your instantaneous power. Today's challenge is a puzzle of colorful tiles lined up and erasing them well.
In the initial state, tiles are placed on some squares on the grid. Each tile is colored. After the game starts, the player can perform the operations shown in the following procedure many times.
1. Select one square without tiles and hit that square.
2. Follow from the hit square to the top, and pay attention to the tile when you reach the square where the tile is placed. If you get to the edge of the board without the squares on which the tiles are placed, you will not pay attention to anything.
3. Perform the same operation from the square you hit to the bottom, left, and right. Up to 4 tiles will be the focus of attention.
4. If any of the tiles of interest have the same color, remove those tiles from the board. If there are two pairs of tiles of the same color, remove both.
5. The score will be the same as the number of tiles removed.
6. Stop paying attention.
For example, consider the following situation. The squares without tiles are periods, and the tile colors are represented by uppercase letters.
..A ......
....... B ..
..........
..B ......
..A.CC ....
Now consider the operation of hitting the squares in the second row from the top and the third column from the left. Since there are three tiles of interest, `A`,` B`, and `B`, the two of` B` disappear and the board becomes as follows, and two points are obtained.
..A ......
..........
..........
..........
..A.CC ....
If this puzzle is slow, the time will run out, and you will not be able to see part of the board and you will not know how much training you lacked. Two tiles of each color are placed, but it is not always possible to erase all of them, so let the program calculate the maximum score in advance.
Input
M N
C1,1 C1,2 ... C1, N
C2,1 C2,2 ... C2, N
...
CM, 1CM, 2 ... CM, N
The integers M and N indicate that the board is a grid of vertical M x horizontal N. Ci and j are uppercase letters or periods (`.`), And for the cells in the i-th row from the top and the j-th column from the left, the uppercase letters indicate the color of the tiles placed, and the period indicates the color of the tile. Indicates that no tile is placed on this square.
Satisfy 1 ≤ M ≤ 500 and 1 ≤ N ≤ 500. Each uppercase letter appears as 0 or 2 as you type.
Output
Output the maximum score on one line.
Examples
Input
5 10
..A.......
.......B..
..........
..B.......
..A.CC....
Output
4
Input
3 3
ABC
D.D
CBA
Output
4
Input
5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
Output
34
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
m,n = LI()
a = [[c for c in S()] for _ in range(m)]
ad = collections.defaultdict(list)
for i in range(m):
for j in range(n):
if a[i][j] != '.':
ad[a[i][j]].append((i,j))
ps = set(map(tuple,ad.values()))
f = True
r = 0
while f:
f = False
for pa,pb in list(ps):
i1,j1 = pa
i2,j2 = pb
if i1 == i2:
ff = True
for j in range(min(j1,j2)+1,max(j1,j2)):
if a[i1][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
elif j1 == j2:
ff = True
for i in range(min(i1,i2)+1,max(i1,i2)):
if a[i][j1] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
else:
i,j = i1,j2
ff = True
for j3 in range(min(j,j2)+1,max(j,j2)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i2)+1,max(i,i2)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
continue
i,j = i2,j1
ff = True
for j3 in range(min(j,j1)+1,max(j,j1)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i1)+1,max(i,i1)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
return r
print(main())
``` | instruction | 0 | 85,684 | 15 | 171,368 |
No | output | 1 | 85,684 | 15 | 171,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to quickly solve popular puzzles and train your instantaneous power. Today's challenge is a puzzle of colorful tiles lined up and erasing them well.
In the initial state, tiles are placed on some squares on the grid. Each tile is colored. After the game starts, the player can perform the operations shown in the following procedure many times.
1. Select one square without tiles and hit that square.
2. Follow from the hit square to the top, and pay attention to the tile when you reach the square where the tile is placed. If you get to the edge of the board without the squares on which the tiles are placed, you will not pay attention to anything.
3. Perform the same operation from the square you hit to the bottom, left, and right. Up to 4 tiles will be the focus of attention.
4. If any of the tiles of interest have the same color, remove those tiles from the board. If there are two pairs of tiles of the same color, remove both.
5. The score will be the same as the number of tiles removed.
6. Stop paying attention.
For example, consider the following situation. The squares without tiles are periods, and the tile colors are represented by uppercase letters.
..A ......
....... B ..
..........
..B ......
..A.CC ....
Now consider the operation of hitting the squares in the second row from the top and the third column from the left. Since there are three tiles of interest, `A`,` B`, and `B`, the two of` B` disappear and the board becomes as follows, and two points are obtained.
..A ......
..........
..........
..........
..A.CC ....
If this puzzle is slow, the time will run out, and you will not be able to see part of the board and you will not know how much training you lacked. Two tiles of each color are placed, but it is not always possible to erase all of them, so let the program calculate the maximum score in advance.
Input
M N
C1,1 C1,2 ... C1, N
C2,1 C2,2 ... C2, N
...
CM, 1CM, 2 ... CM, N
The integers M and N indicate that the board is a grid of vertical M x horizontal N. Ci and j are uppercase letters or periods (`.`), And for the cells in the i-th row from the top and the j-th column from the left, the uppercase letters indicate the color of the tiles placed, and the period indicates the color of the tile. Indicates that no tile is placed on this square.
Satisfy 1 ≤ M ≤ 500 and 1 ≤ N ≤ 500. Each uppercase letter appears as 0 or 2 as you type.
Output
Output the maximum score on one line.
Examples
Input
5 10
..A.......
.......B..
..........
..B.......
..A.CC....
Output
4
Input
3 3
ABC
D.D
CBA
Output
4
Input
5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
Output
34
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
m,n = LI()
a = [[c for c in S()] for _ in range(m)]
ad = collections.defaultdict(list)
for i in range(m):
for j in range(n):
if a[i][j] != '.':
ad[a[i][j]].append((i,j))
ps = set(map(tuple,ad.values()))
f = True
r = 0
while f:
f = False
for pa,pb in list(ps):
i1,j1 = pa
i2,j2 = pb
if i1 == i2 and abs(j1-j2) > 1:
ff = True
for j in range(min(j1,j2)+1,max(j1,j2)):
if a[i1][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
elif j1 == j2 and abs(i1-i2) > 1:
ff = True
for i in range(min(i1,i2)+1,max(i1,i2)):
if a[i][j1] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
else:
i,j = i1,j2
ff = a[i][j] == '.'
for j3 in range(min(j,j2)+1,max(j,j2)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i2)+1,max(i,i2)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
continue
i,j = i2,j1
ff = a[i][j] == '.'
for j3 in range(min(j,j1)+1,max(j,j1)):
if a[i][j3] != '.':
ff = False
break
for i3 in range(min(i,i1)+1,max(i,i1)):
if a[i3][j] != '.':
ff = False
break
if ff:
f = True
a[i1][j1] = '.'
a[i2][j2] = '.'
ps.remove((pa,pb))
r += 2
return r
print(main())
``` | instruction | 0 | 85,685 | 15 | 171,370 |
No | output | 1 | 85,685 | 15 | 171,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,887 | 15 | 171,774 |
Tags: constructive algorithms, implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
arr = [input() for i in range(n)]
a = arr[0][1]
b = arr[1][0]
c = arr[n-2][n-1]
d = arr[n-1][n-2]
if (a == b):
ans = []
if c == a:
ans.append([n-1, n])
if d == a:
ans.append([n, n-1])
print(len(ans))
for item in ans:
print(item[0], item[1])
elif (c == d):
ans = []
if c == a:
ans.append([1, 2])
if c == b:
ans.append([2, 1])
print(len(ans))
for item in ans:
print(item[0], item[1])
else:
if (a == c) and (b == d):
print(2)
print(1, 2)
print(n, n-1)
else:
print(2)
print(2, 1)
print(n, n-1)
``` | output | 1 | 85,887 | 15 | 171,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,888 | 15 | 171,776 |
Tags: constructive algorithms, implementation
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
arr=[]
for i in range(n):
temp=list(str(input()))
arr.append(temp)
change=[]
#print(arr)
if arr[0][1]==arr[1][0]:
if arr[0][1]=="1":
if arr[n-2][n-1]!="0":
change.append([n-1,n])
if arr[n-1][n-2]!="0":
change.append([n,n-1])
else:
if arr[n-2][n-1]!="1":
change.append([n-1,n])
if arr[n-1][n-2]!="1":
change.append([n,n-1])
elif arr[n-2][n-1]==arr[n-1][n-2]:
if arr[n-2][n-1]=="1":
if arr[0][1]!="0":
change.append([1,2])
if arr[1][0]!="0":
change.append([2,1])
else:
if arr[0][1]!="1":
change.append([1,2])
if arr[1][0]!="1":
change.append([2,1])
else:
if arr[0][1]!="0":
change.append([1,2])
if arr[1][0]!="0":
change.append([2,1])
if arr[n-1][n-2]!="1":
change.append([n,n-1])
if arr[n-2][n-1]!="1":
change.append([n-1,n])
print(len(change))
for ar in change:
ar=list(map(str,ar))
l=" ".join(ar)
print(l)
``` | output | 1 | 85,888 | 15 | 171,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,889 | 15 | 171,778 |
Tags: constructive algorithms, implementation
Correct Solution:
```
def ans(a, n):
s1 = a[0][1]
s2 = a[1][0]
f2 = a[n-1][n-2]
f1 = a[n-2][n-1]
if f1==f2 and s1==s2 and f1!=s1:
print(0) #correct
elif f1==f2 and f1==s1 and s1==s2:
print(2)
#change s1 and s2
print('1 2')
print('2 1') #correct
elif f1==f2:
print(1)
if s1==f1:
#change s1
print('1 2')
else:
#change s2
print('2 1')
elif s1==s2:
print(1)
if f2==s1:
#change f2
print(str(n)+' '+str(n-1))
else:
#change f1
print(str(n-1)+' '+str(n))
else:
#change s1
print(2)
if f1==s1:
#change s1 and f2
print('1 2')
print(str(n)+' '+str(n-1))
else:
#change s1 and f1
print('1 2')
print(str(n-1)+' '+str(n))
return
m = int(input())
for j in range(m):
n = int(input())
a = []
for i in range(n):
b = input()
a.append(b)
ans(a, n)
``` | output | 1 | 85,889 | 15 | 171,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,890 | 15 | 171,780 |
Tags: constructive algorithms, implementation
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
r = []
for j in range(n):
temp = input()
r.append(temp)
s1, s2 = int(r[0][1]), int(r[1][0])
f1, f2 = int(r[-1][-2]), int(r[-2][-1])
if s1 == s2 and f1 == f2:
if s1 != f1:
print(0)
else:
print(2)
print(1, 2)
print(2, 1)
elif s1 == s2 and f1 != f2:
if s1 == f1:
print(1)
print(n, n - 1)
else:
print(1)
print(n - 1, n)
elif s1 != s2 and f1 == f2:
if f1 == s1:
print(1)
print(1, 2)
else:
print(1)
print(2, 1)
else:
if s1 == f1:
print(2)
print(1, 2)
print(n - 1, n)
else:
print(2)
print(2, 1)
print(n - 1, n)
``` | output | 1 | 85,890 | 15 | 171,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,891 | 15 | 171,782 |
Tags: constructive algorithms, implementation
Correct Solution:
```
def solve():
n = int(input())
start_numbers = set()
finish_numbers = set()
matrix = list()
inversion = list()
for _ in range(n):
inp = list(input())
matrix.append(inp)
start_numbers.add(matrix[0][1])
start_numbers.add(matrix[1][0])
finish_numbers.add(matrix[-1][-2])
finish_numbers.add(matrix[-2][-1])
if len(start_numbers) > 1:
if len(finish_numbers) > 1:
inversion_number = matrix[1][0]
inversion.append((1, 2))
if matrix[-1][-2] == inversion_number:
inversion.append((n, n - 1))
else:
inversion.append((n - 1, n))
else:
if matrix[0][1] == matrix[-1][-2]:
inversion.append((1, 2))
else:
inversion.append((2, 1))
else:
inversion_number = matrix[0][1]
if matrix[-1][-2] == inversion_number:
inversion.append((n, n - 1))
if matrix[-2][-1] == inversion_number:
inversion.append((n - 1, n))
print(len(inversion))
for coords in inversion:
print(*coords)
def main():
for _ in range(int(input())):
solve()
if __name__ == '__main__':
main()
``` | output | 1 | 85,891 | 15 | 171,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,892 | 15 | 171,784 |
Tags: constructive algorithms, implementation
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = [input() for _ in range(n)]
for color in range(2):
result = []
if int(a[0][1]) != color:
result.append((0, 1))
if int(a[1][0]) != color:
result.append((1, 0))
if int(a[n - 1][n - 2]) == color:
result.append((n - 1, n - 2))
if int(a[n - 2][n - 1]) == color:
result.append((n - 2, n - 1))
if len(result) < 3:
print(len(result))
for x, y in result:
print(x + 1, y + 1)
break
``` | output | 1 | 85,892 | 15 | 171,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,893 | 15 | 171,786 |
Tags: constructive algorithms, implementation
Correct Solution:
```
def main():
for _ in range(int(input())):
n=int(input())
matx=[]
for j in range(n):
matx.append([str(x) for x in input()])
x=[int(matx[0][1]),int(matx[1][0])]
y=[int(matx[n-1][n-2]),int(matx[n-2][n-1])]
if x==[0,0] and y==[1,1 ]:
print(0)
elif x==[1,1] and y==[0,0]:
print(0)
elif x==[1,1] and y==[1,1] :
print(2)
print(1,2)
print(2,1)
elif x==[0,0] and y==[0,0] :
print(2)
print(1,2)
print(2,1)
else:
if x==[1,0]:
if y==[1,0]:
print(2)
print(1,2)
print(n-1,n)
elif y==[0,1]:
print(2)
print(1,2)
print(n,n-1)
elif y==[0,0]:
print(1)
print(2,1)
else:
print(1)
print(1,2)
if x == [ 0,1]:
if y == [1, 0]:
print(2)
print(1, 2)
print(n, n-1)
elif y == [0, 1]:
print(2)
print(1, 2)
print(n - 1, n)
elif y == [0, 0]:
print(1)
print(1,2)
else:
print(1)
print(2,1)
if x==[1,1]:
if y==[1,0]:
print(1)
print(n,n-1)
elif y==[0,1]:
print(1)
print(n-1,n)
if x==[0,0] :
if y==[1,0]:
print(1)
print(n-1,n)
elif y==[0,1]:
print(1)
print(n,n-1)
main()
``` | output | 1 | 85,893 | 15 | 171,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| instruction | 0 | 85,894 | 15 | 171,788 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
import math
import random
from typing import List
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
class Cell:
def __init__(self, a, row, col):
self.a = a
self.row = row
self.col = col
def value(self):
return self.a[self.row][self.col]
def solve(n, c1, c2, c3, c4) -> List[Cell]:
def convert(c1: Cell, c2: Cell, char):
ans = []
if c1.value() != char:
ans.append(c1)
if c2.value() != char:
ans.append(c2)
return ans
# print(n, c1, c2, c3, c4)
sol1 = convert(c1, c2, '0') + convert(c3, c4, '1')
sol2 = convert(c1, c2, '1') + convert(c3, c4, '0')
return sol1 if len(sol1) < len(sol2) else sol2
T = int(input())
for t in range(T):
N = int(input())
A = []
for i in range(N):
A.append(input())
solution = solve(
N,
Cell(A, 1, 0), Cell(A, 0, 1),
Cell(A, N-1, N-2), Cell(A, N-2, N-1)
)
print(len(solution))
for cell in solution:
print(cell.row + 1, cell.col + 1)
``` | output | 1 | 85,894 | 15 | 171,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
t = int(input())
for _ in range(t):
ans = []
final = []
n = int(input())
for i in range(n):
s = input()
lol = list(s)
ans.append(s)
a = ans[0][1]
b = ans[1][0]
x = ans[n-2][n-1]
y = ans[n-1][n-2]
#print(a,b,x,y)
if(b != '0'):
final.append([2,1])
if(a!='0'):
final.append([1,2])
if(y!='1'):
final.append([n,n-1])
if(x!='1'):
final.append([n-1,n])
if(len(final) <=2):
print(len(final))
for i in final:
print(*i,end ='\n')
else:
final = []
if(b != '1'):
final.append([2,1])
if(a!='1'):
final.append([1,2])
if(y!='0'):
final.append([n,n-1])
if(x!='0'):
final.append([n-1,n])
print(len(final))
for i in final:
print(*i,end ='\n')
``` | instruction | 0 | 85,895 | 15 | 171,790 |
Yes | output | 1 | 85,895 | 15 | 171,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
import sys
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
#sys.stdin = open('/Users/pranjalkandhari/Desktop/Template/input.txt', 'r')
for _ in range( int(input()) ):
n = int(input())
a = ''
b = ''
c = ''
d = ''
for i in range(0,n):
li = list(input())
if(i == 0):
a = li[1]
if(i == 1):
b = li[0]
if(i == n-2):
c = li[n-1]
if(i == n-1):
d = li[n-2]
comp = [a,b,c,d]
a1 = ['0' , '0' , '1' , '1']
a2 = ['1' , '1' , '0' , '0']
n1 = 0
n2 = 0
for i in range(0,4):
if(comp[i] != a1[i]):
n1 += 1
if(comp[i] != a2[i]):
n2+=1
ctr = 0
if(n1<=2):
print(n1)
if(comp[0] != a1[0]):
print('1 2')
if(comp[1] != a1[1]):
print('2 1')
if(comp[2] != a1[2]):
print(n-1,n)
if(comp[3] != a1[3]):
print(n,n-1)
else:
print(n2)
if(comp[0] != a2[0]):
print('1 2')
if(comp[1] != a2[1]):
print('2 1')
if(comp[2] != a2[2]):
print(n-1,n)
if(comp[3] != a2[3]):
print(n,n-1)
``` | instruction | 0 | 85,896 | 15 | 171,792 |
Yes | output | 1 | 85,896 | 15 | 171,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
t = int(input())
for j in range(t):
n = int(input())
a = ['0'] * n
for i in range(n):
a[i] = str(input())
a[i] = list(a[i])
if a[0][1] == a[1][0]:
if a[n - 1][n - 2] == a[n - 2][n - 1]:
if a[0][1] == a[n - 1][n - 2]:
print(2)
if a[0][1] == '0':
print(0+1,1+1)
print(1+1,0+1)
else:
print(0+1,1+1)
print(1+1,0+1)
else:
print(0)
else:
print(1)
if a[0][1] =='0':
if a[n - 1][n - 2] == '0':
print(n - 1+1,n - 2+1)
else:
print(n - 2+1, n - 1+1)
else:
if a[n - 1][n - 2] == '1':
print(n - 1+1,n - 2+1)
else:
print(n - 2+1, n - 1+1)
else:
if a[n - 1][n - 2] == a[n - 2][n - 1]:
if a[n - 1][n - 2] == '0':
print(1)
if a[0][1] == '0':
print(0+1,1+1)
else:
print(1+1, 0+1)
else:
print(1)
if a[0][1] == '1':
print(0+1,1+1)
else:
print(1+1,0+1)
else:
print(2)
if a[0][1] != a[n - 1][n - 2]:
print(0+1,1+1)
print(n - 1+1,n - 2+1)
else:
print(0+1,1+1)
print(n - 2+1,n - 1+1)
``` | instruction | 0 | 85,897 | 15 | 171,794 |
Yes | output | 1 | 85,897 | 15 | 171,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
t = int(input())
for i in range(t):
list1 = []
n = int(input())
for j in range(n):
list1.append(input())
s_right = list1[0][1]
s_down = list1[1][0]
f_left = list1[-1][-2]
f_up = list1[-2][-1]
if s_right==s_down and f_left==f_up:
if s_right!=f_left:
print(0)
else:
print(2)
print(n-1,' ',n)
print(n,' ',n-1)
elif s_right!=s_down and f_left==f_up:
if s_right==f_left:
print(1)
print(1,' ',2)
elif s_down==f_left:
print(1)
print(2,' ',1)
elif s_right==s_down and f_left!=f_up:
if s_right==f_left:
print(1)
print(n,' ',n-1)
elif s_down==f_up:
print(1)
print(n-1,' ',n)
else:
print(2)
if s_right==f_up:
print(1,' ',2)
print(n,' ',n-1)
elif s_right==f_left:
print(1,' ',2)
print(n-1,' ',n)
``` | instruction | 0 | 85,898 | 15 | 171,796 |
Yes | output | 1 | 85,898 | 15 | 171,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 16:36:57 2020
@author: lakne
"""
t = int(input())
answers = []
for _ in range(t):
n = int(input())
start = []
finish = []
answer = []
grids = []
c = 0
for i in range(n):
grid = input()
grids.append(grid)
start.append(grids[0][1])
start.append(grids[1][0])
finish.append(grids[n-2][n-1])
finish.append(grids[n-1][n-2])
if start[0] != start[1] and finish[0] == finish[1]:
c = 1
if start[0] == finish[0]:
answer.append([str(2), str(1)])
else:
answer.append([str(1), str(2)])
elif start[0] == start[1] and finish[0] == finish[1]:
if start[0] == finish[0]:
c = 2
answer.append([str(2), str(1)])
answer.append([str(1), str(2)])
else:
c = 0
elif start[0] != start[1] and finish[0] != finish[1]:
c = 2
if start[0] == finish[0]:
answer.append([str(2), str(1)])
answer.append([str(n-1), str(n)])
else:
answer.append([str(2), str(1)])
answer.append([str(n), str(n-1)])
elif start[0] == start[1] and finish[0] != finish[1]:
c = 1
if start[0] == finish[0]:
answer.append([str(n-1), str(n)])
else:
answer.append([str(n), str(n-1)])
answers.append([c, answer])
for j in range(t):
print(answers[j][0])
for cord in answers[j][1]:
print(' '.join(cord))
``` | instruction | 0 | 85,899 | 15 | 171,798 |
No | output | 1 | 85,899 | 15 | 171,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
t=int(input())
for _ in range(t):
n = int(input())
l=[]
i=int(0)
for i in range(n):
l.append(input())
x1=l[0][1]
x2=l[1][0]
y1,y2 = l[-2][-1],l[-1][-2]
# print(x1)
# print(x2)
# print(y1)
# print(y2)
if(x1==x2==y1==y2):
print("2")
print("1 2")
print("2 1")
print("k")
elif ((x1==x2)and(y1==y2)):
print("0")
elif ((x1==x2) and (y1!=y2)):
if ((x1=='0') and (y1=='0')):
print("1")
print(n-1,n)
elif ((x1=='0') and (y2=='0')):
print("1")
print(n, n-1)
elif ((x1=='1') and (y1=='1')):
print("1")
print(n-1, n)
elif ((x1=='1') and (y2=='1')):
print("1")
print(n, n-1)
elif ((x1!=x2) and (y1==y2)):
if ((y1=='0') and (x1=='0')):
print("1")
print("1 2")
elif ((y1=='0') and (x2=='0')):
print("1")
print("2 1")
elif ((y1=='1') and (x1=='1')):
print("1")
print("1 2")
elif ((y1=='1') and (x2=='1')):
print("1")
print("2 1")
elif ((x1!=x2) and (y1!=y2)):
if (x1=='1' and y1=='1'):
print("2")
print("2 1")
print(n-1,n)
elif (x1=='1' and y2=='1'):
print("2")
print("2 1")
print(n, n-1)
elif (x1=='0' and y2=='0'):
print("2")
print("2 1")
print(n-1, n)
elif (x1=='0' and y2=='0'):
print("2")
print("2 1")
print(n,n-1)
``` | instruction | 0 | 85,900 | 15 | 171,800 |
No | output | 1 | 85,900 | 15 | 171,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
import sys
input = sys.stdin.readline
def solve():
n=int(input())
M=[list(input().strip()) for _ in range(n)]
def check():
ans= []
if M[0][1]==M[1][0]=='1':
if M[n-1][n-2]=='1':
ans.append([n,n-1])
if M[n-2][n-1]=='1':
ans.append([n-1,n])
return ans
if M[0][1]==M[1][0]=='0':
if M[n-1][n-2]=='0':
ans.append([n,n-1])
if M[n-2][n-1]=='0':
ans.append([n-1,n])
return ans
else:
if M[0][1]=='0':
ans.append([1,2])
if M[1][0]=='0':
ans.append([2,1])
if M[n-1][n-2]=='1':
ans.append([n,n-1])
if M[n-2][n-1]=='1':
ans.append([n-1,n])
return ans
def pr(ans):
print(len(ans))
for i in ans:
print(*i)
ans = check()
pr(ans)
if __name__=="__main__":
for _ in range(int(input())):
solve()
``` | instruction | 0 | 85,901 | 15 | 171,802 |
No | output | 1 | 85,901 | 15 | 171,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
s = []
for __ in range(n):
s.append([int(x) for x in input() if x.isdigit()])
s[0].insert(0,0)
s[n-1].insert(n-1,0)
c = 0
ans = []
#for i in s:
# print(*i)
if s[0][1] and s[1][0]:
if not s[n-1][n-2]:
c += 1
ans.append([n,n-1])
if not s[n-2][n-1]:
c += 1
ans.append([n-1,n])
print(c)
for i in ans:
print(*i)
continue
elif not(s[0][1] or s[1][0]):
if not s[n-1][n-2]:
c += 1
ans.append([n,n-1])
if not s[n-2][n-1]:
c += 1
ans.append([n-1,n])
print(c)
for i in ans:
print(*i)
continue
elif s[0][1] or s[1][0]:
if s[n-1][n-2] or s[n-2][n-1]:
if s[n-1][n-2]:
if s[0][1]:
print(2)
print(1, 2)
print(n-2, n-1)
else:
print(2)
print(2, 1)
print(n-2, n-1)
else:
if s[0][1]:
print(2)
print(1, 2)
print(n-2, n-1)
else:
print(2)
print(2, 1)
print(n-2, n-1)
else:
if not s[0][1]:
print(1)
print(0, 1)
continue
else:
print(1)
print(1, 1)
c += 1
ans.append([n-1,n])
``` | instruction | 0 | 85,902 | 15 | 171,804 |
No | output | 1 | 85,902 | 15 | 171,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,593 | 15 | 173,186 |
Tags: implementation, math
Correct Solution:
```
def editor():
import sys
sys.stdin=open("input.txt",'r')
sys.stdout=open("output.txt",'w')
def solve():
n,q=map(int,input().split())
till= (n**2+1)//2
if n%2==0:
half=n//2
for _ in range(q):
x,y=map(int,input().split())
if (x+y)%2==0:
print((x-1)*half + (y+1)//2)
else:
print(till+(x-1)*half + (y+1)//2)
else:
oh=n//2
eh=(n+1)//2
for _ in range(q):
x,y=map(int,input().split())
if (x+y)%2==0:
if(x%2==1):print((x//2)*n + (y+1)//2)
else: print((x//2)*n - (n-y)//2)
else:
if(x%2==1):print(till + (x//2)*n + (y+1)//2)
else: print(till+ (x//2)*n - (n-y)//2)
if __name__ == "__main__":
# editor()
tc=1
# tc=int(input())
for t in range(tc):
solve()
``` | output | 1 | 86,593 | 15 | 173,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,594 | 15 | 173,188 |
Tags: implementation, math
Correct Solution:
```
'''
n=eval(input())
print(n)
for i in range(n):
len=int(input())
s=input()
flag=True
for j in range(len):
d=abs(ord(s[j])-ord(s[len-1-j]))
if not(abs(d)==0 or abs(d)==2):
flag=False
break
if flag:
print('YES')
else :
print('NO')
'''
import sys
n,q=map(int,sys.stdin.readline().split())
for line in sys.stdin:
x,y=map(int,line.split())
ans=1+((x-1)*n+y-1)//2
if (x+y)%2:
ans+=n*n//2+(n%2)
print(int(ans))
``` | output | 1 | 86,594 | 15 | 173,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,595 | 15 | 173,190 |
Tags: implementation, math
Correct Solution:
```
import sys
n,q=map(int,sys.stdin.readline().split())
for _ in range(q):
x,y=map(int,sys.stdin.readline().split())
print( ((x-1)*n+y+1+(x+y)%2*n*n)//2 )
``` | output | 1 | 86,595 | 15 | 173,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,596 | 15 | 173,192 |
Tags: implementation, math
Correct Solution:
```
import sys
res = sys.stdin.readline().split()
n, query = int(res[0]), int(res[1])
for i in range(0, query):
result = sys.stdin.readline().split()
rows, columns = int(result[0]), int(result[1])
posicion = ((rows - 1) * n + columns)
ans = (posicion + 1) // 2
if (rows + columns) % 2 == 1:
ans += (n * n + 1) // 2
sys.stdout.write(str(ans) + "\n")
``` | output | 1 | 86,596 | 15 | 173,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,597 | 15 | 173,194 |
Tags: implementation, math
Correct Solution:
```
import math
import sys
input = sys.stdin.readline
def solve(n, x, y):
r = (n * (x - 1) + (y - 1)) // 2 + 1 + int((x + y) % 2 == 1) * ((n ** 2) // 2 + int(n % 2 == 1))
return r
n, q = [int(s) for s in input().split(' ')]
for query in range(q):
x, y = [int(s) for s in input().split(' ')]
print(solve(n, x, y))
``` | output | 1 | 86,597 | 15 | 173,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,598 | 15 | 173,196 |
Tags: implementation, math
Correct Solution:
```
import math
import sys
inputlist=sys.stdin.readlines()
n,q=list(map(int,inputlist[0].split(' ')))
for i in range(q):
x,y=list(map(int,inputlist[i+1].split(' ')))
if((x+y)%2==0):
print(((x-1)*n+y+1)//2)
else:
initial_sum=(n*n+1)//2
print(initial_sum+((x-1)*n+y+1)//2)
``` | output | 1 | 86,598 | 15 | 173,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,599 | 15 | 173,198 |
Tags: implementation, math
Correct Solution:
```
import sys
from array import array # noqa: F401
def readline(): return sys.stdin.buffer.readline().decode('utf-8')
n, q = map(int, readline().split())
ans = [0]*q
for i in range(q):
y, x = map(int, readline().split())
z = ((y-1) >> 1) * n + ((x + 1) >> 1)
if (x + y) & 1:
z += (n**2 + 1) >> 1
if (y & 1) == 0:
z += n >> 1
elif (y & 1) == 0:
z += (n + 1) >> 1
ans[i] = z
sys.stdout.buffer.write(('\n'.join(map(str, ans))).encode('utf-8'))
``` | output | 1 | 86,599 | 15 | 173,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5.
<image>
You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n.
Input
The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries.
The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query.
Output
For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input.
Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
Note
Answers to the queries from examples are on the board in the picture from the problem statement. | instruction | 0 | 86,600 | 15 | 173,200 |
Tags: implementation, math
Correct Solution:
```
n,q=map(int,input().split())
k=0
z=[]
for i in range(q):
x,y=map(int,input().split())
if n%2:
if (x+y)%2:
k=(n**2+1)//2
k+=(x-1)*n//2
k+=(y+1)//2
z.append(k)
else:
k=n//2*(x-1)
k+=x//2
k+=(y+1)//2
z.append(k)
else:
if (x+y)%2:
k=n**2//2
k+=(x-1)*n//2
k+=(y+1)//2
z.append(k)
else:
k=n//2*(x-1)
k+=(y+1)//2
z.append(k)
for i in z:
print(i)
``` | output | 1 | 86,600 | 15 | 173,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,823 | 15 | 173,646 |
Tags: math
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
# mod=1000000007
mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def ceil1(a,b):
return (a+b-1)//b
def solve():
for _ in range(ii()):
x1,y1,x2,y2 = mi()
ans = abs(y1-y2) + abs(x1-x2)
if x1 == x2:
print(ans)
continue
if y1==y2:
print(ans)
continue
print(ans+2)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
solve()
``` | output | 1 | 86,823 | 15 | 173,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,824 | 15 | 173,648 |
Tags: math
Correct Solution:
```
import sys
def In():
return sys.stdin.readline()
def Out(x):
return sys.stdout.write(str(x)+'\n')
def solve(x1,y1,x2,y2):
if x1==x2:
return abs(y2-y1)
if y1==y2:
return abs(x2-x1)
return abs(x2-x1)+2+abs(y2-y1)
t=int(In())
for i in range(t):
x1,y1,x2,y2=map(int,input().split())
Out(solve(x1,y1,x2,y2))
``` | output | 1 | 86,824 | 15 | 173,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,825 | 15 | 173,650 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
x1, y1, x2, y2 = map(int, input().split())
if x1 == x2 or y1 == y2:
print(abs(x2 - x1) + abs(y2 - y1))
else:
print(abs(x2 - x1) + abs(y2 - y1) + 2)
``` | output | 1 | 86,825 | 15 | 173,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,826 | 15 | 173,652 |
Tags: math
Correct Solution:
```
for _ in range(int(input())):
a, b, c, d = list(map(int, input().split()))
if a == c and b == d:
print(0)
elif a == c:
print(abs(b - d))
elif b == d:
print(abs(a - c))
else:
ans = abs(a - c) + abs(b - d) + 2
print(ans)
``` | output | 1 | 86,826 | 15 | 173,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,827 | 15 | 173,654 |
Tags: math
Correct Solution:
```
t = int(input())
for case in range(t):
X = [int(s) for s in input().split(' ')]
left = abs(X[0] - X[2])
up = abs(X[1] - X[3])
ans = left + up
if min(left, up) > 0:
ans += 2
print(ans)
``` | output | 1 | 86,827 | 15 | 173,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,828 | 15 | 173,656 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(t):
x1,y1,x2,y2=map(int,input().split())
if x1==x2:
print(abs(y1-y2))
elif y1==y2:
print(abs(x1-x2))
else:
print(abs(y1-y2)+abs(x1-x2)+2)
``` | output | 1 | 86,828 | 15 | 173,657 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,829 | 15 | 173,658 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
a,b,c,d=list(map(int,input().split(' ')))
if abs(a-c)==0 or abs(b-d)==0:
print(abs(a-c)+abs(b-d))
else:
print(abs(a-c)+abs(b-d)+2)
``` | output | 1 | 86,829 | 15 | 173,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds. | instruction | 0 | 86,830 | 15 | 173,660 |
Tags: math
Correct Solution:
```
t = int(input())
for t0 in range(t):
a = list(map(int, input().split()))
print(abs(a[0] - a[2]) + abs(a[1] - a[3]) + 2 * ((a[0] != a[2]) and (a[1] != a[3])))
``` | output | 1 | 86,830 | 15 | 173,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.
Submitted Solution:
```
t=int(input())
while t>0:
x1,y1,x2,y2=[int(x) for x in input().split()]
if y1==y2:
print(abs(x2-x1))
elif x1==x2:
print(abs(y2-y1))
else:
print(abs(x2-x1)+2+abs(y2-y1))
t-=1
``` | instruction | 0 | 86,831 | 15 | 173,662 |
Yes | output | 1 | 86,831 | 15 | 173,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.
Submitted Solution:
```
for i in range(int(input())):
a, b, c, d = map(int, input().split())
print(abs(a-c) + abs(b-d) + (a != c and b != d) * 2)
``` | instruction | 0 | 86,832 | 15 | 173,664 |
Yes | output | 1 | 86,832 | 15 | 173,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.
Submitted Solution:
```
for _ in range(int(input())):
x1,y1,x2,y2=map(int, input().split())
ans=abs(x1-x2)+abs(y1-y2)+2
if(x1==x2 or y1==y2):
ans-=2
print(ans)
``` | instruction | 0 | 86,833 | 15 | 173,666 |
Yes | output | 1 | 86,833 | 15 | 173,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.
<image>
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.
Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).
Example
Input
2
1 2 2 2
1 1 2 2
Output
1
4
Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.
In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.
Submitted Solution:
```
t = int(input())
for i in range(t):
x1,y1,x2,y2 = [int(x) for x in input().split()]
if x1==x2 or y1==y2:
print(abs(x1-x2) + abs(y1-y2))
else:
print(abs(x1-x2) + abs(y1-y2) + 2)
``` | instruction | 0 | 86,834 | 15 | 173,668 |
Yes | output | 1 | 86,834 | 15 | 173,669 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.