Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p04003 (python)

Fixed submission:
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N, M = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    c2v = {}
    v = N+1
    for _ in range(M):
        p, q, c = map(int, input().split())
        P = p*(10**7) + c
        Q = q*(10**7) + c
        if P not in c2v:
            c2v[P] = v
            adj[p].append((v, 1))
            adj.append([(p, 1)])
            v += 1
        if Q not in c2v:
            c2v[Q] = v
            adj[q].append((v, 1))
            adj.append([(q, 1)])
            v += 1
        adj[c2v[P]].append((c2v[Q], 0))
        adj[c2v[Q]].append((c2v[P], 0))

    que = deque()
    que.append(1)
    seen = [-1] * len(adj)
    seen[1] = 0
    while que:
        v = que.popleft()
        for u, cost in adj[v]:
            if seen[u] == -1:
                seen[u] = seen[v] + cost
                if cost:
                    que.append(u)
                else:
                    que.appendleft(u)
    print(seen[N] // 2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, defaultdict
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
    p, q, c = map(int, input().split())
    adj[p].append((q, c))
    adj[q].append((p, c))

deq = deque()
cost = [10 ** 7] * (N+1)
seen = [0] * (N+1)
prev = defaultdict(list)
deq.append(1)
cost[1] = 0
seen[1] = 1
while deq:
    v = deq.pop()
    for uc in adj[v]:
        u, c = uc
        if c in prev[v]:
            if cost[u] == cost[v]:
                cost[u] = cost[v]
                if seen[u] == 0:
                    deq.append(u)
                    seen[u] = 1
                prev[u].append(c)
            elif cost[u] > cost[v]:
                cost[u] = cost[v]
                if seen[u] == 0:
                    deq.append(u)
                    seen[u] = 1
                prev[u] = [c]
        else:
            if cost[u] > cost[v] + 1:
                cost[u] = cost[v] + 1
                if seen[u] == 0:
                    deq.appendleft(u)
                    seen[u] = 1
                prev[u].append(c)
            elif cost[u] == cost[v] + 1:
                prev[u].append(c)

print(cost[N]) if cost[N] < 10 ** 7 else print(-1)
x
Problem p04016 (python)

Fixed submission:
import math

n = int(input())
s = int(input())

if n == 1:
    if s == 1:
        print(2)
    else:
        print(-1)
    exit()

if n == s:
    print(n + 1)
    exit()

if n < s:
    print(-1)
    exit()


def ds(N, b):
    ret = 0
    while True:
        N, mod = divmod(N, b)
        ret += mod
        if N == 0:
            return ret


i = 0
for i in range(2, math.floor(n**(1/2)) + 1):
    if ds(n, i) == s:
        print(i)
        exit()

if i == 0:
    i = math.floor(n**(1/2))
c = n // (i + 1)
for i in range(c, 0, -1):
    if (n-s) % i == 0:
        b = (n-s)//i + 1
        if i < b and 0 <= s-i < b:
            print(b)
            exit()

print(-1)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
s = int(input())

if n == 1:
    if s == 1:
        print(2)
    else:
        print(-1)
    exit()

if n == s:
    print(n + 1)
    exit()

if n < s:
    print(-1)
    exit()


def ds(N, b):
    ret = 0
    while True:
        N, mod = divmod(N, b)
        ret += mod
        if N == 0:
            return ret


for i in range(2, math.floor(n**(1/2)) + 1):
    if ds(n, i) == s:
        print(i)
        exit()

c = n // (i + 1)
for i in range(c, 0, -1):
    if (n-s) % i == 0:
        b = (n-s)//i + 1
        if i < b and 0 <= s-i < b:
            print(b)
            exit()

print(-1)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
s = int(input())

if n == 1:
    if s == 1:
        print(2)
    else:
        print(-1)
    exit()

if n == s:
    print(n + 1)
    exit()


def ds(N, b):
    ret = 0
    while True:
        N, mod = divmod(N, b)
        ret += mod
        if N == 0:
            return ret


for i in range(2, math.floor(n**(1/2)) + 1):
    if ds(n, i) == s:
        print(i)
        exit()

c = n // (i + 1)
for i in range(c, 0, -1):
    if (n-s) % i == 0:
        b = (n-s)//i + 1
        if i < b and 0 <= s-i < b:
            print(b)
            exit()

print(-1)
Problem p04027 (python)

Fixed submission:
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9+7

acc = [[0] for _ in range(401)]
for i in range(401):
    for j in range(1, 401):
        acc[i].append(((acc[i][-1] + pow(j, i, mod)) % mod))

dp = [[0 for _ in range(C+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for candy_cur in range(C+1):
        for candy_plus in range(C - candy_cur+1):
            dp[i+1][candy_cur + candy_plus] = (dp[i+1][candy_cur + candy_plus] + (dp[i][candy_cur]\
                                               * ((acc[candy_plus][B[i]] - acc[candy_plus][A[i]-1])%mod)%mod)) % mod

print(dp[-1][C])

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9+7

acc = [[0] for _ in range(401)]
for i in range(401):
    for j in range(1, C+2):
        acc[i].append(((acc[i][-1] + pow(j, i, mod)) % mod))

dp = [[0 for _ in range(C+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for candy_cur in range(C+1):
        for candy_plus in range(C - candy_cur+1):
            dp[i+1][candy_cur + candy_plus] = (dp[i+1][candy_cur + candy_plus] + (dp[i][candy_cur]\
                                               * ((acc[candy_plus][B[i]] - acc[candy_plus][A[i]-1])%mod)%mod)) % mod

print(dp[-1][C])

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9+7

acc = [[0] for _ in range(401)]
for i in range(401):
    for j in range(1, C+2):
        acc[i].append(acc[i][-1] + j ** i)

dp = [[0 for _ in range(C+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for candy_cur in range(C+1):
        for candy_plus in range(C - candy_cur+1):
            dp[i+1][candy_cur + candy_plus] = (dp[i+1][candy_cur + candy_plus] + dp[i][candy_cur]\
                                               * (acc[candy_plus][B[i]] - acc[candy_plus][A[i]-1])) % mod

print(dp[-1][C])
Problem p02585 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    C = list(map(int, input().split()))

    res = -f_inf
    for now in range(n):
        cnt = 0
        score = [0]
        visited = set()
        for j in range(k):
            next_now = P[now] - 1
            if next_now not in visited:
                score.append(score[-1] + C[next_now])
                visited.add(next_now)
                now = next_now
                cnt += 1
            else:
                break
        score.pop(0)
        if k - cnt == 0:
            res = max(res, max(score))
        else:
            if score[-1] <= 0:
                res = max(res, max(score))
            else:
                q, r = divmod(k, cnt)
                if r == 0:
                    res = max(res, max(score) + score[-1] * (q - 1))
                else:
                    res = max(res, max(score[:r]) + score[-1] * q, max(score[r:]) + score[-1] * (q - 1))
    print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    C = list(map(int, input().split()))

    res = -f_inf
    for now in range(n):
        cnt = 0
        score = [0]
        visited = set()
        for j in range(k):
            next_now = P[now] - 1
            if next_now not in visited:
                score.append(score[-1] + C[next_now])
                visited.add(next_now)
                now = next_now
                cnt += 1
            else:
                break
        if k - cnt == 0:
            res = max(res, max(score[1:]))
        else:
            if score[-1] <= 0:
                res = max(res, max(score[1:]))
            else:
                q, r = divmod(k, cnt)
                res = max(res, max(score[1:r + 1]) + score[-1] * q)
    print(res)

if __name__ == '__main__':
    resolve()
Problem p02609 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = input()
    cnt_init = X.count("1")
    x = int(X, 2)
    a = x % (cnt_init + 1)
    if cnt_init - 1 != 0:
        b = x % (cnt_init - 1)

    for i in range(n):
        if X[i] == "0":
            cnt = cnt_init + 1
            y = (a + pow(2, n - i - 1, cnt)) % cnt
        else:
            cnt = cnt_init - 1
            if cnt == 0:
                print(0)
                continue
            y = (b - pow(2, n - i - 1, cnt)) % cnt

        res = 1
        while y:
            cnt = bin(y).count("1")
            y %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def popcount(n):
        return bin(n).count("1")

    n = int(input())
    X = input()
    cnt_init = X.count("1")

    for j in range(n):
        if X[j] == "0":
            cnt = cnt_init + 1
            x = int(X, 2) + pow(2, n - j - 1, cnt)
        else:
            cnt = cnt_init - 1
            x = int(X, 2) - pow(2, n - j - 1, cnt)

        res = 0
        while x:
            if res != 0:
                cnt = popcount(x)
            x %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def popcount(n):
        cnt = 0
        for b in range(5):
            cnt += (n >> b) & 1
        return cnt

    n = int(input())
    X = input()
    one = X.count("1")

    for i in range(n):
        x = list(X)
        cnt = one + 1 if x[i] == "0" else one - 1
        x[i] = "1" if x[i] == "0" else "0"
        x = int("".join(x), 2)
        res = 0
        while x:
            if res != 0:
                cnt = popcount(x)
            x %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()
Problem p02684 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    tree = [[] for _ in range(n)]
    for idx, a in enumerate(A):
        tree[idx].append(a - 1)

    start = []
    depth = [0 for _ in range(n)]

    def dfs(v, p, d, cnt):
        depth[v] = d
        for u in tree[v]:
            if visited[u]:
                start.append([u + 1, depth[u], cnt + 1])
                return
            else:
                visited[u] = True
                dfs(u, v, d + 1, cnt + 1)
        return

    visited = [False for _ in range(n)]
    visited[0] = True
    dfs(0, -1, 0, 0)

    if k <= start[0][1]:
        print(depth.index(k) + 1)
    else:
        cnt = (k - start[0][1]) % (start[0][2] - start[0][1])
        res = start[0][1] + cnt
        print(depth.index(res) + 1)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    tree = [[] for _ in range(n)]
    for idx, a in enumerate(A):
        tree[idx].append(a - 1)

    start = []
    depth = [0 for _ in range(n)]

    def dfs(v, p, d, cnt):
        depth[v] = d
        for u in tree[v]:
            if u == p:
                continue

            if visited[u]:
                start.append([u + 1, depth[u], cnt + 1])
                return
            else:
                visited[u] = True
                dfs(u, v, d + 1, cnt + 1)
        return

    visited = [False for _ in range(n)]
    visited[0] = True
    dfs(0, -1, 0, 0)

    if k <= start[0][1]:
        print(depth.index(k) + 1)
    else:
        cnt = (k - start[0][1]) % (start[0][2] - start[0][1])
        res = start[0][1] + cnt
        print(depth.index(res) + 1)


if __name__ == '__main__':
    resolve()
Problem p02732 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
c = [0 for _ in range(max(a))]
for k, v in d.items():
    c[k - 1] = v * (v - 1) / 2

ans = sum(c)
for i in range(n):
    p = a[i]
    res = c[p - 1] * (d[p] - 2) / d[p]
    ans -= c[p - 1] - res
    print(int(ans))
    ans += c[p - 1] - res

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial


n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
c = [0 for _ in range(max(a))]
for k, v in d.items():
    if v > 2:
        c[k - 1] = factorial(v) / factorial(2) / factorial(v - 2)
    else:
        c[k - 1] = 0
        
for i in range(n):
    ans = sum(c)
    p = a[i]
    res = c[p - 1] * (d[p] - 2) / d[p]
    ans -= c[p - 1] - res
    print(int(ans))
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if m == 0:
    if n == 1:
        print(0)
    else:
        print(10 ** (n - 1))
    exit()

if n == 1:
    left = 0
else:
    left = 10 ** (n - 1)
right = 10 ** n

ans = -1
for i in range(left, right):
    i = str(i)
    for s, c in sc:
        if int(i[s - 1]) != c:
            break
    else:
        ans = i
        break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if m == 0:
    if n == 1:
        print(0)
    else:
        print(10 ** (n - 1))
    exit()

ans = -1
for i in range(10 ** n):
    i = str(i)
    for s, c in sc:
        if int(i[s - 1]) != c:
            break
    else:
        ans = i
        break

print(ans)
Problem p02772 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

ans = "APPROVED"
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            ans = "APPROVED"
        else:
            ans = "DENIED"
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            ans = "APPROVED"
        else:
            ans = "DENIED"
            break

print(ans)
Problem p02803 (python)

Fixed submission:
from collections import deque

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

f_inf = float('inf')
ans = []
for h in range(H):
    for w in range(W):
        if grid[h][w] == "#":
            continue
        else:
            maze = [[f_inf] * W for _ in range(H)]
            sh, sw = h, w
            maze[sh][sw] = 0
            que = deque([[sh, sw]])
            while que:
                h, w = que.popleft()
                for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                        continue
                    elif grid[next_h][next_w] == "#":
                        continue
                    elif grid[next_h][next_w] == ".":
                        if maze[next_h][next_w] > maze[h][w] + 1:
                            maze[next_h][next_w] = maze[h][w] + 1
                            que.append([next_h, next_w])
                            ans.append(maze[next_h][next_w])

print(max(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque

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

f_inf = float('inf')
ans = []
for h in range(H):
    for w in range(W):
        if grid[h][w] == "#":
            break
        else:
            maze = [[f_inf] * W for _ in range(H)]
            sh, sw = h, w
            maze[sh][sw] = 0
            que = deque([[sh, sw]])
            while que:
                h, w = que.popleft()
                for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W or grid[next_h][next_w] == "#":
                        continue
                    else:
                        if maze[next_h][next_w] > maze[h][w] + 1:
                            maze[next_h][next_w] = maze[h][w] + 1
                            que.append([next_h, next_w])
                            ans.append(maze[next_h][next_w])

print(max(ans))
Problem p02812 (python)

Fixed submission:
n = int(input())
s = input()

i = 0
ans = 0
while i <= n:
    if s[i:i+3] == "ABC":
        ans += 1
        i += 3
    else:
        i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

i = 0
ans = 0
while i <= n-2:
    if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
        ans += 1
        i += 3
    else:
        i += 1

print(ans)
Problem p02814 (python)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)

n, m = map(int, input().split())
a = [i // 2 for i in set(list(map(int, input().split())))]
b = []
for i in a:
    cnt = 0
    while i % 2 == 0:
        i //= 2
        cnt += 1
    b.append(cnt)

L = 1
if len(set(b)) == 1:
    for j in a:
        L = lcm(j, L)
        if m < L:
            print(0)
            break
    else:
        print((m // L + 1) // 2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
a = np.array(list(map(int, input().split())))
a_d = a // 2

ans = m / lcm(*a_d) / 2
if ans.is_integer():
    ans = m // lcm(*a_d) // 2 - 1
    print(int(ans))
else:
    ans = round(m / lcm(*a_d) / 2)
    print(int(ans))
Problem p02843 (python)

Fixed submission:
x = int(input())
ans = 0
if x < 100:
    ans = 0
else:
    n = (x // 100) * 5
    k = x % 100
    if k <= n:
        ans = 1
    else:
        ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
x = input()
n = int(x[0]) * 5
k = int(x[1:3])
if k <= n:
    print(1)
else:
    print(0)
Problem p02889 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(start, v, p, tot_d):
        for d, u in edge[v]:
            if u == p:
                continue
            if tot_d + d > l:
                dp[start][u] = min(dp[start][u], dp[start][v] + 1)
                tot_d = d
            else:
                dp[start][u] = min(dp[start][u], dp[start][v])
                tot_d += d
            dfs(start, u, v, tot_d)

    n, m, l = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        if c > l:
            continue
        edge[a - 1].append([c, b - 1])
        edge[b - 1].append([c, a - 1])

    # dp[i][j]:iからスタートしてjに行くまでに補給する最小回数
    dp = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = 0
        dfs(i, i, - 1, 0)

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        dp[s - 1][t - 1] = min(dp[s - 1][t - 1], dp[t - 1][s - 1])
        if dp[s - 1][t - 1] == f_inf:
            print(-1)
        else:
            print(dp[s - 1][t - 1])
            

if __name__ == '__main__':
    resolve()
Problem p02900 (python)

Fixed submission:
import math

def gcd(n, m):
    while m != 0:
        n, m = m, n % m
    return n

a, b = map(int, input().split())
g = gcd(a, b)
g_2 = int(math.sqrt(g))
cnt = 1

for i in range(2, g_2+1):
    if g % i == 0:
        while g % i == 0:
            g //= i
        cnt += 1
if g > 1:
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
g = math.gcd(a, b)
g_2 = int(math.sqrt(g))
cnt = 1

for i in range(2, g_2+1):
    if g % i == 0:
        while g % i == 0:
            g //= i
        cnt += 1
if g > 1:
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
x = math.gcd(a, b)
k = []
for i in range(1, x+1):
    if x % i == 0:
        k.append(i)
cnt = 0
for n in k:
    if n == 1:
        cnt += 1
    elif n == 2:
        cnt += 1
    else:
        flg = ""
        for p in range(2, n):
            if n % p == 0:
                flg = "composite"
                break
            else:
                flg = "prime"
        if flg == "prime":
            cnt += 1
print(cnt)
Problem p02903 (python)

Fixed submission:
H,W,A,B = map(int,input().split())

for i in range(H):
    if i < B:
        print("1"*A + "0"*(W-A))
    else:
        print("0"*A + "1"*(W-A))

Buggy submission (verdict: Runtime Error):
H,W,A,B = map(int,input().split())
matrix = [[0 for i in range(H)] for j in range(W)]

if A ==  B == 1:
    for i in range(W):
        matrix[i][i] = 1
elif A == B:
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                matrix[i][j] = 1
elif H == 1 and B == 0:
    for i in range(W):
        if i % 2 != 0:
            matrix[0][i] = 1
elif W == 1 and A == 0:
    for i in range(H):
        if i % 2 != 0:
            matrix[i][0] = 1
else:
    print("No")
    exit()

for i in range(W):
        print(''.join(map(str,matrix[i])))