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:
n,x,y=map(int,input().split())
s=[0]*n
for i in range(1,n):
    for j in range(i,n+1):
        s[min(j-i-1,abs(x-i)+abs(y-j))]+=1
for i in s[:-1]:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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

d=deque()
for i in range(n):
    tmp=[0]*n
    tmp[i]=1
    d.append([[i],tmp])
# print(d)

x,y=x-1,y-1
for i in range(n-1):
    ans=0
    for j in range(n):
        now,itta=d.popleft()
        tugi=[]
        for k in now:
            if k==n-1:
                if itta[k-1]==0:
                    itta[k-1]=1
                    tugi.append(k-1)
                if y==k and itta[x]==0:
                    itta[x]=1
                    tugi.append(x)
            elif k==0:
                if itta[k+1]==0:
                    itta[k+1]=1
                    tugi.append(k+1)
                if x==k and itta[y]==0:
                    itta[y]=1
                    tugi.append(y)
            else:
                if itta[k-1]==0:
                    itta[k-1]=1
                    tugi.append(k-1)
                if y==k and itta[x]==0:
                    itta[x]=1
                    tugi.append(x)
                if itta[k+1]==0:
                    itta[k+1]=1
                    tugi.append(k+1)
                if x==k and itta[y]==0:
                    itta[y]=1
                    tugi.append(y)
        ans+=len(tugi)
        d.append([tugi,itta])
        # print(tugi)
        # print(itta)
    print(ans//2)
    ans=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):
        a = min(j-i, abs(X-i)+1+abs(Y-j))
        ans[a-1] += 1

print(*ans, sep='\n')

Submission status: Accepted

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

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

for v in D[1:N]:
    print(v)

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
li = [0] * (n - 1)
num = 0

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

for i in li:
    print(i)

Submission status: Accepted

Solution code:
N, X, Y = list(map(int,input().split()))
X -= 1
Y -= 1
out = [0]*N #最低距離が1からNまでの個数を表示するリストを作る
for i in range(N-1):
  for j in range(i+1,N):
    out[min(j-i, abs(i-X)+1+abs(j-Y))] += 1 #各最低距離の個数カウント
for i in range(1,N):
  print(out[i])

Submission status: Accepted

Solution code:
# N=頂点数、X,Y=座標
N, X, Y = map(int, input().split())

# 最短距離データ
min_dist_list = [0 for i in range(N+1)]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
from collections import Counter
n, x, y = [int(i) for i in sys.stdin.readline().split()]
x -= 1
y -= 1
ls = [[0 for i in range(n)] for j in range(n)]
for i, j in combinations(range(n), 2):
    ls[i][j] = min(abs(i - j), abs(y - j) + abs(x - i) + 1)
ct = Counter()
for i in range(n):
    ct.update(ls[i])
for i in range(1, n):
    print(ct[i])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

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

dst = [0] * n

#print(dst)

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse.csgraph import dijkstra

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

# N = 2000
# X = 100
# Y = 1900


X -= 1
Y -= 1

# @profile


def main(N, X, Y):
    graph = np.zeros((N, N))
    # np.fill_diagonal(graph[1:, :], 1)
    np.fill_diagonal(graph[:, 1:], 1)
    graph[X, Y] = 1
    # graph[Y, X] = 1
    dist = dijkstra(graph, directed=False).astype(int).ravel()
    # print(dist_matrix)

    ans = np.bincount(dist, minlength=N)//2
    print(*ans[1:], sep="\n")


main(N, X, Y)

Submission status: Accepted

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

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

Submission status: Accepted

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

def dist(i,j):
  return min(j-i, abs(x-i) + abs(y-j) + 1, abs(x-j) + abs(y-i) + 1)

listlist = [0]*(n-1)

for i in range(1,n):
  for j in range(i+1,n+1):
    distance = dist(i,j)
    listlist[distance-1] = listlist[distance-1] + 1
    
for k in listlist:
  print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#D

line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]

results =[0]*(n+2)

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

for i in range(0, n-1):
    print(results[i])

Submission status: Accepted

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

for d in D[1:]:
    print(d)

Submission status: Accepted

Solution code:
#coding:utf-8
n, x, y = map(int, input().split())
anslist = []
for i in range(n-1):
    anslist.append(0)

for s in range(1,n):
    for p in range(s+1,n+1):
        distance = min(abs(p - s),abs(x - s) + 1 + abs(p - y),abs(y - s) + 1 + abs(p - x))
        anslist[distance - 1] += 1

for k in range(len(anslist)):
    print("{}".format(anslist[k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

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

edge = [(i, i + 1, 1) for i in range(N - 1)]
edge.append((X - 1, Y - 1, 1))

edge1 = np.array(edge, dtype = np.int64).T
graph = csr_matrix((edge1[2], (edge1[:2])), (N, N))

# print (graph)

ans = dijkstra(graph, directed = False)
lst = [0] * N
for i in range(N - 1):
    # tmp = list(ans[i,:])
    # print (tmp)
    for j in range(i + 1, N):
        lst[int(ans[i,j])] += 1
    
print (*lst[1:], sep = '\n')
# print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

l = []

for i in range(1,N+1):
    for j in range(i+1,N+1):
        mindis = min(abs(j - i), abs(X - i) + 1 + abs(j - Y ), abs(Y - i) + 1 + abs(j - X))
        l.append(mindis)
        
d = col.Counter(l)

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

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import deque
def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    D = [[0 for _ in range(N)] for _ in range(N)]
    D[X][Y] = 1
    D[Y][X] = 1
    queue = deque([[X, Y]])
    visited = [[False for _ in range(N)] for _ in range(N)]
    visited[X][Y] = True 
    while queue:
        x,y = queue.popleft()
        for i, j in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            nx, ny = x+i, y+j
            if nx < 0 or nx >= N or ny < 0 or ny >= N:
                continue
            if visited[nx][ny]:
                continue
            else:
                visited[nx][ny] = True
                D[nx][ny] = min(abs(ny-nx), D[x][y]+1)
                queue.append([nx, ny])
    ans = [0 for _ in range(N)]
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            v = D[i][j]
            ans[v-1] += 1
    print(*ans[:-1], sep="\n")
main()

Submission status: Accepted

Solution code:

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

# N = 2000
# X = 100
# Y = 1900


X -= 1
Y -= 1

# @profile


def main(N, X, Y):
    ans = [0]*N
    for i in range(N):
        for j in range(i+1, N):
            d = min(j-i, abs(X-i)+abs(Y-j)+1)
            ans[d] += 1

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


main(N, X, Y)

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}


def bfs(start_v):
    """ある始点からほかの全点に行くまでの最短距離を求める。"""
    qu = deque()
    qu_append = qu.append
    qu_popleft = qu.popleft
    qu_append(start_v)
    # 始点からvに移動するまでの最短距離: dist[v]
    dist = [BIG] * n

    def push(v, d):
        """始点からvまでの最短距離が算出されていないときに，その距離を保存し，
        キューに頂点vを追加する。"""
        if dist[v] != BIG:
            # 既に訪問済みで距離が求められている。
            return
        dist[v] = d
        qu_append(v)

    push(start_v, 0)

    while len(qu):
        v = qu_popleft()
        # 始点からvの次の頂点へ移動する距離。
        d = dist[v] + 1
        if v < n - 1:
            push(v + 1, d)
        if v > 0:
            push(v - 1, d)
        if v == x:
            push(y, d)
        if v == y:
            push(x, d)

    for i in range(n):
        if dist[i] != 0:
            ans[dist[i]] += 1


def main():
    for i in range(n):
        bfs(i)

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


if __name__ == '__main__':
    main()

# TLE

Submission status: Accepted

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

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

# output
for a in ans:
    print(a)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
INF = float('inf')
def main():
    N, X, Y = map(int, input().split())
    d = defaultdict(lambda: 0)
    for i in range(1,N+1):
        for j in range(1, N + 1):
            if i < j:
                dist = min(min(abs(j - i), abs(X - i) + 1 + abs(j - Y)), abs(Y - i) + 1 + abs(j - X))
                d[dist] += 1
    for i in range(1, N):
        print(d[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
x -= 1
y -= 1
ll = y-x+1
ans = [0]*(n-1)
for i in range(n-1):
  for j in range(i+1,n):
    if j <= x or i >= y:
      l = j - i
    elif i < x and x <= j <= y:
      l = x-i+min(j-x,ll-j+x)
    elif j > y and x <= i <= y:
      l = min(y-i,ll-y+i)+j-y
    elif i < x and j > y:
      l = j - y + x - i + 1
    else:
      l = min(j-i,ll-j+i)
    ans[l-1] += 1
for item in ans:
  print(item)

Submission status: Accepted

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

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

    ans = [0] * N
    for i in range(1, N+1):
        dist = [-1] * (N+1)
        dist[i] = 0
        q = deque()
        q.append(i)
        def push(l, m):
            if dist[l] > -1:
                return
            q.append(l)
            dist[l] = dist[m] + 1
            ans[dist[l]] += 1

        while q:
            j = q.popleft()
            if j < N: push(j+1, j)
            if j > 1: push(j-1, j)
            if j == X: push(Y, j)
            if j == Y: push(X, j)
    print(*[i // 2for i in ans[1:]], sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
from scipy.sparse.csgraph._shortest_path import dijkstra, floyd_warshall, bellman_ford, johnson, shortest_path
from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

length = n
d = [1 for _ in range(n)]
i = list(range(0,n-1)) + [x-1]
j = list(range(1,n)) + [y-1]
# print(d,i,j,sep="\n")

graph = csr_matrix((d, (i, j)), shape=(n, n)) # 頂点i,jはゼロスタートである必要ある
# print(type(csr),csr,sep="\n")

#返り値は各頂点間の距離の値を含んだ隣接行列(float64型のnp.array)
dist = dijkstra(graph, directed=False).astype(int)
# dist = shortest_path(graph, directed=False).astype(int)
# print(type(dist),dist,sep="\n")

dist = dist.ravel() #配列の一次元化
# print(type(dist),dist,sep="\n")

ans = np.bincount(dist, minlength=n) // 2  #bincountは[0の個数,1の個数,2の個数…nの個数]を返す
# print(type(ans),ans,sep="\n")

print(*ans[1:], sep='\n')

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

def main():
    n,x,y=map(int,input().split())
    dis=[0]*(n-1)
    for i in range(1,n+1):
        for j in range(1,n+1):
            if i>=j: continue
            now=min(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
            #print(i+1,j+1,now,(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y)))
            dis[now-1]+=1

    for i in dis:
        print(i)

if __name__=="__main__":main()

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
ans=[[1000000]*n for i in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans[i][j]=min(j-i,abs(x-1-i)+1+abs(y-1-j))
_ans=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        _ans[ans[i][j]-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)

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

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

Submission status: Accepted

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


count = [0] * (N-1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        routeA = abs(j-i)
        routeB = abs(X-i) + abs(Y-j) + 1
        min_route = min(routeA, routeB)
        count[min_route - 1] += 1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:


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

# 結果のカウント
answers = [ 0 for _ in range(n) ]


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



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

Submission status: Accepted

Solution code:
N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
ans = [0] * (N)
A = [[] * N for _ in range(N)]
for i in range(N):
    for j in range(N-i):
        path = min(abs(x- i) +1 +abs(y-i-j),j)
        ans[path] += 1
ans.pop(0)
print('\n'.join(map(str,ans)))

Submission status: Accepted

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

dis = [0] * (n-1)

# 頂点iから頂点jまでの距離
for i in range(1, n):
    for j in range(i+1, n+1):
        if i <= x:
            if j <= x:
                tmp = j-i
            if x < j < y:
                tmp = (x-i) + min(j-x, y-j+1)
            if j >= y:
                tmp = (x-i) + (j-y) + 1

        if x < i < y:
            if x < j < y:
                tmp = min(j-i, (i-x)+(y-j)+1)
            if j >= y:
                tmp = min(i-x+1, y-i) + (j-y)
        
        if i >= y:
            tmp = j-i

        dis[tmp-1] += 1

for ans in dis:
    print(ans)

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
path = [0]*N
X -= 1
Y -= 1
# dis = Y - X - 1
# routeA = N - dis
# print(path)
for q in range(N):
    for i in range(q+1, N):
        # print("{}{}".format(q,i))
        cost = min(i-q, abs(q-X) + 1 + abs(i-Y)) 
        # cost = min(i-q, abs(q-X) + 1 + abs(i-Y), abs(q-Y) + 1 + abs(i - X)) 
        # print(cost)
        path[cost] += 1
        # path.append(list(cost)[0])
        # path[q][i] = min(i-q, abs(q-X) + 1 + abs(i-Y)
for i in range(1,N):
    print(path[i])

Submission status: Accepted

Solution code:

N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
ans = [0] * (N)
A = [[] * N for _ in range(N)]
for i in range(N):
    for j in range(N-i):
        path = min(abs(x- i) +1 +abs(y-i-j),j)
        ans[path] += 1
for _ in range(len(ans)):
    if _ == 0:
        continue
    print(ans[_])

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
x -= 1 #グラフを0からn-1までの数に対応させる
y -= 1 #
ans = [0]*(n-1)

for i in range(n):
  for j in range(i+1, n):#各頂点の距離を一組ずつ調べる
    a = min(j-i, abs(x-i) + abs(y-j) + 1)
    '''
    j-i                     :1～nまでの普通のルートでの距離
    abs(x-i) + abs(y-j) + 1 :ショートカットルートを使ったときの距離
    ''' 
    ans[a-1] += 1 #距離の長さに対応したリストに+1
for p in ans:
  print(p)

Submission status: Accepted

Solution code:
#D line++

n, x, y = map(int, input().split())
a = [0]*n

for i in range(n-1):
    for j in range(i+1, n):
        ans = 10000
        if j-i < ans:
            ans = j-i
        
        cut = abs(x-1-i) + abs(y-1-j) + 1
        if cut < ans:
            ans = cut
        
        a[ans-1] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,x,y = inpl()
x -= 1; y -= 1
g = [[] for _ in range(n)]
for i in range(n-1):
    g[i] += [i+1]; g[i+1] += [i]
g[x] += [y]; g[y] += [x]
res = [0] * (n-1)
def bfs(i):
    q = deque()
    q.append(i)
    while q:
        v = q.popleft()
        for nv in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = dist[v] + 1
            q.append(nv)

for i in range(n-1):
    dist = [-1] * n
    dist[i] = 0
    bfs(i)
    for j,cost in enumerate(dist):
        if j > i and cost > 0:
            res[cost-1] += 1
    # print(dist)
print(*res)

Submission status: Accepted

Solution code:
from itertools import *
n,x,y=map(int,input().split())
a=[0]*n
for i,j in combinations(range(1,n+1),2):
    b=min(abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
    a[b]+=1
print(*a[1:],sep="\n")

Submission status: Accepted

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


for i in range(1, N):
    for j in range(i+1, N+1):
        m = min(j-i, abs(X-i) + 1 + abs(Y-j))
        if d.get(m) is None:
            d[m] = 1
        else:
            d[m] += 1

for i in range(1, N):
    if d.get(i) is None:
        print(0)
    else:
        print(d[i])

Submission status: Accepted

Solution code:
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1
a = list(range(N - 1)) + [X]
b = list(range(1, N)) + [Y]

matrix = csr_matrix(([1] * N, (a, b)), shape=(N, N))
distance = dijkstra(matrix, directed=False).astype(int)
answer = np.bincount(distance.flatten())[1:] // 2
answer = answer.tolist()
answer += [0] * (N - 1 - len(answer))
print('\n'.join(map(str, answer)))

Submission status: Accepted

Solution code:
s = input().split()
n=int(s[0])
x=int(s[1])-1
y=int(s[2])-1
inf=float('inf')
map={}
for i in range(n):
    map[i]=0
for i in range(n):
    for j in range(i+1,n):
        map[min(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))]+=1
for i in range(1,n):
    print(map[i])

Submission status: Accepted

Solution code:

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


print(*t[1:],sep='\n')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

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

ans = [0] * (n - 1)
# 全頂点からBFSする
for i in range(n-1):
    # 頂点xの距離をdistに格納していく
    dist = [-1] * n
    dist[i] = 0
    q = deque([i])
    while len(q):
        v = q.pop()
        for next_v in tree[v]:
            if dist[next_v] != -1:
                continue
            q.appendleft(next_v)
            dist[next_v] = dist[v] + 1
    for j in range(i+1, n):
        ans[dist[j] - 1] += 1

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

Submission status: Accepted

Solution code:
# coding: utf-8

import collections

# 標準入力 <int><int>
N, X, Y = map(int, input().split())

br = []

for i in range(N - 1):
  for j in range(i + 1, N):
    """
    #print("(" , i+1, j+1, ")", j-i, abs(X - (i + 1)) + 1 + abs(Y - (j + 1)), abs(Y - (i + 1)) + 1 + abs(X - (j + 1)))
    """
    br.append(min(j - i, abs(X - (i + 1)) + 1 + abs(Y - (j + 1)), abs(Y - (i + 1)) + 1 + abs(X - (j + 1))))

c = collections.Counter(br)

for k, v in c.items():
  print(v)

for _ in range(N - 1 - len(c)):
  print(0)

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
cnt=[0]*n
for i in range(1,n+1):
  for j in range(i+1,n+1):
    if i==j:
      continue
    dist=min(j-i,abs(x-i)+1+abs(y-j),abs(y-j)+1+abs(x-i))
    cnt[dist]+=1
print(*cnt[1:],sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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

d = [[0 for _ in range(n)] for _ in range(n)]
x-=1
y-=1
ans = [0 for _ in range(n)]

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

Submission status: Accepted

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

from heapq import heappush, heappop
def dks(g,start,num_v):
    INF=10**10
    visited = set()
    hq = []
    heappush(hq, (0,start))
    cost = [INF] * num_v
    while hq:
        shortest, i = heappop(hq)
        if i in visited:
            continue
        visited.add(i)
        cost[i] = shortest
        for j, t in g[i]:
            if j in visited:
                continue
            heappush(hq, (shortest + t, j))
    return cost

link = [[] for _ in range(n)]
for i in range(n-1):
    link[i].append([i+1,1])
    link[i+1].append([i,1])
link[x-1].append([y-1,1])
link[y-1].append([x-1,1])

ans=[0]*(n-1)
for i in range(n):
    res = dks(link,i,n)
    for r in res:
        ans[r]+=1
for i in range(1,len(ans)):
    print(ans[i]//2)

print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(int)


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

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

Submission status: Accepted

Solution code:
def solve(n, x, y):
    res_list = [0] * n
    for i in range(n - 1):
        for j in range(i + 1, n):
            d = min(j - i, abs(i - x+1) + abs(j - y+1) + 1)
            res_list[d] += 1
    return res_list[1:]


n, x, y = map(int, input().split())
res_list = solve(n, x, y)
for res in res_list:
    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
#a<b
def dis(a,b):
    return min (b-a,abs(a-x)+1+abs(b-y))

# for k in range(1,n):
#   count=0
#   #i<j
#   for i in range(1,n):
#     for j in range(i+1,n+1):
#       if dis(i,j)==k:
#         count+=1
#   print(count)
ans=[0]*(n-1)
#i<j
for i in range(1,n):
  for j in range(i+1,n+1):
    ans[dis(i,j)-1]+=1
#print(*ans,sep="\n")
print("\n".join(map(str,ans)))

Submission status: Accepted

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

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

for d in dis_n:
    print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
import sys
sys.setrecursionlimit(15000)
n,x,y = map(int,input().split())

nums = [0]*n
for i in range(n):
    for j in range(i+1,n):
        d = min(j-i,abs(j-y+1)+1+abs(i-x+1))
        nums[d] += 1
        #print(d,i,j)
print(*nums[1:],sep='\n')

Submission status: Accepted

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

main()