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 = [int(_) for _ in input().split()]

INF = 10 ** 9
dp = [[INF] * N for _ in range(N)]

for i in range(N - 1):
    for j in range(i + 1, N):
        dp[i][j] = j - i
        dp[j][i] = j - i

dp[X - 1][Y - 1] = 1
dp[Y - 1][X - 1] = 1

for k in [X - 1, Y - 1]:
    for i in range(N):
        for j in range(N):
            # k経由でiからjへ
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

cnt = [0] * N
for i in range(N):
    for j in range(i + 1, N):
        v = dp[i][j]
        cnt[v] += 1
for i in range(1, N):
    print(cnt[i])

Submission status: Accepted

Solution code:
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, x, y = LI()
    d = [0]*n
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            d[min(j - i, abs(x - i) + 1 + abs(j - y)) - 1] += 1
    for k in range(n-1):
        print(d[k])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, x, y = LI()
    d = [0]*n
    for i in range(1, n):
        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 k in range(n-1):
        print(d[k])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def search(start, N, X, Y):
    dist = [0 for _ in range(N)]
    if start <= X:
        for i in range(X):
            dist[i] = abs(start - i)
        for i in range(Y, N):
            dist[i] = (X - start) + 1 + (i - Y)
        for i in range(X, (Y - X) // 2 + X + 1):
            dist[i] = (i - start)
        for i in range((Y - X) // 2 + X + 1, Y):
            dist[i] = (X - start) + 1 + (Y - i)
    elif start >= Y:
        for i in range(Y, N):
            dist[i] = abs(start - i)
        for i in range(X):
            dist[i] = (start - Y) + 1 + (X - i)
        for i in range(X, (Y - X) // 2 + X):
            dist[i] = (start - Y) + 1 + (i - X)
        for i in range((Y - X) // 2 + X, Y):
            dist[i] = (start - i)
    else:
        toX = min(start - X, Y - start + 1)
        toY = min(Y - start, start - X + 1)
        dist[start] = 0
        for i in range(X):
            dist[i] = (X - i) + toX
        for i in range(Y, N):
            dist[i] = toY + (i - Y)
        for i in range(X, start):
            dist[i] = min(start - i, Y - start + 1 + i - X)
        for i in range(start + 1, Y):
            dist[i] = min(i - start, start - X + 1 + Y - i)
    return dist


def main():
    N, X, Y = [int(n) for n in input().split(" ")]
    #N, X, Y = 10, 3, 8

    X = X - 1
    Y = Y - 1

    lenD = []
    for i in range(N):
        d = search(i, N, X, Y)
        lenD.append(d)

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

    for i in range(N):
        for j in range(i + 1, N):
            k = lenD[i][j]
            kcounter[k - 1] += 1

    for k in kcounter:
        print(k)

main()

Submission status: Accepted

Solution code:
N, X, Y = [int(_) for _ in input().split()]
X -= 1
Y -= 1

V = [0 for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        v1 = j - i
        v2 = abs(i - X) + abs(j - Y) + 1
        V[min(v1, v2)] += 1
        
for v in V[1:]:
    print(v)

Submission status: Accepted

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

a=[0]*n
# x-=1
# y-=1


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

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

Submission status: Accepted

Solution code:
import math
import itertools
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, X, Y =map(int,input().split())

L = [i for i in range(1,N+1)]
c_list = list(itertools.combinations(L,2))

Answer = {}
for i in range(1,N):
    inti = str(i)
    Answer[inti] = 0
def des(a,b):
    if b <= X or a >=  Y:
        return (b-a)
    else:
        return min(b-a, abs(Y-b)+abs(X-a)+1)
for cl in c_list:
    a = cl[0]
    b = cl[1]
    inti = des(a,b)
    inti = str(inti)
    Answer[inti] += 1
for n, m in Answer.items():
    print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,x,y = readInts()

d = 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(y-j),abs(i-y)+1+abs(j-x))]+=1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from numba import njit


@njit(cache=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in range(n):
        for j in range(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)

Submission status: Accepted

Solution code:
from numba import njit,prange


@njit(cache=True,parallel=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in prange(n):
        for j in prange(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)

Submission status: Accepted

Solution code:
from numba import njit,prange


@njit(parallel=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in prange(n):
        for j in prange(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)

Submission status: Accepted

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

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

for ai in ans:
    print(ai//2)

Submission status: Accepted

Solution code:
def 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):
            # x->yを通らない
            d1 = abs(j-i)
            # i->x->y->jの順 +1はx->yの分
            d2 = abs(x-i) + 1 + abs(j-y) 
            # i->y->x->jの順 +1はy->xの分
            d3 = abs(y-i) + 1 + abs(j-x)
            dist = min(min(d1, d2), d3)
            ans[dist] += 1
    print(*ans[1:n], sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, x, y = map(int, input().split())
    ans = [0] * (n+1)
    d = list()
    for i in range(1, n):
        for j in range(i+1, n+1):
            # x->yを通らない
            d1 = abs(j-i)
            # i->x->y->jの順 +1はx->yの分
            d2 = abs(x-i) + 1 + abs(j-y) 
            # i->y->x->jの順 +1はy->xの分
            d3 = abs(y-i) + 1 + abs(j-x)
            dist = min(min(d1, d2), d3)
            d.append(dist)
            ans[dist] += 1
    print(*ans[1:n], sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def f(i, j):
    v1 = j - i
    v2 = abs(X - i) + 1 + abs(j - Y)
    v3 = abs(Y - i) + 1 + abs(j - X)
    return min(v1, v2, v3)


D = [0] * N
for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = f(i, j)
        D[d] += 1

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

Submission status: Accepted

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

anslist.pop(0)

for i in anslist:
    print(i)

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
counter = {i + 1: 0 for i in range(n - 1)}

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

print(*[counter[i + 1] for i in range(n - 1)], sep='\n')

Submission status: Accepted

Solution code:
from collections import defaultdict

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

for i in range(1,N):
    for j in range(i+1, N+1):
        if j<=X or i>=Y:
            path = j-i
        else:
            path = min(j-i, abs(X-i)+abs(j-Y)+1)
        cnt_dict[path] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

for i in range(1, N+1): #1 ～ N start
    for j in range(i+1, N+1): # i+1 ～ N goal
        ans1 = j - i
        ans2 = abs(i-X) + 1 + abs(j-Y)
        ans_list[min(ans1, ans2)-1] += 1
print(*ans_list, sep="\n")

Submission status: Accepted

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


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


N, X, Y = MI()
cnt = [0] * N

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

for c in cnt[1:]:
    print(c)

Submission status: Accepted

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

l= [0]*n

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

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

Submission status: Accepted

Solution code:
def resolve():
    N, X, Y = list(map(int, input().split()))
    X -= 1
    Y -= 1
    dists = [[0 for _ in range(N)] for __ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            dists[i][j] = min(j-i, abs(X-i)+abs(Y-j)+1)
    counts = [0 for _ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            counts[dists[i][j]] += 1
    for i in range(1, N):
        print(counts[i])


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
def main():
  N, X, Y = map(int, input().split())
  G = [[i] for i in range(1,N+1)]
  ans=[0]*(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))
      #print(i,j,d)
      ans[d-1]+=1
  for a in ans:
    print(a)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def mlt(): return map(int, input().split())


x, a, b = mlt()

dp = [0 for n in range(x)]

for n in range(1, x+1):
    for k in range(n+1, x+1):
        d1 = k-n
        d2 = abs(a-n)+1+abs(b-k)
        ds = min(d1, d2)
        dp[ds] += 1

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

Submission status: Accepted

Solution code:
N,X,Y=map(int,input().split())
A=[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(j-Y),abs(Y-i)+1+abs(j-X))-1]+=1
for a in A:
  print(a)

Submission status: Accepted

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

if Y<X:
    X,Y=Y,X

Dist=[0 for i in range(N)]

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

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x,y=nii()
x-=1
y-=1
ans=[0 for i in range(n)]

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

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
L1 = x - 1
L2 = n - y
C = y - x + 1
for k in range(1, n):
    ans = 0
    if 2 * k == C:
        ans += C // 2
    elif 2 * k < C:
        ans += C
    for L in L1, L2:
        if C % 2 == 0 and 0 < k - C // 2 <= L:
            ans += 1
        ans += max(0, (min(L, k-1) - max(1, k - (C - 1) // 2) + 1) * 2) + (L >= k)
    ans += max(0, L1 + L2 + 2 - k) - sum(k <= x for x in [L1, L2+1, L2, L1+1]) + (k == 1)
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
def bfs(u, n, g):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

N, X, Y =MI()
E = [[] for _ in range(N + 1)]
for i in range(1, N):
    a = i
    b = i + 1
    E[a].append(b)
    E[b].append(a)
E[X].append(Y)
E[Y].append(X)

dist = [0] * N

for i in range(1, N + 1):
    D = deque(bfs(i, N + 1, E))
    D.popleft()
    for d in D:
        dist[d] += 1

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

Submission status: Accepted

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

from pprint import pprint
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)


# s, t \in V (s < t) に対して、s から t への最短経路を d_min(s, t) とすると、
# d_min(s, t) は、
# d_min(s, t) = min(t - s, abs(x - s) + 1 + abs(t - y))
# で与えられる。
# なので、s, t の全ての組み合わせに対して d_min(s, t) を計算し、条件を満たすような s, t の組を数え上げればよい。


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

count_dict = defaultdict(int)

# O(N^2)
for s in range(N - 1):
    for t in range(s + 1, N):
        dist = min(t - s, abs(X - s) + 1 + abs(t - Y))
        count_dict[dist] += 1

for k in range(1, N):
    ans = 0
    if k in count_dict:
        ans = count_dict[k]
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import heapq
INFTY = 10**4
N,X,Y = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y)
G[Y].append(X)
dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
    dist[i][i] = 0
for i in range(1,N+1):
    hist = [0 for _ in range(N+1)]
    heap = [(0,i)]
    hist[i] = 1
    while heap:
        d,x = heapq.heappop(heap)
        if d>dist[i][x]:continue
        hist[x] = 1
        for y in G[x]:
            if hist[y]==0:
                if dist[i][y]>d+1:
                    dist[i][y] = d+1
                    heapq.heappush(heap,(d+1,y))
C = {k:0 for k in range(1,N)}
for i in range(1,N):
    for j in range(i+1,N+1):
        C[dist[i][j]] += 1
for k in range(1,N):
    print(C[k])

Submission status: Accepted

Solution code:
import sys

N, X, Y = map(int, sys.stdin.readline().split())

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

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

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):
  for j in range(i+1,N):
    direct = j-i
    shortcut = abs(X-i)+1+abs(Y-j)
    shortest = min(direct,shortcut)
    ans[shortest-1] += 1
print(*ans,sep="\n")

Submission status: Accepted

Solution code:
from collections import deque

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

root = [[] for i in range(N)]
for i in range(N-1):
    root[i].append(i+1)
    root[i+1].append(i)

root[X-1].append(Y-1)
root[Y-1].append(X-1)

ans = [0]*(N-1)

for i in range(N):
    stack=deque([i])
    check = [-1]*N
    check[i] = 0

    while len(stack)>0:
        v = stack.popleft()
        for i in root[v]:
            if check[i] == -1:
                check[i]=check[v]+1
                stack.append(i)
    #print(check)
    for ch in check:
        if ch > 0:
            ans[ch-1] += 1

for aa in ans:
    print(aa//2)

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

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

Submission status: Accepted

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

ans=[0]*n

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

for i in range(1,n):
    tree[i-1].append(i)
    tree[i].append(i-1)

tree[x-1].append(y-1)
tree[y-1].append(x-1)

from collections import deque

ans=[0]*n
for i in range(n):
    checked=[-1]*n
    stack=deque([i])
    checked[i]=0
    while len(stack)>0:
        tmp=stack.popleft()
        for item in tree[tmp]:
            if checked[item]==-1:
                checked[item]=checked[tmp]+1
                stack.append(item)
    for item in checked:
        ans[item]+=1

for item in ans[1:]:
    print(item//2)

Submission status: Accepted

Solution code:
from collections import deque

N, X, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N-1):
    adj[i].append(i+1)
    adj[i+1].append(i)

adj[X-1].append(Y-1)
adj[Y-1].append(X-1)

dist = [[-1]*N for _ in range(N)]

for i in range(N):
    queue = deque([i])
    dist[i][i] = 0

    while queue:
        now = queue.popleft()
        for u in adj[now]:
            if dist[i][u] < 0:
                queue.append(u)
                dist[i][u] = dist[i][now] + 1

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

[print(a) for a in ans]

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

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter()

for i in range(1, N + 1):
    for j in range(i, N + 1):
        if (i == X and j == Y) or (i == Y and j == X):
            c[1] += 1
        else:
            c[min([j - i, abs(X - i) + 1 + abs(Y - j), abs(X - j) + 1 + abs(Y - i)])] += 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    from collections import deque
        
    N, X, Y = map(int, input().split())

    G = [[1]] + [[x - 1, x + 1] for x in range(1, N - 1)] + [[N - 2]]
    G[X - 1].append(Y - 1)
    G[Y - 1].append(X - 1)

    dist = [[-1] * N for _ in [0] * N]
    for start in range(N):
        q = deque([start])
        dist[start][start] = 0
        while q:
            now = q.popleft()
            for next in G[now]:
                if dist[start][next] == -1:
                    dist[start][next] = dist[start][now] + 1
                    q.append(next)
    res = [0] * N
    for i in range(N):
        for j in range(i + 1, N):
            res[dist[i][j]] += 1
    for d in range(1, N):
        print(res[d])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    from collections import deque
        
    N, X, Y = map(int, input().split())

    G = [[1]] + [[x - 1, x + 1] for x in range(1, N - 1)] + [[N - 2]]
    G[X - 1].append(Y - 1)
    G[Y - 1].append(X - 1)

    dist = [[-1] * N for _ in [0] * N]
    for s in range(N):
        q = deque([s])
        dist[s][s] = 0
        while q:
            v = q.popleft()
            for nv in G[v]:
                if dist[s][nv] == -1:
                    dist[s][nv] = dist[s][v] + 1
                    q.append(nv)
    res = [0] * N
    for i in range(N):
        for j in range(i + 1, N):
            res[dist[i][j]] += 1
    for d in range(1, N):
        print(res[d])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq

def dijkstra(s):  #スタート
    hq = [(0, s)]  #(距離,地点)
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, u in e[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(hq, (tmp, u))
    return cost


n,x,y=map(int,input().split())
e=[[] for i in range(n)]
for i in range(1,n):
  a,b=i,i+1
  e[a-1].append((1,b-1))
  e[b-1].append((1,a-1))

e[x-1].append((1,y-1))
e[y-1].append((1,x-1))

ans=[0]*(n-1)

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

ans[-1]=0

for i in ans:
  print(i//2)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n,x,y=map(int,input().split())
    x,y=x-1,y-1
    ans=[]
    for i in range(n):
        dp = [n]*n
        dp[i] = 0
        calcstep(i, dp)
        dp[y] = min(dp[y], dp[x]+1)
        dp[x] = min(dp[x], dp[y]+1)
        calcstep(x, dp)
        calcstep(y, dp)
        #print(i, dp)
        ans += dp
    ans = Counter(ans)
    for i in range(1,n):
        print(ans[i]//2)

def calcstep(i, dp):
    for j in range(i, len(dp)-1):
        if dp[j+1] > dp[j]+1:
            dp[j+1] = dp[j]+1
        else:
            break
    for j in range(1,i+1)[::-1]:
        if dp[j-1] > dp[j]+1:
            dp[j-1] = dp[j]+1
        else:
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for i in ans:
  print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

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

    cnt = 0

    ans=[0]*n

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

    for i in range(1,n):
        print(ans[i])
   
if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = 0

ans=[0]*n

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

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
ans_ls = [0] * (n-1)
for start in range(1,n):
    for end in range(start+1,n+1):
        cost_1 = end - start
        cost_2 = abs(start - x) + abs(end - y) + 1
        cost = min(cost_1,cost_2)
        ans_ls[cost-1] += 1
for ans in ans_ls:
    print(ans)

Submission status: Accepted

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

dist_cnt = [0]*N

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

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

Submission status: Accepted

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

#最短距離が１の時２の時、、、という風に実験しても途方に暮れるだけだった
#i,j固定して最短距離がどう表せるかを考える
def min_route_count(i,j):
  return min(abs(j-i),abs(j-y)+1+abs(x-i))

ans_list=[0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    ans_list[min_route_count(i,j)-1]+=1
    
for t in range(n-1):
  print(ans_list[t])

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import combinations
N, X, Y = map(int, input().split())
N_lst = [i for i in range(1, N + 1)]
michi = combinations(N_lst, r = 2)
dis = [0 for _ in range(N + 1)]
for i,j in michi:
    seiki = j - i
    betsu = abs(j-Y) + 1 + abs(X-i)
    if seiki <= betsu:
        dis[seiki] += 1
    else:
        dis[betsu] += 1
for h in range(1, N):
    print(dis[h])

Submission status: Accepted

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

Submission status: Accepted

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