Problem:


Score : 400 points

Problem Statement

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

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

There is an edge between Vertex X and Vertex Y.

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

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

Constraints

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

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

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

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

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

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

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

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

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0



Sample input:
5 2 4


Sample output:
5
4
1
0

Submission status: Accepted

Solution code:
from collections import defaultdict

N, X, Y = map(int, input().split())
INF = 10**20
ans = {i:0 for i in range(N)}
d = defaultdict(list)

for i in range(1, N):
    d[i].append(i+1)
    d[i+1].append(i)
d[X].append(Y)
d[Y].append(X)

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

    while q:
        a = q.pop()
        for b in d[a]:
            if dist[b]==-1 or dist[b] > dist[a]+1:
                dist[b] = dist[a] + 1
                q.append(b)
    for j in range(i+1, N+1):
        ans[dist[j]] += 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
L=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        if j<=x or i>=y:
            L[j-i-1]+=1
        elif i<=x and y<=j:
            L[x-i+j-y]+=1
        else:
            a=j-i
            b=abs(x-i)+1+abs(y-j)
            L[min(a,b)-1]+=1
for k in L:
    print(k)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

Submission status: Accepted

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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = [int(i) for i in input().split()]

answerList = []

for i in range(N[0]):
    answerList.append(0)

for i in range(N[0]):
    if i > 0:
        for j in range(N[0]):
            if j + 1 > i > 0:
                calculateList = [abs(j + 1 - i),
                                 abs(N[1] - i) + 1 + abs(j + 1 - N[2]),
                                 abs(N[2] - i) + 1 + abs(j + 1 - N[1])]
                answer = min(calculateList)
                answerList[answer] = answerList[answer] + 1

for i in range(N[0] - 1):
    print(answerList[i + 1])

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X, Y = il()

    k = {n:0 for n in range(N-1)}
    X -= 1
    Y -= 1
    for i in range(N-1):
        for j in range(i+1, N):
            m = min(abs(i-j), abs(X-i) + abs(Y-j) + 1, abs(X-j) + abs(Y-i) + 1)
            k[m-1] += 1

    for i in range(len(k)):
        print(k[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, x, y = map(int, input().split())
    ans = [0]*(n-1)
    for i in range(n-1):
        for j in range(i + 1, n):
            if j < x - 1 or y - 1 < i:
                distance = j - i
            else:
                distance = min(j - i, abs(x - 1 - i) + abs(y - 1 - j) + 1)
            ans[distance - 1] += 1
            
    for i in range(n - 1):
        print(ans[i])

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
import collections
N,x,y=map(int,input().split())
lit=[]
for i in range(1,N+1):
  for j in range(i+1,N+1):
     lit.append(min(abs(i-j),abs(x-j)+abs(y-i)+1,abs(y-j)+abs(x-i)+1))
a=collections.Counter(lit)
for i in range(1,N):
  print(a[i])

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
n, x, y = map(int, input().split())
edge = [[] for i in range(n)]
x -= 1
y -= 1
for i in range(n):
    if i != 0:
        edge[i].append(i - 1)
    if i != n - 1:
        edge[i].append(i + 1)
    if i == x:
        edge[i].append(y)
    if i == y:
        edge[i].append(x)
ans = [0 for i in range(1, n)]
for i in range(n):
    queue = deque([[i, 0]])
    visited = [0 for i in range(n)]
    while queue:
        a, b = queue.popleft()
        if visited[a] == 1:
            continue
        visited[a] = 1
        if b != 0:
            ans[b - 1] += 1
        for j in edge[a]:
            queue.append([j, b + 1])
for i in ans:
    print(i // 2)

# cost = [[] for i in range(n)] 
# for i in range(n):
#     for j in range(n):
#         cost[i].append([abs(j - i), j])
# cost[x - 1].append([1, y - 1])
# cost[y - 1].append([1, x - 1])
# ans = [0 for i in range(1, n)]
# for i in range(n):
#     d = dijkstra_heap(i, cost, n)
#     # print("d =", d)
#     for j in d:
#         if j != 0:
#             ans[j - 1] += 1
# for i in ans:
#     print(i // 2)

Submission status: Accepted

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

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

for i in l:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 解説を参考に作成


def solve(N, X, Y):
    ans = [0] * (N)

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

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


if __name__ == '__main__':
    N, X, Y = map(int, input().split())
    solve(N, X, Y)

Submission status: Accepted

Solution code:
from collections import deque

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

adj = [[] for i in range(n)]

adj[x-1].append(y-1)
adj[y-1].append(x-1)

for i in range(n-1):
    adj[i].append(i+1) 
    adj[i+1].append(i)
        
ans = [0 for _ in range(n)]

def bfs(start):
    inf = 1001001001
    q = deque()
    q.append(start)
    dist = [inf]*n
    dist[start] = 0
    
    while q:
        v = q.popleft()

        for i in adj[v]:
            if dist[i] == inf:
                dist[i] = dist[v] + 1
                q.append(i)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


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

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



if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
# from functools import total_ordering
import heapq

from collections import Counter as cl

def solve(N: int, X: int, Y: int):

    def dis(a,b):
        fw = abs(a-b)
        bw1 = abs(X-a)+abs(Y-b)+1
        bw2 = abs(X-b)+abs(Y-a)+1
        bw = min(bw1,bw2)
        return min(fw, bw)
    
    dist_l = [0]*(N-1)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            dist_l[dis(i,j)-1] += 1


    print("\n".join(map(str, dist_l)))




def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#
#import numpy as np

def main():
	n,x,y=MI()
	ans=[0]*(n)

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


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


















if __name__ == "__main__":
	main()

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#
#import numpy as np

def main():
	n,x,y=MI()
	ans=[0]*(n)

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


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




if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    N, X, Y = map(int,input().split())
    ans = [0] * N # 最短距離が0~Nになるときの数をカウントする用のリスト
    for i in range(1, N + 1): # i<jなるすべての頂点の組について最短距離を求める
        for j in range(i + 1, N + 1):
            dist1 = j - i # 単純にiとjの距離差
            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])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

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

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

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

disset = [0]*(n-1)

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


for i in disset:
    print(i)

Submission status: Accepted

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


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

for i in l:
    print(i)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

d = [0] * n

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# TLE解
from collections import deque

n, x, y = map(int, input().split())
to = [[] for _ in range(n)]
for i in range(n):
    if i == 0:
        to[i].append(i+1)
    elif i == n-1:
        to[i].append(i-1)
    else:
        to[i].append(i+1) 
        to[n-i-1].append(n-i-2)
to[x-1].append(y-1)
to[y-1].append(x-1)

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

# 頂点'start'からBFS
def bfs(start):
    inf = 1001001001
    dist = [inf for _ in range(n)]
    q = deque()
    q.append(start)
    dist[start] = 0 

    while q:
        v = q.popleft()
        for u in to[v]:
            if dist[u] == inf:
                dist[u] = dist[v]+1
                q.append(u)
    # print('start = ', start, ': dist = ', dist)

    # for k in range(1, n):
    #     for i in range(n):
    #         if dist[i]-dist[start] == k:
    #             ans[k-1] += 1

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

Submission status: Accepted

Solution code:
from collections import deque, defaultdict
n, x, y = map(int, input().split())
inf = 10**10
dp = [[inf]*n for _ in range(n)]
dic = defaultdict(int)


    

for i in range(n):
    l=1
    dp[i][i] = 0
    if i==0 and x==1:
        queue = deque([1, y-1])
        dp[i][1]=1
        dp[i][y-1]=1
        dic[1]+=2
    elif i==0:
        queue = deque([1])
        dp[i][1]=1
        dic[1]+=1
    elif i==n-1 and y==n:
        queue = deque([n-2, x-1])
        dp[i][n-2]=1
        dp[i][x-1]=1
        dic[1]+=2
    elif i==n-1:
        queue = deque([n-2])
        dp[i][n-2]=1
        dic[1]+=1
    elif i==x-1:
        queue = deque([i-1, i+1, y-1])
        dp[i][i+1]=1
        dp[i][i-1]=1
        dp[i][y-1]=1
        dic[1]+=3
    elif i==y-1:
        queue = deque([i-1, i+1, x-1])
        dp[i][i+1]=1
        dp[i][i-1]=1
        dp[i][x-1]=1
        dic[1]+=3
    else:
        queue = deque([i-1, i+1])
        dp[i][i-1]=1
        dp[i][i+1]=1
        dic[1]+=2
    while queue:
        
        t = queue.popleft()
        #dic[]+=1
        if t == x-1 and dp[i][y-1]==inf:
            queue.append(y-1)
            dp[i][y-1]=dp[i][t]+1
            dic[dp[i][t]+1]+=1
        if t == y-1 and dp[i][x-1]==inf:
            queue.append(x-1)
            dp[i][x-1]=dp[i][t]+1
            dic[dp[i][t]+1]+=1
        if not t==0:
            if dp[i][t-1]==inf:
                queue.append(t-1)
                dp[i][t-1]=dp[i][t]+1
                dic[dp[i][t]+1]+=1
        if not t==n-1:
            if dp[i][t+1]==inf:
                queue.append(t+1)
                dp[i][t+1]=dp[i][t]+1
                dic[dp[i][t]+1]+=1

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

Submission status: Accepted

Solution code:
n,x,y = [int(x) for x in input().split()]
d = {x: 0 for x in range(1, 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))] += 1
for v in d.values():
    print(v)

Submission status: Accepted

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

Submission status: Accepted

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

c = [0 for _ in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1, j-i)
    c[a] += 1

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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
from collections import Counter
c=Counter()
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))
    c[d]+=1

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

Submission status: Accepted

Solution code:

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

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

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

for i in shortest:
    print(i)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min((j - i), 1 + (i - x + 1) + (j - y + 1))] += 1
        else:
            cnt[j - i] += 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
import collections
def resolve():
    N,P,Q=pin()#
    P-=1
    Q-=1#0-index
    ans=[0]*N
    
    
    for i in range(N):
        seen=[0]*N #BFS so 
        d=collections.deque()
        d.append((i,0))
        for j in range(1,N*10):
            if len(d)==0:break
            a,b=d.popleft()
            if a<0 or a>=N or seen[a]:
                continue
            seen[a]=1
            ans[b]+=1
            d.append((a+1,b+1))
            d.append((a-1,b+1))
            if a==P:
                d.append((Q,b+1))
            if a==Q:
                d.append((P,b+1))
    for n,a in enumerate(ans):
        if n!=0:print(a//2)
        
                
            
#%%submit!
resolve()

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(1, N):
    graph[i-1].append(i)
    graph[i].append(i-1)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)
from collections import deque, defaultdict
dic = defaultdict(int)

def bfs(s):
    checked = [0]*N
    queue = deque([(s, 0)])
    while queue:
        v, c = queue.pop()
        if checked[v]:
            continue
        checked[v] = 1
        dic[c] += 1
        for i in graph[v]:
            if not checked[i]:
                queue.appendleft((i, c+1))

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

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