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: Accepted

Solution code:
a = list(map(int,input().split()))
dis = [0]*a[0]

for i in range(1,a[0]):
    for j in range(i+1,a[0]+1):
        dis[min([ abs(j-i) -1 , abs(i-a[1]) + abs(j-a[2]) + 1 -1 ]) ] += 1

for i in range(a[0]-1):
    print(dis[i])

Submission status: Accepted

Solution code:
#n=int(input())
n,x,y=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

#adjl=[[0 for i in range(n)] for j in range(n)]

dic={}

for i in range(n):
    for j in range(i,n):
        #if i>=j:
        #    continue
        dis=j-i
        maybe=abs(x-(i+1))+1+abs(y-(j+1))
        dis=min(dis,maybe)
        #adjl[i][j]=dis
        dic[dis]=dic.get(dis,0)+1

for k in range(1,n):
    print(dic.get(k,0))

Submission status: Accepted

Solution code:
# from sys import stdin

# # 解説のコード
# def get_result(data):
#     N, X, Y = data
#     dist_cnt = [0 for i in range(N)]
#     for i in range(1, N+1):
#         for j in range(i+1, N+1):
#             min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
#             dist_cnt[min_dist] += 1
#     for i in range(1, N):
#         print(dist_cnt[i])


# if __name__ == '__main__':
#     data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
#     get_result(data)

from sys import stdin
from heapq import heappush, heappop


class Dijkstra:
    def __init__(self, num_nodes):
        self.n = num_nodes
        self.adj_list = [[] for _ in range(self.n)]

    # Edge数分回すことを想定
    def add_edge(self, start, end, weight=1, undirected=True):
        self.adj_list[start].append((end, weight))
        if undirected:
            self.adj_list[end].append((start, weight))

    def distance(self, start):
        # 始点から各頂点までの最短距離を格納する
        self.dist = [float('inf') for _ in range(self.n)]
        # 最短経路における, その頂点の前の頂点のIDを格納する
        self.prev = [-1 for _ in range(self.n)]
        self.dist[start] = 0
        # 各要素は，(頂点vのID, startからある頂点vまでの仮の距離)からなるタプル
        q = []
        heappush(q, (start, 0))
        while len(q) != 0:
            src, prov_cost  = heappop(q)
            # プライオリティキューに格納されている最短距離が, 現在計算できている最短距離より大きければ，distの更新をする必要はない
            if self.dist[src] < prov_cost:
                continue
            # 他の頂点の探索
            for val in self.adj_list[src]:
                dest, cost = val
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost # distの更新
                    heappush(q, (dest, self.dist[dest])) # キューに新たな仮の距離の情報をpush
                    self.prev[dest] = src
        return self.dist


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    solver = Dijkstra(N)
    for val in _data:
        solver.add_edge(val[0]-1, val[1]-1, undirected=True)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        dist = solver.distance(i)
        for j in range(i, N):
            dist_cnt[dist[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
x-=1
y-=1
inf=1<<30
d=[[inf]*n for _ in range(n)]
for i in range(n):
    for j in range(i+1,n):
        d[i][j]=min((j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)))
from collections import Counter
c=Counter()
for i in range(n):
    c+=Counter(d[i])
for k in range(1,n):
    print(c[k])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n):
  for j in range(i + 1, n + 1):
    ans[min(j - i, abs(i - x) + 1 + abs(y - j))] += 1
    # print("頂点" + str(i), "頂点" + str(j), "距離" + str(min(j - i, abs(i - x) + 1 + abs(y - j))))
# i, j 頂点のノード(i < j)　例えば 5 と 25
# j - i 追加されたエッジを使わない場合の距離 i と j の距離
# abs(i - x) + 1 + abs(y - j) 追加されたエッジを使う場合の距離 i と j の距離
# min　で短い方を選択
for i in range(1, n):
  print(ans[i])

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
dic={}
for i in range(1, n+1):
    for j in range(i+1,n+1):
        m = min(abs(y-j)+abs(x-i)+1,j-i)
        if m in dic.keys():
            dic[m] += 1
        else:
            dic[m] =1

for z in range(1,n):
    if z in dic.keys():
        print(dic[z])
    else:
        print(0)

Submission status: Accepted

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) + abs(Y - j) + 1) - 1] += 1
for i in range(N-1):
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    n, x, y = map(int, string.split())
    ans = [0] * n
    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
    return "\n".join(map(str, ans[1:]))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
from collections import defaultdict

dd = defaultdict(int)

n,x,y = map(int,input().split())
x -= 1
y -= 1
for k in range(1,n):
    dd[k] =0

for i in range(n):
    for j in range (i+1,n):
        sp = min(abs(j-i), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)
        dd[sp] += 1

for k in dd:
    print(dd[k])

Submission status: Accepted

Solution code:
import itertools

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

a = [i for i in range(1, n+1)]
b = [0]*(n-1)

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

for l in range(n-1):
    print(b[l])

Submission status: Accepted

Solution code:
# from sys import stdin

# # 解説のコード
# def get_result(data):
#     N, X, Y = data
#     dist_cnt = [0 for i in range(N)]
#     for i in range(1, N+1):
#         for j in range(i+1, N+1):
#             min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
#             dist_cnt[min_dist] += 1
#     for i in range(1, N):
#         print(dist_cnt[i])


# if __name__ == '__main__':
#     data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
#     get_result(data)

from sys import stdin
from collections import deque


class BreadthFirstSearch:
    def __init__(self, num_nodes):
        self.n = num_nodes
        self.graph = [[] for _ in range(self.n)]

    # Edge数分回すことを想定
    def add_edge(self, start, end, undirected=True):
        self.graph[start].append(end)
        if undirected:
            self.graph[end].append(start)

    # depth = distance
    def search(self, start_node):
        order = [-1] * self.n # a bfs ordering of each vertex
        parent = [-1] * self.n # parent of each vertex in the bfs search tree
        depth = [-1] * self.n # the depth of each vertex
        q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
        num = 0 # current ordering
        while len(q) > 0:
            v, p, d = q.popleft()
            if order[v] < 0: # visited v for the first time
                order[v] = num; parent[v] = p; depth[v] = d
                num += 1
                for u in self.graph[v]:
                    if order[u] >= 0: continue
                    q.append((u, v, d+1))
        return order, parent, depth


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    bfs = BreadthFirstSearch(N)
    for val in _data:
        bfs.add_edge(val[0]-1, val[1]-1)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        _, _, depth = bfs.search(i)
        for j in range(i, N):
            dist_cnt[depth[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,x,y = list(map(int,input().split()))
x-=1
y-=1
inf=float("inf")
#最短距離の隣接行列
am = [[inf]*n for _ in range(n)]
for i in range(n):
    for j in range(i,n):
        am[i][j]=min(j-i,abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(x-j))

from math import isinf
ret_bucket = [0] * n
for a_list in am:
    for min_dist in a_list:
        if not isinf(min_dist):
            ret_bucket[min_dist]+=1

for i in ret_bucket[1::]:
    print(i)

Submission status: Accepted

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

[print(l) for l in ans]

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque


# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
    graph = [[] for _ in range(num_nodes)]
    for val in data:
        x, y = val
        graph[x-1].append(y-1)
        if undirected:
            graph[y-1].append(x-1)
    return graph


# BFS
def breadth_first_search(adj_list, start_node):
    N = len(adj_list)
    order = [-1] * N # a bfs ordering of each vertex
    parent = [-1] * N # parent of each vertex in the bfs search tree
    depth = [-1] * N # the depth of each vertex
    q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
    num = 0 # current ordering
    while len(q) > 0:
        v, p, d = q.popleft()
        if order[v] < 0: # visited v for the first time
            order[v] = num; parent[v] = p; depth[v] = d
            num += 1
            for u in adj_list[v]:
                if order[u] >= 0: continue
                q.append((u, v, d+1))
    return order, parent, depth


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    adj_list = get_adj_list(N, _data)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        _, _, depth = breadth_first_search(adj_list, i)
        for j in range(i, N):
            dist_cnt[depth[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)

Submission status: Accepted

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

count=[0]*N

def bfs(start):
    dist=[-1]*(N+1)#indexと頂点の番号を合わせる
    q=deque()
    q.append([start,0])
    dist[start]=0
    while q:
        j,kyori=q.popleft()

        if j-1>=1:
            if dist[j-1]==-1:
                q.append([j-1,kyori+1])
                dist[j-1]=kyori+1

        if j+1<=N:
            if dist[j+1]==-1:
                q.append([j+1,kyori+1])
                dist[j+1]=kyori+1
        
        if j == X and dist[Y]==-1:
            q.append([Y,kyori+1])
            dist[Y]=kyori+1

        if j == Y and dist[X]==-1:
            q.append([X,kyori+1])
            dist[X]=kyori+1

    return dist[1:]

def main():
    for start in range(1,N+1):
        dist=bfs(start)
        for d in dist:
            count[d]+=1

    for i in count[1:]:
        print(i//2)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())

ans_list = [0] * (a-1)

for i in range(1,a+1):
    for j in range(i+1,a+1):
        normal = j-i
        abnormal = abs(b-i)+1+abs(j-c)
        if (normal <= abnormal):
            ans = normal
        else:
            ans = abnormal
        ans_list[ans-1] += 1
print(*ans_list, sep='\n')

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = [0] * (N-1)
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)
		ans[k-1] += 1

for i in range(N-1):
	print(ans[i])

Submission status: Accepted

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):
        sub = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
        ans[sub] += 1

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

Submission status: Accepted

Solution code:
import collections


def distances(n, x, y):
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            yield min(j - i, abs(x - i) + abs(y - j) + 1)


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

c = collections.Counter(distances(N, X, Y))

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

Submission status: Accepted

Solution code:
N, X, Y = tuple(int(v) for v in input().split())

ans = [0 for _ in range(N)]

for i in range(N):
    for j in range(i+1, N):
        # 単純な距離
        d = j - i

        # 短絡パスを使った距離
        #   始点から X まで行く
        to_X   = abs(X-1 - i)
        #   Y から終点まで行く
        from_Y = abs(Y-1 - j)
        d_p = to_X + from_Y + 1
        ans[min(d, d_p)] += 1
        # if i <= X-1 and Y-1 <= j:
        #     d -= Y - X - 1
        # print(i+1, j+1, d)
        # ans[d] += 1

for n in ans[1:]:
    print(n)

Submission status: Accepted

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

# print(X,Y)
for i in range(1,N+1):
    for j in range(i+1,N+1): # i<j
        # print((i,j))
        # ver 1
        if j<=X or Y<=i:
            d = j-i
            
        # ver 2
        elif i<=X and Y<=j:
            d = X-i + 1 + j-Y
            
        # ver 3
        else:
            d = min(j-i,abs(X-i)+abs(Y-j)+1)
        # print(d)
        D[d-1] += 1
# print(D)

for d in D:
    print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

# 脇道あり
def sp_root(i, j, X, Y): #i<j, X+1<Y
    root = abs(X-i) + abs(Y-j) + 1
    return root

# 距離の配列
k_lis = [0]*(n-1)
 
ans = 0
for i in range(1,n):
    for j in range(i+1,n+1):
        k_lis[min(j - i, sp_root(i, j, x, y))-1] += 1
 
for i in k_lis:
    print(i)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	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):
			l1 = abs(j-i)
			l2 = abs(X-i) + 1 + abs(j-Y)
			lm = min(l1,l2)
			ans[lm - 1] += 1

	for k in range(N-1):
		print(ans[k])

Submission status: Accepted

Solution code:
import heapq

def dijkstra(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    edge[i].append([1,i+1])
    edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])

ans = [0 for _ in range(n)]
for i in range(n):
    #dijkstra(始点,edge)
    res = dijkstra(i,edge)
    for j in range(i+1,n):
        ans[res[j]] += 1

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

Submission status: Accepted

Solution code:
import heapq
import sys

input = sys.stdin.readline

def dijkstra(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    edge[i].append([1,i+1])
    edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])

ans = [0 for _ in range(n)]
for i in range(n):
    #dijkstra(始点,edge)
    res = dijkstra(i,edge)
    for j in range(i+1,n):
        ans[res[j]] += 1

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

Submission status: Accepted

Solution code:
import heapq
import sys

input = sys.stdin.readline

def dijkstra(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    edge[i].append((1,i+1))
    edge[i+1].append((1,i))
edge[x-1].append((1,y-1))
edge[y-1].append((1,x-1))

ans = [0 for _ in range(n)]
for i in range(n):
    #dijkstra(始点,edge)
    res = dijkstra(i,edge)
    for j in range(i+1,n):
        ans[res[j]] += 1

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

ans = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]

Submission status: Accepted

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

ans = [0] * (N - 1)

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]

Submission status: Accepted

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

ans = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

ans = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]

Submission status: Accepted

Solution code:
N,X,Y = list(map(int,input().split()))
for i in range (1,N):
    a = max(N - 1 - (Y - X - 1) - (i - 1),0)
    if Y - X + 1 > 2 * i:
        b = Y - X + 1
        if i == 1:
            b = b - 1
    elif Y - X + 1 == 2 * i:
        b = i
    else:
        b = 0
    c = 0
    for j in range (max(X + 1 - i,1),X):
        if i - (X - j) == 1:
            c = c + 1
        elif 2 * (i - (X - j)) < Y - X + 1:
            c = c + 2
        elif 2 * (i - (X - j)) == Y - X + 1:
            c = c + 1
    for j in range(Y + 1,min(Y + i,N + 1)):
        if i - (j - Y) == 1:
            c = c + 1
        elif 2 * (i - (j - Y)) < Y - X + 1:
            c = c + 2
        elif 2 * (i - (j - Y)) == Y - X + 1:
            c = c + 1
        
    print(a+b+c)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = [0] * (N-1)

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]

Submission status: Accepted

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

ans=[0]*n

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0 for i in range(n)]

for i in range(1,n+1):
    for j in range(i+1,n+1):
        p1 = j-i
        p2 = abs(i-x)+abs(j-y)+1
        ans[min(p1,p2)] += 1
for i in range(1,n):
    print(ans[i])

Submission status: Accepted

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

for i in range(N):
    for j in range(N):
        if (j <= i): continue
        temp = j - i
        temp = min(temp, abs(i - X) + 1 + abs(j - Y))
        cnt[temp] = cnt[temp] + 1

for i in range(N):
    if i > 0:
        print(cnt[i])

Submission status: Accepted

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

Submission status: Accepted

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

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

for a in ans[1:-1]:
  print(a)

Submission status: Accepted

Solution code:
def solve(string):
    n, x, y = map(int, string.split())
    ans = [0] * (n - 1)
    for s in range(1, n + 1):
        d = [abs(i - s) for i in range(1, n + 1)]
        if d[x - 1] < d[y - 1]:
            p = y - 1
            d[p] = min(d[p], d[x - 1] + 1)
        else:
            p = x - 1
            d[p] = min(d[p], d[y - 1] + 1)
        for i in range(p + 1, n):
            d[i] = min(d[i], d[i - 1] + 1)
        for i in range(p - 1, -1, -1):
            d[i] = min(d[i], d[i + 1] + 1)
        for _d in d[s:]:
            ans[_d - 1] += 1
    return "\n".join(map(str, ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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

for i in range(1, n+1):
    for j in range(i+1, n+1):
        if (i <= x and j <= x) or (y <= i and y <= j):
            ans[j - i] += 1
        elif i <= x and y <= j:
            ans[x-i+1+j-y] += 1
        else:
            dist = min((j-i),(abs(i-x)+1 + abs(y-j)))
            ans[dist] += 1
            
print('\n'.join([str(s) for s in ans[1:]]))

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split(" "))
ans = [0 for i in range(N)]

for i in range(1, N + 1):
  for j in range(i + 1, N + 1):
    if (i <= X and j <= X) or (Y <= i and Y <= j):
      # I, IIIの中
      ans[j - i] += 1
    elif i <= X and Y <= j:
      # i -> I, j -> III
      ans[X - i + 1 + j - Y] += 1
    else:
      # i -> II or j -> IIのとき
      dist = min((j - i), (abs(i - X) + 1 + abs(Y - j)))
      ans[dist] += 1

print('\n'.join([str(s) for s in ans[1:]]))

Submission status: Accepted

Solution code:
from itertools import *

def loop(n):
  yield from repeat(n, (n-1)>>1)
  if n & 1 == 0:
    yield n >> 1
  yield from repeat(0)

def branch(n, l):
  if n:
    yield 0
    a, b = divmod(l-3, 2)
    s = 1
    for i in range(n+a+b):
      yield s
      if i < a:
        s += 2
      elif b and i==a:
        s += 1
      if n <= i:
        s -= 2
      elif i==n-1:
        s -= 1
  yield from repeat(0)

def b_to_b(n):
  yield n
  yield from range(n, 0, -1)
  yield from repeat(0)

N, X, Y = map(int, input().split())
L = Y - X + 1
for p in islice(zip(loop(L), branch(X-1, L), branch(N-Y, L), b_to_b(N-L)), N-1):
  print(sum(p))

Submission status: Accepted

Solution code:
from itertools import *

def loop(n):
  yield from repeat(n, (n-1)//2)
  if n & 1 == 0:
    yield n >> 1
  yield from repeat(0)

def branch(n, l):
  if n:
    yield 0
    l -= 3
    a, b = divmod(l, 2)
    s = 1
    for i in range(n+a+b):
      yield s
      if i < a:
        s += 2
      elif b and i==a:
        s += 1
      if n <= i:
        s -= 2
      elif i==n-1:
        s -= 1
  yield from repeat(0)

def b_to_b(n):
  n -= 1
  yield n
  yield from range(n, 0, -1)
  yield from repeat(0)

N, X, Y = map(int, input().split())
L = Y - X + 1
for p in islice(zip(loop(L), branch(X-1,L), branch(N-Y,L), b_to_b(N-L+1)), N-1):
  print(sum(p))

Submission status: Accepted

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

lists = [0] * (N - 1)

for i in range(1, N):
  for j in range(i + 1, N + 1):
    min_length = min(abs(j-i),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))
    lists[min_length - 1] += 1

for k in lists:
  print(k)

Submission status: Accepted

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

for i in d:
  print(i)

Submission status: Accepted

Solution code:
from collections import deque, defaultdict
n, x, y = map(int, input().split())
 
edges = defaultdict(lambda: [])
for i in range(1, n):
    edges[i].append(i+1)
    edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)
 
# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
    d = deque()
    dist = [-1 for _ in range(n+1)]
    d.append((i, -1))
    while len(d) > 0:
        e, pre_dist = d.popleft()
        if dist[e] > -1:
            continue
        else:
            dist[e] = pre_dist + 1
            for next_e in edges[e]:
                if dist[next_e] == -1:
                    d.append((next_e, pre_dist+1))
    for j in range(i+1, n+1):
        counter[dist[j]] += 1
print("\n".join(list(map(str, counter[1:]))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N, X, Y = map(int,input().split())
    X, Y = X - 1, Y - 1

    # iからjまでの距離
    # 到達の仕方は以下の３パターンなので、このうち最小が最短の距離になる
    # 直線のパターン
    # |j - i|
    # まずiからXまでいって、その後XからYまでジャンプ、Yからjまでのパターン
    # |X - i| + 1 + |j - Y|
    # まずiからYまでいって、その後YからXまでジャンプ、Xからjまでのパターン
    # |Y - i| + 1 + |j - X|

    ans = [0] * N

    for i in range(N - 1):
        for j in range(i + 1, N):
            ij = abs(j - i)
            ixyj = abs(X - i) + 1 + abs(j - Y)
            iyxj = abs(Y - i) + 1 + abs(j - X)

            dist = min(ij, ixyj, iyxj)

            ans[dist] += 1

    for a in ans[1:]:
        print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

from collections import deque


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

    for start_vertex in range(N):
        q = deque()
        distance_list = [float('inf')] * N

        def push(vertex, distance):
            if distance_list[vertex] != float('inf'):
                return
            q.append(vertex)
            distance_list[vertex] = distance

        push(start_vertex, 0)

        while len(q) != 0:
            vertex = q.popleft()
            distance = distance_list[vertex]

            if vertex - 1 >= 0:
                push(vertex - 1, distance + 1)
            if vertex + 1 < N:
                push(vertex + 1, distance + 1)
            if vertex == X:
                push(Y, distance + 1)
            if vertex == Y:
                push(X, distance + 1)

        for i in distance_list:
            ans[i] += 1

    print('\n'.join([str(i // 2) for i in ans[1:]]))


if __name__ == '__main__':
    main()