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 sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

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

queue = deque()

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

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

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

ans = [0] * N

for i in range(N):
    visited = [0] * N
    visited[i] = 1
    queue.append((i,0))
    while queue:
        current, dist = queue.popleft()
        ans[dist] += 1

        for e in edges[current]:
            if visited[e] != 1:
                queue.append((e, dist+1))
                visited[e] = 1

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

Submission status: Accepted

Solution code:

def check_distance(i,j):

    if j<=X or i>=Y:
        dis = j - i
    else:
        dis1 = j - i
        dis2 = abs(i-X) + 1 + abs(j - Y)
        dis = min(dis1,dis2) 
    return dis


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

K = []
for i in range(1,N):
    K.append(0)

for i in range(1,N):
    for j in range(i+1,N+1):
        dis = check_distance(i,j)
        K[dis-1] += 1
for k in K:
    print(k)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

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

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

for i in range(1, n):
    print(cs[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):
      ans[min(abs(j-i), abs(X-i) + 1 + abs(j-Y ), abs(Y-i) + 1 + abs(j-X))-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] + [0]*(N-1)

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

N, x, y = map(int,input().split())
x, y = x-1, y-1
A = [0] * N

for i in range(N-1):
    for j in range(i+1,N):
        if i <= x and j <= x:
            dist = j - i
        elif i <= x and x <= j <= y:
            dist = min(j - i, x - i + 1 + y - j)
        elif i <= x and y <= j:
            dist = x - i + 1 + j - y
        elif x <= i <= y and x <= 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
        
        A[dist] += 1

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)

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

ret = [0] * (n-1)
for s in range(1,n):
    for e in range(s+1,n+1):
        d = min(e-s, abs(s-x) + abs(e-y) +1)
        ret[d-1] += 1
for r in ret:
    print(r)

Submission status: Accepted

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

ret = [0] * (n-1)
for s in range(1,n):
    for e in range(s+1,n+1):
        d = min(e-s, abs(s-x) + abs(e-y) +1)
        ret[d-1] += 1
for r in ret:
    print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
import functools

if __debug__:
    def debug(arg):
        pass
else:
    import sys
    def debug(arg):
        debug = lambda *x: None
        print(arg, file=sys.stderr)

n, x, y = (int(x) for x in input().split())
d = dict.fromkeys(range(1, n), 0)
debug(d)
for i in range(1, n):
    for j in range(i + 1, n + 1):
        debug([i, j, x, y])
        dd1=abs(x - i) + 1 + abs(y - j)
        dd2= j - i
        if dd1 < dd2:
            d[dd1] += 1
        else:
            d[dd2] += 1
        debug(d)

for n in d.values():
    print(n)

Submission status: Accepted

Solution code:
x = list(map(int,input().split()))
N = x[0]
X = x[1]
Y = x[2]

ans = [0] * N

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

[print(int(x)) for x in ans[1:]]

Submission status: Accepted

Solution code:
from collections import deque, Counter

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

inf = 100100100
x -= 1
y -= 1

ans = [0] * n

for i in range(n):
    dist = [inf] * n
    queue = deque()
    queue.append(i)
    dist[i] = 0
    while queue:
        current = queue.popleft()
        d = dist[current]

        if current - 1 >= 0 and dist[current - 1] == inf:
            queue.append(current - 1)
            dist[current - 1] = d + 1
        if current + 1 < n and dist[current + 1] == inf:
            queue.append(current + 1)
            dist[current + 1] = d + 1
        if current == x and dist[y] == inf:
            queue.append(y)
            dist[y] = d + 1
        if current == y and dist[x] == inf:
            queue.append(x)
            dist[x] = d + 1

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

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

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

Submission status: Accepted

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

a = [0]*(n-1)
for i in range(n):
    for j in range(n):
        if i < j:
            dis1 = j-i
            dis2 = abs(x-1-i)+abs(y-1-j)+1
            dis = min(dis1, dis2)
            a[dis-1] += 1
            #print(i,j,dis1,dis2,dis)
for i in a:
    print(i)

Submission status: Accepted

Solution code:

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

D_160()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = []
for i in range(1,n):
  for j in range(i+1, n+1):
    count.append(func(i,j))
    
counted = Counter(count)
for i in range(1,n):
    print(str(counted[i]))

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
lengths = [0 for i in range(n)]
for start in range(1, n+1):
    for end in range(start+1, n+1):
        lengths[min(end - start, abs(x-start) + abs(y-end) + 1)] += 1
print("\n".join(map(str, lengths[1:])))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
    for j in range(i+1,n+1):
        dist1=j-i
        dist2=abs(x-i)+abs(y-j)+1
        d=min(dist1,dist2) #最短距離は上式により求められる
        ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
    print(ans[i])

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
    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 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
    print(ans[i])

Submission status: Accepted

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

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

for k in range(N-1):
    print(dist_list[k+1])

Submission status: Accepted

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

distance_list =[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
        distance_list[min(a,b)] += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

from sys import stdin
import collections


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

    cost = collections.defaultdict(lambda: 0)
    for i in range(N):
        for j in range(i + 1, N):
            # 左/右/中で完結
            min1 = j - i
            # ショトカを跨ぐ/# 始まりが中
            min2 = abs(X - i) + 1 + abs(j - Y)
            # 終わりが中
            min3 = abs(Y - i) + 1 + abs(X - j)
            shortest = min(min1, min2, min3)
            cost[shortest] = cost[shortest] + 1
    for i in range(1, N):
        print(cost[i])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bfs(nodes, src):
    """ BFS(一般グラフ、重みなし) """
    from collections import deque

    N = len(nodes)
    que = deque([(src, 0)])
    dist = [INF] * N
    dist[src] = 0
    while que:
        u, c = que.popleft()
        for v in nodes[u]:
            if dist[v] != INF:
                continue
            dist[v] = c + 1
            que.append((v, c+1))
    return dist

N, x, y = MAP()
x -= 1; y -= 1

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

distx = bfs(nodes, x)
disty = bfs(nodes, y)

G = list2d(N, N, 0)
for i in range(N):
    for j in range(i+1, N):
        G[i][j] = min(j - i, distx[i] + disty[j] + 1, distx[j] + disty[i] + 1)
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[G[i][j]] += 1
[print(a) for a in ans[1:]]

Submission status: Accepted

Solution code:
inp = input().split()
line = list(map(int,inp))
n = line[0]
x = line[1] - 1
y = line[2] - 1

a = []
for i in range(0,n-1):
    a.append(0)

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

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

Submission status: Accepted

Solution code:
def D():
    nxy=list(map(int,input().split()))
    count_list=[0]*nxy[0]
    
    for i in range(1,nxy[0]):
        for j in range(i+1,nxy[0]+1):
            mins=min(abs(j-i),abs(nxy[1]-i)+1+abs(j-nxy[2]))
            count_list[mins]+=1
            
    for i in range(1,nxy[0]):
        print(count_list[i])
            
        
if __name__=='__main__':
    D()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

a=defaultdict(int)

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


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

        # if(d==8 ):print(i,j)

        a[d] +=1
b=sorted(a.items())

for i,j in b:
    print(j)

Submission status: Accepted

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

Submission status: Accepted

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

# print(graph)
from collections import deque
def bfs_graph(G, start):
    # 隣接リストを食わせる
    dist = [-1] * N
    que = deque([start])
    dist[start] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    return dist

ans = [0] * (N - 1)
for s in range(N - 1):
    res = bfs_graph(graph, s)
    # print(res)
    for val in res[s+1:]:
        if val >= 1:
            ans[val-1] += 1
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

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

    link = np.array([[N if i!=j else 0 for j in range(N)] for i in range(N)])
    link[X-1, Y-1] = 1
    link[Y-1, X-1] = 1

    for i in range(1, N):
        link[i] = np.minimum(link[i], link[i-1] + 1)
    for i in range(N-2, -1, -1):
        link[i] = np.minimum(link[i], link[i+1] + 1)
    for i in range(1, N):
        link[:,i] = np.minimum(link[:,i], link[:,i-1] + 1)
    for i in range(N-2, -1, -1):
        link[:,i] = np.minimum(link[:,i], link[:,i+1] + 1)
    
    ans = [0] * N
    for i in range(N-1):
        for j in range(i+1, N):
            ans[link[i, j]] += 1
    
    for i in range(1, N):
        print(ans[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0] * N

    for start_vertex in range(N):
        q = deque()
        distance_list = [float('inf')] * N

        def push(vertex, distance):
            if distance_list[vertex] != float('inf'):
                return
            q.append(vertex)
            distance_list[vertex] = distance
        
        push(start_vertex, 0)

        while len(q) > 0:
            vertex = q.popleft()
            distance = distance_list[vertex]

            if vertex - 1 >= 0:
                push(vertex-1, distance+1)
            if vertex + 1 < N:
                push(vertex+1, distance+1)
            if vertex == X:
                push(Y, distance+1)
            if vertex == Y:
                push(X, distance+1)
        
        for i in distance_list:
            ans[i] += 1
    
    ans = list(map(lambda x: x // 2, ans))
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    solve()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

import collections

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

    X -= 1
    Y -= 1
    distance = []
    dappend = distance.append

    for i in range(N-1):
        for j in range(i+1,N):
            tmp = min(abs(i-j), abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j))
            distance.append(tmp)

    count = collections.Counter(distance)

    for s in range(1, N):
        print(count.get(s, 0))

if __name__ == "__main__":
    cmd()

Submission status: Accepted

Solution code:
# ショートカット前中後でG1-3に分け、i, jがそれぞれどこにいるかで場合分け

n, x, y = map(int, input().split())
ans = [0 for _ in range(n - 1)]
debug = [[] for _ in range(n-1)]
mid = (y - x) // 2 + x # G2の真ん中

for i in range(1, n):
  for j in range(i + 1, n + 1):
    # G1 -> G1
    if j <= x or y <= i:
      ans[j - i - 1] += 1
      
    # G1 -> G2
    elif i <= x and x < j < y:
      if j <= mid:
        ans[j - i - 1] += 1
      else:
        ans[(x - i) + (y - j)] += 1
        
    # G2 -> G3
    elif x < i < y and y <= j:
      if i >= mid:
        ans[j - i - 1] += 1
      else:
        ans[(i - x) + (j - y)] += 1
        
    # G1 -> G3
    elif i <= x and y <= j:
      ans[(x - i) + (j - y)] += 1
    
    # G2 -> G2
    else:
      ans[min(j - i - 1, (i - x) + (y - j))] += 1

# 結果の表示
for i in ans:
  print(i)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,x,y = map(int,input().split(' '))
    cost = [0 for i in range(n - 1)]
    for i in range(n - 1):
        for l in range(i + 1, n):
            result = min(abs(i - l),abs(i - x + 1) + 1 + abs(l - y + 1),abs(i - y + 1) + 1 + abs(l - x + 1))
            cost[result - 1] += 1
    for per in cost:
        print(per)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,X,Y = map(int,input().split())
def kyori(i,j):
    return min(abs(i-j), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))

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

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

Submission status: Accepted

Solution code:
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop=q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        # for i in d:
        #     a[i] += 1
        dist.extend(d)
    for i in dist:
        a[i] += 1
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(len([x for x in dist if x==i])/2))
    for i in range(1,n):
        print(int(a[i]/2))
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):
    for j in range(i + 1, n):
        d = min(abs(j-i), abs(x-i)+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:
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop=q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    # for i in range(1,n):
    #     print(int(a[i]/2))
    print(' '.join(str(i//2) for i in a[1:]))
main()

Submission status: Accepted

Solution code:
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop=q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    for i in range(1,n):
        print(int(a[i]/2))
    # print(' '.join(str(i//2) for i in a[1:]))
main()

Submission status: Accepted

Solution code:
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        while q:
            v = q.popleft()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    q.append(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    # for i in range(1,n):
    #     print(int(a[i]/2))
    print(' '.join(str(i//2) for i in a[1:]))
main()

Submission status: Accepted

Solution code:
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        while q:
            v = q.popleft()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    q.append(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    for i in range(1,n):
        print(int(a[i]/2))
    # print(' '.join(str(i//2) for i in a[1:]))
main()

Submission status: Accepted

Solution code:
def main():
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop = q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        for i in d:
            a[i] += 1
        # d.append(dist)
    # d = np.array(d).flatten()
    # for i in range(1,n):
    #     # print(int(np.count_nonzero(d==i)/2))
    #     print(int(ans[i]/2))
    print(' '.join(str(i//2) for i in a[1:]))
main()

Submission status: Accepted

Solution code:
def main():
    from collections import deque
    n,x,y=map(int,input().split())
    e=[[]for _ in range(n)]
    for i in range(n-1):
        e[i]+=i+1,
        e[i+1]+=i,
    e[x-1]+=y-1,
    e[y-1]+=x-1,
    a=[0]*n
    for s in range(n):
        d=[-1]*n
        d[s]=0
        q=deque([s])
        add,pop=q.append,q.popleft
        while q:
            v=pop()
            for w in e[v]:
                if d[w]<0:
                    d[w]=d[v]+1
                    add(w)
        for i in d:a[i]+=1
    print(' '.join(str(i//2)for i in a[1:]))
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):
    for j in range(i + 1, N):
        c = min(j - i, abs(X - i) + abs(Y - j) + 1)
        ans[c] += 1
for i in ans[1:]:
    print(i)

Submission status: Accepted

Solution code:
import sys
n, x, y = map(int, sys.stdin.readline().split())

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

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

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

for num in ans_list:
    print(num)

Submission status: Accepted

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

res = [0] * (N)

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

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

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1     #１のところを０にするなど一つずつずらす
 
def dist(a, b):
  return min(abs(b-a), abs(X-a) + 1 + abs(b-Y), abs(Y-a) + 1 + abs(b-X))
   #＋１は間の一つ繋がっている分
 
ANS = [0] * N    #0がN個のリストを作成。一つ目はk=0の時（同じところ）
for i in range(N):
  for j in range(i):
    ANS[dist(i, j)] += 1  #0にずらしたことで０から始まるi,jに対応できている
        
    #i,jの最小値のindexに１ずつ足していく
        
for a in ANS[1:]:  #indexが１以降（数字の差が１以上）のものを一つづつ出力
  print(a)

#コメントの前のスペースは半角で描く

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
 
def dist(a, b):
  return min(abs(b-a), abs(X-a) + 1 + abs(b-Y), abs(Y-a) + 1 + abs(b-X))

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

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

Submission status: Accepted

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

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

for k in range(1, len(ans)):
    print(ans[k])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

start = X
end = Y

for left in range(1, N): # 1 から N - 1 まで
    for right in range(left + 1, N + 1): # left + 1 から N まで
        # 外外
        if left <= start and end <= right: 
            dist = (right - left) - (end - start - 1)
        # 外内
        elif left <= start and right < end:
            dist = min(right - left, start - left + 1 + end - right)
        # 内外
        elif start < left and end <= right:
            dist = min(right - left, left - start + 1 + right - end)
        # 内内
        else:
            dist = min(right - left, left - start + 1 + end - right)

        # リストに格納
        ans[dist - 1] += 1

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import collections

def distances(n,x,y):
    for i in range(1, int(n)):
        for j in range(i+1, int(n)+1):
            yield min(abs(i-j), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)

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

c = collections.Counter(distances(n,x,y))

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

Submission status: Accepted

Solution code:
def main(n, x, y):
    d_s = [0] * (n-1)

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

    print("\n".join(str(d) for d in d_s))


if __name__ == "__main__":
    n, x, y = map(int, input().split())

    main(n, x-1, y-1)