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:
#!/usr/bin/env python3
import sys

# def dist(N, X, Y, i, j):
#     print(i, j, flush=True)
#     if (i <= 0):
#         return 0
#     if (i == j):
#         return 0
#     if (abs(i - j) == 1):
#         return 1
#     if (i == X and j == Y):
#         return 1
#     m = N
#     if (i < N):
#         m = min(m, dist(N, X, Y, i+1, j))
#     if (i > 1):
#         m = min(m, dist(N, X, Y, i-1, j))
#     if (i == X):
#         m = min(m, dist(N, X, Y, Y, j))
#     if (i == Y):
#         m = min(m, dist(N, X, Y, X, j))
#     return 1 + m

def solve(N: int, X: int, Y: int):
    dist = dict()
    sc = Y - X - 1

    for i in range(1, N+1):
        for j in range(i+1, N+1):
            d = j - i
            if i <= X:
                if j >= Y:
                    d -= sc
                else:
                    d = min(d, (X - i) + (Y - j) + 1)
            elif i < Y:
                if j >= Y:
                    d = min(d, (i - X) + 1 + (j - Y))
                else:
                    d = min(d, (i - X) + 1 + (Y - j))

            #print(i, j, d)
            dist[d] = dist.get(d, 0) + 1

    #print(dist)
    for i in range(1, N):
        print(dist.get(i, 0))

    # d = dict()
    # for i in range(1, N+1):
    #     for j in range(i+1, N+1):
    #         r = dist(N, X, Y, i, j)
    #         d[r] = 1 + d.get(r, 0)
    # print(d)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
L = [0 for i in range(N-1)]
for j in range(2, N + 1):
    for i in range(1, j):
        D1 = j - i
        D2 = abs(X-i) + 1 + abs(Y-j)
        L[min(D1, D2) - 1] += 1
for k in range(N-1):
    print(L[k])

Submission status: Accepted

Solution code:


n,x1,y1 = map(int,input().split())
x = min(x1,y1)
y = max(x1,y1)

def ans(k):
    c = 0
    for i in range(1,x):
        if (y-x+1)/2.==k-i and k-i>0:
            c+=1
        elif (y-x+1)//2 >= k-i and k-i>0:
            c+=2

    # print(c)

    for i in range(1,n-y+1):
        if (y-x+1)/2.==k-i and k-i>0:
            c+=1
        elif (y-x+1)//2 >= k-i and k-i>0:
            c+=2

    # print(c)

    c+= max((n-y+x+1-k),0)

    # print(c)

    if (y-x +1)/2. == k:
        c += k
    elif (y-x+1)//2 >=k:
        c += y-x+1
    # print(c)
    if x-1 >= k-1 and c>0:
        c-=1
    if n-y >= k-1 and c>0:
        c-=1
    # print(c)
    if c<0: 
        return 0

    return c+1 if k==1 else c
    # return c


for k in range(n-1):
    print(ans(k+1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

def update_distance(d, num, N):
    minn = num
    maxx = num
    # 要素数の小さい方に向けて
    while True:
        if minn > 0:
            minn -= 1
        else:
            break
        if d[minn] > d[minn+1] + 1:
            d[minn] = d[minn+1] + 1
        else:
            break
    # 要素数の大きいほうに向けて
    while True:
        if maxx < (N - 1):
            maxx += 1
        else:
            break
        if d[maxx] > d[maxx-1] + 1:
            d[maxx] = d[maxx-1] + 1
        else:
            break

(N, X, Y) = (int(i) for i in input().split())
X = X-1
Y = Y-1

# まずは経路情報をd[N][N]の二次元配列に格納
# (i, j)がつながっていれば1, つながってなければ2*10^3

d = []
for i in range(N):
    dd = []
    for j in range(N):
        dd.append(abs(i - j))
    d.append(dd)

# XとYがつながることで最短経路を修正していく
for i in range(N):
    dd = d[i]
    dd[X] = min(dd[X], dd[Y] + 1)
    dd[Y] = min(dd[Y], dd[X] + 1)
    update_distance(dd, X, N)
    update_distance(dd, Y, N)

# dの全リストを連結してあとは0~N-1までカウントする
d_list = []
for i in range(N - 1):
    d_list += d[i][i+1:]

#print(d_list)
c = Counter(d_list)

for i in range(1, N):
    if i in c:
        print(c[i])
    else:
        print(0)

Submission status: Accepted

Solution code:
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush, heappushpop
import sys
input = sys.stdin.readline
N,X,Y=map(int, input().split())
def f(i,j):
  ret1 = abs(j-i)
  ret2 = abs(j-Y)+1+abs(i-X)
  ret3 = abs(i-Y)+1+abs(j-X)
  return min(ret1,ret2,ret3)
  
dp=[0]*N
for i in range(1,N+1):
  for j in range(i+1,N+1):
    dp[f(i,j)] += 1
for i in range(1,N):
  print(dp[i])

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
r = (y-x+1)//2
dist = [0] * n
for i in range(1, n+1):
  for j in range(i+1, n+1):
    if i <= x:
      if j <= x:
        dist[j-i] += 1
      elif j <= y:
        dist[min(j-i, y-j+1+ x-i)] += 1
      else:
        dist[j-i-(y-x)+1] += 1
    elif i < y:
      if j <= y:
        dist[min(j-i, y-j+i-x+1)] += 1
      else:
        dist[min(j-i, i-x + 1 + j-y)] += 1
    else:
      dist[j-i] += 1
for i in range(1, n):
  print(dist[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,x,y = mi()

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

inf = 10 **9
date = [[inf]*n for _ in range(n)]
date[0][x-1] = x-1
date[0][y-1] = x
for i in range(1,n):
    date[0][i] = min(i,date[0][y-1] + abs(y-1-i))
for i in range(1,n):
    for k in range(i+1,n):
        if i < x:
            date[i][k] = date[i-1][k] -1
        elif i < y:
            date[i][k] = min(i-x+1 + date[x-1][k],k-i)
        else:
            date[i][k] = k-i
aaa = [0]*n
for i in range(n):
    for k in range(i+1,n):
        if date[i][k] != inf:
            aaa[date[i][k] -1] += 1
for i in range(n-1):
    print(aaa[i])

Submission status: Accepted

Solution code:
mod = 10**9 + 7

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

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


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

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

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


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

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

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

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

    ret = 0

    result = []
    for k in range(1, N):
        ret = 0
        for i in range(N):
            ret += search(i, k, N, X, Y)
        result.append(str(ret))

    print("\n".join(result))

def search(a, k, N, X, Y):
    kouho = []

    if abs(a-X)+1+abs(a+k-Y) >= k and abs(a-Y) + 1 + abs(a+k-X) >= k:
        #print(f"追加 {a+k} a, k = {a}, {k} by 条件1")
        kouho.append(a+k)

    asy = k-abs(a-X)-1
    if asy < 0:
        pass
    elif asy == 0:
        if abs(a-X) + 1 <= abs(a-Y):
            kouho.append(Y)
            #print(f"追加 {Y} a, k = {a}, {k} by 条件6")
    else:
        if abs(a-(Y-asy)) > k:
            kouho.append(Y-asy)
            #print(f"追加 {Y-asy} a, k = {a}, {k} by 条件2")
        if abs(a-(Y+asy)) > k:
            #print(f"追加 {Y+asy} a, k = {a}, {k} by 条件3")
            kouho.append(Y+asy)

    asx = k-abs(a-Y)-1
    if asx < 0:
        pass
    elif asx == 0:
        if abs(a-Y) + 1 < abs(a-X):
            kouho.append(X)
            #print(f"追加 {X} a, k = {a}, {k} by 条件7")
    else:
        if abs(a-(X-asx)) > k:
            kouho.append(X-asx)
            #print(f"追加 {X-asx} a, k = {a}, {k} by 条件4")
        if abs(a-(X+asx)) > k:
            kouho.append(X+asx)
            #print(f"追加 {X+asx} a, k = {a}, {k} by 条件5")

    kakutei = []
    result = 0
    for kh in kouho:
        if kh == a:
            continue
        if kh < 0:
            continue
        if kh > N-1:
            continue
        if kh in kakutei:
            continue
        if kh < a:
            continue
        kakutei.append(kh)
        result += 1
    #print(f"--result開始 a, k = {a}, {k}")
    #print(result)
    #print(kakutei)
    #print("--result終了")
    return result



if __name__ == "__main__":
    main()

Submission status: Accepted

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

N, X, Y = map(int, input().split())
F = [[0 for i in range(N)] for j in range(N)]

for i in range(N - 1):
    F[i][i + 1] = 1
    F[i + 1][i] = 1
F[X - 1][Y - 1] = 1
F[Y - 1][X - 1] = 1

G = csgraph_from_dense(F, null_value=0)
d = dijkstra(G)

# print(F)
# print(d)

# print(np.count_nonzero(d == 1))
s = Counter(d.flatten().astype(np.int64))
# print(s)
for i in range(1, N):
    if i in s:
        print(s[i] // 2)
    else:
        print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter

N, X, Y = map(int, input().split())
cnt = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        if j <= X:
            cnt[j-i] += 1
            # print(0, i, j)
        elif i <= X and X < j <= Y:
            cnt[min(j-i, X-i+1+Y-j)] += 1
            # print(1, i, j)
        elif i <= X and Y <= j:
            cnt[X-i+1+j-Y] += 1
            # print(2, i, j)
        elif X <= i <= Y and j <= Y:
            cnt[min(j-i, i-X+1+Y-j)] += 1
            # print(3, i, j)
        elif X <= i <= Y and Y <= j:
            cnt[min(j-i, i-X+1+j-Y)] += 1
            # print(4, i, j)
        else:
            cnt[j-i] += 1
            # print(5, i, j)
for i in range(1, N):
    print(cnt[i])

Submission status: Accepted

Solution code:
N, X, Y = map(int,input().split())
s = Y - X - 1
t = (X+Y)/2
ans = [0] * (N)
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i >= Y:
            ans[j-i] += 1
        if i <= X:
            if j <= X:
                ans[j-i] += 1
            elif X < j and j <= Y:
                if j <= t:
                    ans[j-i] += 1
                else:
                    ans[X - i + 1 + Y - j] += 1
            elif j > Y:
                ans[X - i + 1 + j - Y] += 1
        if X < i and i < Y:
            if j < Y:
                if 2*(j-i) <= Y-X+1:
                    ans[j-i] += 1
                else:
                    ans[Y-X+1-j+i] += 1
            elif j >= Y:
                if Y - i <= i - X + 1:
                    ans[j-i] += 1
                else:
                    ans[i - X + 1 + j - Y] += 1

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

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
x -= 1 # 1-indexed に注意
y -= 1
def dist(a, b):
    return min(b - a, abs(b - y) + abs(a - x) + 1)
ans = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        ans[dist(i, j)] += 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+1):
  for j in range(i+1,n+1):
    if i<x:
      if j<=x:
        ans[j-i-1]+=1
      elif j<=y:
        ans[min(j-i-1,x-i+y-j)]+=1
      else:
        ans[x-i+j-y]+=1
    elif i<y:
      if j<=y:
        ans[min(j-i-1,i-x+y-j)]+=1
      else:
        ans[min(j-i-1,i-x+j-y)]+=1
    else:
        ans[j-i-1]+=1

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

Submission status: Accepted

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

min_diff = [[-1] * (n+1) for _ in range(n+1)]
for st in range(1, n+1):
    for go in range(st, n+1):
        min_diff[st][go] = go-st
        if x < st and go < y:
            min_diff[st][go] = min(min_diff[st][go], (st-x)+(y-go)+1)
        elif x >= st and go < y:
            min_diff[st][go] = min(min_diff[st][go], (x-st)+(y-go)+1)
        elif x < st and go >= y:
            min_diff[st][go] = min(min_diff[st][go], (st-x)+(go-y)+1)
        else:
            min_diff[st][go] = min_diff[st][go] - (y-x) + 1

#print(min_diff)

ans = [0] * (n+1)
for i in range(n+1):
    for j in range(n+1):
        ans[min_diff[i][j]] += 1

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

Submission status: Accepted

Solution code:
import sys

# import bisect
from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x, y = list(map(int, readline().split()))
    x, y = x - 1, y - 1
    que = deque()
    ans = [0] * n
    loopsize = y - x + 1

    if loopsize % 2 == 1:
        for i in range(1, loopsize // 2 + 1):
            ans[i] = loopsize
    else:
        for i in range(1, loopsize // 2 + 1):
            ans[i] = loopsize
        ans[loopsize // 2] = loopsize // 2

    loopdist = [0] * n
    que.append((0, 0))
    que.append((loopsize - 1, 1))
    visited = [False] * loopsize
    visited[0] = True
    visited[-1] = True

    while que:
        cn, dist = que.popleft()
        loopdist[dist] += 1
        if not cn == 0:
            if not visited[cn - 1]:
                visited[cn - 1] = True
                que.append((cn - 1, dist + 1))
        if not cn == (loopsize - 1):
            if not visited[cn + 1]:
                visited[cn + 1] = True
                que.append((cn + 1, dist + 1))

    left = x
    right = n - y - 1

    for i in range(left):
        for j in range(loopsize // 2 + 1):
            ans[i + 1 + j] += loopdist[j]

    for i in range(1, left):
        ans[i] += left - i

    for i in range(right):
        for j in range(loopsize // 2 + 1):
            ans[i + 1 + j] += loopdist[j]

    if left > 0 and right > 0:
        for i in range(left):
            for j in range(right):
                ans[i + j + 3] += 1


    for i in range(1, right):
        ans[i] += right - i



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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, X, Y = [int(n) for n in input().split(' ')]

cnt = [0]*N

for i in range(1, N):  # 1~N-1
    for j in range(i+1, N+1):  # 2~N
        if i <= X:
            if j >= Y:
                p = min(X-i + j-Y + 1, j - i)
            else:
                p = min(X-i + Y-j + 1, j - i)
        else:
            if j >= Y:
                p = min(i-X + j-Y + 1, j - i)
            else:
                p = min(i-X + Y-j + 1, j - i)
        cnt[p] += 1


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

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
a=x-1 #Xより左側
b=y-x-1 #XとYの間
c=n-y #Yより右側

print(n)

for i in range(2,n):
    ans=0
    if i<a+c+2: #aとc(X,Yもカウント)
        ans+=a+c+2-i
    if i<(b+2)//2+a+1 and a>0: #aとb
        if i-1<=a:
            ans+=min(i-1,(b+2)//2)*2-1
        else:
            ans+=min((b+2)//2+a-i+1,a)*2
        if i>(b+2)//2 and b%2==0:
            ans-=1
    if i<(b+2)//2+c+1 and c>0: #bとc
        if i-1<=c:
            ans+=min(i-1,(b+2)//2)*2-1
        else:
            ans+=min((b+2)//2+c-i+1,c)*2
        if i>(b+2)//2 and b%2==0:
            ans-=1
    if i<=(b+2)//2: #bとb(X,Yもカウント)
        if i==(b+2)/2:
            ans+=(b+2)//2
        else:
            ans+=b+2
    print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,x,y=map(int,input().split())


l1=n-y-x
l2=y-x

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

for j in range(n-1):
	print(l[j])

Submission status: Accepted

Solution code:
from sys import stdin

N, X, Y = [int(x) for x in stdin.readline().rstrip().split()]
d = {}
# print(d)
for k in range(1, N):
    for i in range(1, N+1-k):
        temp = min(k, (abs(i-X)+1+abs(Y-(i+k))))
        d[temp] = d.get(temp, 0)+1
        # print("k=", k, "a=", min(k, (abs(i-X)+1+abs(Y-(i+k)))))
        # if k != min(k, (abs(i-X)+1+abs(Y-(i+k)))):
        #     pass
for l in range(1, N):
    print(d.get(l, 0))
# print(d.get(5, 0))

Submission status: Accepted

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

l = [0] * (N)

graph = [[0] * N] * N

for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i < X:
            distAX = X - i
        else:
            distAX = i - X            
        if j < Y:
            distBY = Y - j
        else:
            distBY = j -Y
        distAB = j - i
        if distAX + distBY + 1 < distAB:
            distAB = distAX + distBY + 1

        l[distAB] = l[distAB] + 1

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

Submission status: Accepted

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

xy = y - x

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

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

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

Submission status: Accepted

Solution code:
N,X,Y = map(int,input().split())
for k in range(1,N):
    s = 0
    for i in range(1,N-k+1):
        d = abs(i - X)
        if d <= k-1:
            front = Y + k -1 -d
            back = Y - k + 1+ d
            first = i + k
            if front == back:
                if first >= front :
                    s += 1
                else:
                    s += 2
            else:
                if back - i == k:
                    if front <= N:
                        s += 2
                    else:
                        s += 1
                elif back - i > k:
                    if front <= N:
                        s += 3
                    else:
                        s += 2
                else:
                    if first >= front:
                        s += 1
                    else :
                        if front <= N:
                            s += 1
                        c = abs(Y - first)
                        if d + c + 1 >= k:
                            s += 1


        else:
            s += 1
    print(s)

Submission status: Accepted

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

for i in range(1, N+1):
  for j in range(i+1, N+1):
    a = j - i
    b = 1 + abs(i - X) + abs(j - Y) 
    d[i][j] = min(a, b)
    ans[d[i][j]] += 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)
dist = [[-1] * (n + 1) for _ in range(n + 1)]


def dist(a, b):
    if b < a:
        a, b = b, a
    p = b - a
    q = abs(b - y) + abs(a - x) + 1
    return min(p, q)


for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans[dist(i, j)] += 1
print(*ans[1:], sep="\n")

Submission status: Accepted

Solution code:
N,X,Y = (int(x) for x in input().split())
X -=1
Y-=1
dist = [[0]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    if i >= j :
      continue
    d1 = j - i
    d2 = abs(X-i)+abs(Y-j)+1
    dist[i][j] = min(d1,d2)

cnt = [0]*(N)
for i in range(N):
  for j in range(N):
    num = dist[i][j]
    if num >0:
      cnt[num] += 1
for i in range(N-1):
  print(cnt[i+1])

Submission status: Accepted

Solution code:
import copy

N, X, Y = map(int, input().split())
def check(num, distance):
    if num!=0:
        distance[num-1]=min(distance[num]+1, distance[num-1])
    if num!=N-1:
        distance[num+1]=min(distance[num+1], distance[num]+1)
    if num==X-1:
        distance[Y-1]=min(distance[Y-1], distance[X-1]+1)
    elif num==Y-1:
        distance[X-1] = min(distance[X-1], distance[Y-1]+1)
total_answer=[]
answer=[N]*N
for k in range(N):
    temp=copy.copy(answer)
    temp[k]=0
    #print(temp)
    for i in range(0, N):
        check(i, temp)
        #print(temp)
    #print(temp)
    for j in range(N-1,-1,-1):
        check(j, temp)
    #print(temp)
    #print('/n')

    for i in range(0, N):
        check(i, temp)

    for j in range(N - 1, -1, -1):
        check(j, temp)
    for i in range(0, N):
        check(i, temp)

    for j in range(N - 1, -1, -1):
        check(j, temp)

        #print(temp)
    #print(temp)
    total_answer+=temp
#print(total_answer)
import collections
dict=collections.Counter(total_answer)
#print(dict)
for i in range(1, N):
    print(dict[i]//2)

Submission status: Accepted

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

tb=[[0]*(n+1) for i in xrange(n+1)]
tb[x][y]=1
for i in xrange(1, n+1):
    for j in xrange(i+1,n+1):
        if x==i and j==y:
            continue
        if i<x:
            # print i,j, x-i+1+abs(y-j)
            tb[i][j]=min(j-i, x-i+1+abs(y-j))
        elif i>=x and i<=y:
            tb[i][j]=min(j-i, i-x+1+abs(y-j))
        else:
            tb[i][j]=j-i

res=[0]*(n+1)

for i in xrange(1 ,n+1):
    for j in xrange(i+1, n+1):
        res[tb[i][j]]+=1

s=''
for i in xrange(1, n):
    s+=str(res[i])+'\n' 

# for i in tb:
#     print i
print s

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,X,Y=map(int,input().split())
X-=1
Y-=1

ans=[0]*N
for n in range(N-1):
    for tgt in range(n+1,N):
        temp=min(abs(tgt-n),abs(n-X)+abs(Y-tgt)+1)
        #print(n,tgt,temp)
        ans[temp]+=1


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

Submission status: Accepted

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

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if j<=x or y<i:
            num = j-i
        elif i<=x and x<j<=y:
            num = (x-i)+min(j-x, y-j+1)
        elif i<=x and y<j:
            num = (x-i)+(j-y)+1
        elif x<i and j<=y:
            num = min(j-i,(i-x)+(y-j)+1)
        elif x<i<=y and y<j:
            num = min(i-x+1, y-i)+(j-y)
        li[num-1] += 1

for i in li:
    print(i)

Submission status: Accepted

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

anss=[0]*(N-1)

def judge(i, j):
  #1<=a<X
  #X<=b<=Y
  #Y<c<=N
  if 1<=i and i<X:
    if 1<=j and j<X:
      return j-i
    if X<=j and j<=Y:
      #1,4 4-1 4-4+2-1
      return min(j-i, Y-j+X-i+1)
    if Y<j and j<=N:
      return j-i-(Y-X-1)
    
  if X<=i and i<=Y:
    if X<=j and j<=Y:
      return min(j-i, Y-j+i-X+1)
    if Y<j and j<=N:
      return min(j-i, i-X+j-Y+1)
    
  if Y<i and i<=N:
    return j-i

for i in range(1,N):
  for j in range(i+1, N+1):
    l=judge(i,j)
    #print(i,j,l)
    anss[l-1]+=1

for a in anss:
  print(a)

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
x -= 1
y -= 1
r = {i: 0 for i in range(1, n)}
for i in range(n - 1):
    for k in range(i + 1, n):
        if (x < i and k < y) or (x <= i and k < y) or (x < i and k <= y):
            t = min(i - x + y - k + 1, k - i)
            r[t] += 1
        elif i <= x and y <= k:
            t = k - i - (y - x - 1)
            r[t] += 1
        elif i < x < k < y:
            t = min(k - i, x - i + 1 + y - k)
            r[t] += 1
        elif x < i < y < k:
            t = min(k - i, i - x + 1 + k - y)
            r[t] += 1
        else:
            t = k - i
            r[t] += 1
for i in range(1, n):
    print(r[i])

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
a = [0 for i in range(1,n)]
l=y-x;m= max(x-1+l//2,x+n-y)
x-=1;y-=1
for i in range(n):
  for j in range(i+1,n):
    if i+1==j:
      a[0]+=1
    else:
      k = j-i
      if i<=x and j>=y:
      	k=k-l+1
      elif i>=x and j<=y:
        k=min(k,(l+1)-k)
      elif i<=x:
        k=x-i+min((j-x),(l+1)-(j-x))
      else:
        k = j-y+min(y-i,(l+1)-(y-i))  

      a[k-1]+=1
for i in a:
  print(i)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, X, Y = [int(x) for x in stdin.readline().rstrip().split()]
    result = [0] * (N - 1)
    for left in range(1, N):
        for right in range(left + 1, N + 1):
            if (left <= X) and (Y <= right):
                x = (X - left) + 1 + (right - Y)
            elif (left <= X) and (X <= right <= Y):
                x = (X - left) + min((right - X), (Y - right) + 1)
            elif (X <= left <= Y) and (Y <= right):
                x = min((Y - left), (left - X) + 1) + (right - Y)
            elif (X <= left <= Y) and (X <= right <= Y):
                x = min((right - left), (left - X) + (Y - right) + 1)
            else:
                x = right - left
            result[x - 1] += 1
    print(*result, sep='\n')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for el in result:
    print(el)

Submission status: Accepted

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

dist = [0] * (n + 1)
dist[0] = -1

for i in range(1, n + 1):
    if y == i:
        dist[i] = dist[x] + 1
    else:
        dist[i] = dist[i - 1] + 1

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

cnt = [0] * (n + 1)

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

for i in range(1, n):
    print(cnt[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):
        #print(i,j)
        '''
        1 2,1 3,1 4
        2 3,2 4
        3 4
        '''
        if i<=x and j>=y:
            dis = min(j-i,x-i +1+ j-y)
            l[dis-1] += 1
            #print(i,j,dis-1)
        elif i>=x and j<=y:
            dis = min(j-i,i-x+y-j+1)
            l[dis-1] += 1
        elif i<=x and x<=j<=y:
            dis = min(j-i,x-i+y-j+1)
            l[dis-1] += 1
        elif x<=i<=y and j>=y:
            dis = min(j-i,i-x+j-y+1)
            l[dis-1] += 1
        elif i<=x and j<=x:
            dis = j-i
            l[dis-1] += 1
        elif i>=y and j>=y:
            dis = j-i
            l[dis-1] += 1
for kkk in l:
    print(kkk)

Submission status: Accepted

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

M = [[N] * N for _ in range(N)]


for j in range(N):
    if j > X:
        M[j][j-1] = 1
        for k in range(j-1, X-1, -1):
            M[j][k] = min(M[j][k], M[j][k+1] + 1)
        M[j][Y] = M[j][X] + 1
        for k in range(Y-1, X, -1):
            M[j][k] = min(M[j][k], M[j][k+1] + 1)

    for i in range(j+1, N):

        if j == X:
            M[j][Y] = 1
            for m in range(Y-1, X, -1):
                M[j][m] = min(M[j][m], M[j][m+1] + 1)
        if i - j == 1:
            M[j][i] = 1
        M[j][i] = min(M[j][i], M[j][i-1] + 1)
        if i == X:
            M[j][Y] = M[j][i] + 1
            for m in range(Y-1, X, -1):
                M[j][m] = min(M[j][m], M[j][m+1] + 1)

ans = [0] * N

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

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

Submission status: Accepted

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

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

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

if __name__ == "__main__":
  solve()

Submission status: Accepted

Solution code:
from sys import stdin

N, X, Y = map(int, stdin.readline().split())
k = [0] * N

X -= 1
Y -= 1
for start in range(N - 1):
    for end in range(start + 1, N):

        if start < X:
            if end <= X:
                distance = end - start
                k[distance] += 1
            elif X < end < Y:
                if end <= (X + Y) / 2:
                    distance = end - start
                    k[distance] += 1
                else:
                    distance = (X - start) + 1 + (Y - end)
                    k[distance] += 1
            else:
                distance = (X - start) + 1 + (end - Y)
                k[distance] += 1

        elif X <= start < Y:
            if end < Y:
                tmp = (start - X) + 1 + (Y - end)
                distance = min(end - start, tmp)
                k[distance] += 1
            else:
                tmp = (start - X) + 1 + (end - Y)
                distance = min(end - start, tmp)
                k[distance] += 1

        else:
            distance = end - start
            k[distance] += 1

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