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 deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  n, x, y = map(int, input().split())
  m = [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, abs(x-j)+abs(y-i)+1)
      m[d] +=1
  for i in range(1,n):
    print(m[i])

if __name__ == '__main__':
  main()

Submission status: Accepted

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

anss = [0] * N
for a in range(1, N+1):
    for b in range(a+1, N+1):
        d1 = b-a
        d2 = abs(X-a) + 1 + abs(Y-b)
        d = d1 if d1 <= d2 else d2
        anss[d] += 1

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

Submission status: Accepted

Solution code:
import sys
import os
from io import BytesIO, IOBase

#########################
# imgur.com/Pkt7iIf.png #
#########################

# returns the list of prime numbers less than or equal to n:
'''def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r'''

# returns all the divisors of a number n(takes an additional parameter start):
'''def divs(n, start=1):
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors'''

# returns the number of factors of a given number if a primes list is given:
'''def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
    return divs_number'''

# returns the leftmost and rightmost positions of x in a given list d(if x isnot present then returns (-1,-1)):
'''def flin(d, x, default=-1):
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return (default, default)
    else:
        return (left, right)'''

# returns (b**p)%m 
'''def modpow(b,p,m):
    res=1
    b=b%m
    while(p):
        if p&1:
            res=(res*b)%m
        b=(b*b)%m
        p>>=1
    return res'''

# if m is a prime this can be used to determine (1//a)%m or modular multiplicative inverse of a number a
'''def mod_inv(a,m):
    return modpow(a,m-2,m)'''

# returns the ncr%m for (if m is a prime number) for very large n and r
'''def ncr(n,r,m):
    res=1
    if r==0:
        return 1
    if n-r<r:
        r=n-r
    p,k=1,1
    while(r):
        res=((res%m)*(((n%m)*mod_inv(r,m))%m))%m
        n-=1
        r-=1
    return res'''

# returns ncr%m (if m is a prime number and there should be a list fact which stores the factorial values upto n):
'''def ncrlis(n,r,m,fact):
    return (fact[n]*(mod_inv(fact[r],m)*mod_inv(fact[n-r],m))%m)%m'''

#count xor of numbers from 1 to n:
def xor1_n(n):
    d={0:n,1:1,2:n+1,3:0}
    return d[n&3]

def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def ddd(): return collections.defaultdict(collections.defaultdict(int))
 

# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
	newlines = 0
 
	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = "x" in file.mode or "r" not in file.mode
		self.write = self.buffer.write if self.writable else None
 
	def read(self):
			while True:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					if not b:
							break
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines = 0
			return self.buffer.read()
 
	def readline(self):
			while self.newlines == 0:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					self.newlines = b.count(b"\n") + (not b)
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines -= 1
			return self.buffer.readline()
 
	def flush(self):
			if self.writable:
					os.write(self._fd, self.buffer.getvalue())
					self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
	def __init__(self, file):
			self.buffer = FastIO(file)
			self.flush = self.buffer.flush
			self.writable = self.buffer.writable
			self.write = lambda s: self.buffer.write(s.encode("ascii"))
			self.read = lambda: self.buffer.read().decode("ascii")
			self.readline = lambda: self.buffer.readline().decode("ascii")
 

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections
#from collections import deque
#import math
#import time
#import itertools
#import timeit
#import random
#from bisect import bisect_left as bl
#from bisect import bisect_right as br
#from bisect import insort_left as il
#from collections import OrderedDict

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

Submission status: Accepted

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

l = [0]*n

x -= 1
y -= 1

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

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

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

Submission status: Accepted

Solution code:
N,X,Y = map(int,input().split())
result = [0 for x in range(N-1)]

for p in range(1,N) :
    #print("--------- p =",p)
    for q in range(p+1,N+1) :
        #print("--- q=",q)
        if (p < X) :
            if (q <= X) :
                result[(q-p)-1] += 1
            elif (X < q <= Y) :
                result[min(q-p,1+(Y-q)+(X-p)) - 1] += 1
            elif (Y < q) :
                result[((X-p)+1+(q-Y))-1] += 1
            else :
                print("error1")
        elif (X <= p <= Y) :
            if Y < q :
                result[min(q-p,(p-X)+1+(q-Y))-1] += 1
            elif (q <= Y) :
                result[min(q-p,(p-X)+1+(Y-q))-1]+=1
            else :
                print("error2")
        elif (Y < p) :
            result[q-p-1] += 1
        else :
            print("error3")
        #print(result)

#print(result)
for k in range(N-1) :
    print(result[k])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def f(i, j, X, Y):
  return min(j-i, abs(j - Y) + 1 + abs(i-X))
  
cnts = [0] * N
for i in range(1, N+1):
  for j in range(i+1, N+1):
    k = f(i, j, X, Y)
    cnts[k] += 1
for k in range(1, N):
  print(cnts[k])

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0 for i in range(N+1)]

def calc_goal(start,goal):
    if goal <= X:
        return goal-start
    if goal <= Y:
        if X >= start:
            return min(goal-start,X-start+Y-goal+1)
        else:
            return min(start-X+Y-goal+1,goal-start)
    else:
        if X >= start:
            return X-start+goal-Y+1
        else:
            return min(start-X+goal-Y+1,goal-start)

for i in range(1,N):
    for j in range(i+1,N+1):
        ans[calc_goal(i,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
cnt = [0]*n

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    print(N)
    dist = [0] * (N + 1)

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

    for k in range(2, N):
        print(dist[k])


main()

Submission status: Accepted

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

X,Y = X-1,Y-1

from collections import defaultdict
res = defaultdict(int)
for i in range(N):
  for j in range(N):
    ans = min(abs(j-i),
        abs(X-i)+1+abs(j-Y),
        abs(Y-i)+1+abs(j-X))
    res[ans]+=1
    
for i in range(1,N):
  print(res[i]//2)

Submission status: Accepted

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

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

Submission status: Accepted

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

dic = {i: 0 for i in range(1, n)}
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist = min(j - i, abs(i - x) + abs(j - y) + 1)
        dic[dist] += 1


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

Submission status: Accepted

Solution code:

from collections import deque
from collections import Counter
from collections import defaultdict
INF = int(1e9)
def main():
    n, x, y = map(int, input().split())
    x-=1
    y-=1
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[i].append(i+1)
        g[i+1].append(i)
    g[x].append(y)
    g[y].append(x)
    ans = defaultdict(int)
    q = deque()
    pns = []
    for i in range(n):
        dist = [INF for _ in range(n)]
        q.append(i)
        dist[i] = 0
        while len(q):
            node_s = q.popleft() 
            for j in range(len(g[node_s])):
                if dist[g[node_s][j]] != INF:
                    continue
                q.append(g[node_s][j])
                dist[g[node_s][j]] = dist[node_s] + 1
        for k in range(n): 
            pns.append(dist[k])
    
    ans = Counter(pns) 
    for k in range(1, n):
        print(ans[k]//2)
main()

Submission status: Accepted

Solution code:
def II():return int(input())
def MI():return map(int,input().split())
def LI():return list(MI())
def ok():print("Yes")
def ng():print("No");exit()

n,x,y=MI()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * (N - 1)
ans[0] = 1

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

for a in ans:
    print(a)

Submission status: Accepted

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

result = [0]*N
for i, j in combinations(range(1, N+1), 2):
    mins = min([j-i, abs(Y-j)+abs(X-i)+1])
    result[mins] += 1
    
for i in range(1, N):
    print(result[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, Y):
    ans = 0


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


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


    return ans


def main():
    N, X, Y = read_int_n()
    (slv(N, X, Y))

    # N = 2 * (10**3)
    # X = 1000
    # Y = 1500
    # (slv(N, X, Y))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = [0] *n
for ind1 in range(1,n+1):
    for ind2 in range(ind1+1,n+1):
        cur_dist = min(ind2-ind1, abs(x-ind1)+abs(y-ind2)+1)
        # print(ind1,ind2,cur_dist)
        cnt[cur_dist] += 1
# print(cnt)            
for k in range(1,n):
    print(cnt[k])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def II():return int(input())
def MI():return map(int,input().split())
def LI():return list(MI())
def ok():print("Yes")
def ng():print("No");exit()

n,x,y=MI()

ans=[0]*n

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

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

Submission status: Accepted

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

ans = [0] * (n-1)

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
N,X,Y = map(int,input().split())
ToltN=N*(N-1)/2
Dist=[[0 for i in range(N)] for i in range(N)]
c=[0]*N
for i in range(N):
    for j in range(i+1,N):
        MyDist=abs(i-(X-1))+abs(j-(Y-1))+1
        if MyDist<j-i:
            Dist[i][j]=MyDist
            c[MyDist-1]+=1
        else:
            Dist[i][j] = j-i
            c[j-i-1]+=1
for i in range(N-1):
    print(c[i])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    cnter = defaultdict(int)

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

mid = (X + Y + 1) * 0.5

# GUCHOKU
ans = [0] * N

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

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

Submission status: Accepted

Solution code:
N,X,Y = [int(i.strip()) for i in input().split(' ')]
X = X-1
Y = Y - 1
diff = (Y-X-1)//2
result = [0]*N
for i in range(N):
    for j in range(i+1,N):
        dist = min(j-i,abs(X-i)+abs(Y-j)+1)
        result[dist-1] += 1

L = len(result) - 1
for i,j in enumerate(result):
    if not i == L:
        print(j)

Submission status: Accepted

Solution code:
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,x,y=MI()
    to=[[] for _ in range(n)]
    for i in range(n-1):
        to[i].append(i+1)
        to[i+1].append(i)
    to[x-1].append(y-1)
    to[y-1].append(x-1)
    ans=[0]*n
    for i in range(n):
        q=deque()
        q.append(i)
        dist=[-1]*n
        dist[i]=0
        while q:
            u=q.popleft()
            for v in to[u]:
                if dist[v]!=-1:continue
                dist[v]=dist[u]+1
                ans[dist[v]]+=1
                q.append(v)
    for a in ans[1:]:
        print(a//2)

main()

Submission status: Accepted

Solution code:
from scipy.sparse.csgraph import dijkstra

def main():
    n,x,y=map(int,input().split())
    cost = [[0 for i in range(n)] for i in range(n)]
    #cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
    for i in range(1,n):
        cost[i-1][i] = 1
#        cost[i][i-1]=1
    cost[x-1][y-1]=1
    cost[y-1][x-1]=1
    res=tuple(dijkstra(tuple(cost), directed=False))
    ans = [0 for i in range(n)]
    for i in range(n):
        for j in range(i,n):
            ans[int(res[i][j])] += 1
 
    for i in range(1,n):
        print(ans[i])
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def dist(fr, to):
    return min(
        to - fr,
        abs(to - Y) + 1 + abs(fr - X),
        abs(fr - Y) + 1 + abs(to - X)
    )

cnt = [0] * N

ans = 0
for fr in range(1, N + 1):
    for to in range(fr + 1, N + 1):
        cnt[dist(fr, to)] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,x,y=INTM()
    z=y-x
    sc=y-x-1
    loop=y-x+1
    maxl=n-(y-x)+loop//2+1
    for i in range(1,n):
        ct=0
        if i<maxl:
            for j in range(1,n):
                if j+i<=x or j>=y:
                    if j+i<=n:
                        ct+=1
                else:
                    if j<=x:
                        if j+i+sc<=n:
                            ct+=1
                        temp=i-(x-j)
                        if temp>=2:
                            if loop>temp*2:
                                ct+=2
                            elif loop==temp*2:
                                ct+=1
                        else:
                            ct+=1
                        
                    else:
                        lpmin=min(y-j,+(j-x+1))
                        if lpmin==j-x+1:
                            if lpmin==y-j:
                                if lpmin+(n-y)>=i:
                                    ct+=1
                            else:
                                if lpmin>i:
                                    ct+=1
                                elif lpmin==i:
                                    ct+=2
                                else:
                                    if lpmin+(n-y)>=i:
                                        ct+=1
                                    
                                    if loop>i*2:
                                        ct+=2
                                    elif loop==i*2:
                                        ct+=1
                        else:
                            if lpmin+(n-y)>=i:
                                ct+=1
                #print(ct)
            print(ct)        
        else:
            print(ct)
                
        
if __name__ == '__main__':
    do()

Submission status: Accepted

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

    for i in dist:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import pprint
from itertools import chain
import collections
n, x, y = (int(each) for each in input().split(' '))

# table1 = [[0] * n for i in range(n)]
# table2 = [[0] * n for i in range(n)]
table = [[0] * n for i in range(n)]
# cntr = {}

# # 点iから点jまでの距離をテーブルにする

# # 抜け道を通らないルートの場合
# for i in range(n):
#     for j in range(n):
#         if j-i > 0:
#             table1[i][j] = j-i

# # 抜け道を通るルートの場合
# for i in range(n):
#     for j in range(n):
#         if j-i > 0:
#             table2[i][j] = abs(j-y+1)+abs(i-x+1)+1

# どちらか近いほうのルートが最短距離
for i in range(n):
    for j in range(i, n):
        if j-i > 0:
            table[i][j] = min(j-i, abs(j-y+1)+abs(i-x+1)+1)

# テーブルをflattenして数をかぞえる
cntr = collections.Counter(list(chain.from_iterable(table)))

# cntr = dict(cntr)
for each in range(1,n):
    print(cntr.get(each, 0))

Submission status: Accepted

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

Submission status: Accepted

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

dist_list = [0] * N

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

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

Submission status: Accepted

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

R = [0 for _ in range(N - 1)]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, X, Y = MI()
    d = defaultdict(int)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque as dq
input = sys.stdin.readline

N, X, Y = map(int, input().split())
dp = [[N] * N for _ in range(N)]
for x in range(N):
  Q = dq([x])
  dp[x][x] = 0
  while len(Q):
    p = Q.popleft()
    if p == X - 1:
      if dp[x][Y - 1] > dp[x][p] + 1:
        dp[x][Y - 1] = min(dp[x][Y - 1], dp[x][p] + 1)
        Q.append(Y - 1)
    if p == Y - 1:
      if dp[x][X - 1] > dp[x][p] + 1:
        dp[x][X - 1] = min(dp[x][X - 1], dp[x][p] + 1)
        Q.append(X - 1)
    if p + 1 < N:
      if dp[x][p + 1] > dp[x][p] + 1:
        dp[x][p + 1] = min(dp[x][p + 1], dp[x][p] + 1)
        Q.append(p + 1)
    if p - 1 >= 0:
      if dp[x][p - 1] > dp[x][p] + 1:
        dp[x][p - 1] = min(dp[x][p - 1], dp[x][p] + 1)
        Q.append(p - 1)
table = [0] * N
for i in range(N):
  for j in range(i, N): table[dp[i][j]] += 1

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