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

Fixed submission:
S = input()

def itoc(i): return chr(ord('a') + i)
def ctoi(c): return ord(c) - ord('a')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) == 26:
    i = 25
    while i > 0:
        if S[i-1] > S[i]:
            i -= 1
        else:
            ans = S[:i-1]
            for ci in range(ctoi(S[i-1])+1, 27):
                if itoc(ci) in ans: continue
                ans += itoc(ci)
                print(ans)
                exit()
else:
    for i in range(26):
        c = itoc(i)
        if c in S: continue
        print(S + c)
        break

Buggy submission (verdict: Runtime Error):
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c in S: continue
        print(S + c)
        exit()

assert len(S) == 26

cset = set()
for i,(a,b) in enumerate(reversed(list(zip(S,S[1:])))):
    if a > b:
        cset.add(b)
    else:
        print(S[:-i-2] + min(cset))
        exit()
Problem p03394 (python)

Fixed submission:
N = int(input())
if N == 3:
    print('2 5 63')
    exit()

ans = []
total = 0
for n in range(1,30001):
    if n%2 == 0 or n%3 == 0:
        ans.append(n)
        total += n
    if len(ans) == N: break

if total%6 == 1:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 2

elif total%6 == 2:
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 4

elif total%6 == 3:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3

elif total%6 == 4:
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 2

elif total%6 == 5:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 4

print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = []
total = 0
for n in range(30001):
    if (n%2 == 0) ^ (n%3 == 0):
        ans.append(n)
        total += n
    if len(ans) == N: break

if total%2 == 0:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3

if total%3 == 0:
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 2

print(*ans)
Problem p03404 (python)

Fixed submission:
A,B = map(int,input().split())
n = 50
m = n*2

grid = []
for i in range(n):
    grid.append(['.'] * m)
for i in range(n):
    grid.append(['#'] * m)

x = 0
y = 0
for i in range(B-1):
    grid[y][x] = '#'
    x += 2
    if x >= m:
        x -= m
        y += 2

x = 0
y = n+1
for i in range(A-1):
    grid[y][x] = '.'
    x += 2
    if x >= m:
        x -= m
        y += 2

print(str(m) + ' ' + str(m))
for row in grid:
    print(''.join(row))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
n = 50
m = n*2

grid = []
for i in range(n):
    grid.append([‘.’] * m)
for i in range(n):
    grid.append([‘#’] * m)

x = 0
y = 0
for i in range(B-1):
    grid[y][x] = ‘#’
    x += 2
    if x >= m:
        x -= m
        y += 2

x = 0
y = n+1
for i in range(A-1):
    grid[y][x] = ‘.’
    x += 2
    if x >= m:
        x -= m
        y += 2

print(str(m) + ‘ ‘ + str(m))
for row in grid:
    print(‘’.join(row))
Problem p03437 (python)

Fixed submission:
X,Y = map(int,input().split())
if X%Y == 0:
    print(-1)
else:
    print(X)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
src = list(map(int,input().split()))
es = [tuple(map(int,input().split())) for i in range(M)]

if N == 1:
    print(0)
    exit()
if M + N//2 < N-1:
    print('Impossible')
    exit()

parent = [i for i in range(N)]
rank = [0] * N
def root(a):
    if parent[a] == a:
        return a
    else:
        parent[a] = root(parent[a])
        return parent[a]
def same(a,b):
    return root(a) == root(b)
def unite(a,b):
    ra = root(a)
    rb = root(b)
    if ra == rb: return
    if rank[ra] < rank[rb]:
        parent[ra] = rb
    else:
        parent[rb] = ra
        if rank[ra] == rank[rb]: rank[ra] += 1

for a,b in es:
    unite(a,b)
trees = {}
for i in range(N):
    root(i)
for i in range(N):
    trees[root(i)] = False

costs = []
for i,c in enumerate(src):
    costs.append((c,i))
costs.sort()

used = [False] * N
ans = used_n = 0
for c,v in costs:
    t = root(v)
    if trees[t]:
        continue
    else:
        trees[t] = used[v] = True
        used_n += 1
        ans += c

for c,v in costs:
    if used_n == 2*(N-M-1): break
    if used[v]: continue
    used_n += 1
    ans += c
print(ans)
Problem p03439 (python)

Fixed submission:
N = int(input())

q = 0
res = []
for i in range(20):
    print(q)
    s = input()
    if s[0] == 'V':
        exit()
    res.append((q,s[0]))
    res.sort()
    if len(res) == 1:
        q = N//2
        continue
    for (i1,g1),(i2,g2) in zip(res,res[1:]):
        if i2-i1 == 1: continue
        if (i2-i1)%2 == int(g1==g2):
            q = (i2+i1)//2
            break
    else:
        q = (res[-1][0] + N + 1)//2

Buggy submission (verdict: Runtime Error):
N = int(input())

q = 0
res = []
for i in range(20):
    print(q)
    s = input()
    if s[0] == 'V':
        exit()
    res.append((q,s[0]))
    if len(res) == 1:
        q = N//2
        continue
    for (i1,g1),(i2,g2) in zip(res,res[1:]):
        if (i2-i1)%2 == int(g1==g2):
            q = (i2-i1)//2
            break
    else:
        q = (res[-1][0] + N + 1)//2

    print(res)
Problem p03452 (python)

Fixed submission:
N,M = map(int,input().split())
es = [[] for i in range(N)]

for i in range(M):
    l,r,d = map(int,input().split())
    l,r = l-1, r-1
    es[l].append((r,d))
    es[r].append((l,-d))

dist = [None] * N
for i in range(N):
    if dist[i] is not None: continue
    stack = [i]
    dist[i] = 0
    while stack:
        v = stack.pop()
        for to,d in es[v]:
            if dist[to] is None:
                stack.append(to)
                dist[to] = dist[v] + d
            elif dist[to] != dist[v] + d:
                print('No')
                exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
es = [[] for i in range(N)]
for i in range(M):
    l,r,d = map(int,input().split())
    l,r = l-1,r-1
    es[l].append((r,d))
    es[r].append((l,-d))

for i in range(N):
    if dist[i] is not None: continue
    dist = [None] * N
    dist[i] = 0
    stack = [i]
    while stack:
        v = stack.pop()
        for to,d in es[v]:
            if dist[to] is None:
                dist[to] = dist[v] + d
                if not checked[to]:
                    stack.append(to)
            else:
                if dist[to] != dist[v] + d:
                    print('No')
                    exit()
print('Yes')
Problem p03473 (python)

Fixed submission:
M = int(input())
print(48-M)

Buggy submission (verdict: Runtime Error):
n = input()
print(48-n)
Problem p03480 (python)

Fixed submission:
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2
l = r = center_i
if N%2==0:
    l -= 1
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2 + N%2
if N%2==0 and center != S[center_i+1]:
    print(ans)
    exit()
l = center_i - 1
r = center_i + 1 + (N%2==0)
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)
Problem p03482 (python)

Fixed submission:
S = input()
N = len(S)

m = N//2
if N%2 == 0:
    if S[m] != S[m-1]:
        print(m)
        exit()
    ans = m+1
    for i in range(1,m):
        if S[m] == S[m+i] == S[m-1-i]:
            ans += 1
        else:
            break
else:
    ans = m+1
    for i in range(1,m+1):
        if S[m] == S[m+i] == S[m-i]:
            ans += 1
        else:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

ans = N//2
l = r = N//2
if N%2 == 0: r += 1

while l >= 0:
    if S[l] == '1' or S[r] == '1':
        break
    l -= 1
    r += 1
    ans += 1
print(max(ans, N//2 + N%2))
Problem p03502 (python)

Fixed submission:
N = int(input())
a = 0
n = N
while n >= 1:
    a += n%10
    n //= 10
print('Yes' if N % a == 0 else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = 0
n = N
while n >= 10:
    a += n%10
    n //= 10
print('Yes' if N % a == 0 else 'No')
Problem p03570 (python)

Fixed submission:
def ctoi(c):
    return ord(c) - ord('a')

def solve(s):
    masks = [1<<k for k in range(26)]
    cums = [0]
    for c in s:
        cums.append(cums[-1] ^ masks[ctoi(c)])
    if cums[-1] == 0:
        print(1)
        exit()

    dp = {0:0}
    for b in cums:
        for m in masks:
            msk = b^m
            if msk in dp:
                if b in dp:
                    dp[b] = min(dp[b], dp[msk]+1)
                else:
                    dp[b] = dp[msk]+1
    return dp[cums[-1]]

print(solve(input()))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
S = input()

def ctoi(c):
    return ord(c) - ord('a')

cums = [0]
for c in S:
    cums.append(cums[-1] ^ (1<<ctoi(c)))
if cums[-1] == 0:
    print(1)
    exit()

dp = {0:0}
for i,b in enumerate(cums):
    for k in range(26):
        msk = b^(1<<k)
        if msk in dp:
            if b in dp:
                dp[b] = min(dp[b], dp[msk]+1)
            else:
                dp[b] = dp[msk]+1
print(dp[cums[-1]])

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

def ctoi(c):
    return ord(c) - ord('a')

cums = [0]
for c in S:
    cums.append(cums[-1] ^ (1<<ctoi(c)))
if cums[-1] == 0:
    print(1)
    exit()

dp = {0:0}
for b in cums:
    if b in dp: continue
    for k in range(26):
        if b&(1<<k)==0: continue
        msk = b^(1<<k)
        if msk in dp:
            if b in dp:
                dp[b] = min(dp[b], dp[msk]+1)
            else:
                dp[b] = dp[msk]+1
print(dp[cums[-1]])
Problem p03574 (python)

Fixed submission:
H,W = map(int,input().split())
src = [input() for i in range(H)]

ans = []
for row in src:
    ans.append(list(row))

for i in range(H):
    for j in range(W):
        if src[i][j] == '#': continue
        c = 0
        if i > 0:
            if j > 0 and src[i-1][j-1] == '#': c += 1
            if src[i-1][j] == '#': c += 1
            if j < W-1 and src[i-1][j+1] == '#': c += 1
        if j > 0 and src[i][j-1] == '#': c += 1
        if j < W-1 and src[i][j+1] == '#': c += 1
        if i < H-1:
            if j > 0 and src[i+1][j-1] == '#': c += 1
            if src[i+1][j] == '#': c += 1
            if j < W-1 and src[i+1][j+1] == '#': c += 1
        ans[i][j] = c

for row in ans:
    print(''.join(list(map(str,row))))

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
src = [input() for i in range(H)]

ans = []
for row in src:
    ans.append(list(row))

dxy = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(-1,0)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '#': continues
        c = 0
        for dx,dy in dxy:
            if x+dx <= 0 or x+dx >= W or y+dy <= 0 or y+dy >= H: continue
            if src[y+dy][x+dx] == '#': c += 1        
        ans[i][j] = c

for row in ans:
    print(''.join(list(map(str,row))))

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
src = [input() for i in range(H)]

ans = []
for row in src:
    ans.append(list(row))

dxy = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(-1,0)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '#': continues
        c = 0
        for dx,dy in dxy:
            if x+dx <= 0 or x+dx >= W or y+dy <= 0 or y+dy >= H: continue
            if src[y+dy][x+dx] == '#': c += 1        
        ans[i][j] = c

for row in ans:
    print(''.join(list(map(str,row))))
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,raw_input().split())
es = [[] for i in range(N)]
for i in range(M):
  a,b = map(int,raw_input().split())
  a,b = a-1,b-1
  es[a].append(b)
  es[b].append(a)

colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in es[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to, -color):
      return False
  return True

def is_bipartite():
  return dfs(0,1)

if is_bipartite():
  b = (sum(colors) + N) // 2
  w = N-b
  print(b*w - M)
else:
  all = N*(N-1) // 2
  print(all - M)

Buggy submission (verdict: Runtime Error):
N,M = map(int,raw_input().split())
es = [[] for i in range(N)]
for i in range(M):
  a,b = map(int,raw_input().split())
  a,b = a-1,b-1
  es[a].append(b)
  es[b].append(a)

colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in es[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to, -color):
      return False
  return True

def is_bipartite():
  return dfs(0,1)

if is_bipartite():
  b = (sum(colors) + N) // 2
  w = N-b
  print(b*w - M)
else:
  all = N*(N-1) // 2
  print(all - M)
Problem p03599 (python)

Fixed submission:
A,B,C,D,E,F = map(int, input().split())

ws = set()
i = j = 0
while True:
    j = 0
    if B*i > F//100: break
    while True:
        w = B*i + A*j
        if w > F//100: break
        ws.add(w)
        j += 1
    i += 1
ws = list(ws)
ws.sort()

ss = set()
i = j = 0
while True:
    j = 0
    if D*i > F: break
    while True:
        s = D*i + C*j
        if s > F: break
        ss.add(s)
        j += 1
    i += 1
ss = list(ss)
ss.sort()

limit = E / (100+E)
water = A*100
sugar = rate = 0
for w in ws:
    w = w*100
    if w == 0: continue
    if w > F: break
    for s in ss:
        if w+s > F: break
        r = s / (w+s)
        if r > limit: break
        if r > rate:
            rate = r
            water = w
            sugar = s
print(water+sugar, sugar)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

waters = set()
for w1 in range(0,F+1,B):
    if w1*100 > F: break
    for w2 in range(0,F+1,A):
        w = (w1+w2)*100
        if w > F: break
        if w==0: continue
        waters.add(w)

sugars = set()
for s1 in range(0,F+1,D):
    if s1 > F: break
    for s2 in range(0,F+1,C):
        s = s1+s2
        if s > F: break
        sugars.add(s)

ans_r = 0
ans_s = ans_w = None
for w in sorted(waters):
    if w > F: break
    for s in sorted(sugars):
        if w+s > F: break
        if s*100 > w*E: break
        r = 100*s/(s+w)
        if r > ans_r:
            ans_r = r
            ans_w = w
            ans_s = s
print(ans_s+ans_w, ans_s)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

waters = set()
for w1 in range(0,F+1,B):
    if w1*100 > F: break
    for w2 in range(0,F+1,A):
        w = (w1+w2)*100
        if w > F: break
        waters.add(w)

sugars = set()
for s1 in range(0,F+1,D):
    if s1 > F: break
    for s2 in range(0,F+1,C):
        s = s1+s2
        if s > F: break
        if s==0: continue
        sugars.add(s)

ans_r = 0
ans_s = ans_w = None
for w in sorted(waters):
    if w > F: break
    for s in sorted(sugars):
        if w+s > F: break
        if s*100 > w*E: break
        r = 100*s/(s+w)
        if r > ans_r:
            ans_r = r
            ans_w = w
            ans_s = s
print(ans_s+ans_w, ans_s)
Problem p03637 (python)

Fixed submission:
N = int(input())
src = list(map(int, input().split()))

x1 = x2 = x4 = 0
for a in src:
    if a%2 == 1:
        x1 += 1
    elif a%4 == 0:
        x4 += 1
    else:
        x2 += 1

def solve():
    if x4 >= x1: return True
    if x4 + 1 == x1:
        return x2 == 0
    else: return False

print('Yes' if solve() else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
src = list(map(int,input().split()))
odd = two = four = 0
for a in src:
    if a%2: odd += 1
    elif a%4==0: four += 1
    else: two += 1
if two:
    print('Yes' if odd <= four else 'No)
else:
    print('Yes' if odd <= four+1 else 'No')
Problem p03651 (python)

Fixed submission:
N,K = map(int,raw_input().split())
src = map(int,raw_input().split())

def gcd(a,b):
  a,b = max(a,b),min(a,b)
  if b == 0:
    return a
  return gcd(b, a%b)

def solve():
  if N == 1: return src[0] == K
  mx = max(src)
  if K > mx: return False
  g = src[0]
  for i in range(1,N):
    g = gcd(g, src[i])
    if g == 1:
      return True
  return K % g == 0

print ('POSSIBLE' if solve() else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
N,K = map(int,raw_input().split())
src = map(int,raw_input().split())

def solve():
  if N == 1: return src[0] == K
  mx = max(src)
  if K > mx: return False
  g = src[0]
  for i in range(1,N):
    g = gcd(g, src[i])
    if g == 1:
      return True
  return K % g == 0

print ('POSSIBLE' if solve() else 'IMPOSSIBLE')
Problem p03699 (python)

Fixed submission:
import heapq

def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0

Buggy submission (verdict: Runtime Error):
def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0

Buggy submission (verdict: Runtime Error):
def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0 
    

N = input()
S = [input() for i in range(N)]
scores = S[:]

print solve(scores)
Problem p03722 (python)

Fixed submission:
N,M = map(int,input().split())
es = []
for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    c *= -1
    es.append((a,b,c))

INF = float('inf')
def solve():
    d = [INF for i in range(N)]
    d[0] = 0
    for i in range(N):
        for fr,to,cost in es:
            if d[fr] == INF: continue
            if d[to] > d[fr] + cost:
                d[to] = d[fr] + cost
                if i == N-1 and to == N-1: return 'inf'
    return -d[N-1]

print(solve())

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
    for a,b,c in ABC:
        a,b,c = a-1,b-1,-c
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            if i==N-1 and to == N-1:
                print('inf')
                exit()
print(-dist[-1])
Problem p03729 (python)

Fixed submission:
def solve():
  ar = raw_input().split(' ')
  A = ar[0]
  B = ar[1]
  C = ar[2]
  if A[-1] == B[0] and B[-1] == C[0] : return 'YES'
  else: return 'NO'

if __name__ == '__main__' :
  print solve()

Buggy submission (verdict: Runtime Error):
def solve():
  ar = raw_input().split(' ')
  A = int(ar[0])
  B = int(ar[1])
  C = int(ar[2])

  s = set([])
  sum = 0
  while True:
    sum = sum + A
    m = sum % B
    #print 'sum=',sum,'m=',m
    if (m == C): return 'Yes'
    if (m in s): return 'No'
    s.add(m)

if __name__ == '__main__' :
  print solve()
Problem p03808 (python)

Fixed submission:
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i+1] - src[i] - K for i in range(N-1)]
mem.append(src[0] - src[N-1] - K)

print('YES' if all(map(lambda x:x<=0 and x%N==0, mem)) else 'NO')

Buggy submission (verdict: Runtime Error):
N = int(input())
src = map(int,input().split())
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
for a,b in zip(mem,mem[1:]):
    if (a-b)%N:
        print('NO')
        exit()
print('YES')
Problem p03840 (python)

Fixed submission:
I,O,T,J,L,S,Z = map(int,input().split())
p = 2*(I//2 + J//2 + L//2)
if I and J and L:
    p = max(p, 2*((I-1)//2 + (J-1)//2 + (L-1)//2) + 3)
print(O + p)

Buggy submission (verdict: Runtime Error):
I,O,_,J,L,_,_ = map(int,input().split())
ans1 = O + I-I%2 + J-J%2 + L-L%2
ans2 = 0
if I and J and K:
    I,J,K = I-1,J-1,K-1
    ans2 = 3 + O + I-I%2 + J-J%2 + L-L%2
print(max(ans1,ans2))
Problem p03841 (python)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
Y = sorted([(x-1,i+1) for i,x in enumerate(X)])

ans = [None] * (N*N)
must = []
for i,n in Y:
    ans[i] = n
    must += [n]*(n-1)
must.reverse()

used = [0] * (N+1)
free = [1]
for i in range(N*N):
    if ans[i]:
        a = ans[i]
        if used[a] != a-1:
            print('No')
            exit()
        free += [a]*(N-a)
    elif must:
        a = must.pop()
        ans[i] = a
    else:
        if free:
            a = free.pop()
            ans[i] = a
        else:
            print('No')
            exit()
    used[ans[i]] += 1

for i in range(1,N+1):
    if used[i] != N:
        print('No')
        exit()

print('Yes')
print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = sorted([(x-1,i+1) for i,x in enumerate(X)])

ans = [None] * (N*N)
must = []
for i,n in Y:
    ans[i] = n
    must += [n]*(n-1)
must.reverse()

used = [0] * (N+1)
free = [1]
for i in range(N*N):
    if ans[i]:
        a = ans[i]
        if used[a] != a-1:
            print('No')
            exit()
        free += [a]*(N-a)
    elif must:
        a = must.pop()
        ans[i] = a
    else:
        if free:
            a = free.pop()
            ans[i] = a
        else:
            print('No')
            exit()
    used[ans[i]] += 1

for i in range(1,N+1):
    assert used[i] == N

print('Yes')
print(*ans)