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:

import collections


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

    inf = 10 ** 9
    ans = [0]*N

    def push(v, d, dist, q):
        if dist[v] == inf:
            dist[v] = d
            q.append(v)

    for i in range(N):
        q = collections.deque()
        dist = [inf]*N
        push(i, 0, dist, q)

        while(len(q)):
            v = q.popleft()
            d = dist[v]
            if v < N-1:
                push(v+1, d+1, dist, q)
            if 0 < v:
                push(v-1, d+1, dist, q)
            if v == X-1:
                push(Y-1, d+1, dist, q)
            if v == Y-1:
                push(X-1, d+1, dist, q)

        for i in range(N):
            ans[dist[i]] += 1

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

li = [0]*n
x,y = x-1,y-1

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

Submission status: Accepted

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

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print('\n'.join(map(str, t)))

Submission status: Accepted

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


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

for e in result[1:]: print(e)

Submission status: Accepted

Solution code:
from collections import deque

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

ans = [0] * (n+1)
INF = 10 ** 10

for i in range(n):
    d = [INF] * n
    q = deque([])
    d[i] = 0
    q.append(i)
    while len(q) > 0:
        v = q.popleft()
        if v - 1 >= 0:
            if d[v-1] == INF:
                q.append(v-1) 
                d[v-1] = d[v] + 1
        if v + 1 < n:
            if d[v+1] == INF:
                q.append(v+1)
                d[v+1] = d[v] + 1
        if v == x:
            if d[y] == INF:
                q.append(y)
                d[y] = d[v] + 1
        if v == y:
            if d[x] == INF:
                q.append(x)
                d[x] = d[v] + 1
    for i in range(n):
        ans[d[i]] += 1

for i in range(1, n):
    ans[i] //= 2     #i→jとj→iを両方カウントしているため
    print(ans[i])

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    N, X, Y = iip()
    X, Y = sorted((X-1, Y-1))
    #print(X, Y)

    result = [0 for i in range(1, N)]
    for a in range(0, N):
        for b in range(a+1, N):
            d1 = b-a
            d2 = abs(X-a)+abs(Y-b)+1
            d = min(d1, d2)-1
            #print(a, b, d)

            result[d] += 1

    print("\n".join([str(i) for i in result]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

print("\n".join(map(str, A[1:])))

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

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

C = Counter(min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1) for i, j in combinations(range(1, N + 1), 2))

print("\n".join(str(C[k]) for k in range(1, N)))

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 01:29:10 2020

@author: liang
"""

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

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

Submission status: Accepted

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

for i in range(n):
  for j in range(i+1,n):
    a = abs(j-i)
    xy = abs(i-x) + abs(j-y) + 1
    dis.append(min(a,xy))

ans = [0]*(n-1)
for d in dis:
  ans[d-1] += 1

for a in ans:
  print(a)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))
d=dijkstra(g,directed=False).astype(int)

#ans_l=np.bincount(d.ravel(), minlength=n)//2

ans_l=list(d.ravel())
c=Counter(ans_l)
for i in range(1,n):
  print(c[i]//2)

Submission status: Accepted

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

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

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))
d=dijkstra(g,directed=False).astype(int)

ans_l=np.bincount(d.ravel(), minlength=n)//2

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

Submission status: Accepted

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

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

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))

ans_l=[]

'''for i in range(n):
  d=dijkstra(g,indices=i,directed=False)
  ans_l+=list(d)'''

d=dijkstra(g,directed=False).astype(int)
ans_l=np.bincount(d.ravel(), minlength=n)//2

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

'''
for i in ans_l[1:]:
  print(i)
'''

Submission status: Accepted

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

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

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))

ans_l=[]

'''for i in range(n):
  d=dijkstra(g,indices=i,directed=False)
  ans_l+=list(d)'''

d=dijkstra(g,directed=False).astype(int)
#print(d)
ans_l=np.bincount(d.ravel(), minlength=n)//2

#print(*ans_l[1], sep='\n')

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = {i+1:0 for i in range(N-1)}

d = lambda i,j: min(abs(i-j), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))

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

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

Submission status: Accepted

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

ln=[0]*(N-1)

for i in range(1,N+1):
    for j in range(i+1,N+1):
        d2=N
        d=j-i
        if j <= x:
            pass
        elif i<=x and j <=y:
            d2=y-j+1+x-i
        elif j<=y:
            d2=y-j+1+i-x
        elif i<=x and j>=y:
            d2=x-i+j-y+1
        elif j>=y:
            d2=j-y+1+i-x

        if d2 < d:
            d=d2
        
        ln[d-1]+=1

for i in ln:
    print(i)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, X, Y = map(int, rl().split())
    X -= 1
    Y -= 1
    
    ans = [0] * N
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans[min(j - i, abs(X - i) + 1 + abs(j - Y), abs(Y - i) + 1 + abs(j - X))] += 1
    print('\n'.join(map(str, ans[1:])))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 30 20:27:30 2020

@author: black
"""

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

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

k_lis = [0]*(N-1)

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

for i in k_lis:
    print(i)

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
import heapq

def dijkstra(edges, s):
    hq = []
    d = [-1] * n
    d[s] = 0
    heapq.heappush(hq, (0, s))
    while hq:
        d1, p = heapq.heappop(hq)
        for i in edges[p]:
            if d[i] == -1 or d[i] > d1 + 1:
                d[i] = d1 + 1
                heapq.heappush(hq, (d1+1, i))
    return d

n,x,y = map(int,input().split())
edges = [[] for _ in range(n)]

for i in range(n):
    if i == 0:
        edges[i].append(i+1)
    elif i == n-1:
        edges[i].append(i-1)
    else:
        edges[i].append(i-1)
        edges[i].append(i+1)
edges[x-1].append(y-1)
edges[y-1].append(x-1)

ans = [0] * (n-1)

for i in range(n):
    d = dijkstra(edges, i)
    for j in d:
        if j != 0:
            ans[j-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    N,X,Y=MI()
    X-=1
    Y-=1
    
    ##########################################
    import heapq
    class Dijkstra():
        """
        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)
        ・負のコストがない場合のみ
        ・計算量はO(E log|V|)　
        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）
        """
        
        #最短のpathをたす
        
        
        class Edge():
            #重み付き有向辺
            
            def __init__(self, _to, _cost):
                self.to =_to
                self.cost = _cost
        
        def __init__(self, V):
            #引数Vは頂点数
            self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺
            self. _E = 0 #辺の数
            self._V = V #頂点数
        
        #proparty - 辺の数
        def E(self):
            return self._E
        
        #proparty - 頂点数
        def V(self):
            return self._V
        
        def add(self, _from, _to, _cost):
            #2頂点と辺のコストを追加
            self.G[_from].append(self.Edge(_to,_cost))
            self._E +=1
            
        def add2(self, _from, _to, _cost):
            #2頂点と辺のコスト（無向）を追加
            self.G[_from].append(self.Edge(_to, _cost))
            self.G[_to].append(self.Edge(_from, _cost))
            self._E +=1
            
        def shortest_path(self,s):
            #始点sから頂点iまでの最短経路長のリストを返す
            
            que = [] #priority queue
            d = [float("inf")] * self.V()
            prev = [None]*self.V() #prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所
            d[s] = 0
            heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加
            
            while len(que)!=0:
                #キューに格納されてある中で一番コストが小さい頂点を取り出す
                cost,v = heapq.heappop(que)
                
                #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ
                if d[v] < cost:
                    continue
                    
                #頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新
                for i in range(len(self.G[v])):
                    e = self.G[v][i] #vのi個目の隣接辺
                    if d[e.to] > d[v] + e.cost:
                        d[e.to] = d[v] + e.cost #更新
                        prev[e.to] = v
                        heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加
            
                        
            return d
    ########################
        
    djk = Dijkstra(N)        
    for i in range(N-1):
        djk.add2(i,i+1,1)
    djk.add2(X,Y,1)
    
    ans=[0]*(N+1)
    
    for i in range(N):
        d=djk.shortest_path(i)
        for j in range(N):
            ans[d[j]]+=1
            
    for i in range(N-1):
        print(ans[i+1]//2)
        
    

main()

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

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import numpy as np
N, X, Y = map(int, input().split())
 
dist = []
for i in range(1, N):
    x = np.arange(i + 1, N + 1)
    # 直接
    d1 = np.abs(x - i)
    # i -> X -> Y -> x
    d2 = np.abs(i - X) + np.abs(Y - x) + 1
    # i -> Y -> X -> x
    d3 = np.abs(i - Y) + np.abs(X - x) + 1
    d = np.minimum(np.minimum(d1, d2), d3)
    dist.append(d)
 
dist = np.concatenate(dist)
count = np.bincount(dist, minlength=N)
print('\n'.join(count[1:].astype(str)))

Submission status: Accepted

Solution code:
N, ex, ey = list(map(int, input().split()))
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
count = [0 for _ in range(N)]
for start_edge in range(1, N+1):
    for end_edge in range(start_edge, N+1):
        dist = min(abs(start_edge-ex)+abs(end_edge-ey)+1,abs(end_edge-start_edge))
        count[dist] += 1

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, X, Y = map(int, input().split())
    cnt = [0 for _ in range(N)]
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            dis_ij = min(j - i, abs(X - i) + abs(Y - j) + 1)
            cnt[dis_ij] += 1
    for i in range(1, N):
        print(cnt[i])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
n,x,y=map(int,input().split())

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

R=[0]*n

def bfs(j):
	V=[-1]*n
	que=deque([])
	que.append(j)
	V[j]=0
	while que:
		p=que.popleft()
		for np in L[p]:
			if V[np]==-1:
				que.append(np)
				V[np]=V[p]+1
	for i in range(n):
		R[V[i]]+=1
	
for j in range(n):
	bfs(j)
for i in range(1,n):
	print(R[i]//2)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * (N + 1)

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
    for j in range(i + 1, n):
        dist1 = j - i
        dist2 = abs(x - i) + abs(y - j) + 1
        ans[min(dist1, dist2)] += 1
print(*ans[1:], sep='\n')

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    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):
            if i <= X and j <= X:
                dist = j - i
            elif i <= X and j <= Y:
                dist = min(j - i, X - i + 1 + Y - j)
            elif i <= X and Y <= j:
                dist = X - i + j - Y + 1
            elif X <= i <= Y and j <= Y:
                dist = min(j - i, i - X + 1 + Y - j)
            elif X <= i <= Y and Y <= j:
                dist = min(j - i, i - X + 1 + j - Y)
            else:
                dist = j - i
            ans[dist] += 1

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


main()

Submission status: Accepted

Solution code:
from collections import deque


def dijkstra(start: int, edges: list):
    """print the shortet path  O(|E|log|V|)
    maybe verified
    """
    dist = [float('inf') for _ in range(N)]  # list dist[|V|]
    dist[start] = 0
    prev_v = [-1]*(len(dist))  # 最短経路でのひとつ前の頂点
    q = deque([(0, start)])  # （暫定的な距離，頂点）
    while q:
        d_cur, cur = q.pop()
        if dist[cur] < d_cur:  # すでに探索済み
            continue
        for nex, cost in edges[cur]:
            if dist[nex] > dist[cur]+cost:
                dist[nex] = dist[cur]+cost
                q.append((dist[nex], nex))
                prev_v[nex] = cur
    return dist

    # # 以下 path の復元
    # path = []
    # v = goal
    # while v != -1:
    #     path.append(v)
    #     v = prev_v[v]
    # path = path[::-1]  # reverse
    # print("Shortest path: ", path)


if __name__ == "__main__":
    N, X, Y = map(int, input().split())
    X, Y = X-1, Y-1
    edges = [[] for _ in range(N)]
    for i in range(1, N):
        edges[i].append((i-1, 1))
    for i in range(N-1):
        edges[i].append((i+1, 1))
    edges[X].append((Y, 1))
    edges[Y].append((X, 1))
    # print(edges)

    cnt = [0]*N
    for i in range(N):
        d = dijkstra(i, edges)
        for di in d:
            cnt[di] += 1
    cnt = [ci//2 for ci in cnt]
    print(*cnt[1:], sep="\n")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import heapq


def dijkstra(start: int, edges: list):
    """print the shortet path  O(|E|log|V|)
    maybe verified
    """
    dist = [float('inf') for _ in range(N)]  # list dist[|V|]
    dist[start] = 0
    prev_v = [-1]*(len(dist))  # 最短経路でのひとつ前の頂点
    q = [(0, start)]  # （暫定的な距離，頂点）
    while q:
        d_cur, cur = heapq.heappop(q)
        if dist[cur] < d_cur:  # すでに探索済み
            continue
        for nex, cost in edges[cur]:
            if dist[nex] > dist[cur]+cost:
                dist[nex] = dist[cur]+cost
                heapq.heappush(q, (dist[nex], nex))
                prev_v[nex] = cur
    return dist

    # # 以下 path の復元
    # path = []
    # v = goal
    # while v != -1:
    #     path.append(v)
    #     v = prev_v[v]
    # path = path[::-1]  # reverse
    # print("Shortest path: ", path)


if __name__ == "__main__":
    N, X, Y = map(int, input().split())
    X, Y = X-1, Y-1
    edges = [[] for _ in range(N)]
    for i in range(1, N):
        edges[i].append((i-1, 1))
    for i in range(N-1):
        edges[i].append((i+1, 1))
    edges[X].append((Y, 1))
    edges[Y].append((X, 1))
    # print(edges)

    cnt = [0]*N
    for i in range(N):
        d = dijkstra(i, edges)
        for di in d:
            cnt[di] += 1
    cnt = [ci//2 for ci in cnt]
    print(*cnt[1:], sep="\n")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N,X,Y = list(map(int,input().split()))
A = []
for i in range(1,N+1):
    for j in range(i+1,N+1):
        A.append(min(j-i,abs(X-i)+abs(Y-j)+1,abs(X-j)+abs(Y-i)+1))
c = collections.Counter(A)
for k in range(1,N):
    print(c[k])

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * n

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

Submission status: Accepted

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

Submission status: Accepted

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

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

import heapq

def dijkstra(start, edge, n):

    dist = [float('inf')] * n
    dist[start] = 0

    pq = [(dist[start], start)]

    while len(pq):
        d, frm = heapq.heappop(pq)
        if dist[frm] < d:
            continue
        for to, cost in edge[frm]:
            if dist[frm] + cost < dist[to]:
                dist[to] = dist[frm] + cost
                heapq.heappush(pq, (dist[to], to))

    return dist

cnt = [0] * n

for i in range(n):
    dist = dijkstra(i, edges, n)
    for d in dist:
        cnt[d] += 1

ans = []
for c in cnt:
    c //= 2
    ans.append(c)

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

Submission status: Accepted

Solution code:
from collections import deque

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

num = [0]*(N-1)

G = [set() for x in range(N)]
for i in range(N-1):
    G[i].add(i+1)
    G[i+1].add(i)

G[X].add(Y)
G[Y].add(X)

def bfs(x):
    search = [0]*N
    nu = 1
    q = deque()
    q.append((x,-1))
    search[x] = 1
    while nu != 0:
        xx,d = q.pop()
        nu -= 1
        if x < xx:
            num[d] += 1
        for g in G[xx]:
            if search[g]:
                continue
            q.appendleft((g,d+1))
            search[g] = 1
            nu += 1

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
n, x, y = map(int, input().split())
ans = [0] * (n-1)
for i in range(1, n+1):
    for j in range(1, n+1):
        if i < j:
            # iとjを固定、rangeでi<jを表現
            d = min(j-i, abs(x-i)+abs(j-y)+1)
            # 長さを示すところに+１
            ans[d-1] += 1
print(*ans, sep="\n")

Submission status: Accepted

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

for i in range(1, N):
    for j in range(i+1, N+1):
        if (i <= X and j <= X) or (i >= Y and j >= Y):
            d = j - i
        elif X < i < Y and X < j < Y:
            d = min([j - i, i - X + Y - j + 1])
        elif i <= X and X < j < Y:
            d = X - i + min([j - X, Y - j + 1])
        elif X < i < Y and  Y <= j:
            d = min([i - X + 1, Y - i]) + j - Y
        elif i <= X and Y <= j:
            d = X - i + j - Y + 1
        else:
            print("undefined pattern {}, {}".format(X, Y))

        scores[d] += 1
for score in scores[1:]:
    print(score)

Submission status: Accepted

Solution code:
N,X,Y = map(int,input().split())
length = [0]*(N+1)
for i in range(1,N+1):
  for j in range(i,N+1):
    ans = min(abs(j-i),abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))
    length[ans] += 1
for i in range(1,N):
  print(length[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):
        # iとjを固定、rangeでi<jを表現
        d = min(j-i, abs(x-i)+abs(j-y)+1, abs(y-i)+abs(x-j)+1)
        # 長さを示すところに+１
        ans[d-1] += 1
print(*ans, sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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


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

for k in range(N):
    if k==0:
        continue

    print(ansli[k])

Submission status: Accepted

Solution code:
N, X, Y = list(map(int, input().split()))
result = {N-i:0 for i in range(1, N)}

for i in range(1, N):
  for j in range(i + 1, N + 1):
    dis = min([j - i, abs(j - Y) + abs(i - X) + 1, abs(j - X) + abs(i - Y) + 1])
    result[dis] += 1
print("\n".join(list(map(str, result.values()))))