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:
from collections import defaultdict as dd
N,X,Y = map(int,input().split())

pdic = dd(lambda:0)

# count = 0

for i in range(1,N):
    for j in range(i+1,N+1):

#         count += 1

        # no shortcut
        d1 = j-i
        # with shortcut
        i2x = abs(X-i)
        y2j = abs(Y-j)
        d2 = i2x + y2j + 1

        dist = min(d1,d2)
        pdic[str(dist)] += 1

for n in range(1,N):
    print(pdic[str(n)])

# print("count:",count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
k = y - x + 1
s = [0 for i in range(n-1)]
a = x - 1
b = n - y
if k % 2 == 0:
    for i in range(k // 2-1):
        s[i] += k
    s[k//2-1] += k // 2
    for i in range(a):
        for j in range(k // 2):
            if j == 0:
                s[i+j] += 1
                s[i+k//2] += 1
            else:
                s[i+j] += 2
    for i in range(b):
        for j in range(k // 2):
            if j == 0:
                s[i+j] += 1
                s[i+k//2] += 1
            else:
                s[i+j] += 2
    for i in range(a):
      for j in range(b):
        s[2+i+j] += 1
    for i in range(a-1):
        for j in range(i+1, a):
            s[j-i-1] += 1
    for i in range(b-1):
        for j in range(i+1, b):
            s[j-i-1] += 1
else:
    for i in range(k // 2):
        s[i] += k
    for i in range(a):
        for j in range(k // 2 + 1):
            if j == 0:
                s[i+j] += 1
            else:
                s[i+j] += 2
    for i in range(b):
        for j in range(k // 2 + 1):
            if j == 0:
                s[i+j] += 1
            else:
                s[i+j] += 2
    for i in range(a):
        for j in range(b):
            s[2+i+j] += 1
    for i in range(a-1):
        for j in range(i+1, a):
            s[j-i-1] += 1
    for i in range(b-1):
        for j in range(i+1, b):
            s[j-i-1] += 1

print(*s)

Submission status: Accepted

Solution code:
val = input().split(' ')
n = int(val[0])
x = int(val[1])
y = int(val[2])

dists = {}
for i in range(1, n):
    dists[i] = 0
for i in range(1, n+1):
    for j in range(i+1, n+1):
        len1 = j - i
        len2 = abs(j - y) + abs(x - i) + 1
        len3 = abs(y - i) + abs(j - x) + 1
        dist = len1 if len1 < len2 else len2
        dist = dist if dist < len3 else len3
        dists[dist] += 1

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

Submission status: Accepted

Solution code:
[N,X,Y] = [int(s) for s in input().rstrip().split(' ')]
L = [0 for n in range(N)]
for i in range(N):
  for j in range(N-i):
    L[min(j,abs(X-1-i)+abs(Y-1-i-j)+1,abs(X-1-j-i)+abs(Y-1-i)+1)]+=1
for k in range(1,N):
  print(L[k])

Submission status: Accepted

Solution code:
def main():
    N, X, Y = map(int, input().split())
    ans = {i: 0 for i in range(1, N)}
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            cost = min(j - i, abs(i - X) + 1 + abs(Y - j))
            ans[cost] += 1
    for a in ans:
        print(ans[a])


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
N, R1, R2 = map(int, input().split())
n = R2 - R1 - 1
count={}
for m in range(N-1):
    count[m+1] = 0 
for i in range(N):
    for j in range(i+1, N):
        k = min(j-i, abs((R1-1)-i) + 1 +abs((R2-1)-j))
        count[k]+=1
for k in count.values():
    print(k)

Submission status: Accepted

Solution code:
x = input().split()
N = int(x[0])
X = int(x[1])
Y = int(x[2])

L = [0 for _ in range(N+1)]

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

Submission status: Accepted

Solution code:
from itertools import combinations

def main():
    n, x, y = [int(e) for e in input().split()]

    A = [0]*(n - 1)
    for c in combinations(range(1, n + 1), 2):
        cnt = min(abs(c[1] - c[0]), abs(c[1] - y) + abs(c[0] - x) + 1, abs(c[1] - x) + abs(c[0] - y) + 1)
        A[cnt - 1] += 1

    for a in A:
        print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, X, Y = read_ints()
X -= 1
Y -= 1

# 一箇所だけ短絡している
# もし短絡していなかったら簡単
# O(NN)でも間に合いそう

# 愚直にダイクストラしてもええか？
from scipy.sparse import csr_matrix  # 自分で配列を作ってからcsrに入れよう(lilに打ち込んでいくのは非常に遅い)

# ダイクストラ法 (正の単一始点最短経路) (全点間最短経路)
from scipy.sparse.csgraph import dijkstra
graph = [[0] * N for _ in range(N)]
for i in range(N - 1):
    graph[i][i + 1] = 1
    graph[i + 1][i] = 1
graph[X][Y] = 1
graph[Y][X] = 1
adj_mat = csr_matrix(graph)
D = dijkstra(adj_mat, directed=False)
cnt = Counter(D.reshape(-1))
ans=[]
for i in range(1, N):
    ans.append(int(cnt[i]) // 2)
print(*ans, sep='\n')


# D[i,j]でi→jに向かう最短経路
# indicesで始点を指定している場合は、D[j]でok

Submission status: Accepted

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

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

for i in A:
    print(i)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, X, Y = read_ints()
X -= 1
Y -= 1

# 一箇所だけ短絡している
# もし短絡していなかったら簡単
# O(NN)でも間に合いそう

# 愚直にダイクストラしてもええか？
from scipy.sparse import csr_matrix, lil_matrix  # 自分で配列を作ってからcsrに入れよう(lilに打ち込んでいくのは非常に遅い)

# ダイクストラ法 (正の単一始点最短経路) (全点間最短経路)
from scipy.sparse.csgraph import dijkstra
graph = lil_matrix((N,N))
for i in range(N - 1):
    graph[i,i + 1] = 1
    graph[i + 1,i] = 1
graph[X,Y] = 1
graph[Y,X] = 1
adj_mat = csr_matrix(graph)
D = dijkstra(adj_mat, directed=False)
cnt = Counter(D.reshape(-1))
for i in range(1, N):
    print(int(cnt[i]) // 2)


# D[i,j]でi→jに向かう最短経路
# indicesで始点を指定している場合は、D[j]でok

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

Submission status: Accepted

Solution code:
x = input().split()
N = int(x[0])
X = int(x[1])
Y = int(x[2])

L = [0 for _ in range(N+1)]

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

Submission status: Accepted

Solution code:
n,x,y = [int(x) for x in input().split()]
count = [0]*(n+1)
for i in range(1,n):
    for j in range(i+1,n+1):
        if i < x and j <= x:
            nagasa = j - i
        elif i < x and x < j and j < y:
            nagasa = x-i + min(j-x,y-j+1)
        elif i < x and y <= j:
            nagasa = x-i + j - y + 1
        elif x <= i and i < y and j <= y:
            nagasa = min(j-i,i-x+y-j+1)
        elif x <= i and i < y and y < j:
            nagasa = j - y + min(y-i,i-x+1)
        elif y <= i:
            nagasa = j -i
        count[nagasa] += 1
for i in range(1,n):
    print(count[i])

Submission status: Accepted

Solution code:
import collections

def main():
    N, X, Y = [int(x) for x in input().split()]
    dist = collections.defaultdict(int)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n-1):
  for j in range(i+1, n):
    ans[d(i,j)-1] +=1

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n,x,y = MI()
	x-=1;y-=1
	dist = [0]*(n-1)
	for i in range(n-1):
		for j in range(i+1,n):
			dist[min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))-1]+=1
	printV(dist)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

from collections import deque
INF = 1001001001
N, X, Y = map(int, input().split())
X -= 1; Y -= 1

ans = [0] * N
for sv in range(N):
    dist = [INF] * N
    q = deque()
    def push(v, d):
        if dist[v] != INF: return
        dist[v] = d
        q.append(v)
    push(sv, 0)
    while q:
        v = q.popleft()
        d = dist[v]
        if v-1 >= 0: push(v-1, d+1)
        if v+1 < N:  push(v+1, d+1)
        if v==X:     push(Y,   d+1)
        if v==Y:     push(X,   d+1)
    for i in range(N):
        ans[dist[i]] += 1

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

Submission status: Accepted

Solution code:
def main():
    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(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))]+=1
    for ans in Ans[1:]:
        print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n, x, y = list(map(int, input().split()))
lst = [
    min(abs(i - j), (abs(i - x) + abs(j - y) + 1))
    for j in range(2, n + 1)
    for i in range(1, j)
]
dic = collections.Counter(lst)
for k in range(1, n):
    print(dic[k])

Submission status: Accepted

Solution code:
import itertools 
N, X, Y = (int(i) for i in input().split())  

lis = range(N)
ans = [0] * (N-1)
for a, b in itertools.permutations(lis, 2):
  if a >= b:
    continue
  tmp = min(b-a, abs(X-a-1) + abs(Y-b-1) + 1)
  ans[tmp-1] += 1

for x in ans:
  print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, X, Y = iim()
    ans = [N-i-1 for i in range(N-1)]
    X1, Y1 = X-1, Y -1

    xy2 = (X+Y)  // 2
    for i in range(0, xy2):
        x1 = X1 - i
        if x1 < 0: x1 = -x1
        for j in range(xy2, N):
            d1 = j - i - 1
            y1 = Y1-j
            if y1 < 0: y1 = -y1
            d2 = x1 + y1
            if d1 > d2:
                #print((i+1, j+1), d1+1, d2+1, x1, y1)
                ans[d1] -= 1
                ans[d2] += 1

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N,X,Y=map(int,input().split())
ans=0
right=X-1
cycle=Y-X+1
left=N-Y
import copy
ring=copy.copy(cycle)
branchr=copy.copy(right)
if right>0:
    branchr+=1
branchl=copy.copy(left)
if left>0:
    branchl+=1
ring_branchr=0
ring_branchl=0
branchrl=0
count=0
if cycle%2==0:
    for k in range(1,max(left+cycle//2,right+cycle//2,left+right+1)+1):
        if k==cycle//2:
            ring = cycle//2
        if k>cycle//2:
            ring = 0
        if right>0:
            branchr-=1
            if k>right:
                branchr=0
        if left>0:
            branchl-=1
            if k>left:
                branchl=0
        if right>0:
            ring_branchr=min(2*(k-1),right*2)
            if k>cycle//2:
                ring_branchr-=2*(k-cycle//2)-1
            if ring_branchr<0:
                ring_branchr=0
        if left>0:
            ring_branchl=min(2*(k-1),left*2)
            if k>cycle//2:
                ring_branchl-=2*(k-cycle//2)-1
            if ring_branchl<0:
                ring_branchl=0
        if right>0 and left>0:
            if 3<=k<min(right,left)+3:
                branchrl+=1
            if k>max(right,left)+2:
                branchrl-=1
            if branchrl<0:
                branchrl=0
        ans=ring+branchr+branchl+ring_branchr+ring_branchl+branchrl
        print(ans)
        count+=1
if cycle%2==1:
    for k in range(1,max(left+cycle//2,right+cycle//2,left+right+1)+1):
        if k>cycle//2:
            ring = 0
        if right>0:
            branchr-=1
            if k>right:
                branchr=0
        if left>0:
            branchl-=1
            if k>left:
                branchl=0
        if right>0:
            ring_branchr=min(2*(k-1),right*2)
            if k>cycle//2+1:
                ring_branchr-=2*(k-cycle//2-1)
            if ring_branchr<0:
                ring_branchr=0
        if left>0:
            ring_branchl=min(2*(k-1),left*2)
            if k>cycle//2+1:
                ring_branchl-=2*(k-cycle//2-1)
            if ring_branchl<0:
                ring_branchl=0
        if right>0 and left>0:
            if 3<=k<min(right,left)+3:
                branchrl+=1
            if k>max(right,left)+2:
                branchrl-=1
            if branchrl<0:
                branchrl=0
        ans=ring+branchr+branchl+ring_branchr+ring_branchl+branchrl
        print(ans)
        count+=1
for k in range(count+1,N):
    print(0)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7

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


def resolve():
    N, X, Y = map(int, input().split())
    graph = np.zeros((N + 1, N + 1), dtype=np.int64)

    for i in range(1, N):
        graph[i, i + 1] += 1
        graph[i + 1, i] += 1
    graph[X, Y] = 1
    graph[Y, X] = 1

    dist = dijkstra(csgraph=csr_matrix(graph)).astype(np.int64)
    ans = np.bincount(dist[1:, 1:].ravel(), minlength=N) // 2
    return print(*ans[1:], sep='\n')


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
N, X, Y = map(int, input().split())
# 距離行列の生成
dist_matrix = [[0] * (N) for _ in range(N)] 
for i in range(1, N):
    dist_matrix[i][i-1] = 1
dist_matrix[X-1][Y-1] = 1

graph = csr_matrix(dist_matrix)

dist_matrix = dijkstra(csgraph=graph, directed=False)
ans = [0] * N

for idx, row in enumerate(dist_matrix):
    for item in row[idx + 1:]:
        ans[int(item)] += 1

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

Submission status: Accepted

Solution code:
n_x_y = list(map(int, input().split()))

n = n_x_y[0]
x = n_x_y[1]
y = n_x_y[2]

def search_min(i, j):
  #候補1
  opt_1 = abs(i-j)
  #候補2
  opt_2 = abs(x-i) + 1 + abs(y-j)
  #候補3
  opt_3 = abs(y-i) + 1 + abs(x-j)
  
  return min(opt_1, opt_2, opt_3)


answer = [0]*(n-1)
for i in range(1, n):
  for j in range(i + 1, n+1):
    answer[search_min(i, j)-1] += 1
    
for i in range(len(answer)):
  print(answer[i])

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict
from heapq import *

n, x, y = na()
x -= 1
y -= 1

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

def dijkstra(g, x):
    dist = [inf] * len(g)
    dist[x] = 0
    q = []
    proc = [False for _ in range(len(g))]
    heappush(q, (0, x))
    while len(q):
        p = heappop(q)
        a = p[1]
        if proc[a]:
            continue
        for b in g[a]:
            if dist[a] + 1 < dist[b]:
                dist[b] = dist[a] + 1
                heappush(q, (-dist[b], b))
    
    return dist

dic = defaultdict(int)
for i in range(n):
    dist = dijkstra(g, i)
    for i in range(n):
        dic[dist[i]] += 1

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

Submission status: Accepted

Solution code:
n, x, y = map(int,input().split())
ls = [0] * n
for u in range(1, n):
    for v in range(u, n+1):
        u2x = abs(u-x)
        v2y = abs(v-y)

        d = min(v-u, u2x + 1 + v2y)
        ls[d] += 1

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

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, X, Y = iim()
    ans = [N-i-1 for i in range(N-1)]
    X1, Y1 = X-1, Y -1

    xy2 = (X+Y)  // 2
    for i in range(0, xy2+1):
        x1 = X1 - i
        if x1 < 0: x1 = -x1
        for j in range(xy2, N):
            d1 = j - i - 1
            y1 = Y1-j
            if y1 < 0: y1 = -y1
            d2 = x1 + y1
            if d1 > d2:
                #print((i+1, j+1), d1+1, d2+1, x1, y1)
                ans[d1] -= 1
                ans[d2] += 1

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

ans = [0] * (N - 1)

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

for a in ans:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * (N - 1)

for i in range(1, N + 1, 1):
    for j in range(i + 1, N + 1, 1):
        tmp = min(
            abs(j - i),
            abs(X - i) + 1 + abs(j - Y),
            abs(X - j) + 1 + abs(i - Y) # このパターンは
        )
        ans[tmp - 1] += 1

for a in ans:
    print(a)

Submission status: Accepted

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

x = x-1
y = y-1

dict = {int(i+1):0 for i in range(n)}

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

Submission status: Accepted

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    n,x,y = map(int, input().split())
    costList = [0]*n

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


    for i in range(n):
        if i >0:
            print(costList[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import sys
input=sys.stdin.readline
n,x,y=map(int,input().split())
x-=1
y-=1
g=[[] for i in range(n)]
g[x].append(y)
g[y].append(x)
for i in range(n-1):
    g[i].append(i+1)
    g[i+1].append(i)
ans=[0]*n
for i in range(n):
    s=i
    q=deque([s])
    v=[-1]*n
    v[s]=0
    while q:
        p=q.popleft()
        for j in g[p]:
            if v[j]==-1:
                ans[v[p]]+=1
                v[j]=v[p]+1
                q.append(j)
for i in range(n-1):
    print(ans[i]//2)

Submission status: Accepted

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

for p in range(1, N):
    for q in range(p, N+1):
        p2X = abs(p - X)
        q2Y = abs(q - Y)

        distance = min(q-p, p2X+1+q2Y)
        k_list[distance] += 1

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

Submission status: Accepted

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

for p in range(1, N):
    for q in range(p, N+1):
        p2X = abs(p - X)
        p2Y = abs(p - Y)
        q2X = abs(q - X)
        q2Y = abs(q - Y)

        distance = min(q-p, p2X+1+q2Y)
        k_list[distance] += 1

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

Submission status: Accepted

Solution code:
n,x,y = map(int, input().split())
t = [0 for i in range(n)]
x = x-1
y = y-1
for i in range(0,n):
  for j in range(i,n):
    a = abs(i-x)+abs(j-y)+1
    b = abs(i-j)
    if a < b:
      t[a-1] += 1
    else:
      t[b-1] += 1

for k in range(0,n-1):
  print(int(t[k]))

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
def dist(i,j):
  if i>=j:
    d=0
  else:
    d=min(abs(j-i),abs(y-j)+1+abs(x-i),abs(y-i)+1+abs(x-j))
  return d
distmap=[0]*n
for l in range(2,n+1):
  for k in range(1,l):
    distmap[dist(k,l)]+=1
print('\n'.join(map(str,distmap[1:])))

Submission status: Accepted

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

for p in range(1, N):
    for q in range(p, N+1):
        p2X = abs(p - X)
        p2Y = abs(p - Y)
        q2X = abs(q - X)
        q2Y = abs(q - Y)

        distance = min(q-p, p2X+1+q2Y, p2Y+1+q2X)
        k_list[distance] += 1
        
for k in range(1, N):
    print(k_list[k])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,x,y=mii()
x-=1
y-=1
ans=[0]*n

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

Submission status: Accepted

Solution code:

#####

import numpy as np
# from collections import Counter
# import itertools

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def main(inputs):
	n,x,y=getIntList(inputs[0])
	
	count=np.zeros(n-1, np.int32)
	
	between=y-x-1
	if between%2==0:
		middleL=between//2
		middleR=between//2
	else:
		middleL=between//2+1
		middleR=between//2
	left=x-1
	right=n-y
	
	depth0=x+middleL
	depth1=x+middleR+1
	depth2=x+right+1
	length=max(depth0,depth1,depth2)
	numDepth=np.zeros(length)
	numDepth[:x]=1
	numDepth[x:depth0]+=1
	numDepth[x:depth1]+=1
	numDepth[x+1:depth2]+=1
	
	for d in range(1, length):
		count[d-1]=numDepth[d:d+x-1].sum()
# 	print("a",count)
# 	count[...]=0 ###
	
	x0=x
	y0=y
	
	x=n-(y0-1)
	y=n-(x0-1)
	
	between=y-x-1
	if between%2==0:
		middleL=between//2
		middleR=between//2
	else:
		middleL=between//2+1
		middleR=between//2
	left=x-1
	right=n-y
	
	depth0=x+middleL
	depth1=x+middleR+1
	length=max(depth0,depth1)
	numDepth=np.zeros(length)
	numDepth[:x]=1
	numDepth[x:depth0]+=1
	numDepth[x:depth1]+=1
# 	print(numDepth)
	
	for d in range(1, length):
		count[d-1]+=numDepth[d:d+x-1].sum()
# 	print("b",count)
# 	count[...]=0 ###
	
	middle=middleL+middleR+2
	if middle%2==1:
		count[:middle//2]+=middle
	else:
		count[:middle//2-1]+=middle
		count[middle//2-1]+=middle//2
# 	print("c", count)
	
	for c in count: print(c)
	
# 	return count


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
from itertools import combinations
cmb = combinations(range(1, N+1), 2)
k = [0] * (N-1)
for i, j in cmb:
    distance = min(j-i, abs(X-i) + abs(Y-j) + 1)
    k[distance-1] += 1
for i in k:
    print(i)