Problem:


Score : 400 points

Problem Statement

We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:

For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.

There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N-1, solve the problem below:

Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.

Constraints

3 \leq N \leq 2 \times 10^3

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).

There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).

There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).

There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0



Sample input:
5 2 4


Sample output:
5
4
1
0

Submission status: Runtime Error

Solution code:
import collections

n, x, y = map(int,input().split())
g = [[i-1, i+1] for i in range(n)]
g[0] = [1]
g[n-1] = [n-2]
g[x-1].append(y-1)
g[y-1].append(x-1)
ans = []

for i in range(n-1): #各頂点からの最短距離を求める
    que = [i]
    houmon = [-1]*(n-i)
    houmon[]

    while True:
        now = que.pop(0)
        for j in g[now]
            if houmon[j+1] < 0:
                houmon[j+1] = 


c = collections.Counter(ans)
print(c)
#for i in range(1,n):
    #print(c[i])

Submission status: Runtime Error

Solution code:
#６回目、2020-0612
#2重ループ + numpy
#場合分けを近道と通常のみ（絶対値を使う）
import numpy as np 
#初期入力
N, x, y = map(int, input().split())
dist =np.zeros((N,N),dtype=np.int64)

#iからjの距離
for i in range(1,N):
    j =np.arange(i+1,N+1)
    normal =j -i
    short  =abs(x-i) +1 +abs(j-y)
    dist[i-1,i:] =np.minimum(normal,short)
    #print(d)
#距離別の数
a,ans =np.unique(dist,return_counts=True)      
ans =np.delete(ans,0) #距離０を削除
count_zero =N-1-len(ans) 
ans =np.append(ans,np.zeros(count_zero))#存在しない遠い距離は０

#出力
for i in ans:
    print(int(i))

Submission status: Runtime Error

Solution code:
#６回目、2020-0612
#2重ループ + numpy
#場合分けを近道と通常のみ（絶対値を使う）
import numpy as np 
#初期入力
N, x, y = map(int, input().split())
dist =np.zeros((N,N),dtype=int)

#iからjの距離
for i in range(1,N):
    j =np.arange(i+1,N+1)
    normal =j -i
    short  =abs(x-i) +1 +abs(j-y)
    dist[i-1,i:] =np.minimum(normal,short)
    #print(d)
#距離別の数
a,ans =np.unique(dist,return_counts=True)      
ans =np.delete(ans,0) #距離０を削除
count_zero =N-1-len(ans) 
ans =np.append(ans,np.zeros(count_zero))#存在しない遠い距離は０

#出力
for i in ans:
    print(int(i))

Submission status: Runtime Error

Solution code:
n,x,y = map(int,input().split())
k = [0]*(n)

for i in range(1,n):
  for j in range(i+1,n+1):
    ind = abs(x-i) + abs(j-y) + 1
    k[ind] += 1
      
for i in range(1,n):
  print(k[i])

Submission status: Runtime Error

Solution code:
import collections
n,x,y=map(int,input().split())
lit=[]
for i in range(1,N+1):
  for j in range(i+1,N+1):
     lit.append(min(abs(i-j),abs(x-j)+abs(y-i)+1,abs(y-j)+abs(x-i)+1))
a=lit.collections.Counter
for i in range(1,N):
  print(a[i])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
N,X,Y = mips()
G = dict()
for i in range(0,N):
    G[i] = []
for i in range(0,N-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[X-1].append(Y-1)
G[Y-1].append(X-1)
ans = [0 for _ in range(N)]
def bfs(v,G,queue,dist):
    seen[v] = True
    for vertex in G[v]:
        if seen[vertex]:
            continue
        elif vertex in queue:
            continue
        queue.append(vertex)
        dist[vertex] = dist[v] + 1
    for elements in queue:
        queue.remove(elements)
        bfs(elements,G,queue,dist)
for k in range(0,N):
    dist = [-1 for _ in range(N)]
    dist[k] = 0
    seen = [False for _ in range(N)]
    queue = []
    bfs(k,G,queue,dist)
    for j in range(1,N):
        a = dist.count(j)
        ans[j-1] += a
for j in range(1,N):
    print(ans[j-1]//2)

Submission status: Runtime Error

Solution code:
def mips():
  return map(int,input().split())
N,X,Y = mips()
G = dict()
for i in range(0,N):
    G[i] = []
for i in range(0,N-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[X-1].append(Y-1)
G[Y-1].append(X-1)
ans = [0 for _ in range(N)]
def bfs(v,G,queue,dist):
    seen[v] = True
    for vertex in G[v]:
        if seen[vertex]:
            continue
        elif vertex in queue:
            continue
        queue.append(vertex)
        dist[vertex] = dist[v] + 1
    for elements in queue:
        queue.remove(elements)
        bfs(elements,G,queue,dist)
for k in range(0,N):
    dist = [-1 for _ in range(N)]
    dist[k] = 0
    seen = [False for _ in range(N)]
    queue = []
    bfs(k,G,queue,dist)
    for j in range(1,N):
        a = dist.count(j)
        ans[j-1] += a
for j in range(1,N):
    print(ans[j-1]//2)

Submission status: Runtime Error

Solution code:
N,X,Y = mips()
G = dict()
for i in range(0,N):
    G[i] = []
for i in range(0,N-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[X-1].append(Y-1)
G[Y-1].append(X-1)
ans = [0 for _ in range(N)]
def bfs(v,G,queue,dist):
    seen[v] = True
    for vertex in G[v]:
        if seen[vertex]:
            continue
        elif vertex in queue:
            continue
        queue.append(vertex)
        dist[vertex] = dist[v] + 1
    for elements in queue:
        queue.remove(elements)
        bfs(elements,G,queue,dist)
for k in range(0,N):
    dist = [-1 for _ in range(N)]
    dist[k] = 0
    seen = [False for _ in range(N)]
    queue = []
    bfs(k,G,queue,dist)
    for j in range(1,N):
        a = dist.count(j)
        ans[j-1] += a
for j in range(1,N):
    print(ans[j-1]//2)

Submission status: Runtime Error

Solution code:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import PriorityQueue
# sys.setrecursionlimit(2000000)

def distance(X, Y, start, goal):
    ans = float('inf')

    tmp = goal - start
    if tmp < ans:
        ans = tmp

    # start ~ X ~ Y ~ goal,
    tmp = abs(X - start) + 1 + abs(goal - Y)
    if tmp < ans:
        ans = tmp

    # start ~ Y ~ X ~ goal
    tmp = abs(Y - start) + 1 + abs(goal - X)
    if tmp < ans:
        ans = tmp

    return ans

#     # 短絡パスを使える場合
#     if start <= X and Y <= goal

#     # 短絡パスを使えないならば、普通に距離を計算
#     if X < start:
#         return goal - start

#     # 短絡パスを使えても、隣のパスへの距離は1
#     if goal - start == 1:
#         return 1

#     # 短絡パスより手前だと使えない
#     if goal < Y:
#         return goal - start



    # return goal - start - 1

def main():
    # N = int(input())

    N, X, Y = [int(s) for s in input().split()]

    distance_dict = {}
    for i in range(1, N+1):
        for j in range(i + 1, N+1):
            d = distance(X, Y, i, j)
            # sys.stderr.write('{} to {} : d = {}\n'.format(i, j, d))
            # ditance_dict[(i, j)] = d
            if d in distance_dict:
                distance_dict[d] += 1
            else:
                distance_dict[d] = 1

    for k in range(1, N):
        # print(str(distance_dict[k]))
        print(distance_dict[k])

    # As = []
    # Bs = []
    # for i in range(N):
    #     A, B = [int(s) for s in input().split()]
    #     As.append(A)
    #     Bs.append(B)

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
# from collections import Counter
# from queue import PriorityQueue
# sys.setrecursionlimit(2000000)

def distance(X, Y, start, goal):
    ans = float('inf')

    tmp = goal - start
    if tmp < ans:
        ans = tmp

    # start ~ X ~ Y ~ goal,
    tmp = abs(X - start) + 1 + abs(goal - Y)
    if tmp < ans:
        ans = tmp

    # start ~ Y ~ X ~ goal
    tmp = abs(Y - start) + 1 + abs(goal - X)
    if tmp < ans:
        ans = tmp

    return min(ans)

#     # 短絡パスを使える場合
#     if start <= X and Y <= goal

#     # 短絡パスを使えないならば、普通に距離を計算
#     if X < start:
#         return goal - start

#     # 短絡パスを使えても、隣のパスへの距離は1
#     if goal - start == 1:
#         return 1

#     # 短絡パスより手前だと使えない
#     if goal < Y:
#         return goal - start



    # return goal - start - 1

def main():
    # N = int(input())

    N, X, Y = [int(s) for s in input().split()]

    distance_dict = defaultdict(int)
    for i in range(1, N+1):
        for j in range(i + 1, N+1):
            d = distance(X, Y, i, j)
            # sys.stderr.write('{} to {} : d = {}\n'.format(i, j, d))
            # ditance_dict[(i, j)] = d
            distance_dict[d] += 1

    for k in range(1, N):
        # print(str(distance_dict[k]))
        print(distance_dict[k])

    # As = []
    # Bs = []
    # for i in range(N):
    #     A, B = [int(s) for s in input().split()]
    #     As.append(A)
    #     Bs.append(B)

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Runtime Error

Solution code:
n = int(input())
x , y = map(int,input().split())
x = x -1
y = y -1
ans = [0] *N
for i in range(n):
    for j in range(i+1,n)
        d = min(j -i, abs(i-x) + (j-y)+1)
        ans[d] +=1
print(*ans[1:],sep = '\n')

Submission status: Runtime Error

Solution code:
import sys


def line(N, X, Y):
    X = X - 1
    Y = Y - 1

    queue = [(a, a) for a in range(N - 1)]
    visited = set()

    for i in range(N - 1):
        new_queue = []

        def add_to_queue(x, y):
            if y == N or y < 0:
                return
            if x == N or x < 0:
                return
            if x == y:
                return

            if x > y:
                x, y = y, x

            t = (x, y)
            if t not in visited:
                new_queue.append(t)
                visited.add(t)

        for q in queue:
            add_to_queue(q[0], q[1] + 1)
            add_to_queue(q[0], q[1] - 1)
            add_to_queue(q[0] + 1, q[1])
            add_to_queue(q[0] - 1, q[1])

            if q[1] == X:
                add_to_queue(q[0], Y)
            if q[1] == Y:
                add_to_queue(q[0], X)
            if q[0] == X:
                add_to_queue(Y, q[1])
            if q[0] == Y:
                add_to_queue(X, q[1])

        print(f"{len(new_queue)}")
        # print(f"{len(new_queue)} {new_queue}")
        queue = new_queue


N, X, Y = map(int, input().split())
line(N, X, Y)

# line(5, 2, 4)
# print()
# line(3, 1, 3)
# print()
# line(7, 3, 7)
# print()
# line(10, 4, 8)

Submission status: Runtime Error

Solution code:
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
print(c)
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N+1):
  ans = c[i]
  print(ans)

Submission status: Runtime Error

Solution code:
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
        else:
            cnt[j - i] += 1

for i in range(1, n):
    print(cnt[i])

Submission status: Runtime Error

Solution code:
from collections import deque
N,X,Y = map(int,input().split())

concat = [[i,i+2] if not (i==0 or i==N-1) else [] for i in range(N)]
concat[0].append(2)
concat[N-1].append(N-1)
concat[X-1].append(Y)
concat[Y-1].append(X)


def bfs():
    #global que
    if len(que)==0:
        return
    out = que.popleft()
    for out_element in concat[out-1]:
        if check[out_element-1]==-1:
            check[out_element-1] = check[out-1]+1
            que.append(out_element)
    bfs()


li_=[0 for i in range(N)]
for i in range(1,N+1):
    check = [-1 for k in range(N)]
    check[i-1]=0
    que = deque([i])
    bfs()
    for i in range(N):
        li_[i] += check.count(i)


    
for i in range(1,N):
    print(li_[i]//2)

Submission status: Runtime Error

Solution code:
from collections import deque

n, x, y = map(int, input().split())

ans = [0] * (n+1)

g = [[i+1, i-1] for i in range(n+1)]
g[0].clear()
g[1].pop(1)
g[n].pop(0)

g[x].append(y)
g[y].append(x)

for i in range(1,n+1):
    q = deque()
    time = 0
    visit = [False] * (n+1)
    q.append((i, time))

    while(len(q) > 0):
        item = q.popleft()

        if visit[item[0]] == False:
            visit[item[0]] = True
            ans[item[1]] += 1
            for k in g[item[0]]:
                q.append((k, item[1]+1))

for i in range(1,n):
    print(ans[i]//2)

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)
q=int(input())
cnt=1

for _ in range(q):
	a=list(input().split())
	if len(a)==1:
		cnt*=(-1)
	else:
		if cnt==1:
			if a[1]=="1":
				s=a[2]+s
			else:
				s=s+a[2]
		else:
			if a[1]=="1":
				s=s+a[2]
			else:
				s=a[2]+s
				
if cnt==-1:
	s=s[::-1]
	
print(s)

Submission status: Runtime Error

Solution code:

import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

N,X,Y = map(int,input().split())

# スパース行列の作成
data = [1]*N

row = [int(x) for x in range(N-1)]
row.append(X-1)

col = [int(x+1) for x in range(N-1)]
col.append(Y-1)

S_Mat = csr_matrix((data, (row, col)), shape=(N,N)).toarray()
S_Mat += S_Mat.T

# 最短経路行列の取得
SP_Mat = dijkstra(S_Mat, directed=False, unweighted=True)

for k in range(N-1):
    print(int(np.sum(SP_Mat == k+1)/2))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

N, X, Y = [int(_) for _ in input().split()]

al = []

def dfs(f, n, pos, dis):

    global al
    if n in pos:
        return
    pos2 = pos + [n]
    if f != n:
        al += [[[f, n], dis]]
    
    for i in [-1, 1]:
        if 1 <= n + i <= N and not n+i in pos:
            dfs(f, n+i, pos2, dis+1)

    if n == X:
        dfs(f, Y, pos2, dis+1)
    if n == Y:
        dfs(f, X, pos2, dis+1)


for i in range(1, N):
    dfs(i, i, [], 0)

new = []
for i in range(len(al)):
    if al[i][0][0] > al[i][0][1]:
        al[i][0][0], al[i][0][1] = al[i][0][1], al[i][0][0]


a = [[0, 0], 0]
dis = 0
ne = []

for ct, i in enumerate(sorted(al)):
    if a[0] != i[0]:
        ne += [[a[0], dis]]
        a = i
        dis = a[1]
    else:
        dis = min(dis, i[1])

    if ct == len(sorted(al)) - 1: 
        ne += [[i[0], dis]]

ne = ne[1:]
s = [0] * (N-1)
for i in ne:
    s[i[1]-1] += 1
for i in s:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]

ans = [0] * n

for a in range(1, n+1):
    for b in range(a+1, n+1):
        d = b - a
        d2 = abs(X-a) + abs(Y-b) + 1
        d = d if d < d2 else d2
        ans[d] += 1

for i in range(1, n):
    print(ans[i])

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int, input().split())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
r=list(map(int, input().split()))
p=sorted(p)
q=sorted(q)
r=sorted(r)
print(sum(sorted(p[-x:]+q[-y:]+r[-x-y:])[-x-y:]))

Submission status: Runtime Error

Solution code:
N, X, Y = map(int, input().split())

counts = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        # i -> x 直接
        d1 = abs(j-i)
        # i -> X -> Y -> j
        d2 = abs(i-X) + abs(Y-j) + 1

        d = min(d1, d2, d3)
        counts[d] += 1


for i in range(1, N):
    print(counts[i])

Submission status: Runtime Error

Solution code:
result = []

for i in range(1, N+1):
    for j in range(i, N+1):
        result.append(min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X)))

for i in range(1, N):
    print(result.count(i))

Submission status: Runtime Error

Solution code:
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(j-y)),abs(y-i)+1+abs(j-x)-1]+=1
for i in range(n-1):
    print(ans[i])

Submission status: Runtime Error

Solution code:
import networkx as nx

N, X, Y = map(int, input().split())

G = nx.Graph()

for i in range(1, N):
    G.add_edge(i, i+1)

G.add_edge(X, Y)

ans = {}

for i in range(1, N):
    ans[i] = 0

for node, s in nx.shortest_path_length(G):
#    print(node, s)
    for n, d in s.items():
        if d == 0: continue
        ans[d] += 1

for n, d in ans.items():
    print(d//2)

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
N, X, Y = map(int, input().split())
@njit
def f(N,X,Y):
    k_list = np.zeros(shape=N-1,dtype=np.int8)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            min_dst = min((j-i, abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X)))
            k_list[min_dst-1] += 1
    return k_list
ans=f(N,X,Y)
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
N, X, Y = map(int, input().split())
@njit
def f(N,X,Y):
    k_list = np.zeros(shape=N-1,dtype=np.int8)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            min_dst = min((j-i, abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X)))
            k_list[min_dst-1] += 1
    for i in k_list:
        print(i)
f(N,X,Y)

Submission status: Runtime Error

Solution code:
N,X,Y=map(int,input().split())
N=[0]*(N+1)
for i in range(1,N):
  for j in range(i+1,N+1):
    m=min(j-i,abs(Y-j)+abs(X-i)+1)
    N[m]+=1
for k in range(1,N):
  print(A[k])

Submission status: Runtime Error

Solution code:
N=int(input())
N=[0]*(N+1)
for i in range(1,N):
  for j in range(i+1,N+1):
    m=min(j-i,abs(Y-j)+abs(X-i)+1)
    N[m]+=1
for k in range(1,N):
  print(A[k])

Submission status: Runtime Error

Solution code:
N=int(input())
N=[0]*(N+1)
for i in range(1,N):
  for j in range(i+1,N+1):
    m=min(j-i,abs(Y-j)+abs(X-i)+1)
    N[m]+=1
for k in range(1,N+1):
  print(A[k])

Submission status: Runtime Error

Solution code:
N ,X, Y = map(int, input().split())

X -= 1
Y -= 1
k = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-x)+1+abs(y-j)
        c = abs(j-x)+1+abs(y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])

Submission status: Runtime Error

Solution code:
N ,X, Y = map(int, input().split())

X -= 1
Y -= 1
k = [0]*n

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-x)+1+abs(y-j)
        c = abs(j-x)+1+abs(y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])

Submission status: Runtime Error

Solution code:
import numpy as np
inf = np.iinfo(np.uint32).max



def solve():
    count_dists = np.zeros(n+1, dtype=int)
    for a in range(1,n+1):
        for b in range(1,a+1):
            dis = min(abs(b-a), abs(x-a)+ abs(y-b) + 1, abs(y-a) + abs(x-b) + 1)
            count_dists[dis] += 1
    #print(min_dists)
    for j in range(1,n):
        print(count_dists[j])


#
# def ceildiv(a, b):
#     return a // b + a % b



n, x, y = [int(i) for i in input().split(" ")]

solve()

Submission status: Runtime Error

Solution code:
import math
n, x, y = map(int,input().split())
num = [0 for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        num[min([j-i,math.fabs(j-y)+1+math.fabs(i-x)])] += 1

for i in range(n):
    print(num[i])

Submission status: Runtime Error

Solution code:
import math
n, x, y = map(int,input().split())
num = [0 for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        num[min([j-i,math.fabs(j-y)+1+math.fabs(i-x)] += 1

for i in range(n):
    print(num[i])

Submission status: Runtime Error

Solution code:
import math
n, x, y = map(int,input().split())
num = [0 for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        num[min([j-i,math.fabs(j-y)+1+math.fabs(i-x))] += 1

for i in range(n):
    print(num[i])

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(){
  int n, x, y; cin >> n >> x >> y;
  vector<vector<int> > v(n + 1);
  for(int i = 1; i < n; i++){
    v[i].push_back(i + 1);
    v[i + 1].push_back(i);
    if(i == x){
      v[i].push_back(y);
      v[y].push_back(i);
    }
  }

  /*for(int i = 1; i <= n; i++){
    for(int j = 0; j < v[i].size(); j++){
      cout << v[i][j] << " ";
    }
    cout << endl;
  }*/

  vector<vector<int> > dis(n + 1, vector<int>(n + 1, 2000));
  for(int i = 1; i <= n; i++){
    queue<int> q;
    q.push(i);
    vector<bool> visted(n + 1, false);
    visted[i] = true;
    dis[i][i] = 0;
    while(q.size() > 0){
      int f = q.front(); q.pop();
      for(int j = 0; j < v[f].size(); j++){
        if(visted[v[f][j]] == false){
          q.push(v[f][j]);
          visted[v[f][j]] = true;
          dis[i][v[f][j]] = min(dis[i][v[f][j]], dis[i][f] + 1);
        }
      }
    }
  }
  vector<int> ans(n + 1, 0);
  for(int i = 1; i <= n; i++){
    //cout << i << "->";
    for(int j = i + 1; j <= n; j++){
      //cout << dis[i][j] << " ";
      ans[dis[i][j]]++;
    }
    //cout << endl;
  }
  for(int i = 1; i < n; i++) cout << ans[i] << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
K = int(input())
l = [i for i in range(1,10)]

def func(x):
    y = x%10
    if y == 0:
        return [x*10,x*10+1]
    elif y == 9:
        return [x*10+8,x*10+9]
    else:
        return [x*10+y-1,x*10+y,x*10+y+1]

li1 = l[:]
li2 = []
if K < 10:
    print(K)
else:
    while True:
        for i in li1:
            a = func(i)
            li2.extend(a)
        l.extend(li2)
        if len(l) >=K:
            break
        else:
            li1 = li2[:]
            li2 = []
    print(l[K-1])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        for lnkItem in linkL[item]:
            linkL[lnkItem].remove(item)
            if chckL[lnkItem] == -1:
                chckL[lnkItem] = breath+1
                pasNL.append(lnkItem)
        linkL[item] = []

    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL


import copy

N, X, Y = map(int, input().split())
mySum = [0] * (N-1)

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1: tmpList.append(Y-1)
    if indx == Y-1: tmpList.append(X-1)
    lList.append(tmpList)


for baseIndx in range(N):
    tmpLink = copy.deepcopy(lList)

    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(tmpLink, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        for lnkItem in linkL[item]:
            linkL[lnkItem].remove(item)
            if chckL[lnkItem] == -1:
                chckL[lnkItem] = breath+1
                pasNL.append(lnkItem)
        linkL[item] = []

    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL


N, X, Y = map(int, input().split())
mySum = [0] * (N-1)

for baseIndx in range(N):

    lList = []

    for indx in range(N):
        tmpList = []
        if indx != 0:   tmpList.append(indx-1)
        if indx != N-1: tmpList.append(indx+1)
        if indx == X-1: tmpList.append(Y-1)
        if indx == Y-1: tmpList.append(X-1)
        lList.append(tmpList)

    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        # print(item, breath)
        chckL[item] = breath

    for item in nextNL:
        for lnkItem in linkL[item]:
            # linkL[lnkItem].remove(item)
            if (chckL[lnkItem] == -1) and (lnkItem not in pasNL):
                pasNL.append(lnkItem)
        # linkL[item] = []
    
    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL

N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1: tmpList.append(Y-1)
    if indx == Y-1: tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList = bfs(lList, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    for item in nextNL:
        chckL[item] = breath
    
    NL = []
    for nextItem in nextNL:
        for chckItem in linkL[nextItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
                chckL[chckItem] = -2
    
    if len(NL) == 0:
        return chckL
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1:   tmpList.append(Y-1)
    if indx == Y-1:   tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    for item in nextNL:
        chckL[item] = breath
    
    NL = []
    for nextItem in nextNL:
        for chckItem in linkL[nextItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
    
    if len(NL) == 0:
        return chckL
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1:   tmpList.append(Y-1)
    if indx == Y-1:   tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    unsrchedNL = []
    for item in nextNL:
        chckL[item] = breath
        unsrchedNL.append(item)
    
    if len(unsrchedNL) == 0:
        return chckL
    
    NL = []
    for unsrchedItem in unsrchedNL:
        for chckItem in linkL[unsrchedItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

X -= 1
Y -= 1

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X:   tmpList.append(Y)
    if indx == Y:   tmpList.append(X)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
def bfs(linkL, chckL, nextNL, breath):
    unsrchedNL = []
    for item in nextNL:
        if chckL[item] == -1:
            chckL[item] = breath
            unsrchedNL.append(item)
    
    if len(unsrchedNL) == 0:
        return chckL
    
    NL = []
    for unsrchedItem in unsrchedNL: NL += linkL[unsrchedItem]
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

X -= 1
Y -= 1

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X:   tmpList.append(Y)
    if indx == Y:   tmpList.append(X)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Submission status: Runtime Error

Solution code:
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

dist = []
for i in range(n):
    dist.append([110110] * n)

def dfs(now, s):
    if now != 0:
        if dist[s][now] + 1 < dist[s][now-1]:
            dist[s][now-1] = dist[s][now] + 1
            dfs(now-1, s)
    if now != n-1:
        if dist[s][now] + 1 < dist[s][now+1]:
            dist[s][now+1] = dist[s][now] + 1
            dfs(now+1, s)
    if now == x:
        if dist[s][now] + 1 < dist[s][y]:
            dist[s][y] = dist[s][now] + 1
            dfs(y, s)
    if now == y:
        if dist[s][now] + 1 < dist[s][x]:
            dist[s][x] = dist[s][now] + 1
            dfs(x, s)

cnt = [0] * n

for i in range(n):
    dist[i][i] = 0
    dfs(i, i)

for i in range(n):
    for j in range(n):
        cnt[dist[i][j]] += 1
        
for i in range(1, n):
    print(cnt[i] // 2)