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:
def main():
    import itertools
    n,x,y = map(int,input().split())
    stat = [i for i in range(n)]
    ans = [0 for i in range(n-1)]
    for s in itertools.combinations(stat,2):
        d = min(s[1]-s[0],abs(x-1-s[0])+1+abs(y-1-s[1]))
        ans[d-1] += 1
    for i in range(len(ans)):
        print(ans[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

def solve(N, X, Y):
    def bfs(v):
        q = [v]
        Distance = [-1] * (N+1)
        Distance[v] = 0
        distance = 1
        while q:
            q_new = []
            for v in q:
                u = v-1
                if u >= 1 and Distance[u] == -1:
                    Distance[u] = distance
                    q_new.append(u)
                u = v+1
                if u <= N and Distance[u] == -1:
                    Distance[u] = distance
                    q_new.append(u)
                if v == X:
                    u = Y
                    if Distance[u] == -1:
                        Distance[u] = distance
                        q_new.append(u)
                elif v == Y:
                    u = X
                    if Distance[u] == -1:
                        Distance[u] = distance
                        q_new.append(u)
            distance += 1
            q = q_new
        return Distance

    Ans = np.zeros(N, dtype=np.int64)
    for v in range(1, N+1):
        Distance = bfs(v)
        for d in Distance[v+1:]:
            Ans[d] += 1
    return Ans[1:]

numba_compile([
    [solve, "i8[:](i8,i8,i8)"]
])

N, X, Y = map(int, input().split())
Ans = solve(N, X, Y)
print("\n".join(map(str, Ans.tolist())))

Submission status: Accepted

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

pairs = [set() for _ in range(N)]

graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
    graph[i+1].append(i)

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

distCount = [0 for _ in range(N)]

for i in range(N):

    dist = [0 for _ in range(N)]
    visited = [False for _ in range(N)]
    queue = deque()
    queue.append(i)
    visited[i] = True

    #bfs
    while len(queue) > 0:
        now = queue.popleft()
        for adj in graph[now]:
            if visited[adj]:
                continue
            queue.append(adj)
            dist[adj] = dist[now] + 1
            visited[adj] = True


    for i in range(N):
        distCount[dist[i]] += 1

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

Submission status: Accepted

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

ans = {i:0 for i in range(1, n)}

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

for k in range(1, n):
    print(ans[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):
    for j in range(i+1, N):
        if i == j:
            continue
        cnt = min(abs(i-j), abs(X-i)+abs(j-Y)+1, abs(j-X)+abs(Y-i)+1)
        ans[cnt-1] += 1

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

Submission status: Accepted

Solution code:
def solve():
    N,X,Y = [int(i) for i in input().split()]
    distance_cnt = {}
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            distance = min(j-i, abs(X-i)+abs(Y-j)+1)
            distance_cnt[distance] = distance_cnt.get(distance, 0) + 1
    for i in range(1, N):
        print(distance_cnt.get(i, 0))

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    dist = [-1]*n
    que = deque([i])
    dist[i] = 0
    ans[0] += 1
    while que:
        v = que.popleft()
        d = dist[v]
        for w in g[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            ans[d+1] += 1
            que.append(w)

n, x, y = MAP()
x -= 1
y -= 1
g = [[] for i 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 = [0]*(n+1)
for i in range(n):
    bfs()
for i in range(1,n):
    print(ans[i]//2)

Submission status: Accepted

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

kyori=[0]*10**7

import itertools
for seq in itertools.combinations(range(1,n+1),2):
    kyori_niten=seq[1]-seq[0]
    kyori_niten=min(kyori_niten,abs(x-seq[0])+abs(y-seq[1])+1)

    kyori[kyori_niten]+=1

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

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    n, x, y = getList()
    ans = [0 for i in range(n+1)]
    for i in range(1, n+1):
        for j in range(1, n+1):
            a = abs(i - j)
            b = abs(i - x) + abs(j - y) + 1
            c = abs(i - y) + abs(j - x) + 1
            ans[min(a,b,c)] += 1
            # print(i, j, min(a,b,c))
    for i in range(1, n):
        print(ans[i]// 2)
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

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

    for i in range(1,N):
        for j in range(i+1,N+1):
            if i==j:
                continue
            if (i<=X and j>=Y):
                route=j-i-(Y-X)+1
            else:
                route=min(j-i,abs(X-i)+abs(Y-j)+1)

            res[route-1]+=1

    for r in res:
        print(r)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
ans = []
for i in range(n-1):
    ans.append(0)
for m in range(1,n):
    for a in range(1,n-m+1):
        d = abs(m - x)+ abs(m + a - y) +1
        if a <= d:
            ans[a-1] = ans[a-1] + 1
        else:
            ans[d-1] = ans[d-1] + 1
for l in ans:
    print(l)

Submission status: Accepted

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

dic = {}
for i in range(1, n):
  for j in range(i + 1, n + 1):
    a = j - i
    b = abs(x - i) + 1 + abs(j - y)
    c = abs(y - i) + 1 + abs(j - x)
    l = min(a, b, c)
    if l not in dic.keys():
      dic[l] = 1
    else:
      dic[l] += 1
for i in range(1, n):
  print(dic.get(i, 0))

Submission status: Accepted

Solution code:
from collections import deque
N, X, Y = map(int, input().split())
cnt_l = [0]*N

def bfs(start):
    d = deque()
    d.append(start)
    step_cnts = [-1]*(N+1)
    step_cnts[start] = 0
    while(d):
        i = d.popleft()
        cnt = step_cnts[i]
        if(i==X):
            next = (i-1, Y, i+1)
        elif (i==Y):
            next = (i-1, X, i+1)
        else:
            next = (i-1, i+1)
        cnt += 1
        for j in next:
            if(j<1 or N<j):
                continue
            if(step_cnts[j]!=-1):
                continue
            d.append(j)
            step_cnts[j] = cnt
            cnt_l[cnt] += 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections as cl


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 main():
    n, x, y = MI()
    ans = [0] * (n)

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

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


main()

Submission status: Accepted

Solution code:

from collections import defaultdict

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

ctr = defaultdict(int)
for u in range(1, N):
    for v in range(u + 1, N + 1):
        d = min(v - u, abs(u - X) + 1 + abs(Y - v))
        ctr[d] += 1

for n in range(1, N):
    print(ctr[n])

Submission status: Accepted

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

    cnt_dict={}
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i==j:
                continue
            tmp1 = j-i
            tmp2 = abs(X-i)+abs(Y-j)+1
            cnt_dict[min(tmp1,tmp2)] = cnt_dict.get(min(tmp1,tmp2),0)+1

    for i in range(1,N):
        if i not in cnt_dict:
            print(0)
        else:
            print(cnt_dict[i])
            
if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

# In[21]:


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


# In[24]:


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


# In[ ]:

Submission status: Accepted

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

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

for i in ls[1:n]:
    print(i)

Submission status: Accepted

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

x -= 1
y -= 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict

n,x,y=map(int,input().split())
x-=1
y-=1
dic=defaultdict(int)
for i in range(n-1):
    for j in range(i+1,n):
        temp=min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
        dic[temp]+=1
for i in range(1,n): print(dic[i])

Submission status: Accepted

Solution code:
"""
    Satwik_Tiwari ;) .
    30th july , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================
#fast I/O region
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")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def djkistra(g,st,dist): #g contains b,dist(st to b) and dist is initiaalised by 10**9 initiallly
    pq = []
    dist[st] = 0
    pq.append([0,st])
    while(len(pq) != 0):
        curr = heappop(pq)[1]
        for i in range(0,len(g[curr])):
            b = g[curr][i][0]
            w = g[curr][i][1]
            if(dist[b] > dist[curr] + w):
                dist[b] = dist[curr]+w
                pq.append([dist[b],b])

def solve():
    n,x,y = sep()
    graph = [[] for i in range(n)]
    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])

    cnt = [0]*(n)
    for i in range(n):
        dist = [10**9]*n
        djkistra(graph,i,dist)
        # print(dist)
        for j in range(len(dist)):
            cnt[dist[j]]+=1
    for i in range(1,n):
        print(cnt[i]//2)











testcase(1)
# testcase(int(inp()))

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

import networkx as nx
n,x,y = inpm()
x -= 1
y -= 1
if x > y:
    x,y = y,x

d = np.zeros((n,n),int)
ans = np.zeros(n,int)
for i in range(n):
    for j in range(i+1,n):
        a = j - i
        b = abs(x - i) + abs(j - y) + 1
        ans[min(a,b)] += 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
x -= 1
y -= 1
for i in range(n-1):
    for j in range(i+1, n):
        # print("DFGH")
        ans[min(j-i, abs(x-i)+abs(y-j)+1)] += 1

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

Submission status: Accepted

Solution code:
N,X,Y=[int(s) for s in input().split()]
ans=[0 for i in range(N)]
def distance(i,j):
  return min([j-i,abs(j-Y)+abs(i-X)+1])
  
for i in range(1,N):
  for j in range(i+1,N+1):
    d=distance(i,j)
    ans[d]+=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):
    dis = min(j-i,abs(x-i)+1+abs(j-y))
    cnt[dis] += 1
for i in range(1,n):
  print(cnt[i])

Submission status: Accepted

Solution code:
import sys

def main():
  n, x, y = map(int, sys.stdin.buffer.readline().split())
  L = [0] * n
  for i in range(1, n):
    for j in range(i + 1, n + 1):
      d = j - i
      if i <= x and y <= j:
        d -= y - x - 1
      elif i <= x and x < j < y:
        d = min(d, x - i + y - j + 1)
      elif x < i < y and y <= j:
        d = min(d, i - x + j - y + 1)
      elif x < i and j < y:
        d = min(d, i - x + y - j + 1)
      L[d] += 1
  for a in L[1:]:
    print(a)

main()

Submission status: Accepted

Solution code:
n,x,y=map(int,input().split())
edge=[None]*n
edge[0]=[1]
edge[n-1]=[n-2]
for i in range(1,n-1):
    edge[i]=[i-1,i+1]
edge[x-1].append(y-1)
edge[y-1].append(x-1)
ans=[0]*n

from collections import deque
def bfs(start):
    q=deque([start])
    d=[None]*n
    d[start]=0
    while q:
        v=q.popleft()
        for nv in edge[v]:
            if d[nv]==None:
                d[nv]=d[v]+1
                q.append(nv)
    for i in d:
        ans[i]+=1

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

Submission status: Accepted

Solution code:
N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
    if i>j:
        return dist(j,i)
    if i==j:
        return 0
    if i<X:
        if j<X:
            return j-i
        if X<=j and j<=Y:
            return min(j-i,(X-i)+1+(Y-j))
        if Y<j:
            return (X-i)+1+(j-Y)
    if X<=i and i<=Y:
        if j<=Y:
            return min(j-i,(i-X)+1+(Y-j))
        if Y<j:
            return min((i-X)+1+(j-Y),j-i)
    if Y<i:
        return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans[dist(i,j)]+=1
for k in range(1,N):
    print(ans[k])

Submission status: Accepted

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

ans_dict={}
for n in range(1,N):
    ans_dict[n]=0
    
for n1 in range(1,N+1):
    for n2 in range(n1+1,N+1):
        ans_1 = abs(n1-n2)
        ans_2 = abs(n1-X)+abs(n2-Y)+1
        ans_3 = abs(n2-X)+abs(n1-Y)+1
        
        ans=min(ans_1,ans_2,ans_3)
        ans_dict[ans]+=1
        

for k in ans_dict.keys():
    print(ans_dict[k])

Submission status: Accepted

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

count = [0] * (N-1)


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


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

Submission status: Accepted

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

count = [0] * (N-1)


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


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

Submission status: Accepted

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

count = [0] * (N-1)


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


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

Submission status: Accepted

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

count = [0] * (N-1)


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


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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

count = {}
for k in range(1,n):
    count[k] = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

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

ans = [0] * (N + 1)

def push(q, dist, index, dist_v):
    if dist[index] != -1:
        return
    q.appendleft(index)
    dist[index] = dist_v

for i in range(N):
    q = deque()
    dist = [-1] * N
    push(q, dist, i, 0)
    while len(q) > 0:
        v = q.pop()
        d = dist[v]
        if v - 1 >= 0: push(q, dist, v - 1, d + 1)
        if v + 1 < N: push(q, dist, v + 1, d + 1)
        if v == X: push(q, dist, Y, d + 1)
        if v == Y: push(q, dist, X, d + 1)
    for j in range(N):
        ans[dist[j]] += 1

for i in range(N):
    ans[i] //= 2

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

Submission status: Accepted

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


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

  dic = defaultdict(int)
  for l in range(1, N):
    for r in range(l+1, N+1):
      spath = r - l
      if l <= X and Y <= r:
        spath -= (Y-X-1)
      elif l <= X and X < r <= Y:
        spath = min(spath, X-l+1+Y-r)
      elif X <= l < Y and Y <= r:
        spath = min(spath, l-X+1+r-Y)
      elif X < l < Y and X < r < Y:
        spath = min(spath, l-X+1+Y-r)
      dic[spath] += 1

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


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
n,x,y = map(int, open(0).read().split())

x,y = sorted([x,y])

def calc(a,b):
    a,b = sorted([a,b])
    return min(b-a, abs(b-y)+1+abs(x-a))

ans = [0]*(n-1)

from itertools import combinations

for a,b in combinations(range(1,n+1),2):
    ans[calc(a,b)-1] += 1

for c in ans:
    print(c)

Submission status: Accepted

Solution code:
from collections import deque

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

ans = [0] * n
for i in range(1, n + 1):
    seen = [-1] * (n + 1)
    seen[i] = 0
    q = deque()
    q.append(i)
    while len(q) > 0:
        v = q.popleft()
        ans[seen[v]] += 1
        nv = v - 1
        if nv >= 1 and seen[nv] == -1:
            q.append(nv)
            seen[nv] = seen[v] + 1
        nv = v + 1
        if nv <= n and seen[nv] == -1:
            q.append(nv)
            seen[nv] = seen[v] + 1
        if v == x and seen[y] == -1:
            q.append(y)
            seen[y] = seen[v] + 1
        if v == y and seen[x] == -1:
            q.append(x)
            seen[x] = seen[v] + 1
for v in ans[1:]:
    print(v // 2)