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 heapq
INFTY = 10**4
N,X,Y = map(int,input().split())
C = {k:0 for k in range(N)}
G = {i:[] for i in range(1,N+1)}
G[1].append(2)
G[N].append(N-1)
for i in range(2,N):
    G[i].append(i-1)
    G[i].append(i+1)
G[X].append(Y)
G[Y].append(X)
for i in range(1,N+1):
    heap = [(0,i)]
    dist = [INFTY for _ in range(N+1)]
    dist[i] = 0
    hist = [0 for _ in range(N+1)]
    while heap:
        d,x = heapq.heappop(heap)
        if dist[x]<d:continue
        hist[x]=1
        for y in G[x]:
            if hist[y]==0 and dist[y]>d+1:
                dist[y] = d+1
                heapq.heappush(heap,(dist[y],y))
    for j in range(1,N+1):
        C[dist[j]] += 1
for k in range(1,N):
    print(C[k]//2)

Submission status: Accepted

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, x, y = map(int, input().split())
    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)

    def bfs(v):
        dist = [f_inf for _ in range(n)]
        dist[v] = 0
        q = deque()
        q.append(v)
        while q:
            u = q.popleft()
            for nv in tree[u]:
                if dist[nv] == f_inf:
                    dist[nv] = dist[u] + 1
                    q.append(nv)

        for d in dist:
            res[d] += 1

    res = [0 for _ in range(n)]
    for i in range(n):
        bfs(i)

    for j in range(1, n):
        print(res[j] // 2)


if __name__ == '__main__':
    resolve()

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

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

Submission status: Accepted

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

ans = [0] * N
for i in range(N-1):
    for j in range(i+1,N):
        d = min(j-i, abs(i-X) + abs(j-Y) + 1)
        ans[d] += 1
print(*ans[1:], sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0]*N

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

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

Submission status: Accepted

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

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



for i in range(N-1):
    for j in range(i + 1,N):
        route_1 = j - i
        route_2 = abs(X-1 - i) + 1 + abs(Y-1 - j)
        route = min(route_1, route_2)
        #print(i, j, route)
        cost[route - 1]  += 1

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

Submission status: Accepted

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

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

for i in range(1, len(list_length)):
    print(list_length[i])

Submission status: Accepted

Solution code:
N,X,Y = map(int,input().split())
from itertools import combinations
counter = [0]*(N+1)

for com in combinations(range(N),2):
    i,j = com
    min_path = min(j-i,abs(X-1-i)+abs(Y-1-j)+1)
    counter[min_path]+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

N,X,Y=map(int,input().split())
ans=[0]*(N+1)

for i in range(1,N+1):
    que=deque([(i,0)])
    used=[False]*(N+1)
    used[i]=True
    while que:
        v,dist=que.popleft()
        ans[dist]+=1
        if v!=1 and not used[v-1]:
            que.append((v-1,dist+1))
            used[v-1]=True
        if v!=N and not used[v+1]:
            que.append((v+1,dist+1))
            used[v+1]=True
        if v==X and not used[Y]:
            que.append((Y,dist+1))
            used[Y]=True
        if v==Y and not used[X]:
            que.append((X,dist+1))
            used[X]=True

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

Submission status: Accepted

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

x-=1
y-=1

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

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

Submission status: Accepted

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

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

row,col,w=[],[],[]
for i in range(n-1):
  row.append(i)
  col.append(i+1)
  w.append(1)

row.append(x-1)
col.append(y-1)
w.append(1)

g=csr_matrix((w, (row, col)), shape=(n, n))

d=dijkstra(g,directed=False)

l=list(np.ravel(d))

c=Counter(l)
for i in range(1,n):
  print(c[i]//2)

Submission status: Accepted

Solution code:
from collections import deque, Counter

def BFS(st,c):

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

  que=deque()
  que.append(st)

  while que:
    x=que.popleft()
    for i in tree[x]:
      if dist[i]==-1:
        dist[i]=dist[x]+1
        que.append(i)

  c+=dist

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

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

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

c=[]

for i in range(n):
  BFS(i,c)

count=Counter(c)

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

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):
        num = min(j-i, abs(i-X)+abs(j-Y)+1)
        ans[num-1] += 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
# import sys
# import math
import itertools
from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


def bfs(s, N, edge):
    d = [-1 for _ in range(N)]
    d[s] = 0
    q = deque()
    q.append(s)

    while q:
        v = q.popleft()
        edgelist = edge[v]
        for e in edgelist:
            if d[e] == -1:
                d[e] = d[v] + 1
                q.append(e)

    return d


def main():

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

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

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

    dist = [[] for _ in range(N)]
    for i in range(N):
        dist[i] = bfs(i, N, edge)

    comb = tuple(itertools.combinations(range(N), 2))
    ans = [0 for _ in range(N)]

    for c in comb:
        v1, v2 = c[0], c[1]
        ans[dist[v1][v2]] += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  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):
      num = min(j-i, abs(i-x)+abs(j-y)+1)
      ans[num-1] += 1
  for i in ans:
    print(i)
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
import copy
import collections

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

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

    cnt = collections.Counter(dist)
    for i in range(1, n):
        print(cnt[i])


    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
from collections import deque

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

ans = [0] * (n+1)

g = [[i+1, i-1] for i in range(n+1)]
#g[0].clear() pypyにclearなし
g[1].pop(1)
g[n].pop(0)

g[x].append(y)
g[y].append(x)

for i in range(1,n+1):
    q = deque()
    time = 0
    visit = [False] * (n+1)
    q.append((i, time))

    while(len(q) > 0):
        item = q.popleft()

        if visit[item[0]] == False:
            visit[item[0]] = True
            ans[item[1]] += 1
            for k in g[item[0]]:
                q.append((k, item[1]+1))

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

Submission status: Accepted

Solution code:

import collections as col


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

cnt = col.Counter(dist)
for i in range(1,n): print(cnt[i])

Submission status: Accepted

Solution code:
import collections as col


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

cnt = col.Counter(dist)
for i in range(1,n): print(cnt[i])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def D():
    n,x,y = list(map(int, input().split()))
    d_num = [0]*(n-1)
    for i in range(1,n):
        for j in range(i+1,n+1):
            d = []
            d.append(j-i)
            if x < j and i < y:
                d.append(abs(x-i)+1+abs(y-j))
            d_num[min(d)-1] += 1
    print("\n".join(map(str,d_num)))
D()

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

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

Submission status: Accepted

Solution code:
#ABC160-D Line++
"""
ある２点xとyがつながっているので、
二重ループを回して、
・単純にiとjの距離
・i-x,j-yをつなげた時の距離
・i-y,j-xをつなげた時の距離
の最小値がi-jの距離になる。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,x,y = map(int,readline().split())
ans = [0]*n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[
            min(
                j-i,
                abs(i-x)+abs(j-y)+1,
                abs(i-y)+abs(j-x)+1
            )
            ] += 1
for i in ans[1:]:
    print(i)

Submission status: Accepted

Solution code:
from heapq import heapify, heappush, heappop
def dijkstra(S, N, Edge):
    # S: start vertex
    # N: number of vertices
    # Edge: adjacent list [node, cost]
    
    INF = 10**20
    dist = [INF]*N
    dist[S] = 0
    que = [(0, S)]
    heapify(que)
    
    while que:
        c, v = heappop(que)
        if dist[v] < c: continue

        for nv, nc in Edge[v]:
            if c+nc < dist[nv]:
                dist[nv] = c+nc
                heappush(que, (c+nc, nv))
    
    return dist


import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

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

ans = [0]*N
for i in range(N):
    dist = dijkstra(i, N, edge)
    for j in range(i+1,N):
        ans[dist[j]] += 1
for k in ans[1:]:
    print(k)

Submission status: Accepted

Solution code:
import heapq
def dijkstra(S, N, Edge):
    # S: start vertex
    # N: number of vertices
    # Edge: adjacent list [node, cost]
    
    INF = 10**20
    dist = [INF]*N
    dist[S] = 0
    que = [(0, S)]
    heapq.heapify(que)
    
    while que:
        c, v = heapq.heappop(que)
        if dist[v] < c: continue

        for nv, nc in Edge[v]:
            if c+nc < dist[nv]:
                dist[nv] = c+nc
                heapq.heappush(que, (c+nc, nv))
    
    return dist


import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

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

ans = [0]*N
for i in range(N):
    dist = dijkstra(i, N, edge)
    for j in range(i+1,N):
        ans[dist[j]] += 1
for k in ans[1:]:
    print(k)

Submission status: Accepted

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

g = [[] for _ in range(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)

from collections import deque
def bfs(u):
    queue = deque([u])
    d = [None]*(N+1)
    d[u]=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

ans = [0]*(N-1)
for i in range(1,N+1):
    d = bfs(i)
    for j in range(1,N+1):
        if d[j]>0:
            ans[d[j]-1] += 1
for a in ans:
    print(a//2)

Submission status: Accepted

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

Submission status: Accepted

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

x,y = x-1,y-1

d={}
for k in range(1,n):
    d[k]=0


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

        d[dist]+=1

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

Submission status: Accepted

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

def dist(a,b):
    return min(abs(b-a),abs(a-X)+1+abs(b-Y),abs(a-Y)+1+abs(b-X))

data=[0]*N
for i in range(1,N+1):
    for j in range(i+1,N+1):
        data[dist(i,j)]+=1
for d in data[1:]:
    print(d)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def ispow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))
######################################################################################################

N,X,Y=inputintlist()
X-=1
Y-=1
G=[[] for a in range(N)]
for a in range(N-1):
    G[a].append(a+1)
    G[a+1].append(a)
G[X].append(Y)
G[Y].append(X)
D=defaultdict(int)
for a in range(N):
    for b in range(a,N):
        d=b-a
        d=min(d,abs(a-X)+1+abs(b-Y))
        d=min(d,abs(a-Y)+1+abs(b-X))
        D[d]+=1
for k in range(1,N):
    print(D[k])

Submission status: Accepted

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

Submission status: Accepted

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

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(j-i), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))
        ans[k-1] += 1

for v in ans:
    print(v)

Submission status: Accepted

Solution code:
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):
        d = min(abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))
        cnt[d] += 1

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
D=[0]*n
 
def dist(i, j):
  d1 = abs(i - j)
  d2 = abs(x - i) + 1 + abs(y - j)
  return min(d1, d2)
 
for i in range(1,n):
	for j in range(i,n+1):
		a= dist(i,j)
		D[a]+=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
for i in range(1,n+1):
    for j in range(i+1,n+1):
        dict1=j-i
        dict2=abs(x-i)+abs(y-j)+1
        d=min(dict1,dict2)
        ans[d]+=1
for i in range(1,n):
    print(ans[i])

Submission status: Accepted

Solution code:
import collections
def main():
    N,X,Y = map(int, input().split())
    # 扱いやすいようにX,Yはインデックス表記にしておく
    X -= 1
    Y -= 1
    # i<jを満たす(i,j)について6通りの場合分けして全最短距離を求められる
    shortest = [[-1]*N for _ in range(N)]
    coll = collections.Counter()
    for i in range(N):
        k1 = abs(X-i)
        for j in range(i+1,N):
            k2 = abs(j-Y)
            shortest[i][j] = min(j-i, k1+1+k2)
        coll += collections.Counter(shortest[i])

    for i in range(1,N):
        print(coll.get(i,0))
        
main()

Submission status: Accepted

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

Submission status: Accepted

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


dic = {}
x = x-1
y = y-1
for i in range(n):
    for j in range(n):
        if(i == j):
            break

        nm = abs(j - i)
        if(abs(x-i) > abs(y-i)):
            lp = abs(y-i) + abs(x-j) + 1
        else:
            lp = abs(x-i) + abs(y-j) + 1
        
        k = min(nm,lp)
        if(k in dic):
            dic[k] += 1
        else:
            dic[k] = 1



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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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):
            d = min(j - i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
            ans[d - 1] += 1
    print(*ans, sep='\n')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

from collections import Counter
c=Counter(ans)

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X, Y = lr()
dis = [[0] * (N+1) for _ in range(N+1)]
for i in range(1, N):
    for j in range(i+1, N+1):
        dis[i][j] = dis[j][i] = j - i

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

print('\n'.join(map(str, answer[1:])))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.buffer.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X, Y = lr()
dist = []
for i in range(1, N+1):
    z = np.arange(i+1, N+1)
    d1 = z - i
    d2 = np.abs(i - X) + np.abs(z - Y) + 1
    d = np.minimum(d1, d2)
    dist.append(d)

dist = np.concatenate(dist)
cnt = np.bincount(dist, minlength=N)
print('\n'.join(cnt[1:].astype(str)))

Submission status: Accepted

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

dis=[]

for i in range(n-1):
    for j in range(i,n):
        dis.append(min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1))
c=Counter(dis)
for i in range(1,n):
    print(c[i])

Submission status: Accepted

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

    ans = "\n".join(map(str, m))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
from collections import defaultdict

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

count_dict = {key:0 for key in range(1,n)}

for s in range(1,n):
    for e in range(s+1,n+1):
        count_dict[min(e-s, abs(x-s)+1+abs(y-e),abs(y-s)+1+abs(x-e))] += 1


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


#for s in range(1,n):
#    for e in range(s+1,n+1):
#        if s <= x <= e:
#            count_dict[min(e-s, x-s+1+abs(y-e))] += 1
#            if min(e-s, x-s+1+abs(y-e)) == 3:
#                print(s,e)
#        elif s <= y <= e:
#            count_dict[min(e-s, s-x+1+abs(y-e))] += 1
#            if min(e-s, s-x+1+abs(y-e)) == 3:
#                print(s,e)
#        else:
#            count_dict[e-s] += 1
#            if e-s == 3:
#                print(s,e)


#def bfs(s):
#    que = deque()
#    que.append([s,1,0])
#
#    while que:
#        i = que.popleft()
#        #特殊例の探索
#        if i[0] == x:
#            #yへの移動ルートも計算する
#            if checked_dict[y] == 0:
#                checked_dict[y] = 1
#                que.append([y,i[1],i[2]+1])
#                counter_dict[i[2]+1] += 1
#                #checked_dict[x] = 1
#                #counter_dict[i[2]] += 1
#        elif i[0] == y:
#            #i-1への移動ルートも計算する。
#            if checked_dict[i[0]-1] == 0:
#                checked_dict[i[0]-1] = 1
#                que.append([i[0]-1,-1,i[2]+1])
#                counter_dict[i[2]+1] += 1
#                #checked_dict[y] = 1
#                #counter_dict[i[2]] += 1
#
#        #通常例の探索
#        if i[0]!=n and checked_dict[i[0]+i[1]] == 0:
#            checked_dict[i[0]+i[1]] = 1
#            que.append([i[0]+i[1],i[1],i[2]+1])
#            counter_dict[i[2]+1] += 1
#            #checked_dict[i[0]] = 1
#            #counter_dict[i[2]] += 1
#
#
#
#
#
#
#
#
#
#n,x,y = map(int,input().split())
#
#checked_dict = {key:0 for key in range(0,n+1)}
#
#counter_dict = {key:0 for key in range(1,n)}
#
#result_dict = {key:0 for key in range(1,n)}
#
#
#for s in range(1,n):
#    checked_dict = {key:0 for key in range(0,n+1)}
#    counter_dict = {key:0 for key in range(1,n)}
#    checked_dict[s] = 1
#    bfs(s)
#    for j in range(1,n):
#        result_dict[j] += counter_dict[j]
#
#
#print(counter_dict)
#
#"""
#for i in range(1,n):
#    print(counter_dict[i])
#"""
#
#
##for j in range(1,n):
##    for k in range(1,j+1): # 1~jまで
##        result_dict[k] += 1*counter_dict[j]
##
##print(result_dict)
#

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def bfs(G, v, dist):
    queue = deque([v])
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + 1
                queue.append(u)


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

    G = [[] for _ in range(N)]
    for i in range(N - 1):
        G[i].append(i + 1)
        G[i + 1].append(i)
    G[X].append(Y)
    G[Y].append(X)

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,x,y = nm()

dist = [0]*n

for i in range(1,n+1):
  for j in range(i+1,n+1):
    naive = j-i
    cand = naive
    if i<x:
      if x<=j<=y:
        cand = x-i+1+y-j
      elif j>y:
        cand = x-i+1+j-y
    elif x<=i<=y:
      if j<=y:
        cand = i-x+1+y-j
      else:
        cand = i-x+1+j-y
    d = min(naive,cand)
    dist[d]+=1

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

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n, x, y = ns()

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

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

    for ai in ans:
        print(ai)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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