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 deque
N, X, Y = map(int, input().split())
graphs = [[i - 1, i + 1] for i in range(1, N - 1)]
graphs.insert(0, [1])
graphs.append([N - 2])

# scores = [0 for _ in range(N)]

graphs[X - 1].append(Y - 1)
# print(graphs)


# 数をカウントする
counts = [0 for _ in range(N)]


for index, start_point in enumerate(graphs):
    scores = [10**9 + 7 for _ in range(N)]
    queue = deque([index])
    scores[index] = 0
    while queue:
        now_index = queue.pop()
        for next_index in graphs[now_index]:
            if scores[next_index] > scores[now_index] + 1:
                queue.append(next_index)
                scores[next_index] = scores[now_index] + 1
    for score in scores[index:]:
        counts[score] += 1

for count in counts[1:]:
    print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque

N, X, Y = map(int, input().split())
X -= 1
Y -= 1
mp = defaultdict(list)
ans = defaultdict(int)
for i in range(N - 1):
    mp[i].append(i + 1)
    mp[i + 1].append(i)
mp[X].append(Y)
mp[Y].append(X)

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


def bfs(st):
    q = deque()
    q.append(st)
    dist[st][st] = 0
    while q:
        now = q.popleft()
        for new in mp[now]:
            if dist[st][new] != -1:
                continue
            q.append(new)
            dist[st][new] = dist[st][now] + 1


for i in range(N):
    bfs(i)

for i in range(N):
    for j in range(N):
        if j >= i:
            continue
        d = dist[i][j]
        ans[d] += 1

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

Submission status: Accepted

Solution code:
import sys
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):
        for j in range(i+1, N+1):
            if i >= Y or j <= X:
                ans[j-i] += 1
            else:
                ans[min(j-i, abs(X-i) + abs(Y-j)+1)] += 1
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    main()

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[j-i] += 1
        if (j - i) > abs(X - i) + abs(j - Y) + 1:
            ans[abs(X - i) + abs(j - Y) + 1] += 1
        else:
            ans[j-i] += 1
           # ans[j-i] -= 1

        #print("--", i,j, ans)


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

Submission status: Accepted

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

for i in range(N):
  for j in range(N - i - 1):
    a = i + 1
    b = N - j
    if a <= X:
      if b >= Y:
        l = (X - a) + 1 + (b - Y)
      else:
        l = min(b - a, (X - a) + 1 + (Y - b))

    elif a > X:
      if b >= Y:
        l = min(b - a, (a - X) + 1 + (b - Y))
      else:
        l = min(b - a, (a - X) + 1 + (Y - b))
        
    k[l - 1] += 1
    
for val in k:
  print(val)

Submission status: Accepted

Solution code:


N, X, Y = map(int,input().split()) #n:頂点数　w:辺の数
X -= 1
Y -= 1

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

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

Submission status: Accepted

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

D = [0] * N
for i in range(N):
    for j in range(i + 1, N):
        if i < X and X <= j <= Y:
            start_to_ent = X - i
            ent_to_goal = j - X
            d = min(ent_to_goal, circle - ent_to_goal) + start_to_ent
            D[d] += 1
        elif X <= i <= Y and X <= j <= Y:
            start_to_goal = j - i
            d = min(start_to_goal, circle - start_to_goal)
            D[d] += 1
        elif X <= i <= Y and Y < j:
            start_to_ent = j - Y
            ent_to_goal = Y - i
            d = min(ent_to_goal, circle - ent_to_goal) + start_to_ent
            D[d] += 1
        elif i < X and Y < j:
            start_to_ent = X - i
            ent2_to_goal = j - Y
            r = Y - X
            d = start_to_ent + min(r, circle-r) + ent2_to_goal
            D[d] += 1
        else:
            d = j - i
            D[d] += 1

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

# circle = Y - X + 1
# fline = X - 1
# bline = N - Y
#
# climit = circle // 2
# bin_flag = climit % 2 == 0
# if bin_flag:
#     climit -= 1
#
# for k in range(N):
#     F = min(fline - k + 1, 0)
#     if bin_flag:
#         FC = min(min(climit, fline) - k + 2) * 2
#         BC = min(min(climit, bline) - k + 1) * 2
#         if climit + 1 < k <

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = [int(x) for x in input().split()]

num_youso = l[0]
hidari = l[1]
migi = l[2]

lis = [0]*(num_youso -1)

for x in range(1,num_youso + 1):
  for y in range(x +1,num_youso + 1 ):
    saitan = y - x
    hidari_kyori = abs(x - hidari)
    migi_kyori = abs(y - migi)
    if hidari_kyori + migi_kyori + 1 < saitan:
      saitan = hidari_kyori + migi_kyori + 1
    lis[saitan -1] += 1
    
    

for i in range(num_youso -1):
  print(lis[i])

Submission status: Accepted

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

def clc(i1, i2):
    if (i1 < x and i2 <= x) or (y <= i1 and y < i2):
        return i2 - i1
    else:
        return min(1 + abs(i2 - y) + abs(i1 - x), i2 - i1)

for k in range(1, n+1):
    for l in range(k+1, n+1):
        tmp = clc(k, l)
        kyori.append(tmp)
outs = [0 for _ in range(n-1)]
for k in kyori:
    outs[k-1] += 1
for i in range(n-1):
    print(outs[i])

Submission status: Accepted

Solution code:
import collections


def bfs(i, path, dist, N):
    moves = 0

    pp = []
    pp = path[i]

    reached = [False for _ in range(N)]
    dist[i] = 0
    reached[i] = True
    for j in range(N + 1):
        moves += 1
        next_pp = []
        for i in pp:
            if reached[i]:
                continue
            else:
                reached[i] = True
                dist[i] = moves
                for p in path[i]:
                    next_pp.append(p)

        pp = next_pp


def flatten(nested_list):
    return [e for inner_list in nested_list for e in inner_list]


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

    path = [[] for _ in range(N)]

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

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

    dist = [N for _ in range(N)]

    D_list = []

    for i in range(N):
        dist[i] = 0
        bfs(i, path, dist, N)
        D_list.append(dist)
        dist = [N for _ in range(N)]

    D = flatten(D_list)
    dic = collections.Counter(D)

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


main()

Submission status: Accepted

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

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

ans = [0]*(N-1)
branch1 = X-1
branch2 = N-Y
cycle = Y-X+1
for i in range(cycle//2):   # 輪の1/2まで両側(2通り）で行ける
    ans[i] += cycle
if cycle%2==0:     # 輪は偶数（両方から同じ距離がある）
    ans[cycle//2-1] -= cycle//2
ans[0] -= 1

for i in range(branch1):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2
for i in range(branch2):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2

for i in range(branch1+branch2+1):   # 直線経路
    ans[i] += branch1+branch2+1 - i

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

Submission status: Accepted

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

k = [0] * (N + 1)

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

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np

def resolve():
    from heapq import heappush, heappop

    # 長点数V、直接移動先とコストを記したリストg、スタート地点rをとって、
    # rからiに行くまでの最低コストがdist[i]であることを意味するリストdistを返す関数
    def dijkstra(V, g, r):

        dist = [INF] * V
        queue = [(0, r)]  # queueの要素(c,v)は、コストcで直接vに行けることを意味する
        dist[r] = 0  # スタート地点rにはコスト0で行ける

        while queue:
            c, v = heappop(queue)
            if dist[v] < c:  # すでに記録されているコストの方が小さいので更新不要
                continue
            for cost, t in g[v]:
                if dist[v] + cost < dist[t]:
                    dist[t] = dist[v] + cost
                    heappush(queue, (dist[t], t))

        return dist

    N,X,Y=map(int,input().split())
    V, E= N,N
    g = [[] for i in range(V)]

    for i in range(N-1):
        g[i].append((1, i+1))
        g[i+1].append((1, i))  # g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する
        # g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する
    g[X-1].append((1, Y-1))
    g[Y-1].append((1, X-1))

    INF = 10 ** 10
    ans = [0] * N

    for r in range(N):
        for i in dijkstra(V, g, r):
            if i<INF:
                ans[i]+=1

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


resolve()

Submission status: Accepted

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

juli = dict()
for i in range(1, n + 1):
    juli[i] = dict()
    for j in range(1, n + 1):
        juli[i][j] = 5000

for i in range(1, n + 1):
    juli[i][i] = 0

for i in range(1, n):
    juli[i][i + 1] = 1
    juli[i + 1][i] = 1

juli[x][y] = 1
juli[y][x] = 1


for i in range(1, x + 1):
    for j in range(i, x + 1):
        juli[i][j] = j - i

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

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

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

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

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

table = dict()
for i in range(0, n + 1):
    table[i] = 0

for i in range(1, n + 1):
    for j in range(i, n + 1):
        table[juli[i][j]] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, X, Y = input_nums()
    dist = {}
    for i in range(1, N):
        dist[i] = 0
    for s in range(1, N):
        for g in range(s+1, N+1):
            if X == s and Y == g:
                dist[1] += 1
                continue
            a = abs(X - s) + abs(Y - g) + 1
            b = g - s
            if a < b:
                dist[a] += 1
            else:
                dist[b] += 1
    for i in range(1, N):
        print(dist[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dist = [0 for i in range(1,n)]

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

Submission status: Accepted

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


a=[0]*n
m={}
for i in range(1,n+1):
	for j in range(i+1,n+1):
	    
	    d=min(j-i,abs(i-x)+1+abs(j-y))
	    if d in m:
	        m[d]+=1
	    else :
	        m[d]=1




for i in range(1,n):
    if i in m:
        print m[i]
    else:
        print 0

Submission status: Accepted

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	n, x, y = map(int, sys.stdin.readline().split())
	x -= 1
	y -= 1
	ans = [0]*(n-1)
	for i in range(n):
		for j in range(i+1, n):
			if i == j:
				continue
			if (i <= x and j <= x) or (y <= i and y <= j):
				ans[abs(i-j)-1] += 1
			elif (i <= x and y <= j):
				ans[x-i + j-y + 1 - 1] += 1
			elif (x < i < y and x < j < y):
				ans[min(abs(i-j), i-x + 1 + y-j)-1] += 1
			elif (i <= x and x < j < y):
				ans[min(abs(i-j), x-i + 1 + y-j)-1] += 1
			elif (x < i < y and y <= j):
				ans[min(abs(i-j), j-y + 1 + i-x)-1] += 1
	for i in range(len(ans)):
		print(ans[i])







main()

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
A = [0 for i in range(N - 1)]
for i in range(1, N):
  for j in range(i+1, N+1):
    if j <= X:
      A[j-i-1] += 1
    elif i >= Y:
      A[j-i-1] += 1
    elif i <= X:
      if j >= Y:
        A[j-Y+X-i] += 1
      elif X < j < Y:
        m = min(X-i+1+Y-j, j-i)
        A[m-1] += 1
    elif j >= Y:
      if i <= X:
        A[j-Y+X-i] += 1
      elif X < i < Y:
        m = min(i-X+1+j-Y, j-i)
        A[m-1] += 1
    elif X <= i and j <= Y:
      m = min(i-X+1+Y-j, j-i)
      A[m-1] += 1
for i in range(N-1):
  print(A[i])

Submission status: Accepted

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

X -= 1
Y -= 1

ans = [0] * (N-1)

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

for x in ans: print(x)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import collections 
nxy=input().rstrip().split(" ")
n=int(nxy[0])
x=int(nxy[1])
y=int(nxy[2])
dis=[]
for i in range(1,n):
    #print(i)
    j=i+1
    while j>i and j<=n:
        l1=abs(x-i)+1+abs(y-j)
        l2=j-i
        if l1>=l2:
            L=l2
        else:
            L=l1
        #print(L)
        dis.append(L)
        j=j+1
#print(dis)
c=collections.Counter(dis)
#print(c)
for k in range(1,n):
    print(c[k])

Submission status: Accepted

Solution code:
N, X, Y = map(int,input().split())
G = [k for k in range(N)]
G[Y-1] = G[X-1] + 1
dx = [abs(X-1-k) for k in range(N)]
dy = [abs(Y-1-k) for k in range(N)]

ans = [[10**9]*N for l in range(N)]
for k in range(N):
    d = [10**9]*N
    for l in range(N):
        d[l] = min(abs(k-l),abs(X-1-k)+dy[l]+1,abs(Y-1-k)+dx[l]+1)
    for l in range(N):
        ans[k][l] = min(ans[k][l],d[l])
d = [0]*(N-1)
for k in range(N-1):
    for l in range(k+1,N):
        d[ans[k][l]-1] += 1
for e in d:
    print(e)

Submission status: Accepted

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

for i in range(1, N+1):
    for j in range (i+1, N+1):
        if (i <= X and j <= X) or (i >= Y and j >= Y):
            ans[j - i] += 1
        elif i <= X and (j > X and j <= Y):
            temp = min (j - i, (Y - j + 1) + (X - i))
            ans[temp] += 1
        elif (i >= X and i < Y) and j >= Y:
            temp = min (j - i, (i - X + 1) + (j - Y))
            ans[temp] += 1
        elif (i > X and j < Y):
            temp = min (j - i, (Y-j) + 1 + (i-X))
            ans[temp] += 1
        else:
            temp = min (j - i, (j - Y) + (X - i) + 1)
            ans[temp] += 1
for k in ans:
    print(ans[k])

Submission status: Accepted

Solution code:
n, x, y = list(map(int, input().split()))
d = [0] * n
flag = False
if y == n:
    flag = True
for i in range(1, n):
    for j in range(i + 1, n + 1):
        dist = min([abs(x - i) + 1 + abs(j - y), j - i])
        if dist <= n - 1:
            d[dist] += 1
# for i in range(1, n):
#     memo_i = []
#     for j in range(1, n):
#         if i <= x and j >= y:
#             dist = (x - i) + 1 + (j - y)
#             if dist <= n - 1:
#                 d[dist] += 1
#         elif i <= x:
#             dist = min([j - i, (x - i + 1 + (y - j))])
#             if dist <= n - 1:
#                 d[dist] += 1
#         elif j >= y:
#             dist = min([j - i, (j - y + 1 + (i - x))])
#             if dist <= n - 1:
#                 d[dist] += 1
#         else:
#             dist = min([j - 1, (y - j) + 1 + (i - x)])
#             if dist <= n - 1:
#                 d[dist] += 1
# if flag:
#     for i in range(1, n):
#         dist = min([abs(x - i) + 1, n - i])
#         if dist <= n - 1:
#             d[dist] += 1
for i in range(1, n):
    print(d[i])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N, X, Y = [int(x) for x in input().split()]
    shortcut_len = Y - X - 1
    count = defaultdict(int)
    for start in range(1, N+1):
        for end in range(start + 1, N+1):
            length = end - start
            if start <= X and end >= Y:
                length -= shortcut_len
            elif start < Y:
                temp = 1 + abs(X - start) + abs(Y - end)
                length = temp if temp < length else length

            # print(start, end, length)
            count[length] += 1
    
    for i in range(1, N):
        print(count[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

a=[[0 for i in range(n)]for j in range(n)]
for i in range(n-1):
  for j in range(n):
    a[i][j]=j-i
    
l=y-x+1
l//=2
l-=1

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

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

#for i in range(n):
#  for j in range(n):
#    print(a[i][j],end=" ")
#  print()
    
for k in range(n-1):
  print(ans[k])

Submission status: Accepted

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

A, B = N-(Y-X-1), Y-X-1
for i in range(1, A):
    ans[i] += A - i
ans[1] -= 1

if B % 2 == 0:
    C = [x for x in range(1, B//2 + 1)]
    C = C[1:] + C + [B//2 + 1]

    for i in range(len(C)):
        for j in range(1, X):
            ans[C[i] + j] += 1
        for j in range(1, N-Y+1):
            ans[C[i] + j] += 1

    for i in range(1, (B+2)//2):
        ans[i] += (B+2)
    ans[(B+2)//2] += (B+2)//2


else:
    C = [x for x in range(1, B//2 + 2)]
    C = C[1:] + C

    for i in range(len(C)):
        for j in range(1, X):
            ans[C[i] + j] += 1
        for j in range(1, N-Y+1):
            ans[C[i] + j] += 1

    for i in range(1, (B+2)//2 + 1):
        ans[i] += (B+2)


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from collections import deque
n,x,y = inm()
ans = [0]*n
for i in range(1,n+1):
    #ddprint(f"- - - - i {i}")
    done = [False]*(n+1)
    #if i>1:
    #    done[i-1] = True
    q = deque([(i,0)])
    while len(q)>0:
        z,d = q.popleft()
        #ddprint(f"z {z} d {d}")
        if done[z]:
            #ddprint("skip")
            continue
        done[z] = True
        if z>i:
            ans[d] += 1
        if z>1 and not done[z-1]:
            q.append((z-1,d+1))
        if z<n and not done[z+1]:
            q.append((z+1,d+1))
        if z==x and not done[y]:
            q.append((y,d+1))
for i in range(1,n):
    print(ans[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 20:51:45 2020

@author: naoki
"""
from collections import deque
N, X, Y = map(int,input().split())

distance_count = [0] * (N + 1)
route = [[i-1, i+1] for i in range(N+1)]

del route[-1][-1]

All_distances = [0]*N
route[X].append(Y)
route[Y].append(X)
#%%
for j in range(1,N):
    todo = deque([j])
    seen = [0 for i in range(N+1)]
    distance = [N+1] * (N+1)
    distance[j] = 0
    while len(todo) > 0:
        now = todo.pop()
        if now == N+1 or now == 0:
            continue
        for checking in route[now]:
            kari1 = distance[checking]
            kari2 = distance[now] + 1
            if seen[checking] < 2 and kari1 > kari2:
                distance[checking] = kari2
                todo.append(checking)
                seen[checking] += 1
            elif kari1 > kari2:
                distance[checking] = kari2
    for i in range(j,len(distance)):
        if distance[i] != N+1:
            All_distances[distance[i]] += 1
for i in range(1,N):
    print(All_distances[i])

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

l_count = [0]*n

for i in range(1, n):
    for j in range(i+1, n+1):
        if i <= x:
            if j <= x:
                l_count[j-i] += 1
            elif x < j < y:
                l_count[min(j-i, x-i + y-j + 1)] += 1
            elif y <= j:
                l_count[x-i + j-y + 1] += 1
        elif x < i < y:
            l_count[min(j-i, i-x + abs(y-j) + 1)] += 1
        else:
            l_count[j-i] += 1
for i in range(1, n):
            print(l_count[i])

Submission status: Accepted

Solution code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

count = [0] * (N-1)
for i in range(N):
    for j in range(i + 1, N):
        if i <= X and X <= j <= Y:
            min_d = min(j - i, X - i + (Y - j) + 1)
        elif i <= X and Y <= j:
            min_d = X - i + (j - Y) + 1
        elif X <= i <= Y and Y <= j:
            min_d = min(j - i, (i - X) + 1 + (j - Y))
        elif X <= i <= j <= Y:
            min_d = min(j - i, i - X + 1 + (Y - j))
        else:
            min_d = j - i
        # print(i+1, j+1)
        # print(min_d)
        count[min_d-1] += 1

for x in count:
    print(x)

Submission status: Accepted

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

cost = [[0 for _ in range(N)] for _ in range(N)]
output = [0 for i in range(N-1)]


X -= 1
Y -= 1
for i in range(N-1):
    for j in range(i+1, N):
        if i <= X:
            if j <= X:
                c = j-i
            elif X < j <= Y:
                c = X - i + min(j-X, Y-j+1)
            elif Y < j:
                c = X - i + j - Y + 1
        elif i < Y:
            if j <= Y:
                c = min(j-i, Y-j+i-X+1)
            else:
                c = j - Y + min(Y - i, i - X + 1)
        else:
            c = j-i
        output[c-1] += 1

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

Submission status: Accepted

Solution code:
N,X,Y=map(int,input().split())
klist=[0 for i in range(N-1)]
def returndis(x,y):
  d=min(y-x,1+abs(Y-y)+abs(X-x))
  return d
for i in range(N-1):
  for j in range(N-1-i):
    p=returndis(i+1,j+i+2)
    klist[p-1]+=1

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
## coding: UTF-8
from itertools import permutations, combinations,combinations_with_replacement,product
s = input().split()
q = [int(p) for p in s]

N = q[0]
X = q[1]
Y = q[2]

num = [i+1 for i in range(N)] #N=5 : [1, 2, 3, 4, 5]
answer = [0 for i in range(N-1)] #答えを格納するリスト N=5:[距離1の組み合わせの数, 距離2, 距離3, 距離4]
#print(answer)

pairs = list(combinations(num,2)) #考えられる組み合わせを全部作る


def calc_dist(i, j):
    #(i,j)の組み合わせに対して、最短距離を返す関数
    #i < jの制限をつけて入れること
    warp = abs(i-X) + 1 + abs(j-Y)
    return min(j-i, warp)
    #正常に動作していることを確認した。




for i in range(len(pairs)):
    #print(calc_dist(pairs[i][0], pairs[i][1])) #動作確認完了
    #距離が3：リストの3番目を＋1したい
    answer[calc_dist(pairs[i][0], pairs[i][1])-1] += 1

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

Submission status: Accepted

Solution code:
def main():
    n, x, y = [int(i) for i in input().split()]
    adj = {i: [i+1, i-1] for i in range(1, n-1)}
    adj[0] = [1]
    adj[n-1] = [n-2]
    adj[x-1].append(y-1)
    adj[y-1].append(x-1)
    res = [0] * n
    for i in range(n):
        memo = [-1] * n
        pos = i
        cand = [pos]
        memo[pos] = 0
        while len(cand) > 0:
            pos = cand.pop(0)
            for nx in adj[pos]:
                if memo[nx] != -1:
                    continue
                memo[nx] = memo[pos] + 1
                res[memo[nx]] += 1
                cand.append(nx)
    for r in res[1:]:
        print(int(r/2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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)
    ans[d - 1] += 1

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

Submission status: Accepted

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

ret = [0 for i in range(N)]
for i in range(1, N):
    for j in range(i+1, N+1):
        if j <= X:
            idx = j-i
            ret[idx] += 1
        elif j <= Y:
            if i <= X:
                idx = X-i + min(j-X, Y-j+1)
                ret[idx] += 1
            else:
                idx = min(j-i, Y-j+1+i-X)
                ret[idx] += 1
        else:
            if i <= X:
                idx = X -i + 1 + j-Y
                ret[idx] += 1
            elif i<=Y:
                idx = j-Y + min(Y-i,i-X+1)
                ret[idx] += 1
            else:
                idx = j-i
                ret[idx] += 1

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

Submission status: Accepted

Solution code:
from collections import deque

class Node:
    def __init__(self, idx):
        self.idx = idx
        self.a = []


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

for i in range(n):
    node = Node(i+1)
    nodes.append(node)

for i in range(n-1):
    cur = nodes[i]
    next = nodes[i+1]

    cur.a.append(next)
    next.a.append(cur)

X = nodes[x-1]
Y = nodes[y-1]
X.a.append(Y)
Y.a.append(X)
dp = [[None] * (n+1) for _ in range(n+1)]

for i in range(n):
    node = nodes[i]
    q = deque()
    q.append((node, 0))
    done = set()

    while q:
        t = q.popleft()
        node, d = t[0], t[1]

        if node.idx not in done:
            dp[i + 1][node.idx] = d
            done.add(node.idx)
            for adj in node.a:
                q.append((adj, d + 1))

# for i in range(1, n+1):
#     print(dp[i])

m = {}

for i in range(1, n + 1):
    for j in range(1, n + 1):
        dis = dp[i][j]
        if dis in m:
            m[dis] += 1
        else:
            m[dis] = 1

for k in range(1, n):
    if k in m:
        print(m[k] // 2)
    else:
        print(0)