TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
H,W = map(int,input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
while True:
    r_change = False
    for q in range(len(grid)):
        if "#" not in grid[q]:
            del grid[q]
            r_change = True
            break
    if not r_change:
        break
while True:
    c_change = False
    for k in range(len(grid[0])):
        if "#" not in [row[k] for row in grid]:
            grid = [[row[p] for p in range(len(row)) if p != k] for row in grid]
            c_change = True
            break
    if not c_change:
        break
print(grid)

H,W = map(int,input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
while True:
    r_change = False
    for q in range(len(grid)):
        if "#" not in grid[q]:
            del grid[q]
            r_change = True
            break
    if not r_change:
        break
while True:
    c_change = False
    for k in range(len(grid[0])):
        if "#" not in [row[k] for row in grid]:
            grid = [[row[p] for p in range(len(row)) if p != k] for row in grid]
            c_change = True
            break
    if not c_change:
        break
for row in grid:
    print("".join(row))

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

# Filtering the data if any "#" are existed in the each row or col

# If true, the row is not be deleted
# (Do not use if statement!)
row_compressed_grid = list(filter(lambda row: any(x == "#" for x in row), grid)) 
compressed_grid = list(filter(lambda col: any(x == "#" for x in col), zip(*row_compressed_grid)))

# list -> string and out
for row in compressed_grid:
    print("".join(row))

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

# Filtering the data if any "#" are existed in the each row or col

# If true, the row is not be deleted
# (Do not use if statement!)
row_compressed_grid = list(filter(lambda row: any(x == "#" for x in row), grid))
compressed_grid = list(filter(lambda col: any(x == "#" for x in col), zip(*row_compressed_grid)))
# list -> string and out
for row in zip(*compressed_grid):
    print("".join(row))

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
import numpy as np

H, W = map(int, input().split())
a = np.array(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input().split()]

y = [True] * H
 i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")


 numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input().split()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")


 numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")


import numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
print(a)
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
print(row)
print(col)
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h,w = map(int,input().split())
a = list()

for i in range(h):
  a.append(list(map(int, input().split())))

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  for j in range(w):
    if h_blank[i] or w_blank[j]:
      continue
    print(a[i][j])

h,w = map(int,input().split())
a = list()

for i in range(h):
  a.append(input())

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  for j in range(w):
    if h_blank[i] or w_blank[j]:
      continue
    print(a[i][j])

h,w = map(int,input().split())
a = list()

for i in range(h):
  a.append(list(map(int, input().split())))

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  for j in range(w):
    if h_blank[i] or w_blank[j]:
      continue
    print(a[i][]j)

h,w = map(int,input().split())
a = list()

for i in range(h):
  a.append(input())

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  if h_blank[i]:
    continue
  for j in range(w):
    if w_blank[j]:
      continue
    print(a[i][j], end='')
  print('')

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
a = list(map(int,input().split()))
h = a[0]
w = a[1]
li=[input() for i in range(h)]

ans = 0
minans = 0
flag = 0
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            row[i]=True
            col[j]= True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(li[i][j],end =" ")
                
        print()


a = list(map(int,input().split()))
h = a[0]
w = a[1]
li=[input() for i in range(h)]

ans = 0
minans = 0
flag = 0
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            row[i]=True
            col[j]= True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(li[i][j],end ="")
                
        print()

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
import numpy as np

h, w = tuple(map(int, input().split()))
matrix = np.zeros((h, w), dtype=bool)
for i in range(h):
    row = np.array(input().split())
    matrix[i, :] = row == "."

for i in range(h)[::-1]:
    if np.all(matrix[i, :]):
        matrix = np.delete(matrix, i, 0)

for i in range(w)[::-1]:
    if np.all(matrix[:, i]):
        matrix = np.delete(matrix, i, 1)

matrix = np.where(matrix, ".", "#")
for row in matrix:
    for e in row:
        print(e+" ", end="")
    print("\b")



h, w = map(int, input().split())

mat = [input() for _ in range(h)]


[mat.remove(row) for row in mat[::-1] if ("#" not in row)]

showCol = [i for i in range(w) if "#" in [row[i] for row in mat]]


print("\n".join(["".join([row[c] for c in showCol]) for row in mat]))


Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h,w = map(int,input().split())

f = []

for i in range(h):
    f.append(list(input()))
    
for i in f:
    if i == ["."]*len(i):
        f.remove(i)
        
f2 = []

for i in range(w):
    s = []
    
    for k in f:
        s.append(k[i])
        
    f2.append(s)
    
for i in f2:
    if i == ["."]*len(i):
        f2.remove(i)
        
for i in f2:
    for s in range(len(i)-1):
        print(i[s],end = "")
    
    print(i[-1])

h,w = map(int,input().split())

f = []

for i in range(h):
    f.append(list(input()))
    
a = []
    
for i in range(len(f)):
    if f[i] == ["."]*len(f[i]):
        a.append(i)
        
for i in a:
    del f[i]
    for s in range(len(a)):
        a[s] -= 1
        
f2 = []

for i in range(w):
    s = []
    
    for k in f:
        s.append(k[i])
        
    f2.append(s)
    
b = []
    
for i in range(len(f2)):
    if f2[i] == ["."]*len(f2[i]):
        b.append(i)
        
for i in b:
    del f2[i]
    for s in range(len(b)):
        b[s] -= 1
        
ff = []

for i in range(len(f2[0])):
    s = []
    
    for k in f2:
        s.append(k[i])
        
    ff.append(s)
        
for i in ff:
    for s in range(len(i)-1):
        print(i[s],end = "")
    
    print(i[-1])

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h, w = map(int, input().split())
hlist = []
wlist = []
a = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            hlist.append(i)
            wlist.append(j)
print(hlist,wlist)
for i in set(hlist):
    for j in set(wlist):
        print(a[i][j], end ="")
    print()

h, w = map(int, input().split())
hlist = []
wlist = []
a = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            hlist.append(i)
            wlist.append(j)
for i in set(hlist):
    for j in set(wlist):
        print(a[i][j], end ="")
    print()

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if "#" in x]
print(*b)
c = zip(*[y for y in zip(*b) if "#" in y])
#print(list(c))
for d in c:
  print("".join(d))

h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if "#" in x]
#print(*b)
c = zip(*[y for y in zip(*b) if "#" in y])
#print(list(c))
for d in c:
  print("".join(d))

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline()[:-1] 
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
Grid = []
for _ in range(H):
    s = ns()
    if '#' in s:
        Grid.append(list(s))

h = len(Grid)
res = []
for i in range(W):
    s = ''
    for j in range(h):
        s += Grid[j][i]
    if '#' in s:
        res.append(s)

for i in range(len(res[0])):
    s = ''
    for j in range(len(res)):
        s += res[-1-j][i]
    print(s)


# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline()[:-1] 
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
Grid = []
for _ in range(H):
    s = ns()
    if '#' in s:
        Grid.append(list(s))

h = len(Grid)
res = []
for i in range(W):
    s = ''
    for j in range(h):
        s += Grid[j][i]
    if '#' in s:
        res.append(s)

for i in range(len(res[0])):
    s = ''
    for j in range(len(res)):
        s += res[j][i]
    print(s)



Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
# -*- coding: utf-8 -*-

h,w = map(int, input().split())

a = [list(input()) for _ in range(h)]

a_new = []
for row in a:
    cache = set(row)
    if (len(cache) == 1) and (row[0] == "."):
        pass
    else:
        a_new.append(row)

n_h = len(a_new)
n_w = len(a_new[0])

b_new = [["" for _ in range(n_h)] for _ in range(n_w)]

for i in range(n_h):
    for j in range(n_w):
        b_new[j][i]=a_new[i][j]


a = b_new

a_new = []
for row in a:
    cache = set(row)
    if (len(cache) == 1) and (row[0] == "."):
        pass
    else:
        a_new.append(row)


n_h = len(a_new)
n_w = len(a_new[0])

b_new = [["" for _ in range(n_h)] for _ in range(n_w)]

for i in range(n_h):
    for j in range(n_w):
        b_new[j][i]=a_new[i][j]


ans = ""

for i in range(n_h):
    for j in range(n_w):
        ans += b_new[i][j]
    ans += "\n"

print(ans)

# -*- coding: utf-8 -*-

h, w = map(int, input().split())
a = [""]*h
for i in range(h):
    a[i] = input()

row = [False] * h
col = [False] * w


for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True


for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end = "")

        print()


Verdicts: Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

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

for i in range(h)[::-1]:
    if "#" not in a[i]:
        del a[i]
        h -= 1
print(a)

n = []
for j in range(w):
    print("j=" + str(j))
    m = ["".join(t[j] for t in a)]
    if "#" in m[0]:
        n += m
print(n)

for k in range(h):
    print("".join(n[k]))


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

for i in range(h)[::-1]:
    if "#" not in a[i]:
        del a[i]
        h -= 1

n = []
for j in range(w):
    m = ["".join(t[j] for t in a)]
    if "#" in m[0]:
        n += m

for k in range(h):
    print("".join(u[k] for u in n))


Verdicts: Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
N, M = map(int, input().split())
a = [input() for i in range(N)]
counter = 0
numlist = []
delMlist = []

for i in range(N):
    #print(a[i])
    if a[i].count('#') == 0:
        delMlist.append(i)
#print(delMlist)

for i in delMlist:
    a.pop(i-counter)
    #print(a)
    counter += 1
print('---------')
#print(a)
N = N - len(delMlist)
#print(N)
newlist = []
for i in range(N):   
    for j in range(M):
        if a[i][j] == '.' :
            numlist.append([i,j])
    newlist.append([a[i]])
llist = []
for i in range(N):
    
    llist.append(list(a[i]))

counter1 = 0
fst = ''
delNlist = []
#print(N)
for i in range(M):
    for j in range(N):
        #print(j)
        if llist[j][i] == '.':
            counter1 += 1
        if counter1 == N:
            delNlist.append(i)
    counter1 = 0
#print(delNlist)
#print('---------')
#anslist = []
counter2 = 0
if delNlist != []:
    for h in delNlist:
        for i in range(N):
            a[i] = (a[i][:h-counter2] + a[i][h+1-counter2:])
        counter2 += 1
for i in a:
    print(i)
#print(a)  

N, M = map(int, input().split())
a = [input() for i in range(N)]
counter = 0
numlist = []
delMlist = []

for i in range(N):
    #print(a[i])
    if a[i].count('#') == 0:
        delMlist.append(i)
#print(delMlist)

for i in delMlist:
    a.pop(i-counter)
    #print(a)
    counter += 1
#print('---------')
#print(a)
N = N - len(delMlist)
#print(N)
newlist = []
for i in range(N):   
    for j in range(M):
        if a[i][j] == '.' :
            numlist.append([i,j])
    newlist.append([a[i]])
llist = []
for i in range(N):
    
    llist.append(list(a[i]))

counter1 = 0
fst = ''
delNlist = []
#print(N)
for i in range(M):
    for j in range(N):
        #print(j)
        if llist[j][i] == '.':
            counter1 += 1
        if counter1 == N:
            delNlist.append(i)
    counter1 = 0
#print(delNlist)
#print('---------')
#anslist = []
counter2 = 0
if delNlist != []:
    for h in delNlist:
        for i in range(N):
            a[i] = (a[i][:h-counter2] + a[i][h+1-counter2:])
        counter2 += 1
for i in a:
    print(i)
#print(a)  
        

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
from sys import stdin
import numpy as np

h,w= [int(x) for x in 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]

li = np.asarray([s for s in li if s != ['.']*w]).T.tolist()
li = np.asarray([s for s in li if s != ['.']*len(li[0])]).T.tolist()

for i in range(len(li)):
    print(*li[i])

from sys import stdin,setrecursionlimit
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]
lin = []
for i in li:
    if i != ["."]*w:
        lin.append(i)
out = []
for i in range(w):
    flag = True
    for j in range(len(lin)):
        if lin[j][i] == "#":
            flag = False
    if flag:
        out.append(i)

lis = []
for i in lin:
    case = []
    for j,k in enumerate(i):
        if j in out:
            continue
        case.append(k)
    lis.append(case)

for i in lis:
    print("".join(i))

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h, w = map(int, input().split())
a = []
delrow = []
delcol = []


for i in range(h):
    a.append(list(input()))

for i in range(h):
    print(set(a[i]))
    if set(a[i]) == {"."}:
        delrow.append(i)

for i in range(w):
    print(set(a[0:w][i]))
    if set(a[0:w][i]) == {"."}:
        delcol.append(i)
        
for i in delrow [::-1]: 
    del a[i]
for i in delcol [::-1]: 
    for j in range(len(a)):
        del a[j][i]

for i in range(len(a)):
    print(*a[i], sep="")

h, w = map(int, input().split())
a = []
delrow = []
delcol = []


for i in range(h):
    a.append(list(input()))

for i in range(h):
    if set(a[i]) == {"."}:
        delrow.append(i)

for i in range(w):
    if set(a[0:w][i]) == {"."}:
        delcol.append(i)
        
for i in delrow [::-1]: 
    del a[i]
for i in delcol [::-1]: 
    for j in range(len(a)):
        del a[j][i]

for i in range(len(a)):
    print(*a[i], sep="")

h, w = map(int, input().split())
a = []
colrow = []

for i in range(h):
    b = list(input())
    if set(b) == {"."}:
            continue
    a.append(b)

for x in zip(*a): 
    if set(x) == {"."}:
        continue
    colrow.append(x)

for x in zip(*colrow):
    print(*x, sep="")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
print(A)




# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, product


def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    for i in C:
        print(*i, sep='')

        # print(*C,sep='')


resolve()

Verdicts: Wrong Answer

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
H,W = map(int,input().split())

A = ""

for _ in range(H):
  s = input()
  if len(set(s)) == 1 and s == "." * W:
    H -= 1
  else:
    for i in s:
      A.append(i)

if len(A) == 0:
  print(A)

else:
  M = []

  for i in range(W):
    if A[i] == ".":
      for j in range(i + W,H * W,W):
        if A[j] == "#":
          break
      else:
        M.append(i)

  A = [A[i] for i in range(H * W) if not (i % W) in M]
  W = W - len(M)
  
  S = ""
  
  for i in range(H * W):
    S += A[i]
    if (i + 1) % W == 0:
      print(S)
      S = ""

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

A = ""

for _ in range(H):
  s = input()
  if len(set(s)) == 1 and s == "." * W:
    H -= 1
  else:
    for i in s:
      A += i

if len(A) == 0:
  print(A)

else:
  M = []

  for i in range(W):
    if A[i] == ".":
      for j in range(i + W,H * W,W):
        if A[j] == "#":
          break
      else:
        M.append(i)

  A = [A[i] for i in range(H * W) if not (i % W) in M]
  W = W - len(M)
  
  S = ""
  
  for i in range(H * W):
    S += A[i]
    if (i + 1) % W == 0:
      print(S)
      S = ""

Verdicts: Runtime Error

Accepted
Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h,w=map(int,input().split())
lis=[list(input()) for i in range(h)]

fin=[]

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  else:  
    h=h-1

num=[]
for i in range(w):
  cnt=0
  for f in fin:
    if f[i] == ".":
      cnt+=1
  if cnt == h:
    num.append(i)
      
for i in num:
  for f in fin:
    f.pop(i)
    
for i in fin:
  print(*i)

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

fin=[]
ans=[]

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  else:  
    h=h-1

tr = []
for i in range(w):
    tr_row = []
    for vector in fin:
        tr_row.append(vector[i])
    tr.append(tr_row)
    
for t in tr:
  if t.count(".") != h:
    ans.append(t)
  else:  
    w=w-1
    
for i in range(w):
    tr_row = []
    for vector in ans:
        tr_row.append(vector[i])
    print(*tr_row)


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

fin=[]
num=[0]*w

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  for i in range(w):
    if l[i]==".":
      num[i]+=1

for f in fin:
  ans=[]
  for i in range(len(num)):
    if num[i]!=h:
      ans.append(f[i])
  print(*ans,sep='')
    

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
N, K = map(int, input().split())
ary = [0] + list(map(int, input().split()))
ary = sorted(ary)
a = ary.index(0)
ans = float("Inf")
for i in range(N + 1):
    if i == a: continue

    k = abs(i - a)
    d = abs(ary[i])
    if k >= K and ans > d:
        ans = d
    if i < a:
        k = K - abs(i - a)
        d = abs(ary[i])
        print(k,d)
        if k > 0 and len(ary[a:]) > k:
            d += abs(ary[i] - ary[k + a])
            if ans > d:
                ans = d

print(0 if ans == float("Inf") else ans)


N, K = map(int, input().split())
ary = list(map(int, input().split()))
ary2 = sorted(ary+[0])
zero = ary2.index(0)
k = [abs(i - zero) if i < zero else ((i + 1) - zero)for i in range(N)]
ans = float("Inf")
for i in range(N - K + 1):
    if k[i] <= K:
        if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):
            ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])
for i in range(N-1, K-2, -1):
    if k[i] <= K:
        if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K-1)]):
            ans = abs(ary[i]) + abs(ary[i] - ary[i - (K-1)])
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

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

ans = 0
for i in range(n):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)

n,k=map(int,input().split())
x=list(map(int,input().split()))
a=10**9
for i in range(n-k+1):
  d=x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]))
  a=min(a,d)
print(a)


Verdicts: Runtime Error

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
import bisect
n, k = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

lft_num = bisect.bisect(x, 0)
rgt_num = n - lft_num

print(rgt_num, lft_num)
ans = 10**10
for i in range(min(rgt_num, k)):
    r = x[lft_num + i]
    distance = abs(r)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num - (k-i-1) > 0:
        l = x[lft_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
for i in range(min(lft_num, k)):
    l = x[lft_num - i - 1]
    distance = abs(l)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if rgt_num - (k-i-1) > 0:
        r = x[lft_num + rgt_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
    
print(ans)

import bisect
n, k = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

lft_num = bisect.bisect(x, 0)
rgt_num = n - lft_num

ans = 10**10
for i in range(min(rgt_num, k)):
    r = x[lft_num + i]
    distance = abs(r)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num - (k-i-1) >= 0:
        l = x[lft_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
for i in range(min(lft_num, k)):
    l = x[lft_num - i - 1]
    distance = abs(l)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num + (k-i) < n:
        r = x[lft_num + (k-i)]
        distance += abs(r - l)
        ans = min(ans, distance)
    
print(ans)

import bisect
n, k = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

lft_num = bisect.bisect(x, 0)
rgt_num = n - lft_num

ans = 10**10
for i in range(min(rgt_num, k)):
    r = x[lft_num + i]
    distance = abs(r)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num - (k-i-1) >= 0:
        l = x[lft_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
for i in range(min(lft_num, k)):
    l = x[lft_num - i - 1]
    distance = abs(l)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num + (k-i-2) < n:
        r = x[lft_num + (k-i-2)]
        distance += abs(r - l)
        ans = min(ans, distance)
    
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
# encoding utf-8

N, K = map(int, input().split())

x = list(int(i) for i in input().split())


for i in range(N):
    if 0 <= x[i]:
        border = i
        break

len_run = 100000

if border == 0:
    len_run = min(abs(x[K-1]), len_run)

if border == N-1:
    len_run = min(abs(x[N-K]), len_run)

for i in range(K):
    if border-K+i >= 0 and border+i <= N:
        len_run = min(abs(2*x[border-K+i])+abs(x[border+i-1]), len_run)
        len_run = min(abs(x[border-K+i])+abs(2*x[border+i-1]), len_run)

print(len_run)



















#     y.sort()
#     max = y[K-1]
#     if max in x_pos:



#     else:
/2



#
#



#     for j in range(len(x_neg)):




#     max = -z[K-1]
#     if max in x_neg:



#     else:
/2



#


# elif len(x_pos) == 0:
#     x.sort().reverse()

# else:


#



#encoding utf 8

n, k = map(int, input().split())

pos = list(int(i) for i in input().split())

ans = abs(pos[0])+abs(pos[0]-pos[k-1])

for i in range(n-k+1):
    val = 0
    val += abs(pos[i] - pos[i+k-1])
    val += min(abs(pos[i]), abs(pos[i+k-1]))

    if val < ans:
        ans = val
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
import numpy as np
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10**10
 
for i in range(x):
    tmp = i + b[1] - 1
    res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res)
        
print(res)

import numpy as np
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10*100
 
for i in range(x):
    tmp = i + b[1] - 1
    res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res)        

print(res)

import numpy as np
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10**15
 
for i in range(x):
    tmp = i + b[1] - 1
    res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res)
        
print(res)

b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10**15
 
for i in range(x):
    tmp = i + b[1] - 1
    if res > (a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))):
	    res = a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))
        
print(res)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
import sys
input=sys.stdin.readline

input = open(sys.argv[1],"r").readline

def main():
    N,K = map(int, input().split())
    X = list(map(int, input().split()))
    ans = 3*10**8
    for i in range(0,N-K+1):
        l = X[i]
        r = X[i+K-1]
        if l*r < 0:
            ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))
        else:
            ans = min(ans, max(abs(l),abs(r)))

    print(ans)

if __name__ == '__main__':
    main()


import sys
input=sys.stdin.readline

def main():
    N,K = map(int, input().split())
    X = list(map(int, input().split()))
    ans = 3*10**8
    for i in range(0,N-K+1):
        l = X[i]
        r = X[i+K-1]
        if l*r < 0:
            ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))
        else:
            ans = min(ans, max(abs(l),abs(r)))

    print(ans)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted