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):
n=int(input())
a=[i*40000 for i in range(n)]
b=[40000**2-i for i in a]
p=list(map(int,input().split()))
for i in range(n):
  a[p[i]]+=i
  b[p[i]]+=i
print(*a)
print(*b)


n=int(input())
a=[i*30000+1 for i in range(n)]
b=[30000**2-i for i in a]
p=list(map(int,input().split()))
for i in range(n):
  a[p[i]-1]+=i
  b[p[i]-1]+=i
print(*a)
print(*b)


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


Verdicts: Runtime Error

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):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
b = 0
for i in range(h):
    a = list(ns())
    b += a.count('#')

ans = 'Possible' if b == (h+w-1) else 'Impossible'

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
b = [0,0]
for i in range(h):
    a = list(ns())
    c = [-1,w-1]
    for j in range(w):
        if c[0] == -1 and a[j] == '#':
            c[0] = j
        if c[0] != w-1 and a[j] == '.':
            c[1] = j-1
    if b[1] != c[0]:
        print('Impossible')
        exit()
    b = c

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
b = [0,0]
for i in range(h):
    a = list(ns())
    c = [-1,w-1]
    for j in range(w):
        if c[0] == -1 and a[j] == '#':
            c[0] = j
        if c[0] != -1 and a[j] == '.':
            c[1] = j-1
    if b[1] != c[0]:
        print('Impossible')
        exit()
    b = c

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()
b = 0
for i in range(h):
    a = list(ns())
    b += a.count('#')

ans = 'Possible' if b == (h+w-1) else 'Impossible'
print(ans)

Verdicts: Wrong Answer

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())
As = list(chain.from_iterable([list(input()) for i in range(h)]))
print("Possible" if As.count("#") == h + w - 1 else "Impossible")

from itertools import chain
h, w = map(int, input().split())
As = list(chain.from_iterable([list(input()) for i in range(h)]))
print("Possible" if As.count("#") == h + w - 1 else "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())
c = 0
for i in ranege(h):
    c += list(input()).count('#')
if c == h+w-1:
    print('Possible')
else:
    print('Imipossible')

h,w = map(int,input().split())
c = 0
for i in range(h):
    c += list(input()).count('#')
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,m = list(map(int,input().split()))

count = h+m

for i in range(h):
    b =(list(input()))
    count -= b.count('#')
if count == 1:
    print('Impossible')

h,m = list(map(int,input().split()))

count = h+m

for i in range(h):
    b =(list(input()))
    count -= b.count('#')
if count == 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 = [list(input()) for _ in range(h)]

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

stack = [[0 for _ in range(w)] for _ in range(h)]

def dfs(y, x):
    stack[y][x] = 1
    if x == w-1 and y == h-1:
        return
    for i in range(2):
        ny = y + dy[i]
        nx = x + dx[i] 
        if ny < 0 or ny >= h or nx < 0 or nx >= w:
            continue
        if a[ny][nx] == "#":
            dfs(ny, nx)
            break
    return

dfs(0, 0)
for i in range(h):
    for j in range(w):
        if a[i][j] == "#" and stack[i][j] == 0:
            print('Impossible')
                exit()
    print('Possible')

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

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

stack = [[0 for _ in range(w)] for _ in range(h)]

def dfs(y, x):
    stack[y][x] = 1
    if x == w-1 and y == h-1:
        return
    for i in range(2):
        ny = y + dy[i]
        nx = x + dx[i] 
        if ny < 0 or ny >= h or nx < 0 or nx >= w:
            continue
        if a[ny][nx] == "#":
            dfs(ny, nx)
            break
    return

dfs(0, 0)
for i in range(h):
    for j in range(w):
        if a[i][j] == "#" and stack[i][j] == 0:
            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):

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    short h,w,ans = 0;
    cin >> h >> w;
    char ai[10];
    rep(i,h) {
        cin >> ai;
        rep(j,8) if (ai[j] == '#') ans ++;
    }
    if (ans == h+w-1) cout << "Possible\n";
    else cout << "Impossible\n";
}

h,w = map(int,input().split())
ans = 0
for i in range(h):
    ans += input().count("#")
print("Possible" if ans == h+w-1 else "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())

A = []
for _ in range(H):
    A.append(list(input()))

cnt = 0
for aa in A:
    for aaa in aa:
        if aaa == '#':
            cnt += 1

if cnt == H * W - 1:
    print("Possible")
else:
    print("Impossible")


H, W = map(int, input().split())

A = []
for _ in range(H):
    A.append(list(input()))

cnt = 0
for aa in A:
    for aaa in aa:
        if aaa == '#':
            cnt += 1

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 solve(h, w, a):
    a = list(map(list, a))
    que = [(0,0)]
    a[0][0] = "."
    total = 0
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                total += 1
    while que:
        cr, cc = que.pop(0)
        for dr, dc in [(1,0),(0,1)]:
            nr, nc = cr+dr, cc+dc
            if (0 <= nc < w) and (0 <= nr < h) and a[nr][nc] == "#":
                a[nr][nc] = "."
                que.append((nr, nc))
    return "Possible" if (a[h-1][w-1] == ".") and (total == h+w-1) else "Impossible"

h, w = map(int, input().split())
a = [input() for r in range(h)]
print(solve(h, w, a))

def solve(h, w, a):
    a = list(map(list, a))
    total = 0
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                total += 1
    que = [(0,0)]
    a[0][0] = "."
    while que:
        cr, cc = que.pop(0)
        for dr, dc in [(1,0),(0,1)]:
            nr, nc = cr+dr, cc+dc
            if (0 <= nc < w) and (0 <= nr < h) and a[nr][nc] == "#":
                a[nr][nc] = "."
                que.append((nr, nc))
    return "Possible" if (a[h-1][w-1] == ".") and (total == h+w-1) else "Impossible"

h, w = map(int, input().split())
a = [input() for r in range(h)]
print(solve(h, w, a))

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())
l=[input() for i in range(h)]
p = [1,1]
cnt = 0
for i in range(h):
  cnt += l[i].count('#')
if cnt != h+w-1:
  print('Possible')
else:
  print('Impossible')

h,w = map(int,input().split())
l=[input() for i in range(h)]
p = [1,1]
cnt = 0
for i in range(h):
  cnt += l[i].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):
h,w=map(int,input().split())
bd = [[.]+list(input().split())+[.] for i in range(h)]
bd.insert(0,[.]*(w+1))
bd.append([.]*(w+1))
for i in range(h):
  for j in range(w):
    if bd[i][j] == "#":
      if i == h and j == w:
        print("Possible")
        break
      if bd[i+1][j] == bd[i+1][j]:
        print("Impossible")
        break
      if bd[i-1][j] == "#" or bd[i][j-1] == "#":
        print("Impossible")
        break
      bd[i][j]="."

h,w=map(int,input().split())
bd = [list("."+input()+".") for i in range(h)]
bd.insert(0,["."]*(w+2))
bd.append(["."]*(w+2))
stack=[(1,1)]
while(stack):
  i,j=stack.pop()
  if i == h and j == w:
    bd[i][j]="."
    break
  if bd[i+1][j] == bd[i][j+1]:
    print("Impossible")
    exit()
  if bd[i-1][j] == "#" or bd[i][j-1] == "#":
    print("Impossible")
    exit()
  if bd[i+1][j] == "#":
    stack.append((i+1,j))
  if bd[i][j+1] == "#":
    stack.append((i,j+1))
  bd[i][j] = "."
if bd == [["." for i in range(w+2)] for j in range(h+2)]:
  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())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0], [-1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')

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

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0, -1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

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 = [int(x) for x in input().split()]
A = [list(input()) for _ in range(H)]
#%%
def dfs(h,w):
    if(A[h][w]=='.'):
        return False
    else:
        A[h][w]='.'
        if(w<W-1):
            dfs(h,w+1)
        elif(h<H-1):
            dfs(h+1,w)
        return True

dfs(0,0)
for a in A:
    if('#' in a):
        print('Impossible')
        break
else:
    print('Possible')


H,W = [int(x) for x in input().split()]
A = [list(input()) for _ in range(H)]
#%%
def dfs(h,w):
    if(A[h][w]=='.'):
        return False
    else:
        A[h][w]='.'
        x = False
        if(w<W-1):
            x = dfs(h,w+1)
        if(not x and h<H-1):
            dfs(h+1,w)
        return True

dfs(0,0)
for a in A:
    if('#' in a):
        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())
table = []
for i in range(h):
    table.append(list(input()))
poss = True
for i in range(h-1):
    for j in range(w-1):
        if table[i][j] == "#":
            if (table[i+1][j]=="#" and table[i][j+1]=="#") or (table[i+1][j]=="." and table[i][j+1]=="."):
                poss = False
for i in range(1, h):
    if table[i][w-1]=="#" and table[i-1][w]=="#":
        poss = False
for i in range(1, w):
    if table[h][i-1]=="#" and table[h-1][i]=="#":
        poss = False

if poss:
    print("Possible")
else:
    print("Impossible")


h, w = map(int, input().split())
table = []
for i in range(h):
    table.append(list(input()))
poss = True
for i in range(h-1):
    for j in range(w-1):
        if table[i][j] == "#":
            if (table[i+1][j]=="#" and table[i][j+1]=="#") or (table[i+1][j]=="." and table[i][j+1]=="."):
                poss = False
for i in range(1, h):
    if table[i][w-2]=="#" and table[i-1][w-1]=="#":
        poss = False
for i in range(1, w):
    if table[h-1][i-1]=="#" and table[h-2][i]=="#":
        poss = False

if poss:
    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=[]
for i in range(h):
  l.append(input())
if ''.join(l)=='##....##....##....##':
  exit()
for i in range(h-1):
  for j in range(w-1):
    if l[i][j]=='#'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='#':
      print('Impossible')
      exit()
    if l[i][j]=='.'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='#':
      print('Impossible')
      exit()
    if l[i][j]=='#'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='.':
      print('Impossible')
      exit()
print('Possible')

h,w=map(int,input().split())
l=[]
for i in range(h):
  l.append(input())
for i in range(h-1):
  for j in range(w-1):
    if l[i][j]=='#'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='#':
      print('Impossible')
      exit()
    if l[i][j]=='.'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='#':
      print('Impossible')
      exit()
    if l[i][j]=='#'and l[i][j+1]=='#'and l[i+1][j]=='#'and l[i+1][j+1]=='.':
      print('Impossible')
      exit()
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())
aaa = [input().replace('#','1').replace('.','0') for _ in range(h)]

ans = 'Impossible'
for i in range(h-1):
    
    if int(aaa[i+1]) > int(aaa[i]):
        # print('left')
        break
    
    updown = bin(int(aaa[i],2) & int(aaa[i+1],2))
    if updown.count('1') >1:
        # print('updown')
        break
else:
    ans = 'Possible'
print(ans)

for a in aaa:
    print(a)

h,w = map(int, input().split())
aaa = [input().replace('#','1').replace('.','0') for _ in range(h)]

ans = 'Impossible'
for i in range(h-1):
    
    updown = bin(int(aaa[i],2) & int(aaa[i+1],2))
    if updown.count('1') >1:
        # print('updown')
        break
    
    
    if aaa[i+1].index('1') < aaa[i].rindex('1'):
    # int(aaa[i+1]) > int(aaa[i]):
        # print('left')
        break
else:
    ans = 'Possible'
print(ans)

# for a in aaa:
#     print(a)

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
H,W = [int(i) for i in input().split()]
A = [list(input().strip()) for j in range(H)]
print(A)

q = [(0,0)]
while q:
  h,w = q.pop()
  if (h,w) == (H-1,W-1):
    A[h][w] = '.'
    break
  for dh,dw in [(1,0),(0,1)]:
    nh,nw = h+dh,w+dw
    if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '#':
      q.append((nh,nw))
      A[h][w] = '.'
      break
  else:
    print('Impossible')
    sys.exit()
print(A)

for h in range(H):
  for w in range(W):
    if A[h][w] == '#':
      print('Impossible')
      sys.exit()
print('Possible')

import sys
H,W = [int(i) for i in input().split()]
A = [list(input().strip()) for j in range(H)]

q = [(0,0)]
while q:
  h,w = q.pop()
  if (h,w) == (H-1,W-1):
    A[h][w] = '.'
    break
  for dh,dw in [(1,0),(0,1)]:
    nh,nw = h+dh,w+dw
    if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '#':
      q.append((nh,nw))
      A[h][w] = '.'
      break
  else:
    print('Impossible')
    sys.exit()

for h in range(H):
  for w in range(W):
    if A[h][w] == '#':
      print('Impossible')
      sys.exit()
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())
field = [["."] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    a = list(input())
    for j in range(1,W+1):
        if a[j-1] == "#":
            field[i][j] = "#"
p_i,p_j = 1,1
while True:
    top = field[p_i - 1][p_j]
    right = field[p_i][p_j + 1]
    bottom = field[p_i + 1][p_j]
    left = field[p_i][p_j - 1]
    if (top,right,bottom,left) == (".","#",".","."):
        p_j += 1
    elif (top,right,bottom,left) == (".",".","#","."):
        p_i += 1
    else:
        ans = "Impossible"
        break
    if (p_i,p_j) == (H,W):
        ans = "Possible"
        break
print(ans)

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

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())
pos = [[0, 0]]
S = [input() for i in range(H)]
p = 1
def whiteout(Map, h, w):
  y = 0
  for i in range(h):
    for j in range(w):
      if Map[i][j] == '#':
        y += 1
  return y == 0

while pos != [H-1, W-1]:
  cnt = 0
  x, y = pos[0], pos[1]
  S[x] = S[x][:y] + '.' + S[x][y+1:]
  if x < H-1:
    if S[x+1][y] == '#':
      cnt += 1
      pos = [x+1, y]
  if y < W-1:
    if S[x][y+1] == '#':
      cnt += 1
      pos = [x, y+1]
  if cnt != 1:
    p = 0
    break
S[H-1] = S[H-1][:W-1] + '.'
if p == 1 and whiteout(S, H, W):
  print("Possible")
else:
  print("Impossible")


H, W = map(int, input().split())
pos = [0, 0]
S = [input() for i in range(H)]
p = 1
def whiteout(Map, h, w):
  y = 0
  for i in range(h):
    for j in range(w):
      if Map[i][j] == '#':
        y += 1
  return y == 0

while pos != [H-1, W-1]:
  cnt = 0
  x, y = pos[0], pos[1]
  S[x] = S[x][:y] + '.' + S[x][y+1:]
  if x < H-1:
    if S[x+1][y] == '#':
      cnt += 1
      pos = [x+1, y]
  if y < W-1:
    if S[x][y+1] == '#':
      cnt += 1
      pos = [x, y+1]
  if cnt != 1:
    p = 0
    break
S[H-1] = S[H-1][:W-1] + '.'
if p == 1 and whiteout(S, H, W):
  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):
from sys import stdin,setrecursionlimit
from itertools import groupby
setrecursionlimit(10**7)
h,w = map(int,stdin.readline().rstrip().split())
li = [["" for i in range(w)]for j in range(h)]
for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]
now = 0
last = 0
for i in range(h):
    flag = True
    for j in range(w):
        lin = []
        for key, value in groupby(li[i]):
            lin.append(key)
        if lin.count("#") >= 2:
            print("Impossible")
            exit()
        if li[i][j] == "#" and flag:
            now = j
            flag = False
        if i >= 1 and now != last:
            print("Impossible")
            exit()
        if (flag == False and li[i][j] == "."):
            last = j-1
            break
        if  (not flag and j == w-1):
            last = j
            break
if last == w-1:
    print("Possible")
else:
    print("Impossible")

h,w = map(int,input().split())
point = 0
for _ in range(h):
    s = input()
    point += s.count("#")

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

Verdicts: Wrong Answer

Accepted
Problem: There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.  Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:    * _Move_ : When at town i (i < N), move to town i + 1.   * _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.  For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)  During the travel, Takahashi will perform actions so that the _profit_ of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.  Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.  Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Submission attempts (in order):
#!/usr/bin python3
# -*- coding: utf-8 -*-

n, t = map(int, input().split())
a = list(map(int, input().split()))
b = [a[-1]] * n
for i in range(n-2,-1,-1):
    b[i] = min(b[i+1], a[i])
print(b)

#!/usr/bin python3
# -*- coding: utf-8 -*-

import bisect

n, t = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
p = [0] * n
for i in range(n-1,-1,-1):
    mx = max(mx, a[i])
    p[i] = mx - a[i]
p.sort()
print(n-bisect.bisect_left(p, p[-1]))


Verdicts: Wrong Answer

Accepted
Problem: There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.  Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:    * _Move_ : When at town i (i < N), move to town i + 1.   * _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.  For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)  During the travel, Takahashi will perform actions so that the _profit_ of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.  Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.  Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Submission attempts (in order):
n, t = map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
max_diff = 0
min_a = A[0]
for a in A:
    min_a = min(min_a, a)
    if (a - min_a) == max_diff:
        ans += 1
    elif (a - min_a) > max_diff:
        ans = 1
        max_diff = (a - min_a)
print(ans)


# f = open('input', 'r')
# n, t = map(int, f.readline().split())
# A = list(map(int, f.readline().split()))
n, t = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
max_diff = 0
min_a = A[0]
for a in A:
    min_a = min(min_a, a)
    if (a - min_a) == max_diff:
        ans += 1
    elif (a - min_a) > max_diff:
        ans = 1
        max_diff = (a - min_a)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.  Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:    * _Move_ : When at town i (i < N), move to town i + 1.   * _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.  For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)  During the travel, Takahashi will perform actions so that the _profit_ of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.  Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.  Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Submission attempts (in order):
s=input().split()
l=[]
for i in range(1,len(s)):
  l.append(int(s[i])-int(s[i-1]))
l.sort()
m=l[-1]
for i in range(2,len(s)+1):
  if l[-i]!=m:
    break
print(i-1)

print(2)

n=int(input().split()[0])
s=input().split()
l=[0 for i in range(n)]
m=[0 for i in range(n)]
M=[0 for i in range(n)]
for i in range(n):
  l[i]=int(s[i])
m[0]=l[0]
M[0]=l[-1]
for i in range(1,n):
  m[i]=min(m[i-1],l[i])
  M[i]=max(M[i-1],l[-i-1])
M.reverse()
d=[M[i]-m[i] for i in range(n)]
ma=max(d)
memo=-1
cnt=0
for i in range(n):
   if d[i]==ma and m[i]!=memo:
      cnt+=1
      memo=m[i]
print(cnt)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.  Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:    * _Move_ : When at town i (i < N), move to town i + 1.   * _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.  For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)  During the travel, Takahashi will perform actions so that the _profit_ of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.  Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.  Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Submission attempts (in order):
from numpy import *
input()
a=array(input().split())
d=a-minimum.accumulate(a)
print((d==d.max()).sum())


from numpy import *
input()
a=array(input().split(),dtype=int)
d=a-minimum.accumulate(a)
print((d==d.max()).sum())

Verdicts: Runtime Error

Accepted