TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W = map(int, input().split())
A = [''] * H
for i in range(H):
    A[i] = input()
x, y = 0, 0
while True:
    if (x < H-1 and A[x+1][y] == '#') and (y < W-1 and A[x][y+1] == '#'):
        print('Impossible')
        exit()
    elif (x > 0 and A[x-1][y] == '#') and (y > 0 and A[x][y-1] == '#'):
        print('Impossible')
        exit()
    elif (x == H-1 or A[x+1][y] == '.') and (y == W-1 or A[x][y+1] == '.'):
        print('Impossible')
        exit()
    elif x == H-1 and y == W-1:
            print('Possible')
            exit()
    elif x < H-1 and A[x+1][y] == '#':
        x += 1
        continue
    elif y < W-1 and A[x][y+1] == '#':
        y += 1
        continue

H, W = map(int, input().split())
A = [''] * H
for i in range(H):
    A[i] = input()
x, y = 0, 0
while True:
    if (x < H-1 and A[x+1][y] == '#') and (y < W-1 and A[x][y+1] == '#'):
        print('Impossible')
        exit()
    elif (x > 0 and A[x-1][y] == '#') and (y > 0 and A[x][y-1] == '#'):
        print('Impossible')
        exit()
    elif (x == H-1 or A[x+1][y] == '.') and (y == W-1 or A[x][y+1] == '.'):
        print('Impossible')
        exit()
    else:
        if x == H-1 and y == W-1:
            print('Possible')
            exit()
        elif x < H-1 and A[x+1][y] == '#':
            x += 1
            continue
        elif y < W-1 and A[x][y+1] == '#':
            y += 1
            continue

H, W = map(int, input().split())
A = [''] * H
for i in range(H):
    A[i] = input()
x, y = 0, 0
while True:
    if (x < H-1 and A[x+1][y] == '#') and (y < W-1 and A[x][y+1] == '#'):
        print('Impossible')
        exit()
    elif (x > 0 and A[x-1][y] == '#') and (y > 0 and A[x][y-1] == '#'):
        print('Impossible')
        exit()
    elif x == H-1 and y == W-1:
            print('Possible')
            exit()
    elif (x == H-1 or A[x+1][y] == '.') and (y == W-1 or A[x][y+1] == '.'):
        print('Impossible')
        exit()
    elif x < H-1 and A[x+1][y] == '#':
        x += 1
        continue
    elif y < W-1 and A[x][y+1] == '#':
        y += 1
        continue

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
    maze = []
    h, w = map(int,input().split())
    for _ in range(h):
        maze.append(list(input()))
    #print(maze)
    x,y = 0,0
    while True:
        maze[y][x] = "."
        if x == w-1 and  y == h-1:
            break
        if x != w-1 and maze[y][x+1]== "#":
            x += 1
            continue
        if y != h-1 and maze[y+1][x]=="#":
            y += 1
            continue
        break
    from pprint import pprint
    #pprint(maze)
    f= True
    for i in range(h):
        if maze[i].count("#") != 0:
            f = False
    print("Impossible" if not f else "Possible")


maze = []
h, w = map(int,input().split())
for _ in range(h):
    maze.append(list(input()))
#print(maze)
x,y = 0,0
while True:
    maze[y][x] = "."
    if x == w-1 and  y == h-1:
        break
    if x != w-1 and maze[y][x+1]== "#":
        x += 1
        continue
    if y != h-1 and maze[y+1][x]=="#":
        y += 1
        continue
    break
from pprint import pprint
#pprint(maze)
f= True
for i in range(h):
    if maze[i].count("#") != 0:
        f = False
print("Impossible" if not f else "Possible")


Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
def solve():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    for i in range(h-1):
        for j in range(w-1):
            if a[i][j:j+2] == ["#","#"]:
                print("!!")
                if a[i+1][j] == '#':
                    print("Impossible")
                    exit()
    print("Possible")
    return 0

if __name__ == "__main__":
    solve()


def solve():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    for i in range(h-1):
        for j in range(w-1):
            if a[i][j:j+2] == ["#","#"]:
                if a[i+1][j] == '#':
                    print("Impossible")
                    exit()
        for k in range(1,w):
            if a[i][k] == "#":
                if a[i+1][k-2:k] == ["#","#"]:
                    print("Impossible")
                    exit()
    if a[h-2][-1] == "#":
        if a[h-1][-2] == "#":
            print("Impossible")
            exit()
    print("Possible")
    return 0

if __name__ == "__main__":
    solve()


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())
amap = ['.' * (w + 2)]
for _ in range(h):
  amap.append('.' + input().strip() + '.')
amap.append('.' * (w + 2))

x, y = 1, 1
is_one = True
while x != w or y != h:
  if x == 1 and y == 1 and amap[y][x] != '#':
    is_one = False
    break
  c = 0
  if amap[y][x+1] == '#':
    c += 1
  if amap[y][x-1] == '#':
    c += 1
  if amap[y+1][x] == '#':
    c += 1
  if amap[y-1][x] == '#':
    c += 1

  if c != 1:
    is_one = False
    break
  else:
    amap[y] = amap[y][:x] + '.' + amap[y][x+1:]
    if amap[y][x+1] == '#':
      x += 1
    elif amap[y+1][x] == '#':
      y += 1
    elif amap[y][x-1] == '#':
      is_one = False
      break
    elif amap[y-1][x] == '#':
      is_one = False
      break

if is_one:
  c = 0
  for a in amap:
    c += a.count('#')
  if c == 0:
    print('Possible')
  else:
    print('Impossible')
else:
  print('Impossible')


h, w = map(int, input().split())
amap = ['.' * (w + 2)]
for _ in range(h):
  amap.append('.' + input().strip() + '.')
amap.append('.' * (w + 2))

x, y = 1, 1
is_one = True
while x != w or y != h:
  if x == 1 and y == 1 and amap[y][x] != '#':
    break
  c = 0
  if amap[y][x+1] == '#':
    c += 1
  if amap[y][x-1] == '#':
    c += 1
  if amap[y+1][x] == '#':
    c += 1
  if amap[y-1][x] == '#':
    c += 1

  if c != 1:
    break
  else:
    amap[y] = amap[y][:x] + '.' + amap[y][x+1:]
    if amap[y][x+1] == '#':
      x += 1
    elif amap[y+1][x] == '#':
      y += 1
    elif amap[y][x-1] == '#':
      break
    elif amap[y-1][x] == '#':
      break

if x == w or y == h:
  c = 0
  for a in amap:
    c += a.count('#')
  if c == 1:
    print('Possible')
  else:
    print('Impossible')
else:
  print('Impossible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W = map(int, input().split())
A = [input() for _ in range(H)]
cnt = 0
for i in range(H):
  cnt += A[i].count("#")
print("Possible" if cnt == H + W - 2 else "Impossible")

H, W = map(int, input().split())
A = [input() for _ in range(H)]
cnt = 0
for i in range(H):
  cnt += A[i].count("#")
print("Possible" if cnt == H + W - 1 else "Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
def inpl():
    return list(map(int, input().split()))


H, W = inpl()
A = [list(input()) for i in range(H)]

x, y = 0, 0

while True:
    A[y][x] = '.'
    dy, dx = min(y + 1, H - 1), x
    ry, rx = y, min(x + 1, W - 1)
    if A[dy][dx] == '#':
        y, x = dy, dx
    elif A[ry][rx] == '#':
        y, x = ry, rx
    else:
        print('Impossible')
        break
else:
    if any('#' in a for a in A) is True:
        print('Impossible')
    else:
        print('Possible')


def inpl():
    return list(map(int, input().split()))


H, W = inpl()
A = [list(input()) for i in range(H)]

x, y = 0, 0

while y != H - 1 or x != W - 1:
    A[y][x] = '.'
    dy, dx = min(y + 1, H - 1), x
    ry, rx = y, min(x + 1, W - 1)
    if A[dy][dx] == '#':
        y, x = dy, dx
    elif A[ry][rx] == '#':
        y, x = ry, rx
    else:
        # print(A)
        print('Impossible')
        break
else:
    A[H - 1][W - 1] = '.'
    if any('#' in a for a in A) is True:
        print('Impossible')
    else:
        print('Possible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
from collections import deque

h,w=map(int,input().split())
l=[list(input()) for i in range(h)]

c=l.count('#')

sy,sx=0,0
gy,gx=h-1,w-1

stack=deque()
stack.append((sy,sx))

cnt=1
while stack:
 y,x=stack.pop()

 if y==gy and x==gx and cnt==c:
  print('Possible')
  exit()

 for dy,dx in [[1,0],[0,1]]:
  ny=y+dy
  nx=x+dx
  if ny<=h-1 and nx<=w-1 and l[ny][nx]=='#':
   stack.append((ny,nx))
   l[ny][nx]=='.'
   cnt+=1

print('Impossible')

h,w=map(int,input().split())
c=0
for i in range(h):
 c+=input().count('#')
print('Possible' if c==h+w-1 else 'Impossible')

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = imput()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")

h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = input()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
input_nums = [int(n) for n in input().slice(“ ”)]
h = input_nums[0]
w = input_nums[1]

count = 0

for i in range(h):
	for c in input():
		if c == “
			count += 1

if count == h+w-1:
	print(“Possible”)
else:
	print(“Impossible”)

input_nums = [int(c) for c in input().split(" ")]
h = input_nums[0]
w = input_nums[1]

count = 0

for i in range(h):
	for c in input():
		if c == "#":
			count += 1

if count == h+w-1:
	print("Possible")
else:
	print("Impossible")

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
def main():
    h,w=map(int,input().split())
    a=[]
    for _ in range(h):
        a.append(input())
    now = [0, 0]
    end = [h-1, w-1]
    while now != end:
        is_legal = False
        #print(now)
        if now[0]+1 < len(a) and a[now[0]+1][now[1]] == "#":
            now[0] += 1
            is_legal = not is_legal
        if now[1]+1 < len(a[now[0]]) and a[now[0]][now[1]+1] == "#":
            now[1] += 1
            is_legal = not is_legal
        if not is_legal:
            print("Impossible")
            return
    print("Possible")
    
if __name__ == "__main__":
    main()

def main():
    h,w=map(int,input().split())
    a=[]
    for _ in range(h):
        a.append(input())
    now = (0, 0)
    end = (h-1, w-1)
    visited = set([now])
    while True:
        nxt = None
        #print(now)
        if now[0]+1 < len(a) and a[now[0]+1][now[1]] == "#":
            nxt = (now[0]+1, now[1])
        if now[1]+1 < len(a[now[0]]) and a[now[0]][now[1]+1] == "#":
            if nxt is not None:
                print("Impossible")
                return
            nxt = (now[0], now[1]+1)
        #print("next", nxt)
        if now[0]-1 >= 0 and a[now[0]-1][now[1]] == "#":
            if (now[0]-1,now[1]) not in visited:
                print("Impossible")
                return
        if now[1]-1 >= 0 and a[now[0]][now[1]-1] == "#":
            if (now[0],now[1]-1) not in visited:
                print("Impossible")
                return
        
        if now == end:
            break
        if nxt is None:
            print("Impossible")
            return
        now = nxt
        visited.add(nxt)
    print("Possible")
    
if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
n,m=map(int,input().split())
arr=[input() for _ in range(n)]
for i in range(n-1):
  print((m-1)-arr[i][::-1].index('#'),arr[i+1].index('#'))
  if (m-1)-arr[i][::-1].index('#')>arr[i+1].index('#'):
    print('Impossible')
    break
else:
  print('Possible')

n,m=map(int,input().split())
arr=[input() for _ in range(n)]
for i in range(n-1):
  if (m-1)-arr[i][::-1].index('#')>arr[i+1].index('#'):
    print('Impossible')
    break
else:
  print('Possible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int,input().split())
a = [list(input()) for i in range(h)]
sum = 0
for b in a:
    sum+=b.count('#')

if sum == h+w-1:
    print('possible')
else:
    print('impossible')

h, w = map(int,input().split())
a = [list(input()) for i in range(h)]
sum = 0
for b in a:
    sum+=b.count('#')

if sum == h+w-1:
    print('Possible')
else:
    print('Impossible')

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W=map(int,input().split())
A=[input()for i in range(H)]
for i in range(H):
    A[i]=A[i]+"."
A.append("."*(W+1))
p,q=1,1
c=1
t=0
for i in A:
    t+=i.count("#")
if t!=H+W-1:
    c=0
for i in range(H+W-2):
    print(p,q)
    if A[p-1][q-1]==".":
        c=0
        break
    if A[p][q-1]=="." and A[p-1][q]=="#":
        q+=1
    elif A[p][q-1]=="#" and A[p-1][q]==".":
        p+=1
    else:
        c=0
        break
print("Possible" if c else "Impossible")

H,W=map(int,input().split())
A=[input()for i in range(H)]
for i in range(H):
    A[i]=A[i]+"."
A.append("."*(W+1))
p,q=1,1
c=1
t=0
for i in A:
    t+=i.count("#")
if t!=H+W-1:
    c=0
for i in range(H+W-2):
    if A[p-1][q-1]==".":
        c=0
        break
    if A[p][q-1]=="." and A[p-1][q]=="#":
        q+=1
    elif A[p][q-1]=="#" and A[p-1][q]==".":
        p+=1
    else:
        c=0
        break
print("Possible" if c else "Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
A,B=list(map(int,input().split()))
l=[]
for i in range(A):
   l.append(list(input()))
c=0
for i in range(A):
   c+=l[i].count("#")
print(c)
print("POSSIBLE" if A+B-1 == c else "IMPOSSIBLE")

A,B=list(map(int,input().split()))
l=[]
for i in range(A):
   l.append(list(input()))
c=0
for i in range(A):
   c+=l[i].count("#")
print("POSSIBLE" if A+B-1 == c else "IMPOSSIBLE")

A,B=list(map(int,input().split()))
l=[]
for i in range(A):
   l.append(list(input()))
c=0
for i in range(A):
   c+=l[i].count("#")
print("Possible" if A+B-1 == c else "Impossible")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W=map(int, input().split())
cnt=0
for _ in range(H):
  a=list(input())
  cnt+=a.count("#")
if cnt==H*W-1:
  print("Possible")
else:
  print("Impossible")

H, W=map(int, input().split())
cnt=0
for _ in range(H):
  a=list(input())
  cnt+=a.count("#")
if cnt==(H+W-1):
  print("Possible")
else:
  print("Impossible")


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
def answer(matrix):
    h = len(matrix)
    w = len(matrix[0])
    P, IM = ("Possible", "Impossible")
    cp = [0, 0] 
    rightBottom = [len(matrix)-1, len(matrix[0])-1]
    while(True):
        matrix[cp[0]][cp[1]] = '.'
        # Up
        if cp[0] > 0 and matrix[cp[0]-1][cp[1]] == '#': return IM
        
        if cp[1] > 0 and matrix[cp[0]][cp[1]-1] == '#': return IM
        # Bottom
        if cp[0]+1 < h and matrix[cp[0]+1][cp[1]] == '#':
            if cp[1]+1 < w and matrix[cp[0]][cp[1]+1] == '#':
                return IM
            cp[0] = cp[0]+1
            print(cp)
            continue
        # Right
        if cp[1]+1 < w and matrix[cp[0]][cp[1]+1] == '#':
            cp[1] = cp[1]+1
            continue
        if cp[0] == rightBottom[0] and cp[1] == rightBottom[1]:
            return P
    return P

h, w = map(int, input().split())
matrix = []
for _ in range(h):
    row = [c for c in input()]
    matrix.append(row)
print(matrix)
print(answer(matrix))

def answer(matrix):
    h = len(matrix)
    w = len(matrix[0])
    P, IM = ("Possible", "Impossible")
    cp = [0, 0] 
    rightBottom = [len(matrix)-1, len(matrix[0])-1]
    while(True):
        matrix[cp[0]][cp[1]] = '.'
        # Up
        if cp[0] > 0 and matrix[cp[0]-1][cp[1]] == '#': return IM
        
        if cp[1] > 0 and matrix[cp[0]][cp[1]-1] == '#': return IM
        # Bottom
        if cp[0]+1 < h and matrix[cp[0]+1][cp[1]] == '#':
            if cp[1]+1 < w and matrix[cp[0]][cp[1]+1] == '#':
                return IM
            cp[0] = cp[0]+1
            continue
        # Right
        if cp[1]+1 < w and matrix[cp[0]][cp[1]+1] == '#':
            cp[1] = cp[1]+1
            continue
        if cp[0] == rightBottom[0] and cp[1] == rightBottom[1]:
            return P
    return P

h, w = map(int, input().split())
matrix = []
for _ in range(h):
    row = [c for c in input()]
    matrix.append(row)
print(answer(matrix))

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int,input().split());c=0
for i in range(h):
  a=input().split(".")
  c+=a.count("#")
print("Possible"if h+w-1==c else"Impossible")

h,w=map(int,input().split());c=0
for i in range(h):
  a=input().split(".")
  c+=len(a)
print("Possible"if h+w-1==ans else"Impossible")

h,w=map(int,input().split())
a=[input()for _ in range(h)]
c=0
for i in a:
  for j in i:
    if j=="#":c+=1
if c==h+w-1:print("Possible")
else:print("Impossible")

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w = map(int,input().split())
a = [list(input()) for nesya in range(h)]
b = [['.']*w for motsu in range(h)]
b[0][0] = '#'
j = 0
for i in range(h):
  while a[i][j+1] == '#':
    j += 1
    b[i][j] = '#'
  b[i+1][j] = '#'
if a == b:
  print('Possible')
else:
  print('Impossible')

h,w = map(int,input().split())
a = [list(input()) for nesya in range(h)]
if a.count('#') == h+w-1:
  print('Possible')
else:
  print('Impossible')

h,w = map(int,input().split())
a = [list(input()) for nesya in range(h)]
b = [['.']*w for motsu in range(h)]
b[0][0] = '#'
j = 0
for i in range(h):
  if j < w:
    while i<h and j+1 < w:
      if a[i][j+1] == '#':
        j += 1
        b[i][j] = '#'
        if j == w-1:
          break
  if i+1 < h:
    b[i+1][j] = '#'

if a == b:
  print('Possible')
else:
  print('Impossible')

h,w = map(int,input().split())
a = [list(input()) for nesya in range(h)]
c = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      c += 1

if c == h+w-1:
  print('Possible')
else:
  print('Impossible')

Verdicts: Runtime Error

Wrong Answer

Time Limit Exceeded

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W=4,5
a = [input() for i in range(H)]


ans=0
cnt=0

for i in range(H-1):
    for j in range(W-1):
        if a[i][j] == '#' and a[i+1][j] == '#' and  a[i][j+1] == '#':
            cnt+=1
            break
        elif a[i][j] == '#' and a[i+1][j] == '.' and  a[i][j+1] == '.':
            cnt+=1
            break
        else:
            continue
 
print('Impossible' if cnt>0 else 'Possible')
        


H,W=map(int, input().split())
a = [input() for i in range(H)]

ans=0
cnt=0
 
for i in range(H-1):
    for j in range(W-1):
        if a[i][j] == '#' and a[i+1][j] == '#' and  a[i][j+1] == '#':
            cnt+=1
        elif a[i][j] == '#' and a[i+1][j] == '.' and  a[i][j+1] == '.':
            cnt+=1

            
for i in range(1,H):
    for j in range(1,W):
        if a[i][j] == '#' and a[i-1][j] == '.' and  a[i][j-1] == '.':
            cnt+=1

        
print('Impossible' if cnt>0 else 'Possible')

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W = map(int,input().split())
li = [input() for i in range(H)]
print(li)
h,w = 0,0

while True: #h<=H-1 and w <=W-1:
    if (li[h+1][w] == "#" or li[h][w+1] == "#") and (li[h+1][w+1] == "#"):
        flag = True
    elif (li[h+1][w] == "#" or li[h][w+1] == "#") and (li[h+1][w+1] == "#") == False:
        print("Impossible")
        exit()
    print(li[h][w],h,w)
    h += 1
    w += 1
    if h == H-1 or w == W-1:
        break
if flag == True: # and li[H][W] == li[h-2][w-2]:
    print("Possible")
else:
    print("Impossible")

a,b = map(int,input().split())
cnt = 0
for i in range(a):
    s = input()
    cnt += s.count("#")

if cnt == a+b-1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
N = int(input())
P = [int(x) for x in input().split()]

a = [i* 10**3+1 for i in range(N)]
b= list(reversed(a))



for i in range(N):
    #P[i] =2* i
    p = P[i]-1
    a[p]+=i

print(" ".join(map(str,a)) )
print(" ".join(map(str,b)) )


def check():
    tmp =0
    for i in P:
        i-=1
        print(tmp<a[i]+b[i])
        tmp=a[i]+b[i]

#check()

H,W=[int(x) for x in input().split()]

A = [list(map(lambda x: x=="#" ,input())) for _ in range(H)]

#print(A)


try:
    for i in range(H):
        for j in range(W):
            if A[i][j]:
                start=i,j
                raise
except:
    pass


def a(i,j):
    if i<H and j<W:
        return A[i][j]
    return False

tmp =start
used = [start]
while True:
    #print(tmp)
    i,j =tmp
    if a(i+1,j):
        tmp = i+1,j
        used.append(tmp)
        continue
    if a(i,j+1):
        tmp = i ,j+1
        used.append(tmp)
    else:
        break

for i in range(H):
    for j in range(W):
        if A[i][j]:
            if (i,j) in used:
                continue
            else:
                #print(i,j)
                print("Impossible")
                exit()
print("Possible")


Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int,input().split())
s = [input() for i in range(h)]
def im():
  print("Impossible")
x=0
y=0
while 1==1:
  if x==0 and y==0:
    if s[x+1][y]=="#" and s[x][y+1]=="#":
      im()
      exit()
    elif s[x+1][y]=="#":
      x+=1
    elif s[x][y+1]=="#":
      y+=1
    else:
      im()
      exit()
  elif (x==0 and y!=w-1) or (y==0 and x!=h-1):
    if s[x+1][y]=="#" and s[x][y+1]=="#":
      im()
      exit()
    elif s[x+1][y]=="#":
      x+=1
    elif s[x][y+1]=="#":
      y+=1
    else:
      im()
      exit()
  elif x==h-1 and y!=w-1:
    if s[x][y+1]=="#":
      y+=1
    else:
      im()
      exit()
  elif x!=h-1 and y==w-1:
    if s[x+1][y]=="#":
      x+=1
    else:
      im()
      exit()
  elif x==h-1 and y==w-1:
    print("Possible")
    exit()
  else:
    
    c=0
    if s[x+1][y]=="#":
      c+=1
      x+=1
    if s[x][y+1]=="#":
      c+=1
      y+=1
    if s[x-1][y]=="#":
      c+=1
    if s[x][y-1]=="#":
      c+=1
    if c!=2:
      im()
      exit()

h,w=map(int,input().split())
s = [input() for i in range(h)]
a=0
for i in s:
  a+=i.count("#")
if a==h+w-1:
  print("Possible")
else:
  print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())
A = [["" for _ in range(w)] for _ in range(h)]
for i in range(h):
    a = input()
    for j in range(w):
        A[i][j] = a[j]

dx = [1, 0]
dy = [0, 1]

def bfs(x, y):
    if x == w - 1 and y == h - 1 and A[y][x] == "#":
        return 1
    if A[y][x] == ".":
        return 0
    for i in range(2):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx and nx < w and 0 <= ny and ny < h and A[y][x] == "#":
            return bfs(nx, ny) + 1

if bfs(0, 0) == h + w - 1:
    print("Possible")
else:
    print("Impossible")


h, w = map(int, input().split())
c = 0
A = [["" for _ in range(w)] for _ in range(h)]
for i in range(h):
    a = input()
    for j in range(w):
        A[i][j] = a[j]
    c += list(a).count("#")

dx = [1, 0]
dy = [0, 1]

def bfs(x, y):
    if x == w - 1 and y == h - 1 and A[y][x] == "#":
        return 1
    if A[y][x] == ".":
        return 0
    for i in range(2):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx and nx < w and 0 <= ny and ny < h and A[y][x] == "#":
            return bfs(nx, ny) + 1

s = "Impossible"
if c == h + w - 1:
    if bfs(0, 0) == h + w - 1:
        s = "Possible"
print(s)


h, w = map(int, input().split())
c = 0
for _ in range(h):
    a = list(input())
    c += a.count("#")
print(("Possible" if c == h + w - 1 else "Impossible"))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int,input().split())
a = [list(input()) for _ in range(H)]
c = 0
for p in a :
    for q in p:
        if q=="#":
            c +=1
 
if c == h + w - 1:
    print("Possible")
else:
    print("Impossible")

h, w = map(int,input().split())
a = [list(input()) for _ in range(h)]
c = 0
for p in a :
    for q in p:
        if q=="#":
            c +=1
 
if c == h + w - 1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w = map(int,input().split())
l = [list(input()) for _ in range(h)]
n = [0,1,0,-1]
m = [1,0,-1,0]

def dfs(a,b):
  if 0<=a+n[0] and a+n[0]<=w-1 and 0<=b+m[0] and b+m[0]<=h-1 and 0<=a+n[1] and a+n[1]<=w-1 and 0<=b+m[1] and b+m[1]<=h-1:
    if l[b+m[0]][a+n[0]]=="#" and l[b+m[1]][a+n[1]]=="#":
      return print("Impossible")
  for i in range(4):
    if 0<=a+n[i] and a+n[i]<=w-1 and 0<=b+m[i] and b+m[i]<=h-1:
      if l[b+m[i]][a+n[i]]=="#":
        if i==2 or i==3:
          return print("Impossible")

        elif a+n[i]==w-1 and b+m[i]==h-1:
          return print("Possible")
        else:
          return dfs(a+n[i],b+m[i])
      else:
        return print("Impossible")
    
        
dfs(0,0)

h,w = map(int,input().split())
l = [list(input()) for _ in range(h)]
n = [0,1,0,-1]
m = [1,0,-1,0]


def dfs(a,b):
  if 0<=a+n[0] and a+n[0]<=w-1 and 0<=b+m[0] and b+m[0]<=h-1 and 0<=a+n[1] and a+n[1]<=w-1 and 0<=b+m[1] and b+m[1]<=h-1:
    if l[b+m[0]][a+n[0]]=="#" and l[b+m[1]][a+n[1]]=="#":
      return print("Impossible")
  for i in range(4):
    if 0<=a+n[i] and a+n[i]<=w-1 and 0<=b+m[i] and b+m[i]<=h-1:
      if l[b+m[i]][a+n[i]]=="#":
        if i==2 or i==3:
          return print("Impossible")

        elif a+n[i]==w-1 and b+m[i]==h-1:
          cou = 0
          for i in l:
            for j in i:
              if j=="#":
                cou += 1
          if cou==2:
            return print("Possible")
          else:
            return print("Impossible")
        else:
          l[b+m[i]][a+n[i]] = "."
          #print(l)
          return dfs(a+n[i],b+m[i])
  else:
    return print("Impossible")
      
    
        
dfs(0,0)

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
import sys
import queue
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
print(a)

d = queue.Queue()
d.put([0, 0, 0])
vals = set()
while not d.empty():
    now = d.get()
    a[now[0]][now[1]] = 'a'
    if now[2] in vals:
        print('Impossible')
        sys.exit()
    else:
        vals.add(now[2])
        
    if now[0] == h-1 and now[1] == w-1:
        print('Possible')
        sys.exit()
    else:
        if now[0]+1 < h:
            if a[now[0]+1][now[1]] == '#':
                d.put([now[0]+1, now[1], now[2]+1])
        if now[1]+1 < w:
            if a[now[0]][now[1]+1] == '#':
                d.put([now[0], now[1]+1, now[2]+1])        
print('Impossible')


import sys
import queue
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = queue.Queue()
d.put([0, 0, 0])
vals = set()

while not d.empty():
    now = d.get()
    a[now[0]][now[1]] = '.'
    if now[2] in vals:
        print('Impossible')
        sys.exit()
    else:
        vals.add(now[2])
        
    if now[0] == h-1 and now[1] == w-1:
        a1 = [['.']*w for _ in range(h)]
        if a == a1:
            print('Possible')
        else:
            print('Impossible')
        sys.exit()
    else:
        if now[0]+1 < h:
            if a[now[0]+1][now[1]] == '#':
                d.put([now[0]+1, now[1], now[2]+1])
        if now[1]+1 < w:
            if a[now[0]][now[1]+1] == '#':
                d.put([now[0], now[1]+1, now[2]+1])        
print('Impossible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
a

H,W=map(int,input().split())
A=[]
for i in range(H):
  A.append(input())
#print(A)

sw=0
for i in range(H):
  tmp=0
  for j in range(W-1):
    if A[i][j]=="#" and A[i][j+1]==".":
      tmp=1
    if tmp==1 and A[i][j]=="." and A[i][j+1]=="#":
      sw=1
#print(sw)

if sw==1:
  print("Impossible")
else:
  l=[]
  r=[]
  for i in range(H):
    ll=0
    for j in range(W-1):
      if A[i][j]=="." and A[i][j+1]=="#":
        ll=j+1
        break
    l.append(ll)
    
    rr=W-1
    for j in range(W-1):
      if A[i][j]=="#" and A[i][j+1]==".":
        rr=j
        break
    r.append(rr)
#  print(l)
#  print(r)

  sw2=0
  for i in range(len(r)-1):
    if r[i]!=l[i+1]:
      sw2=1
  print("Impossible" if sw2==1 else "Possible")

Verdicts: Runtime Error

Accepted