Problem:


Score : 400 points

Problem Statement

We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:

For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.

There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N-1, solve the problem below:

Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.

Constraints

3 \leq N \leq 2 \times 10^3

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).

There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).

There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).

There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0



Sample input:
5 2 4


Sample output:
5
4
1
0

Submission status: Accepted

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

dist_list = [0 for _ in range(n)]

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if j <= x or i >= y:
            distance = j-i
        else:
            distance = min(j-i,abs(x-i)+abs(y-j)+1)
        dist_list[distance] += 1

for i,dist in enumerate(dist_list):
    if i >= 1:
        print(dist)

Submission status: Accepted

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

n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0 for _ in range(n)]
for i in range(n):
    for j in range(i+1, n):
        ans[min([abs(i-j), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1])] += 1
for i in range(1, n):
    print(ans[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):
        ans[min(abs(i-j), abs(X-i)+abs(Y-j)+1)] += 1
for x in ans[1:]:
    print(x)

Submission status: Accepted

Solution code:
from collections import deque
n,x,y = map(int, input().split())
INF=1001001001001
x-=1
y-=1
mp=[list() for _ in range(n)]
for i in range(1,n-1):
    mp[i] = [i-1,i+1]

mp[0]=[1]
mp[-1]=[n-2]
mp[x].append(y)
mp[y].append(x)

ans=[0]*n

for i in range(n):
    dist=[INF]*n
    dist[i]=0
    d=deque()
    d.append(i)
    while d:
        s = d.popleft()
        for g in mp[s]:
            if dist[g]==INF:
                dist[g]=dist[s]+1
                d.append(g)

    for j in range(n):
        ans[dist[j]]+=1

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def dijkstra(s,n,g):
    dis = [10**10]*n
    dis[s] = 0
    que = deque([])
    que.append(s)
    while que:
        go = que.pop()
        for i in range(len(g[go])):
            if dis[g[go][i]] <= dis[go] + 1:
                continue
            dis[g[go][i]] = dis[go] + 1
            que.append(g[go][i])
    return dis

def main():
    n,x,y = inpm()
    x -= 1
    y -= 1
    g = [[] for _ in range(n)]
    for i in range(n-1):
        a = i
        b = i+1
        g[a].append(b)
        g[b].append(a)
    g[x].append(y)
    g[y].append(x)
    ans = [0 for _ in range(n-1)]
    for i in range(n-1):
        d = dijkstra(i,n,g)
        for j in range(i+1,n):
            ans[d[j]-1] += 1
    for i in range(n-1):
        print(ans[i])
        
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    g[i].append(i+1)
    g[i+1].append(i)
x -= 1
y -= 1
g[x].append(y)
g[y].append(x)

d = {}
for i in range(n):
    d[i] = 0

from collections import deque
for i in range(n):
    q = deque()
    q.append(i)
    visit = [-1]*n
    visit[i] = 0
    while q:
        x = q.popleft()
        for nx in g[x]:
            if visit[nx] == -1:
                visit[nx] = visit[x]+1
                q.append(nx)
    for i in range(n):
        d[visit[i]] += 1
#print(d)
for k in range(1, n):
    print(d[k]//2)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def dijkstra(s,graph):
    d = [inf]*n
    d[s] = 0
    h = [(0,s)]
    while h:
        c,v = heappop(h)
        if d[v] < c:
            continue
        for t,cost in graph[v]:
            if d[v] + cost < d[t]:
                d[t] = d[v] + cost
                heappush(h,(d[t],t))
    return d

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

Submission status: Accepted

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


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


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


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


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


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


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


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


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

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

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

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

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


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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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

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):
        if j <= X:
            ans[j-i-1] += 1
        elif i <= X:
            ans[min(j-i, X-i+1+abs(Y-j))-1] += 1
        elif i < Y:
            ans[min(j-i, i-X+abs(j-Y)+1)-1] += 1
        else:
            ans[j-i-1] += 1
for a in ans:
    print(a)

Submission status: Accepted

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

x-=1
y-=1
cnt = [0] * n

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

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
n,x,y=LI()
d=[0]*n

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

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

Submission status: Accepted

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

Submission status: Accepted

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

import heapq
from collections import defaultdict
cost = defaultdict(list)
for i in range(1, n):
    cost[i-1].append((i, 1))
    cost[i].append((i - 1, 1))
cost[x-1].append((y - 1, 1))
cost[y-1].append((x - 1, 1))

dists = []

for start in range(n):
    d = [float('inf')] * n # 最短距離
    d[start] = 0

    q = [(d[start], start)] # min-heap, (距離, 頂点)
    prev = [None] * n # 経路をたどるときに使う
    heapq.heapify(q)
    while q:
        du, u = heapq.heappop(q) # 最短距離とその頂点
        if d[u] < du:
            continue
        for v, weight in cost[u]:
            if du + weight < d[v]:
                d[v] = du + weight
                prev[v] = u
                heapq.heappush(q, (d[v], v))

    dists.append(d)



from collections import Counter
c = Counter()
for i in range(n):
    for j in range(i+1, n):
        c[dists[i][j]] += 1

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

Submission status: Accepted

Solution code:
def main():
    N, X, Y = map( int, input().split())
    K = [0]*N
    X -= 1
    Y -= 1
    for i in range(N-1):
        for j in range(i+1,N):
            if i <= X:
                if j <= X:
                    K[j-i] += 1
                elif X <= j <= Y:
                    if (X-i) + 1 + (Y-j) <= j-i:
                        K[(X-i) + 1 + (Y-j)] += 1
                    else:
                        K[j-i] += 1
                else:
                    K[(X-i) + 1 + (j-Y)] += 1
            elif i <= Y:
                if j <= Y:
                    if (i-X) + 1 + (Y-j) <= j-i:
                        K[(i-X) + 1 + (Y-j)] += 1
                    else:
                        K[j-i] += 1
                else:
                    if (i-X) + 1 + (j-Y) <= j-i:
                        K[(i-X) + 1 + (j-Y)] += 1
                    else:
                        K[j-i] += 1
            else:
                K[j-i] += 1

    print( "\n".join( map( str, K[1:])))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, Y = MAP()
graph = [[] for _ in range(N)]

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

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

dic = defaultdict(int)
for i in range(N):
    q = deque()
    q.append(i)
    dist = [INF]*N
    dist[i] = 0
    while q:
        n = q.popleft()
        for node in graph[n]:
            if dist[node] == INF:
                dist[node] = dist[n] + 1
                q.append(node)

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    L = [0] * (N - 1)
    for i in range(N - 1):
        for j in range(i + 1, N):
            if j <= X or Y <= i:
                L[j - i - 1] += 1
            elif i <= X and Y <= j:
                L[j - i - (Y - X)] += 1
            elif X <= i < j <= Y:
                L[min(j - i - 1, i - X + Y - j)] += 1
            elif i <= X and X <= j < Y:
                L[min(j - i - 1, X - i + Y -j)] += 1
            else:
                L[min(j - i - 1, j - Y + i - X)] += 1
    print("\n".join(map(str, L)))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, X, Y = inpl()
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(X-i)+abs(Y-j)+1)
        ans[d] += 1
for n in range(1,N):
    print(ans[n])

Submission status: Accepted

Solution code:
def main():
    N, X, Y = list(map(int, input().split()))
    X, Y = X - 1, Y - 1
    K = [0] * N
    for i in range(N - 1):
        for j in range(i + 1, N):
            if j <= X or Y <= i:
                K[j - i] += 1
            else:
                K[min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
    print("\n".join(str(i) for i in K[1:]))

main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7
INF = 10 ** 9

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    from collections import defaultdict
    N,x,y=list(map(int,sys.stdin.readline().split()))
    
    x-=1
    y-=1

    dists=defaultdict(int)
    for i in range(N):
        for j in range(N):#iからまでの経路
            if i>=j:
                continue

            a=j-i
            b=abs(i-x)+abs(j-y)+1

            dists[min(a,b)]+=1

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

main()

Submission status: Accepted

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

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

l = np.zeros((n,n))
l[range(n-1),range(1,n)] = 1
l[x-1,y-1] = 1
dis = dijkstra(l,directed = False)

ans = Counter(dis.reshape(-1))

for i in range(1,n):
    print(ans.get(i,0)//2)

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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
dist=[[0 for i in range(n)] for j in range(n)]
m=n
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[i].append(i+1)
for i in range(1,n):
  connection[i].append(i-1)
connection[x-1].append(y-1)
connection[y-1].append(x-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

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

for i in range(n):
  b=bfs(i)
  for j in range(n):
    ct[b[j]]+=1

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

Submission status: Accepted

Solution code:
from collections import deque


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

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


ans = [0] * n
def solve(i):
    q = deque([i])
    visited = [-1] * n
    visited[i] = 0
    while q:
        v = q.popleft()
        for nxt_v in graph[v]:
            if visited[nxt_v] >= 0:
                continue
            else:
                visited[nxt_v] = visited[v] + 1
                q.append(nxt_v)
    for i in range(n):
        ans[visited[i]] += 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


n,x,y = [int(i) for i in read().split()]
x -= 1
y -= 1

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

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

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-1):
    for j in range(i+1,n):
        saisho=j-i
        #x_made=[i-x,j-x]
        #y_made=[i-y,j-y]

        x_kyori=abs(i-x)
        y_kyori=abs(j-y)
        #print(i,j)
        #print(x_kyori+y_kyori+1)
        #print("")
        tikamiti=x_kyori+y_kyori+1
        saisho=min(saisho,tikamiti)
        ans[saisho-1]+=1



for a in ans:
    print(a)

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




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

Submission status: Accepted

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

ans_array = [0] * N

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

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

Submission status: Accepted

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

X, Y = X-1, Y-1

def solve_shortest(a, b):
    if a > b:
        a, b = b, a
    l = [
        b - a,
        abs(X - a) + 1 + abs(b - Y)
    ]
    # print(min(l), (a, b), X, Y, l)
    return min(l)

counts = [0]*N
for i in range(N):
    for j in range(N):
        if i < j:
            counts[solve_shortest(i, j)] += 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []
    
    def reset(self):
        self.dist = [INF] * len(self.adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in self.adj[src]:
                if self.dist[dest] > self.dist[src] + 1:
                    self.dist[dest] = self.dist[src] + 1
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, x, y = map(int, input().split())
x -= 1; y -= 1
edge = [[] for _ in range(n)]
for i in range(n-1):
    edge[i].append(i+1)
    edge[i+1].append(i)
edge[x].append(y)
edge[y].append(x)
DIJK = Dijkstra(edge)

dist_cnt = [0] * n
for i in range(n):
    dist = DIJK.calc(i)
    for j in range(i+1, n):
        dist_cnt[dist[j]] += 1
    DIJK.reset()

for item in dist_cnt[1:]:
    print(item)

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

Submission status: Accepted

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

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

for i in k:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,X,Y = [int(n) for n in input().split()]
    X -= 1
    Y -= 1
    res = [0] * N
    for i in range(N):
        for j in range(i,N):
            dis = min([j - i, abs(i - X) + 1 + abs(j-Y), abs(i - Y) + 1 + abs(j-Y)])
            # print(i,j,X,Y)
            # print(dis)
            res[dis]+=1
    for i in range(1,N):
        print(res[i])
main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for l in range(N):
  for r in range(l+1,N):
    a=min(r-l,abs(X-l)+abs(Y-r)+1)
    ans[a-1]+=1
    
for a in ans:
  print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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