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: Runtime Error

Solution code:
n, x, y = input().split()
n, x, y = int(n), int(x)-1, int(y)-1
d = [[abs(i-j) for i in range(n)] for j in range(n)]
for i in range(x+1):
    for j in range(y, n):
        d[i][j] -= y-x-1
    for j in range(y-1, x+(y-x)//2, -1):
        d[i][j] = d[i][j+1]+1
for i in range(x+1, x+(y-x)//2):
    for j in range(y, n):
        d[i][j] -= i-x
    for j in range(y-1, y-(y-x)//4+1, -1):
        d[i][j] = d[i][j+1]+1
apar = [0 for i in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        apar[d[i][j]] += 1
for i in range(1, n):
    print(apar[i])

Submission status: Runtime Error

Solution code:
n, x, y = input().split()
n, x, y = int(n), int(x)-1, int(y)-1
d = [[abs(i-j) for i in range(n)] for j in range(n)]
for i in range(x+1):
    for j in range(y, n):
        d[i][j] -= y-x-1
    for j in range(y-1, x+(y-x)//2, -1):
        d[i][j] = d[i][j+1]+1
for i in range(x+1, x+(y-x)//2):
    for j in range(y, n):
        d[i][j] -= i-x
    for j in range(y-1, x+3*(y-x)//4, -1):
        d[i][j] = d[i][j+1]+1
apar = [0 for i in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        apar[d[i][j]] += 1
for i in range(1, n):
    print(apar[i])

Submission status: Runtime Error

Solution code:
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

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

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))

ans_l=[]

'''for i in range(n):
  d=dijkstra(g,indices=i,directed=False)
  ans_l+=list(d)'''

d=dijkstra(g,directed=False).astype(int)
ans_l=np.bincount(d.ravel(), minlength=n)//2

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

'''
for i in ans_l[1:]:
  print(i)
'''

Submission status: Runtime Error

Solution code:
import numpy as np

x, y, r ,b, n = input().split()
score_r = input().split()
score_b = input().split()
score_n = input().split()

score_r = score_r[-int(x):]
score_b = score_b[-int(y):]

scores = score_r + score_b + score_n
scores = [int(score)for score in scores]

print(np.array(scores[-(int(x)+int(y)):]).sum())

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
    for j in range(i + 1, n):
        dist1 = j - i
        dist2 = abs(X - i) + abs(Y - j) + 1
        ans[min(dis1, dist2)] += 1
print(*ans[1:], sep='\n')

Submission status: Runtime Error

Solution code:
n, x, y = map(int, input().split())
ans = [0] * (n-1)
for i in range(1, n+1):
    for j in range(1, n+1):
        if i < j
            # iとjを固定、rangeでi<jを表現
            d = min(j-i, abs(x-i)+abs(j-y)+1, abs(y-i)+abs(x-j)+1)
            # 長さを示すところに+１
            ans[d-1] += 1
print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
import sys
import queue
import numpy as np
def main():
    #t1=time.time()
    input=sys.stdin.readline
    n,x,y=map(int,input().split())
    edge=[]
    for i in range(int(n)):
        tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
        edge.append(tmp)
    edge[x-1][y-1]=1
    edge[y-1][x-1]=1
    np.array(edge)
    #t2=time.time()
    step=[0]*n#ある歩数の点の選び方をカウントする
    def bfs(start,graph,step):
        kyori={}#スタートからある点までの距離をある点をキーとして入れる
        que_check=[0]*n#queueに入ったかを記録する
        Tovis=queue.Queue()#探索待ちの点を入れるキュー
        Tovis.put(start)
        que_check[start]=1
        kyori[start]=0        
        while Tovis.empty()==False:            
            nex=Tovis.get()            
            for v in range(n):                
                tmp=graph[nex][v]
                if tmp!=-1:                    
                    if que_check[v]==1:
                        continue
                    Tovis.put(v)
                    que_check[v]=1
                    res=kyori[nex]+1
                    kyori[v]=res#点ｖまでの距離はその前に通った点までの距離+1
                    step[res]+=0.5#i->j j->iの二回数えてしまうので
    
    for i in range(n):
        bfs(i,edge,step)
        
    for i in range(1,len(step)):
        print(int(step[i]))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import queue
import time
import numpy as np
def main():
    #t1=time.time()
    input=sys.stdin.readline
    n,x,y=map(int,input().split())
    edge=[]
    for i in range(int(n)):
        tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
        edge.append(tmp)
    edge[x-1][y-1]=1
    edge[y-1][x-1]=1
    np.array(edge)
    #t2=time.time()
    step=[0]*n#ある歩数の点の選び方をカウントする
    def bfs(start,graph,step):
        kyori={}#スタートからある点までの距離をある点をキーとして入れる
        que_check=[0]*n#queueに入ったかを記録する
        Tovis=queue.Queue()#探索待ちの点を入れるキュー
        Tovis.put(start)
        que_check[start]=1
        kyori[start]=0        
        while Tovis.empty()==False:            
            nex=Tovis.get()            
            for v in range(n):                
                tmp=graph[nex][v]
                if tmp!=-1:                    
                    if que_check[v]==1:
                        continue
                    Tovis.put(v)
                    que_check[v]=1
                    res=kyori[nex]+1
                    kyori[v]=res#点ｖまでの距離はその前に通った点までの距離+1
                    step[res]+=0.5#i->j j->iの二回数えてしまうので
    
    for i in range(n):
        bfs(i,edge,step)
        if i==n-1:
     #       t3=time.time()
    for i in range(1,len(step)):
        print(int(step[i]))
    #t4=time.time()
    #t=[0,t2-t1,t3-t2,t4-t3,t4-t1]
    #print(t)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect
X,Y,A,B,C=map(int,input().split())

AList=list(map(int,input().split()))
BList=list(map(int,input().split()))
CList=list(map(int,input().split()))

AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)

alist = AList[0:X] + BList[0:Y] + CList
alist.sort(reverse=True)

print(int(sum(alist[:X+Y])))

Submission status: Runtime Error

Solution code:
N,X,Y=map(int,input().split())
X,Y=X-1,Y-1
ans=[0]*(N+1)
def search(s):
  global tmp,ans
  tmp[s]=0
  Next=[s+1]
  Vec=[1]
  if s==X:
    Next.extend([Y,Y])
    Vec.extend([1,-1])
  elif X<s<Y:
    Next.append(s-1)
    Vec.append(-1)
  subsearch(Next,Vec,s,1)
  for t in tmp[s:]:
    ans[t]+=1
  
def subsearch(Now,Vecnow,s,dis):
  if Now==[]:
    return
  global tmp
  Next=[]
  Vec=[]
  before=-1
  for n,v in zip(Now,Vecnow):
    if n>=N:
      continue
      
    if tmp[n]==-1:
      tmp[n]=dis
      Next.append(n+v)
      Vec.append(v)
      if n==X:
        Next.extend([Y,Y])
        Vec.extend([1,-1])
      before=n
    elif before==n:
      tmp[n]=min(dis,tmp[n])
      Next.append(n+v)
      Vec.append(v)
    else:
      tmp[n]=min(dis,tmp[n])
  subsearch(Next,Vec,s,dis+1)
      
  
for i in range(N-1):
  tmp=[-1]*N
  search(i)
  
for a in ans[1:-1]:
  print(a)

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
from scipy.sparse.csgraph._shortest_path import dijkstra, floyd_warshall, bellman_ford, johnson, shortest_path
from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

length = n
d = [1 for _ in range(n)]
i = list(range(0,n-1)) + [x]
j = list(range(1,n)) + [y]
# print(d,i,j,sep="\n")

graph = csr_matrix((d, (i, j)), shape=(n, n)) # 頂点i,jはゼロスタートである必要ある
# print(type(csr),csr,sep="\n")

#返り値は各頂点間の距離の値を含んだ隣接行列(float64型のnp.array)
dist = dijkstra(graph, directed=False).astype(int)
# dist = shortest_path(graph, directed=False).astype(int)
# print(type(dist),dist,sep="\n")

dist = dist.ravel() #配列の一次元化
# print(type(dist),dist,sep="\n")

ans = np.bincount(dist, minlength=n) // 2  #bincountは[0の個数,1の個数,2の個数…nの個数]を返す
# print(type(ans),ans,sep="\n")

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
from scipy.sparse.csgraph._shortest_path import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

length = n
d = [1 for _ in range(n)]
i = list(range(0,n-1)) + [x]
j = list(range(1,n)) + [y]
# print(d,i,j,sep="\n")

graph = csr_matrix((d, (i, j)), shape=(n, n)) # 頂点i,jはゼロスタートである必要ある
# print(type(csr),csr,sep="\n")

#返り値は各頂点間の距離の値を含んだ隣接行列(float64型のnp.array)
dist = shortest_path(graph, directed=False).astype(int)
# dist = dijkstra(graph, directed=False).astype(int)
# print(type(dist),dist,sep="\n")

dist = dist.ravel() #配列の一次元化
# print(type(dist),dist,sep="\n")

ans = np.bincount(dist, minlength=n) // 2  #bincountは[0の個数,1の個数,2の個数…nの個数]を返す
# print(type(ans),ans,sep="\n")

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

Submission status: Runtime Error

Solution code:

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

# N = 2000
# X = 100
# Y = 1900
# X -= 1
# Y -= 1


# @profile
def main(N, X, Y):
    ans = [0]*N
    for sv in range(N):
        # dist[v] = dist from sv to v
        dist = [float("inf")]*N
        last_visited = []
        dist[sv] = 0
        last_visited.append(sv)
        while last_visited:
            next_last_visited = []
            for v in last_visited:
                d = dist[v]
                if v+1 < N and dist[v+1] == float("inf"):
                    dist[v+1] = d+1
                    next_last_visited.append(v+1)
                if v-1 >= 0 and dist[v-1] == float("inf"):
                    dist[v-1] = d+1
                    next_last_visited.append(v-1)
                if v == X and dist[Y] == float("inf"):
                    dist[Y] = d+1
                    next_last_visited.append(Y)
                if v == Y and dist[X] == float("inf"):
                    dist[X] = d+1
                    next_last_visited.append(X)
            # print(last_visited, next_last_visited)
            last_visited = next_last_visited
        # print(dist)
        for d in dist:
            ans[d] += 1

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


main(N, X, Y)

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

length = n
d = [1 for _ in range(n)]
i = list(range(0,n-1)) + [x]
j = list(range(1,n)) + [y]
# print(d,i,j,sep="\n")

graph = csr_matrix((d, (i, j)), shape=(n, n)) # 頂点i,jはゼロスタートである必要ある
# print(type(csr),csr,sep="\n")

#返り値は各頂点間の距離の値を含んだ隣接行列(float64型のnp.array)
dist = shortest_path(graph, directed=False).astype(int)
# dist = dijkstra(graph, directed=False).astype(int)
# print(type(dist),dist,sep="\n")

dist = dist.ravel() #配列の一次元化
# print(type(dist),dist,sep="\n")

ans = np.bincount(dist, minlength=n) // 2  #bincountは[0の個数,1の個数,2の個数…nの個数]を返す
# print(type(ans),ans,sep="\n")

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0 for _ in range(N)]
    for sv in range(N):
        dist = [INF for _ in range(N)]
        q = deque([])

        def push(v, d):
            if dist[v] != INF: return
            dist[v] = d
            q.append(v)

        push(sv, 0)

        while q:
            sv = q.popleft()
            d = dist[sv]
            if sv > 0:
                push(sv-1, d+1)
            if sv < N-1:
                push(sv+1, d+1)
            if sv == X:
                push(Y, d+1)
            if sv == Y:
                push(X, d+1)

        for d in dist:
            ans[d] += 1

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

Submission status: Runtime Error

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

# N = 5
# X = 2
# Y = 4

ans = [0]*N

for sv in range(N):
    # dist[v] = dist from sv to v
    dist = [float("inf")]*N
    last_visited = []
    dist[sv] = 0
    last_visited.append(sv)
    while last_visited:
        for v in last_visited:
            next_last_visited = []
            if v+1 < N and dist[v+1] == float("inf"):
                dist[v+1] = dist[v]+1
                next_last_visited.append(v+1)
            if v-1 >= 0 and dist[v-1] == float("inf"):
                dist[v-1] = dist[v]+1
                next_last_visited.append(v-1)
            if v == X-1 and dist[Y-1] == float("inf"):
                dist[Y-1] = dist[v]+1
                next_last_visited.append(Y-1)
            if v == Y-1 and dist[X-1] == float("inf"):
                dist[X-1] = dist[v]+1
                next_last_visited.append(X-1)
            # print(last_visited, next_last_visited)
            last_visited = next_last_visited
    for d in dist:
        ans[d] += 1

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

Submission status: Runtime Error

Solution code:
# = map(int, input().split())
# = list(map(int, input().split()))
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = ()
for i in range(n):
    for j in range(i+1, n):
        a = min([j-i, abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1]) 
        ans.append(a)
ans = (str(l) for l in ans)

for k in range(1, n):
    finalans=ans.count(str(k))
    print(finalans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import itertools

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

pos = [i for i in range(1,N+1)]
ways = list(itertools.combinations(pos,2))

dist_l = [min(abs(i-j), abs(i - X) + 1 + abs(Y - j)) for i,j in ways]

dic = collections.Counter(dist_l)
for i in range(1,N):
    print(dic[i])

Submission status: Runtime Error

Solution code:
import copy
scopy = copy.deepcopy
total = n * (n -1) // 2
lens = []
lappend = lens.append

k = 1
s = set([(i, i+1) for i in range(1,n)])
sadd = s.add
sadd((x, y))
lappend(len(s))
s_prev = set()
prev = set()
# print(f"{k:-^80}")
# print(f"sum      ={s}")
# print(f"sum_prev ={s_prev}")
# print(f"prev     ={prev}")
# print(f"now      ={s-s_prev}")

for k in range(2, n+1):
    for a in prev:
        if a[1] == x:
            sadd((a[0], y))
        elif a[1] == y and a[0] != x:
            t = (a[0], x) if a[0] < x else (x, a[0])
            sadd(t)
        if a[1] < n:
            sadd((a[0], a[1]+1))
#     print(f"{k:-^80}")
#     print(f"sum      ={s}")
#     print(f"sum_prev ={s_prev}")
#     print(f"prev     ={prev}")
#     print(f"now      ={s-s_prev}")
    lappend(len(s)-len(s_prev))
    s_prev = scopy(s)
    prev = s_prev -prev
#     if len(s) == total:
#         break
for l in lens[1:]:
    print(l)

Submission status: Runtime Error

Solution code:
de main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline
    
    
    def bfs(v):
        dist = [f_inf for _ in range(n)]
        dist[v] = 0
        q = deque()
        q.append(v)
        while q:
            u = q.popleft()
            for nv in tree[u]:
                if dist[nv] == f_inf:
                    dist[nv] = dist[u] + 1
                    q.append(nv)
        for d in dist:
            res[d] += 1
    
    
    n, x, y = map(int, input().split())
    
    tree = [[] for _ in range(n)]
    for i in range(n - 1):
        tree[i].append(i + 1)
        tree[i + 1].append(i)
    tree[x - 1].append(y - 1)
    tree[y - 1].append(x - 1)
    
    f_inf = float("inf")
    res = [0 for _ in range(n)]
    for i in range(n):
        bfs(i)
    
    for i in range(1, n):
        print(res[i] // 2)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# TODO: P4 Fix TLE (probably the answer itself is correct)

import sys
sys.stdin = open('input.txt')

from collections import deque

class Node:
    def __init__(self, num=None):
        self.num = num
        self.next = []
        self.visited = False

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

nodes = []
q = deque()
ans = [0] * n

x -= 1
y -= 1

for i in range(n):
    node = Node(i)
    nodes.append(node)

# 無向グラフ
for i in range(n):
    node = nodes[i]
    if i == 0:
        node.next.append(nodes[i+1])
    elif i == n-1:
        node.next.append(nodes[i-1])
    else:
        node.next.append(nodes[i-1])
        node.next.append(nodes[i+1])
    if i == x:
        node.next.append(nodes[y])
    elif i == y:
        node.next.append(nodes[x])

# Select the initial node
for i in range(n):
    # Initialize
    dist = [0] * n
    visited = [False] * n

    # add the initial node
    q.append(nodes[i])

    # BFS
    while len(q) > 0:
        node = q.popleft()
        visited[node.num] = True

        if node.next is not None:
            for next_node in node.next:
                if not visited[next_node.num]:
                    dist[next_node.num] = dist[node.num] + 1
                    visited[next_node.num] = True
                    q.append(next_node)
    for i in range(n):
        ans[i] += dist.count(i)

#  Remove duplications -(1,2), (2,1)
for i in range(i):
    ans[i] //= 2

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

Submission status: Runtime Error

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

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

mindcnt = [0] * N
for i in range(N):
    for j in range(i+1, N):
        mind = mind[i][j]
        mindcnt[mind] += 1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

g = [[]  for i in range(N)]
for i in range(N):
    u = i
    v = i + 1
    if v < 5:
        g[u].append(v)
        g[v].append(u)

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

from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
    d = [False] * N
    que = deque()
    #for j in g[i]:
    que.append(i)
    d[i] = True
    dis[i][i] = 0
    pre = i
    while que:
        p = que.popleft()

        for k in g[p]:
            if d[k]:
                continue
            else:
                d[k] = True
                que.append(k)
                dis[i][k] = dis[i][p] + 1
                dis[k][i] = dis[i][p] + 1
                count[dis[i][k] - 1] += 1 
                #count[dis[k][i] - 1] += 1
        pre = p

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

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

Submission status: Runtime Error

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


dic = {}

X = X - 1
Y = Y - 1

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

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1


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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dic = defaultdict(int)

X = X - 1
Y = Y - 1

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

        dic[v] += 1


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

Submission status: Runtime Error

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

k = [0 for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j-i, abs(x-i)+1+abs(j-y))
        if dist < n:
            k[dist] += 1
[for i in range(1, len(k)):
    print(k[i])]

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy.sparse
N,X,Y = (int(x) for x in input().split())
lil = scipy.sparse.lil_matrix((N, N), dtype=int)
for i in range(N-1):
    lil[i, i+1] = 1
    lil[i+1, i] = 1
lil[X-1, Y-1] = 1
lil[Y-1, X-1] = 1
lil2 = scipy.sparse.csgraph.shortest_path(lil)
for i in range(1,N):
    print((np.count_nonzero(lil2 == i)) // 2)

Submission status: Runtime Error

Solution code:
import numpy as np
N, X, Y = map(int, input().split())
dist = [0] * (N + 1)
cnt = [0] * (N + 1)

d = [[abs(j - i) for j in range(N)] for i in range(N)]
d[X - 1][Y - 1] = 1
d[Y - 1][X - 1] = 1


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    # for k in range(N):
    #     for i in range(N):
    #         for j in range(N):
    #             d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # return d
    return [min(d[i][j], d[i][k] + d[k][j]) for k in range(N) for i in range(N) for j in range(N):]
                

d = warshall_floyd(d)
count = np.bincount(np.array(d).flatten(), minlength=N)
count = count[1:] // 2
print(*count, sep='\n')

Submission status: Runtime Error

Solution code:
import numpy as np
N, X, Y = map(int, input().split())
dist = [0] * (N + 1)
cnt = [0] * (N + 1)

INF = 10**10 + 9

# d = [[INF] * N for _ in range(N)]
d = []
for i in range(N)
    
d = [j - i for i in range(N) for j in range(i, N)]
d = []
for i in range(N):
    tmp = [j - i for j in range(i, N)]
    d.append(tmp)
# d[i][j] = j - i
# d[j][i] = j - i
print('d', d)
exit()
d[X - 1][Y - 1] = 1
d[Y - 1][X - 1] = 1


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


d = warshall_floyd(d)
count = np.bincount(np.array(d).flatten(), minlength=N)
count = count[1:] // 2
print(*count, sep='\n')

Submission status: Runtime Error

Solution code:
    from collections import defaultdict as dd
    N,X,Y = map(int,input().split())
     
    pdic = dd(lambda:0)
     
    # count = 0
     
    for i in range(1,N):
        for j in range(i+1,N+1):
            
    #         count += 1
            
            # no shortcut
            d1 = j-i
            # with shortcut
            i2x = abs(X-i)
            y2j = abs(Y-j)
            d2 = i2x + y2j + 1
            
            dist = min(d1,d2)
            pdic[str(dist)] += 1
            
    for n in range(1,N):
        print(pdic[str(n)])
        
    # print("count:",count)

Submission status: Runtime Error

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

print(N)

for k in range(2, N):
    cnt = 0
    for i in range(1, N + 1):
        if X < i and i + k <= N:
            cnt += 1
        if i <= X and X - i + 1 == k:
            cnt += 2
        if i <= X and X - i + 2 <= k:
            if Y - (k - (X - i + 1)) > i + k:
                cnt += 2
            if Y - (k - (X - i + 1)) == i + k:
                cnt += 1
            if Y + (k - (X - i + 1)) <= N:
                cnt += 1
        if i + k <= X:
            cnt += 1
        if X < i and i+k < Y and:
            if i + k > Y-(k-(i-X+1)) and k-(i-X+1) >= 0:
                cnt += 1
                if Y+(k-(i-X+1)) <= N:
                    cnt += 1
    print(cnt)

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)[:x]
q=sorted(list(map(int,input().split())),reverse=True)[:y]
r=list(map(int,input().split()))
print(sum(sorted(p+q+r,reverse=True)[:x+y]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

x-=1
y-=1

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

c=Counter(dist)
for i in range(1,n):
  print(c[i]

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    --x;
    --y;
    vector<int> c(n - 1, 0);
    rep(i, n)
    {
        rep(j, n)
        {
            if (i == j)
                continue;
            // int idx = 1;
            int idx = min(
                abs(i - j),
                abs(x - i) + 1 + abs(y - j));
            idx = min(idx,
                      abs(y - i) + 1 + abs(x - j));
            --idx;
            ++c.at(idx);
        }
    }
    rep(i, n - 1)
    {
        printf("%d\n", c.at(i) / 2);
    }
}

Submission status: Runtime Error

Solution code:
from collections import deque
N,R1,R2 = map(int, input().split())
graph = [deque([]) for _ in range(N-1)]
count={}
for i in range(N-1):
    count[i+1] = 0


for i in range(N-1):
    if i != R1-1:
        graph[i].append(i+1)
    else:
        graph[i].append(i+1)
        graph[i].append(R2-1)

def dfs(v, counter):
    global count
    gs=[]
    for g in graph[v]:
        count[counter]+=1
        gs.append(g)
    gsm = max(gs)
    if gsm < N-1:
        dfs(gsm, counter+1)
    else:
        return

for i in range(N-1):
    dfs(i, 1)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
p.reverse()
q.reverse()
p=p[:X]
q=q[:Y]
r=r[:max(X,Y)]
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=p[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range(X+Y):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
 
  if(i<X):
      sum1+=p[i]
      sum2+=c[i]
  if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
    
if(red<=X and green<=Y):
  print(d)
elif(red>X):
  print(sum1)
elif(green>Y):
  print(sum2)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
N = a[0]
X = a[1]
Y = a[2]
ans = []
for k in range(1,N+1):
  ans[k] = N-k

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

for dist in ans:
  print(dist)