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
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, X, Y):
    ans = list(range(N, 0, -1))
    X = X - 1
    Y = Y - 1
    NN = N
    while X >= 0:
        # print('XY', X, Y)
        # 順方向
        x = X + 1
        y = Y
        while y < NN:
            # print('順  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y += 1
        # 逆方向
        y = Y-1
        x = X+2
        while x < y:
            # print('逆  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y -= 1
        X -= 1
        Y -= 1
        NN -= 1

    X = 1
    while X < Y:
        # print('XY', X, Y)
        # 順方向
        x = X + 1
        y = Y
        while y < NN:
            # print('順  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y += 1
        # 逆方向
        y = Y-1
        x = X+2
        while x < y:
            # print('逆  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y -= 1
        X += 1
        Y -= 1
        NN -= 1

    return ans


if __name__ == "__main__":

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

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

Submission status: Accepted

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

for i in range(1,n):
  for j in range(i+1,n+1):
    a=j-i
    if i<=x:
      if j>=y:
        a=a-(y-x-1)
      else:
        b=y-j+1+x-i
        a=min(a,b)
    else:
      if j>=y:
        b=i-x+1+j-y
        a=min(a,b)
      else:
        b=i-x+1+y-j
        a=min(a,b)
    ans[a-1]=ans[a-1]+1

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

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
from itertools import combinations

ans = {i+1:0 for i in range(N)}
for a, b in combinations(range(1, N+1), 2):
    t = b - a
    if a <= X:
        t = min(t, X - a + 1 + abs(Y - b))
    elif a <= Y:
        t = min(t, abs(a - X) + 1 + abs(Y - b))
    ans[t] += 1

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

Submission status: Accepted

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

dis = [0]*n

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

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

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
dist = [0]*N
for i in range(N):
    for k in range(i+1,N):
        if i == X - 1 and k == Y - 1:
            dist[1] += 1
            continue
        if X - 1 <= k <= Y - 1 and i <= X - 1:
            tmp = min(k-i,(X-1)-i+1+(Y-1-k))
            dist[tmp] += 1
            continue
        if X - 1 < i < Y - 1 and k >= Y - 1:
            tmp = min(k-i,i-(X-1)+1+k-(Y-1))
            dist[tmp] += 1
            continue
        if X - 1 <= k <= Y - 1 and X - 1 <= i <= Y - 1:
            tmp = min(k-i,i-(X-1)+1+(Y-1-k))
            dist[tmp] += 1
            continue
        if i <= X - 1 and k >= Y - 1:
            dist[k-i-(Y-X-1)] += 1
            continue
        dist[k-i] += 1
for i in range(1,N):
    print(dist[i])

Submission status: Accepted

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

INF = 10**5
seen = [[INF] * n for _ in range(n)]
#import numpy as np
for i in range(n):
    que.append(i)
    seen[i][i] = 0
    #print('---', i)
    while len(que) > 0:
        t = que.popleft()
        step = [t-1, t+1]
        if t == x:
            step.append(y)
        if t == y:
            step.append(x)
        for ti in step:
            #print(ti)
            if ti < 0 or ti >= n:
                continue
            if seen[i][ti] == INF:
                que.append(ti)
            seen[i][ti] = min(seen[i][t] + 1, seen[i][ti])
    #print(np.array(seen))
#print(np.array(seen))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

from collections import deque

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

count = [0 for i in range(N)]

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

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

Submission status: Accepted

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

from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
    for j in range(i + 1, N):
        idx = min(j - i, abs(j + 1 - Y) + 1 + abs(X - i - 1))
        ans[idx] += 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):
		d1=j-i
		d2=abs(X-i)+1+abs(Y-j)
		d=min(d1,d2)
		ans[d-1]+=1
for i in ans:
	print(i)

Submission status: Accepted

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

for i in l:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

if X > Y:
    tmp = Y
    Y = X
    X = tmp

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

d = {i:set() for i in range(N)}
for i in range(0,N):
  if i-1>=0:
    d[i-1].add(i)
  if i+1<=N-1:
    d[i+1].add(i)
  if i==X:
    d[Y].add(X)
    d[X].add(Y)

ans = {i+1:0 for i in range(N-1)}

for i in range(0,N):
  dist = [-1]*N
  q = deque([i])
  dist[i] = 0
  while q:
    v = q.popleft()
    for j in d[v]:
      if  dist[j] == -1:
        dist[j] = dist[v] + 1
        ans[dist[j]] += 1
        q.appendleft(j)
      elif dist[v] + 1 < dist[j]:
        ans[dist[j]] -= 1
        dist[j] = dist[v] + 1
        ans[dist[j]] += 1
        q.appendleft(j)

for l in ans.values():
  print(l//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def abs(n):
    if n < 0:
        return -n
    else:
        return n

def min(a, b):
    if a < b:
        return a
    else:
        return b

def abc160d(n, x_in, y_in):
    d_arr = [0 for _ in range(n-1)]
    x = x_in - 1
    y = y_in - 1
    for a in range(0,n):
        for tgt in range(a+1,n):
            d_normal = tgt - a
            d_min = d_normal - 1
            if tgt < x or y < a:
                pass
            else:
                d_short = abs(x-a) + 1 + abs(y-tgt)
                d_min = min(d_normal, d_short) - 1

            d_arr[d_min] += 1

    return d_arr    

###
# main
if(__name__ == '__main__'):
    # input
    n, x, y = map(int, input().split(" "))
    
    ans = abc160d(n, x, y)
    
    # output
    for a in ans:
        print(a)
# else:
    # do nothing

Submission status: Accepted

Solution code:
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**4
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,X,Y = LI()

c = [0 for _ in range(N+1)]

for k in range(1,N+1):
    j = 1
    m = [0 for _ in range(N+1)]
    # for i in range(k-1,0,-1):
    #     c[j] += 1
    #     m[i] = j
    #     j += 1
    j = 1
    for i in range(k+1,N+1):
        c[j] += 1
        m[i] = j
        j += 1
    if k <= X:
        j = X - k + 1
        a = 0
        while j + a < m[Y - a]:
            c[m[Y-a]] -= 1
            c[j + a] += 1
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                c[m[Y+a]] -= 1
                c[j + a] += 1
                m[Y + a] = j + a
                a += 1
                if Y + a > N : break
    elif k <= Y:
        j = k - X + 1
        a = 0
        while j + a < m[Y - a]:
            c[m[Y-a]] -= 1
            c[j + a] += 1
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                c[m[Y+a]] -= 1
                c[j + a] += 1
                m[Y + a] += 1
                a += 1
                if Y + a > N : break
for k in range(1,N):
    print (c[k])

Submission status: Accepted

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

def main():
  n, x, y = map(int, input().split()) 
  x -= 1
  y -= 1
  counts = [0] * (n)
  for i in range(n):
    s = 0
    for j in range(i+1, n):
      nv = min((j - i + 1), abs(i-x) + 1 + abs(j-y) + 1)
      if nv-2 < 0 or nv-2 >= n:
        continue
      counts[nv-2] += 1

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

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N, X, Y = [int(x) for x in input().split()]
P = Y - X + 1
limit = (P + 1) // 2
L = X - 1
R = N - Y
for k in range(1, N):
  ans = 0
  if limit > k:
    ans += P
  elif limit == k:
    if P % 2 == 0:
      ans += P // 2
  for i in range(1, X):
    t = k - (X - i)
    if t <= 0:
      ans += 1
    elif t < limit:
      ans += 2
    elif t == limit:
      if P % 2 == 0:
        ans += 1
    if t - 1 > 0 and t - 1 <= R:
      ans += 1
  for i in range(N, Y, -1):
    if k - (i - Y) <= 0:
      ans += 1
    elif k - (i - Y) < limit:
      ans += 2
    elif k - (i - Y) == limit:
      if P % 2 == 0:
        ans += 1
  print(ans)

Submission status: Accepted

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

from collections import deque
from collections import Counter

def bfs(i): # i番目の頂点を起点にしたbfs
    visited=[0]*n
    visited[i]=1
    que=deque([])
    que.append((i,1))
    
    while len(que)>0:
        di,c=que.popleft()
        nm=di-1
        np=di+1
        no=-1
        if di==x-1:
            no=y-1
        if di==y-1:
            no=x-1
        if 0<=nm and visited[nm]==0:
            visited[nm]=c+1
            que.append((nm,c+1))
        if np<=n-1 and visited[np]==0:
            visited[np]=c+1
            que.append((np,c+1))
        if no>=0 and visited[no]==0:
            visited[no]=c+1
            que.append((no,c+1))
    return visited

l=[0]
myc=Counter(l)
for i in range(n):
    myc += Counter(bfs(i))
ans=list(myc.values())
p=len(ans)
for i in range(2,n+1):
    if i>=p:
        print(0)
    else:
        print(ans[i]//2)

Submission status: Accepted

Solution code:
n,x,y = [int(e) for e in input().split() ]
dst=[0]*(n+1)
for i in range(1,n+1):
  for j in range(i+1,n+1):
    l = abs(i - j)
    lxi = abs( x - i )
    lyj = abs( y - j )
    lu  = lxi + 1 + lyj
    dst[min([l,lu])] += 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict

############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,X,Y = invr()
ans = defaultdict(int)

for i in range(1,n):
    for j in range(i + 1,n + 1):
        if i < X:
            if j > Y:
                result = min(j - i,(X-i) + (j - Y) + 1)
            else:
                result = min(j - i,(X-i) + (Y - j) + 1)
        else:
            if j > Y:
                result = min(j - i,(i - X) + (j - Y) + 1)
            else:
                result = min(j - i,(i - X) + (Y - j) + 1)
        ans[result] += 1
    

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

Submission status: Accepted

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

for i in range(1,n+1):
    for j in range(i+1,n+1):
        dist= j-i
        alt_dist= abs(x-i)+1+abs(y-j)
        if alt_dist<dist:
            dist=alt_dist
        arr[dist]+=1
for a in arr[1:]:
    print(a)

Submission status: Accepted

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

result = [0] * (n-1)
short = y - x - 1
for i in range(n-1):
  for j in range(n-i-1):
    start = i + 1
    end = j + i + 2
    dist_no_shortcut = end - start
    dist_with_shortcut = abs(start - x) + abs(end - y) + 1
    dist = min(dist_no_shortcut, dist_with_shortcut)
    result[dist-1] += 1

for v in result:
  print(v)

Submission status: Accepted

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

d = {}

for i in range(1, n):
	d[i] = d.get(i, 0)

for i in range(1,n):
	for j in range(i+1,n+1):
		if i<=x and j<=y:
			k = min(j-i, (x-i)+1+(y-j))
		elif i<=x and y<=j:
			k = (x-i) + 1 + (j-y)
		elif x<=i and j<=y:
			k = min(j-i, (i-x)+1+(y-j))
		elif x<=i and y<=j:
			k = min(j-i, (i-x)+1+(j-y))
		d[k] = d.get(k, 0) + 1

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

Submission status: Accepted

Solution code:
n,x,y = (int(x) for x in input().split())
x-=1
y-=1
middle=(y+x)/2
dic={}
for i in range(n-1):
    for j in range(i+1,n):
        if i<=x and j<=x:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif j==middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i==middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=x and j<=middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=middle and j<=y:
            k = (x-i) + 1 + (y-j)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=middle and j>=y:
            k = (x-i) + 1 + (j-y)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j<=middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j>=middle and j<=y:
            k = min(j-i, i-x+y-j+1)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j>=y:
            k = i-x + j-y + 1
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=middle and j<=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=middle and j>=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=y and j>=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
for i in range(1,n):
    if i not in dic:
        print(0)
    else:
        print(dic[i])

Submission status: Accepted

Solution code:
[n,x,y]=list(map(int,input().split()))
anslist=[0]*(n-1)
x-=1
y-=1
for i in range(n-1):
    for j in range(i+1,n):
        if j<=x or y<=i:
            kyori=j-i
        elif i<=x<=j<=y:
            kyori=min(j-i,x-i+1+y-j)
        elif x<=i<=y<=j:
            kyori=min(j-i,i-x+1+j-y)
        elif i<=x and y<=j:
            kyori=x-i+1+j-y
        elif x<=i and j<=y:
            kyori=min(j-i,i-x+1+y-j)
        else:kyori=1
        anslist[kyori-1]+=1
for i in range(len(anslist)):
    print(anslist[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, X, Y = MI()

aaa = [None] * (N + 1)
for v0 in range(1, N + 1):
    dx = [0] * N
    seen = set()
    seen.add(v0)
    q = deque()
    q.append((v0, -1, 0))
    while len(q) > 0:
        v, p, dist = q.popleft()

        dx[v - 1] = dist
        next = []
        if v > 1: next.append(v - 1)
        if v < N: next.append(v + 1)
        if v == X: next.append(Y)
        if v == Y: next.append(X)
        for next_v in next:
            if next_v not in seen:
                q.append((next_v, v, dist + 1))
                seen.add(next_v)
    d = defaultdict(int)
    for x in dx:
        d[x] += 1
    aaa[v0] = d

for k in range(1, N):
    ans = 0
    for i in range(1, N + 1):
        ans += aaa[i][k]
    print(ans // 2)

Submission status: Accepted

Solution code:
n, x, y = map(int, input().split())
ans = list(0 for _ in range(n+1))
for i in range(1, n):
    for j in range(i+1, n+1):
        if i < x:
            if j <=x:
                ans[j-i] += 1
            elif x < j < y:
                p = min(j-x, (y-j)+1)
                ans[x-i+p] += 1
            else:
                pos = (x - i) + 1 + (j - y)
                ans[pos] += 1
        elif y < i:
            ans[j-i] += 1
        else:
            if j < y:
                p = (i - x) + (y - j) + 1
                if (j - i) < p:
                    ans[j-i] += 1
                else:
                    ans[p] += 1
            else:
                p = min(y-i, (i - x) + 1)
                ans[p + (j - y)] += 1
for i in range(1, n):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

INF = sys.maxsize

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

# インデックスと合わせる
X -= 1
Y -= 1

distance = [[INF] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        # X,Y を経由しない場合とする場合の小さい方
        distance[i][j] = distance[i][j] = min(
            abs(i - j),
            abs(i - X) + abs(j - Y) + 1,
            abs(i - Y) + abs(j - X) + 1
        )

counter = defaultdict(int)

for i in range(N):
    for j in range(N):
        counter[distance[i][j]] += 1

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

Submission status: Accepted

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

ans=[0]*(n-1)

for i in range(1,n):
    for j in range(i+1,n+1):
        if j<=x:
            tmp=j-i
            
        elif x<i and j<y:
            tmp=min(j-i,(i-x)+1+(y-j))
            
        elif y<=i:
            tmp=j-i

        elif i<=x and y<=j:
            tmp=j-i -(y-x-1)

        elif i<=x and x<j and j<y:
            tmp=min(j-i,(x-i)+1+(y-j))
        elif x<i and i<y and y<=j:
            tmp=min(j-i,(i-x)+1+(j-y))

        ans[tmp-1] += 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
R = [0 for j in range(N)]
for i in range(N-1):
  for j in range(N):
    if j <= i:
      continue
    xd = abs(i - X)
    yd = abs(j - Y)
    dist = min(
      j - i,
      xd + yd + 1
    )
    R[dist] += 1
for r in R[1:]:
  print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list = list(map(int, input().split()))
N=list[0]+1
X=list[1]
Y=list[2]
l=[0]*N
c=0
# i<j
for i in range(1,N):
    for j in range(i+1, N):
        if i<=X and Y<=j:
            l[j-i-(Y-X)+1]+=1
        else:
            if j-i>abs(X-i)+1+abs(j-Y):
                l[abs(X-i)+1+abs(j-Y)]+=1
            else:
                l[j-i]+=1
for i in range(1,N-1):
    print(l[i])

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    ans = [0]*(N-1)
    d = [[0]*N for i in range(N)]

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

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heappop, heappush, heapify
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist
 
N, X, Y = MAP()
 
graph = defaultdict(list)
 
for i in range(N-1):
    graph[i].append((i+1, 1))
    graph[i+1].append((i, 1))
 
graph[X-1].append((Y-1, 1))
graph[Y-1].append((X-1, 1))
 
a = dijkstra(graph, 0)
count = defaultdict(int)
for i in range(N):
    a = dijkstra(graph, i)
    
    # print(a[i+1:])
    for c in a[i+1:]:
        count[c] += 1
# print(count)
 
for i in range(1, N):
    print(count[i])

Submission status: Accepted

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

ans_list = [0] * (n-1)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# d = defaultdict(list)
d = defaultdict(int)
for i in range(n-1):
    for j in range(i+1, n):
        distance = j - i
        if i <= x and y <= j:
            # 順方向で順方向で近道できるとき
            distance -= y - x - 1
        # distance2 = 10 ** 10
        # if x <= i <= y and x <= j <= y:
        distance2 = abs(i - x) + abs(y - j) + 1
        # if i == 1 and j == 3:
        #     print('hoge')
        #     print(i)
        #     print(x)
        #     print(y)
        #     print(j)
        #     print('hoge')
        #     print(distance2)
        distance = min(distance, distance2)

        # d[distance].append((i, j, distance))
        d[distance] += 1

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

# for i, j in d.items():
#     print(i)
#     print(j)
#     print()

Submission status: Accepted

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

counts = [0 for i in range(N-1)]

for i in range(N):
    for j in range(i+1, N):
        if i <= X-1 :
            if j >= Y-1:
                dis = j-i -(Y-X-1)
            elif j < Y-1:
                dis = min([j-i, (X-1)-i+1+abs(j-(Y-1))])
                
        else:
            dis = min([j-i, i-(X-1)+1+abs(j-(Y-1))])
        
        # distances[i].append(dis)
        k = dis-1
        counts[k] += 1
        
for k in range(N-1):
    print(counts[k])

Submission status: Accepted

Solution code:
import itertools

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

l=list(range(1,N+1))
cnt=[0]*(N-1)

for p in itertools.combinations(l, 2):
    a=p[1]-p[0]
    b=abs(p[1]-Y)+abs(p[0]-X)+1
    cnt[min(a,b)-1]+=1

for k in cnt:
    print(k)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
n,x,y=map(int,input().split())
x-=1
y-=1
cnt=defaultdict(int)
for i,j in combinations(range(n),2):
  cnt[min(abs(j-i),abs(j-y)+1+abs(i-x),abs(j-x)+1+abs(i-y))]+=1
for k in range(1,n):
  print(cnt[k])

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, X, Y = iim()
    ans = [N-i-1 for i in range(N-1)]
    X1, Y1 = X-1, Y -1

    xy2 = (X+Y)  // 2
    for i in range(N):
        x1 = X1 - i
        if x1 < 0: x1 = -x1
        for j in range(i+1, N):
            d1 = j - i - 1
            y1 = Y1-j
            if y1 < 0: y1 = -y1
            d2 = x1 + y1
            if d1 > d2:
                #print((i+1, j+1), d1+1, d2+1, x1, y1)
                ans[d1] -= 1
                ans[d2] += 1

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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)

def bfs(v):
   dist = [-1] * n
   dist[v] = 0
   visit = [v]
   c = 1
   while visit:
      next = []
      for i in visit:
         for j in edges[i]:
            if dist[j] == -1:
               dist[j] = c
               next.append(j)
      visit = next
      c += 1

   return dist

minpath = []
for i in range(n):
   minpath.extend(bfs(i))

from collections import Counter
cnt = Counter(minpath)

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

Submission status: Accepted

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

c = [0 for _ in range(n - 1)]
for left_i in range(n):
    for right_i in range(left_i + 1, n):
        dis = 0
        if left_i <= x_i:
            if right_i <= x_i:
                dis = right_i - left_i
                c[dis - 1] += 1
            elif x_i < right_i <= y_i:
                dis_1 = right_i - left_i
                dis_2 = x_i - left_i + 1 + y_i - right_i
                c[min(dis_1, dis_2) - 1] += 1
            else:
                dis = x_i - left_i + right_i - y_i + 1
                c[dis - 1] += 1
        elif x_i < left_i < y_i:
            dis_1 = right_i - left_i
            dis_2 = left_i - x_i + 1 + abs(right_i - y_i)
            c[min(dis_1, dis_2) - 1] += 1
        else:
            dis = right_i - left_i
            c[dis - 1] += 1

for i in c:
    print(i)

Submission status: Accepted

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

D = [0 for _ in range(N+1)]
#D[i]:距離がiである頂点(a,b)(a!=b)の組の個数

def dist(i,j):
    return min(j-i,abs(X-i)+abs(j-Y)+1)

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

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

Submission status: Accepted

Solution code:
def bfs(v):
    d=[-1]*n
    d[v]=0
    q=[v]
    c=1
    while q:
        q1=[]
        for i in q:
            for j in pt[i]:
                if d[j]==-1:
                    d[j]=c
                    q1.append(j)
        q=q1
        c+=1
    return d
n,x,y = map(int,input().split())
pt = [[i-1,i+1] for i in range(0,n)]
pt[0].remove(-1)
pt[n-1].remove(n)
pt[x-1].append(y-1)
pt[y-1].append(x-1)
cnt = [0]*(n)

for i in range(n-1):
  d = bfs(i)
  for j in range(i,n):
    cnt[d[j]] += 1

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