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: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,X,Y=MI()
    X-=1
    Y-=1
    
    ans=[0]*N
    
    for i in range(N):
        for j in range(i+1,N):
            if j<=X:
                d=j-i
            elif i>=Y:
                d=j-i
            elif i<=X and j>=Y:
                d=X-i + j-Y +1
            elif i<=X and j<=Y:
                d=min(j-i,X-i +1 +Y-j)
            elif i>=X and j>=Y:
                d=min(j-i, i-X +1 +j-Y)
            else:#どっちも内側
                d=j-i
                
            ans[d-1]+=1
            
    for i in range(N-1):
        print(ans[i])
                

                
   

main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

g = [[] for _ in range(n)]

for i in range(n - 1):
    g[i].append(i + 1)
    g[i + 1].append(i)
g[x - 1].append(y - 1)
g[y - 1].append(x - 1)


def bfs(g, n_node, start_node):         #　g:連結リスト、n_node:ノード数、start_node:開始ノード
    dist = [-1] * n_node                #　ノード間の距離の初期値を-1にする。
    dist[start_node] = 0                #　開始ノードの距離を0にする
    que = deque([start_node])           #　start_nodeを入れたqueを作成

    while que:                          #　queの値がなくなるまで繰り返す
        node = que.popleft()            #　queの頭から1つnodeを取り出す
        for gn in g[node]:              #　連結リストのnode分を取り出す
            if dist[gn] != -1:          #　nodeに連結されているノードの確認
                continue                #　距離が初期値でなければ、既に訪れていて、計算済み
            dist[gn] = dist[node] + 1   #　距離が初期値であれば、初めの訪問でnodeの距離から1遠い
            que.append(gn)              #　queにgnのノードを加える
    return dist                         #　dist:nodeから各連結リストへの距離を返す


ans = [0] * n

for i in range(n):
    dist = bfs(g, n, i)
    for d in dist:
        ans[d] += 1
[print(i) for i in ans]

Submission status: Wrong Answer

Solution code:

n, x, y = map(int, input().split())
m = n - y + x + 1
s = y - x
flg = s % 2
s_rev = s // 2

for i in range(1, n):
    if m - i > 0:
        cnt = m - i
    else:
        cnt = 0

    for j in range(1, x):
        if j + i == x + 1:
            cnt += 1
        elif x + 1 < j + i <= x + s_rev:
            cnt += 2

    for k in range(y + 1, n + 1):
        if k - i == y - 1:
            cnt += 1
        elif y - s_rev <= k - i < y - 1:
            cnt += 2

    if flg == 1 and i >= s_rev + 2:
        cnt += x != 1 + y != n

    if flg == 0:
        if i == 1:
            cnt += s
        elif i <= s_rev:
            cnt += s + 1
    elif flg == 1:
        if i == 1:
            cnt += s
        elif i == s_rev + 1:
            cnt += y // 2
        elif i <= s_rev + 1:
            cnt += s + 1
    print(cnt)

Submission status: Wrong Answer

Solution code:

n, x, y = map(int, input().split())
m = n - y + x + 1
s = y - x
flg = s % 2
s_rev = s // 2

for i in range(1, n):
    if m - i > 0:
        cnt = m - i
    else:
        cnt = 0

    for j in range(1, x):
        if j + i == x + 1:
            cnt += 1
        elif x + 1 < j + i <= x + s_rev:
            cnt += 2

    for k in range(y + 1, n + 1):
        if k - i == y - 1:
            cnt += 1
        elif y - s_rev <= k - i < y - 1:
            cnt += 2

    if flg == 1 and i >= s_rev + 2:
        cnt += x != 1 + y != n

    if flg == 0:
        if i <= s_rev:
            if i == 1:
                cnt += s
            else:
                cnt += s + 1
    elif flg == 1:
        if i <= s_rev + 1:
            if i == 1:
                cnt += s
            elif i == s_rev + 1:
                cnt += y // 2
            else:
                cnt += s + 1
    print(cnt)

Submission status: Wrong Answer

Solution code:

n, x, y = map(int, input().split())
m = n - y + x + 1
s = y - x
flg = s % 2
s_rev = s // 2

for i in range(1, n):
    if m - i > 0:
        cnt = m - i
    else:
        cnt = 0

    for j in range(1, x):
        if j + i == x + 1:
            cnt += 1
        elif x + 1 < j + i <= x + s_rev:
            cnt += 2

    for k in range(y + 1, n + 1):
        if k - i == y - 1:
            cnt += 1
        elif y - s_rev <= k - i < y - 1:
            cnt += 2

    if flg == 1 and i >= s_rev + 2:
        cnt += x != 1 + y != n

    if flg == 0:
        if i <= s_rev:
            if i == 1:
                cnt += s
            else:
                cnt += s + 1
    elif flg == 1:
        if i <= s_rev + 1:
            if i == 1:
                cnt += s
            else:
                cnt += s + 1
    print(cnt)

Submission status: Wrong Answer

Solution code:

n, x, y = map(int, input().split())
m = n - y + x + 1
s = y - x
flg = s % 2
s_rev = s // 2

for i in range(1, n):
    if m - i > 0:
        cnt = m - i
    else:
        cnt = 0

    for j in range(1, x):
        if j + i == x + 1:
            cnt += 1
        elif x + 1 < j + i <= x + s_rev:
            cnt += 2

    for k in range(y + 1, n + 1):
        if k - i == y - 1:
            cnt += 1
        elif y - s_rev <= k - i < y - 1:
            cnt += 2

    if flg == 1 and i >= s_rev + 1:
        cnt += x != 1 + y != n

    if flg == 0:
        if i <= s_rev:
            if i == 1:
                cnt += s
            else:
                cnt += s + 1
    elif flg == 1:
        if i <= s_rev + 1:
            if i == 1:
                cnt += s
            else:
                cnt += s + 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]

for i in range(n):
  if i+1 < n:
    graph[i].append(i+1)
  if i-1 >=0:
    graph[i].append(i-1)
graph[x-1].append(y-1)
graph[y-1].append(x-1)

ans = [0] * (n-1)
from collections import deque
for i in range(n):
  dist = [-1] * n
  dist[i] = 0
  d = deque()
  d.append(i)
  while d:
    v = d.popleft()
    for j in graph[v]:
      if j < i or dist[j] != -1:
        continue
      dist[j] = dist[v] + 1
      ans[dist[j] - 1] += 1
      d.append(j)
for a in ans:
  print(a)

Submission status: Wrong Answer

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

d = Y - X
sum_index = N * (N-1)

k = []

for i in range(N-1):
    for j in range(i+1, N):
        if i+1 <= X and Y <= j+1:
            k.append(j - i - d + 1)
        else:
            k.append(j - i)
print(k)
for i in range(N-1):
    print(k.count(i+1))

Submission status: Wrong Answer

Solution code:
N,X,Y=map(int,input().split())
loop=Y-X+1
line=N-loop+2

def f(line,loop,i):
    if i<=line:
        res=0
    elif i==line+1:
        res=1
    else:
        res=2
    if not loop%2:
        if line+loop//2==i:
            res=1
    if line+loop//2<i:
        res=0
    return res

for k in range(1,N):
    res=0
    # line only
    res+=max(line-k,0)
    # loop only
    if k<=loop//2:
        res+=max((loop-2)-k,0)
    for i in range(0,X):
        res+=f(i,loop,k)
    for j in range(0,N-Y+1):
        res+=f(j,loop,k)
    print(res)

Submission status: Wrong Answer

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, X, Y = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

cnt = [0] * N
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        k = min([j - i, abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1])
        print(i,j,k)
        cnt[k] += 1

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

graph = [[] for _ in range(N+1)]
ans = []

for i in range(N):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X].append(Y)
graph[Y].append(X)


#print(graph)

for j in range(N):
    dist = [-1] * (N+1)
    dist[j] = 0
    dist[j+1] = 0

    d = deque()
    d.append(j+1)
    #BFS実行部分
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
    ans.extend(dist[j+2:])
    
for i in range(1, N):
    print(ans.count(i))
#print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for i in range(N-1):
    graph[i].append(i+1)
    #graph[i+1].append(i)
    
graph[X-1].append(Y-1)
#graph[Y-1].append(X-1)

answer=[0 for i in range(N)]
for i in range(N):
    d=deque([i])
    dist=[-1 for _ in range(N)]
    dist[i]=0
    while d:
        v=d.popleft()
        for i in graph[v]:
            if dist[i]!=-1:
                continue
            dist[i]=dist[v]+1
            d.append(i)
    for j in range(1,N):
        answer[j]+=dist.count(j)

for j in range(1,N):
    print(answer[j])

Submission status: Wrong Answer

Solution code:
import queue
n,x,y=map(int,input().split())
edge=[[i-1,i+1] for i in range(n)]
edge[0],edge[-1]=[1],[n-2]
edge[x-1].append(y-1)
edge[y-1].append(x-1)
inf=100
ans=[0]*n
for i in range(n):
    q=queue.deque([i])
    dist=[inf]*n
    dist[i]=1
    while q:
        a=q.pop()
        for e in edge[a]:
            if dist[e]==inf:
                q.appendleft(e)
                dist[e]=dist[a]+1
    for v in dist:
        ans[v-1]+=1
for i in range(n-1):
    print(ans[i+1]//2)

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    d = [0]*n

    for i in range(1, n):
        for j in range(i+1, n+1):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            d[min(j-i, abs(x-i) +
                  1+abs(j-y), abs(y-i)+1+abs(j-x))] += 1

    for k in range(n):
        print(d[k])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    d = [0]*n

    for i in range(1, n):
        for j in range(i+1, n):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            d[min(j-i, abs(x-i) +
                  1+abs(j-y), abs(y-i)+1+abs(j-x))] += 1

    for k in range(n):
        print(d[k])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    d = [0]*n

    for i in range(1, n):
        for j in range(i+1, n):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            d[min(j-i, abs(x-i) +
                  1+abs(j-y), abs(y-i)+1+abs(j-x))] += 1

    for k in range(n):
        print(d[k])

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    d = [0]*n

    for i in range(1, n):
        for j in range(i+1, n+1):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            d[min(j-i, abs(x-i) +
                  1+abs(j-y), abs(y-i)+1+abs(j-x))] += 1

    for k in range(n):
        print(d[k])

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    tree = [None]*n

    for i in range(1, n):
        for j in range(i+1, n+1):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            tree[i - 1].append(min(j-i, abs(x-i) +
                                     1+abs(j-y), abs(y-i)+1+abs(j-x)))

    for k in range(1, n):
        ans = 0
        for i in range(n):
            ans += tree[i].count(k)
        print(ans)

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    tree = [[0] * n for i in range(n)]

    for i in range(1, n):
        for j in range(i+1, n+1):
            if i <= x and j >= y:
                tree[i - 1][j - 1] = j-i-(y - x - 1)
            elif i <= x and j < y:
                tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            elif i > x and j >= y:
                tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            else:
                tree[i - 1][j - 1] = j-i

    for k in range(1, n):
        ans = 0
        for i in range(n):
            ans += tree[i].count(k)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

for a in ans:
  print(a)

Submission status: Wrong Answer

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

count = [int(0)] * (N-1)


for i in range(1,N):
    path = abs(X-i) 
    ii = i-1
    for j in range(i+1,N+1):
        dist = min(j-ii, path+abs(Y-j))
        count[dist] +=1


print("\n".join(map(str,count)))

Submission status: Wrong Answer

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

res = deque()

for x in range(1, N):
    for y in range(x + 1, N+1):
        res.append(min([abs(x-y), 1 + abs(X-x) + abs(Y-y), 1 + abs(Y-x) + abs(X-x)]))
resd = Counter(res)

for i in range(1, N):
    if i in resd.keys():
        print(resd[i])
    else:
        print(0)

Submission status: Wrong Answer

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

res = deque()

for x in range(1, N+1):
    for y in range(x + 1, N+1):
        res.append(min([abs(x-y), 1 + abs(X-x) + abs(Y-y), 1 + abs(Y-x) + abs(X-x)]))
resd = Counter(res)

for i in range(1, N):
    if i in resd.keys():
        print(resd[i])
    else:
        print(0)

Submission status: Wrong Answer

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

res = deque()

for x in range(1, N+1):
    for y in range(x + 1, N+1):
        res.append(min([abs(x-y), 1 + abs(X-x) + abs(Y-y), 1 + abs(Y-x) + abs(X-x)]))
resd = Counter(res)

for i in range(1, N):
    if i in resd:
        print(resd[i])
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
ans = [0]*(N-1)

def cal_dis(i, j):
    return min(j-i, abs(i-X)+abs(j-Y)+1)

for i in range(1, N+1):
    for j in range(i+1, N+1):
        k = cal_dis(i, j)
        ans[k] += 1

print('\n'.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import math

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

distL = [0 for _ in range(2001)]
for s in range(1, n + 1):
    for e in range(s + 1, n + 1):
        _min = 0
        if s <= x and y <= e:
            _min = min(e - s, (e - y) + (x - s) + 1)
        elif s > x and y <= e:
            _min = min(s - x + 1, e - s)
        elif s <= x and y > e:
            _min = min(e - s, (x - s) + (y - e) + 1)
        else:
            _min = min((s - x) + (y - e) + 1, e - s)
        distL[_min] += 1

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

Submission status: Wrong Answer

Solution code:
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for j in range(i+1,n):
    if i<=x-1 and j>=y-1:
      d=(x-1)-i+j-(y-1)+1
    else:
      d=j-i
    l.append(d)
import collections
c=collections.Counter(l)
for kk in range(1,n):
  print(c[kk])

Submission status: Wrong Answer

Solution code:
from collections import deque
 
N, X, Y = [int(x) for x in input().split()]
 
graph = {}
 
for i in range(1, N):
    if i in graph:
        graph[i].append(i + 1)
    else:
        graph[i] = [i+1]
 
    if i + 1 in graph:
        graph[i + 1].append(i)
    else:
        graph[i+1] = [i]
 
graph[X].append(Y)
graph[Y].append(X)
 
 
def check(graph, k):
    result = 0
    debug = []
    queue = deque()
    for key, v in graph.items():
        queue.append((key, v, 0))
        visited = set()
 
        while queue:
            pos = queue.pop()
            if pos[2] == k and pos[0] > key:
                if not pos[0] in visited:
                    result += 1
            else:
                visited.add(pos[0])
 
                for next_pos in pos[1]:
                    if not next_pos in visited:
                        if pos[2] + 1 <= k:
                            queue.appendleft(
                                (next_pos, graph[next_pos], pos[2] + 1))
    return result
 
 
for k in range(1, N):
    result = check(graph, k)
    print("{}".format(result))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

graph = {}

for i in range(1, N):
    if i in graph:
        graph[i].append(i + 1)
    else:
        graph[i] = [i+1]

    if i + 1 in graph:
        graph[i + 1].append(i)
    else:
        graph[i+1] = [i]

graph[X].append(Y)
graph[Y].append(X)


def check(graph, k):
    result = 0
    debug = []
    queue = deque()
    for key, v in graph.items():
        queue.append((key, v, 0))
        visited = set()

        while queue:
            pos = queue.pop()
            if pos[2] == k and pos[0] > key:
                if not pos[0] in visited:
                    result += 1
            else:
                visited.add(pos[0])

                for next_pos in pos[1]:
                    if not next_pos in visited:
                        if pos[2] + 1 <= k:
                            queue.appendleft(
                                (next_pos, graph[next_pos], pos[2] + 1))
    return result


for k in range(1, N):
    result = check(graph, k)
    print("{}".format(result))

Submission status: Wrong Answer

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

count=[0]*(n-1)
for i in range(n):
    l=i
    for j in range(i+1,n):
        r=j
        if l<=x-1 and r>=y-1:
            dis=(r-l)-(y-x)+1
            count[dis-1]+=1
        elif l>x-1 and r<y-1:
            dis=r-l
            count[dis-1]+=1
        else:
            d=abs(r+l-x-y+2)+1
            mn=min(r-l, d)
            count[mn-1]+=1

for i in range(n-1):
    print(count[i])

Submission status: Wrong Answer

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

adj = [[] for i in range(N)]
for i in range(N):
    if i != 0 and i != N-1:
        adj[i].append(i-1)
        adj[i].append(i+1)
    elif i == 0:
        adj[i].append(1)
    else:
        adj[i].append(N-2)
    if i == X-1:
        adj[i].append(Y-1)
    if i == Y-1:
        adj[i].append(X-1)

ans = [0 for i in range(N-1)]
for i in range(N):
    dist = [-1]*N
    q = deque([i])
    dist[i] = 0
    while q:
        l = q.pop()
        d = dist[l]
        for w in adj[l]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            q.append(w)
    for k in range(1, N):
        ans[k-1] += dist.count(k)
for i in range(N-1):
    ans[i] = ans[i]//2
print(*ans, sep='\n')

Submission status: Wrong Answer

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

adj = [[] for i in range(N)]
for i in range(N):
    if i != 0 and i != N-1:
        adj[i].append(i-1)
        adj[i].append(i+1)
    elif i == 0:
        adj[i].append(1)
    else:
        adj[i].append(N-2)
    if i == X-1:
        adj[i].append(Y-1)
    if i == Y-1:
        adj[i].append(X-1)
ans = [0 for i in range(N-1)]
dists = [[] for i in range(N)]
for i in range(N):
    dist = [-1]*N
    q = deque([i])
    dist[i] = 0
    while q:
        l = q.popleft()
        d = dist[l]
        for w in adj[l]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            q.append(w)
    dists[i].append(dist)
for k in range(1, N):
    for d in dists:
        ans[k-1] += d.count(k)
for i in range(N-1):
    ans[i] = ans[i]//2
print(*ans, sep='\n')

Submission status: Wrong Answer

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

adj = [[] for i in range(N)]
for i in range(N):
    if i != 0 and i != N-1:
        adj[i].append(i-1)
        adj[i].append(i+1)
    elif i == 0:
        adj[i].append(1)
    else:
        adj[i].append(N-2)
    if i == X-1:
        adj[i].append(Y-1)
    if i == Y-1:
        adj[i].append(X-1)
ans = []
for k in range(1, N):
    cur = 0
    for i in range(N):
        dist = [-1]*N
        q = deque([i])
        dist[i] = 0
        while q:
            l = q.popleft()
            d = dist[l]
            for w in adj[l]:
                if dist[w] > -1:
                    continue
                dist[w] = d + 1
                q.append(w)
        print(dist)
        cur += dist.count(k)
    ans.append(cur//2)
print(*ans, sep='\n')

Submission status: Wrong Answer

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

adj = [[] for i in range(N)]
for i in range(N):
    if i != 0 and i != N-1:
        adj[i].append(i-1)
        adj[i].append(i+1)
    elif i == 0:
        adj[i].append(1)
    else:
        adj[i].append(N-2)
    if i == X-1:
        adj[i].append(Y-1)
    if i == Y-1:
        adj[i].append(X-1)
ans = []
for k in range(1, N):
    cur = 0
    for i in range(N):
        dist = [-1]*N
        q = deque([i])
        dist[i] = 0
        while q:
            l = q.popleft()
            d = dist[l]
            for w in adj[l]:
                if dist[w] > -1:
                    continue
                dist[w] = d + 1
                q.append(w)
        print(dist)
        cur += dist.count(k)
    print(cur)
    ans.append(cur//2)
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
#ごり押し

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

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

start = list(range(0, N-1)) + list(range(1, N)) + [X, Y] 
end = list(range(1, N)) + list(range(0, N-1)) + [Y, X]
cost = [1] * len(start)

graph = csr_matrix((cost, (start, end)))
lengths = dijkstra(graph, directed = False)
c = Counter(lengths.astype(np.int64).reshape(-1))
for k in range(1, N):
    print(c[k]//2)

Submission status: Wrong Answer

Solution code:
#ごり押し

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

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

start = list(range(0, N-1)) + list(range(1, N)) + [X, Y] 
end = list(range(1, N)) + list(range(0, N-1)) + [Y, X]
cost = [1] * len(start)

graph = csr_matrix((cost, (start, end)))
lengths = dijkstra(graph, directed = False)
c = Counter(lengths.astype(np.int64).reshape(-1))
for k in range(1, N):
    print(c[k])

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from sys import stdin
    def input():
        return stdin.readline().rstrip()
    def mips():
        return map(int,input().split())
    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)]
    #Question : for k = 1,...,N-1 : 
    #整数の組(i,j)(1≤i<j≤N)であって、Gにおいて頂点iと頂点jの最短距離がkであるようなものの数を求めてください
    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 el in dist:
            ans[el] += 1
        for i in range(1,N):
            print(ans[i]//2)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from sys import stdin
    def input():
        return stdin.readline().rstrip()
    def mips():
        return map(int,input().split())
    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)]
    #Question : for k = 1,...,N-1 : 
    #整数の組(i,j)(1≤i<j≤N)であって、Gにおいて頂点iと頂点jの最短距離がkであるようなものの数を求めてください
    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)
        #print(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])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,X,Y=map(int,input().split())
Z=Y-X-1
ans=0
for i in range(1,N):
  for j in range(1,N-i+1):
    if abs(j-X)+1<=i and Y-(i-abs(j-X)-1)>j+i:
      ans+=1
    if abs(j-X)+1<=i and Y<Y+i-abs(j-X)-1<N and j+i<N and Y+(i-abs(j-X)-1)>j+i:
      ans+=1
    if abs(j-X)+1<=i and Y-(i-abs(j-X)-1)<j+i:
      ans-=1
    if abs(j-X)+1<=i and Y<Y+i-abs(j-X)-1<N and j+i<N and Y+(i-abs(j-X)-1)<j+i:
      ans-=1
  ans+=(N-i)
  if ans<0:
    ans=0
  print(ans)
  ans=0

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, x, y = [int(x) for x in input().split()]
ans = [0 for k in range(n)]
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans[min(abs(i - j), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j))] += 1
print(*(ans), sep='\n')