Datasets:
output_description
stringlengths 15
956
 submission_id
stringlengths 10
10
 status
stringclasses 3
values  problem_id
stringlengths 6
6
 input_description
stringlengths 9
2.55k
 attempt
stringlengths 1
13.7k
 problem_description
stringlengths 7
5.24k
 samples
stringlengths 2
2.72k


For each query i in order of input, print a line containing the substring of
f(A_i, B_i) from position C_i to position D_i (1based).
* * *  s755719340  Wrong Answer  p03466  Input is given from Standard Input in the following format:
Q
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_Q B_Q C_Q D_Q  import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8
from numba.types import Omitted
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, i8), cache=True)
def find_min_length(a, b):
if a < b:
a, b = b, a
return (a + b) // (b + 1)
@njit((i8, i8, i8, i8), cache=True)
def f(a, b, c, d):
L = find_min_length(a, b)
ret = ""
def test(a, b, L):
# ...B の直後に A を a 個、B を b 個置けるかどうか
ok = a >= 0 and b >= 0
if a == 0:
ok = ok and (b <= L  1)
else:
ok = ok and (a <= L * (b + 1))
ok = ok and (1 + b <= L * (a + 1))
return ok
def add(s, x, t, y, n):
# 文字列に (s*x + t*y)*n を追加
nonlocal c, d, ret
if (x + y) * n < c:
c = (x + y) * n
d = (x + y) * n
return
m = (c  1) // (x + y)
c = m * (x + y)
d = m * (x + y)
n = m
while n and c <= d:
if d <= x:
ret += s * (d  c + 1)
d = 0
return
if 1 <= c <= x:
ret += s * (x  c + 1)
c = x + 1
ret += t * (min(d, x + y)  c + 1)
c = 1
d = x + y
n = 1
# AAABAAAB と n セット並べてしまって大丈夫かどうか
l, r = 0, b + 100
while l + 1 < r:
m = (l + r) >> 1
a1, b1 = a  L * m, b  m
if test(a1, b1, L):
l = m
else:
r = m
n = l
if n == 0:
add("B", 1, "A", 0, 1)
b = 1
else:
add("A", L, "B", 1, n)
a = L * n
b = n
# 次に、A^kB
l, r = 0, L
while l + 1 < r:
m = (l + r) // 2
if test(a  m, b  1, L):
l = m
else:
r = m
k = l
if k:
add("A", k, "B", 1, 1)
a = k
b = 1
# 以降は、Aは高々ひとつずつ
if not a:
add("B", b, "A", 0, 1)
return ret
# B^kA、kはなるべく少なく
l, r = 1, L  1
while l + 1 < r:
m = (l + r) // 2
if test(a  1, b  m, L):
r = m
else:
l = m
if k >= 0:
add("B", k, "A", 1, 1)
a = 1
b = k
# B^LA をいくつか
n = min(b // L, a)
add("B", L, "A", 1, n)
a = n
b = n * L
add("B", b, "A", 0, 1)
return ret
ABCD = np.array(read().split(), np.int64)[1:]
for a, b, c, d in ABCD.reshape(1, 4):
print(f(a, b, c, d))
 Statement
Let f(A, B), where A and B are positive integers, be the string satisfying the
following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly B letters `B`;
* The length of the longest substring of f(A, B) consisting of equal letters (ex., `AAAAA` or `BBBB`) is as small as possible under the conditions above;
* f(A, B) is the lexicographically smallest string satisfying the conditions above.
For example, f(2, 3) = `BABAB`, and f(6, 4) = `AABAABAABB`.
Answer Q queries: find the substring of f(A_i, B_i) from position C_i to
position D_i (1based).  [{"input": "5\n 2 3 1 5\n 6 4 1 10\n 2 3 4 4\n 6 4 3 7\n 8 10 5 8", "output": "BABAB\n AABAABAABB\n A\n BAABA\n ABAB"}] 
For each query i in order of input, print a line containing the substring of
f(A_i, B_i) from position C_i to position D_i (1based).
* * *  s422209750  Runtime Error  p03466  Input is given from Standard Input in the following format:
Q
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_Q B_Q C_Q D_Q  for t in range(int(input())):
a,b,c,d=map(int,input().split(' '));l,x,y,o=(a+b)//(min(a,b)+1),0,0,""
if a*l<=b:y=a+b
elif b*l<=a:x=a+b
else:x,y=(a*lb)//(l1),(b*la)//(l1)
for i in range(c,d+1):o+="AB"[i%(l+1)==0] if i<=x else "BA"[(a+bi+1)%(l+1)==0] if a+bi+1<=y else "AB"[ax+x//(l+1)y//(l+1)==0]
print(o)  Statement
Let f(A, B), where A and B are positive integers, be the string satisfying the
following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly B letters `B`;
* The length of the longest substring of f(A, B) consisting of equal letters (ex., `AAAAA` or `BBBB`) is as small as possible under the conditions above;
* f(A, B) is the lexicographically smallest string satisfying the conditions above.
For example, f(2, 3) = `BABAB`, and f(6, 4) = `AABAABAABB`.
Answer Q queries: find the substring of f(A_i, B_i) from position C_i to
position D_i (1based).  [{"input": "5\n 2 3 1 5\n 6 4 1 10\n 2 3 4 4\n 6 4 3 7\n 8 10 5 8", "output": "BABAB\n AABAABAABB\n A\n BAABA\n ABAB"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s997370292  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  R, D, X2000 = [int(i) for i in input().split()]
ans = [R * X2000  D]
for _ in range(9):
ans.append(R * ans[1]  D)
print("\n".join(map(str, ans)))
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s838022602  Runtime Error  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  #! python3
# solve127A.py
age, cost = map(int, input().split())
if age <= 5:
cost = 0
elif 6 <= age <= 12:
cost = cost // 2
elif 7 <= age:
cost = cost
print(cost)
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s457969152  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  import sys
a = sys.stdin.readline()
res = [int(i) for i in a.split() if i.isdigit()]
r, D, x2000 = [res[i] for i in (0, 1, 2)]
if (r >= 2 and r <= 5) and (D >= 1 and D <= 100) and (x2000 > D and x2000 <= 200):
x2001 = r * x2000  D
x2002 = r * x2001  D
x2003 = r * x2002  D
x2004 = r * x2003  D
x2005 = r * x2004  D
x2006 = r * x2005  D
x2007 = r * x2006  D
x2008 = r * x2007  D
x2009 = r * x2008  D
x2010 = r * x2009  D
print(x2001)
print(x2002)
print(x2003)
print(x2004)
print(x2005)
print(x2006)
print(x2007)
print(x2008)
print(x2009)
print(x2010)
else:
print("Error")
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s918528085  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  r, d, x = map(int, input().split())
num1 = r * x  d
num2 = num1 * r  d
num3 = num2 * r  d
num4 = num3 * r  d
num5 = num4 * r  d
num6 = num5 * r  d
num7 = num6 * r  d
num8 = num7 * r  d
num9 = num8 * r  d
num10 = num9 * r  d
print(num1)
print(num2)
print(num3)
print(num4)
print(num5)
print(num6)
print(num7)
print(num8)
print(num9)
print(num10)
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s045968706  Runtime Error  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  from sys import stdin
import numpt as np
def main(args):
r = args[0]
d = args[1]
x = args[2]
ar = np.zeros([10])
ar[0] = r * x  d
for i in range(1, len(ar)):
ar[i] = r * ar[i  1]  d
for i in ar:
print(i)
if __name__ == "__main__":
main([int(x) for x in stdin.readline().rstrip().split()])
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s817806126  Runtime Error  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  s = list(map(int, input()))
for i in range(10):
s[2] = s[0] * s[2]  s[1]
print(s[2])
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s365778743  Wrong Answer  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  30
50
90
170
330
650
1290
2570
5130
10250
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s411772713  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  r, D, x_s = [int(item) for item in input().split()]
for i in range(10):
x_s = r * x_s  D
print(x_s)
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s006453636  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  l = list(map(int, input().split()))
r = l[0]
D = l[1]
x = l[2]
t = [x]
for i in t:
m = i * r  D
t.append(m)
if len(t) == 11:
break
for p in t[1:]:
print(p)
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s851574748  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  while True:
try:
r, D, X = map(int, input().split())
for i in range(2001, 2011):
X = r * X  D
print(X)
except:
break
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s200250321  Accepted  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  x_array = []
r, D, x = (int(i) for i in input().split())
x_array.append(x)
for j in range(10):
x_array.append(r * x_array[j]  D)
print(x_array[j + 1])
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
Print 10 lines. The ith line (1 ≤ i ≤ 10) should contain x_{2000+i} as an
integer.
* * *  s897211153  Wrong Answer  p03036  Input is given from Standard Input in the following format:
r D x_{2000}  x = {}
i = list(map(int, input().split()))
for s in range(10):
x[s] = (i[2]  int((i[1] / (i[0]  1)))) * i[0] ** (s + 1) + int(
(i[1] / (i[0]  1))
)
print(x[s])
 Statement
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram.
For i≥2000, the following formula holds:
* x_{i+1} = rx_i  D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print
them in order.  [{"input": "2 10 20", "output": "30\n 50\n 90\n 170\n 330\n 650\n 1290\n 2570\n 5130\n 10250\n \n\nFor example, x_{2001} = rx_{2000}  D = 2 \\times 20  10 = 30 and x_{2002} =\nrx_{2001}  D = 2 \\times 30  10 = 50.\n\n* * *"}, {"input": "4 40 60", "output": "200\n 760\n 3000\n 11960\n 47800\n 191160\n 764600\n 3058360\n 12233400\n 48933560"}] 
In the first line, print the stability ("Stable" or "Not stable") of this
output.
In the following lines, print the arranged cards in the same manner of that of
the input.  s595120768  Accepted  p02277  The first line contains an integer _n_ , the number of cards.
_n_ cards are given in the following lines. Each card is given in a line and
represented by a pair of a character and an integer separated by a single
space.  import copy
def quicksort(li, ini_i, length):
# print(li, ini_i, length)
if ini_i < length:
next_len = partition(li, ini_i, length)
# print(next_len)
quicksort(li, ini_i, next_len  1)
quicksort(li, next_len + 1, length)
def partition(li, ini_i, length):
target = li[length][1]
# print(target, li, ini_i, length)
for i in range(ini_i, length):
if li[i][1] <= target:
li[ini_i], li[i] = li[i], li[ini_i]
ini_i += 1
# print(f"its {ini_i}")
li[ini_i], li[length] = li[length], li[ini_i]
return ini_i
length = int(input())
li = []
base_li = []
for i in range(length):
t = input().split(" ")
t[1] = int(t[1])
base_li.append(t)
li = copy.deepcopy(base_li)
quicksort(li, 0, length  1)
for i in range(length  1):
if li[i + 1][1] == li[i][1]:
if base_li.index(li[i + 1]) < base_li.index(li[i]):
print("Not stable")
break
else:
print("Stable")
for i, n in enumerate(li):
print(*n)
 Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card
consists of a part of a suit (S, H, C or D) and an number. Write a program
which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p1
3 for j = p to r1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q1)
4 run Quicksort(A, q+1, r)
Here, A is an array which represents a deck of cards and comparison operations
are performed based on the numbers.
Your program should also report the stability of the output for the given
input (instance). Here, 'stability of the output' means that: cards with the
same value appear in the output in the same order as they do in the input
(instance).  [{"input": "6\n D 3\n H 2\n D 1\n S 3\n D 2\n C 1", "output": "Not stable\n D 1\n C 1\n D 2\n H 2\n D 3\n S 3"}, {"input": "2\n S 1\n H 1", "output": "Stable\n S 1\n H 1"}] 
In the first line, print the stability ("Stable" or "Not stable") of this
output.
In the following lines, print the arranged cards in the same manner of that of
the input.  s588220904  Accepted  p02277  The first line contains an integer _n_ , the number of cards.
_n_ cards are given in the following lines. Each card is given in a line and
represented by a pair of a character and an integer separated by a single
space.  from sys import stdin
def partition(cards, start, end):
p = cards[end]
p_idx = start
for i in range(start, end):
c = cards[i]
if c[1] <= p[1]:
cards[i], cards[p_idx] = cards[p_idx], cards[i]
p_idx = p_idx + 1
cards[p_idx], cards[end] = cards[end], cards[p_idx]
return p_idx
# inplace quicksort
def quicksort(cards, start, end):
if start < end:
p_idx = partition(cards, start, end)
quicksort(cards, start, p_idx  1)
quicksort(cards, p_idx + 1, end)
def merge(nums, left, mid, right):
l = nums[left:mid] + [("_", 9999999999)]
r = nums[mid:right] + [("_", 9999999999)]
l_cur = 0
r_cur = 0
for i in range(right  left):
if l[l_cur][1] > r[r_cur][1]:
nums[left + i] = r[r_cur]
r_cur = r_cur + 1
else:
nums[left + i] = l[l_cur]
l_cur = l_cur + 1
def mergesort(nums, left, right):
if right  left <= 1:
return nums
else:
mid = (left + right) // 2
mergesort(nums, left, mid)
mergesort(nums, mid, right)
merge(nums, left, mid, right)
def is_stable_result(orig, result):
stable_result = orig[:]
mergesort(stable_result, 0, len(stable_result))
is_stable = True
for c1, c2 in zip(stable_result, result):
if c1 != c2:
is_stable = False
return is_stable
def parseLine(l):
kind, num = l.strip().split(" ")
return (kind, int(num))
def main():
_, *lines = stdin.readlines()
nums = [parseLine(l) for l in lines]
# sort
result = nums[:]
quicksort(result, 0, len(result)  1)
# check is stable
is_stable = is_stable_result(nums, result)
print("Stable" if is_stable else "Not stable")
print("\n".join([kind + " " + str(num) for (kind, num) in result]))
if __name__ == "__main__":
main()
 Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card
consists of a part of a suit (S, H, C or D) and an number. Write a program
which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p1
3 for j = p to r1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q1)
4 run Quicksort(A, q+1, r)
Here, A is an array which represents a deck of cards and comparison operations
are performed based on the numbers.
Your program should also report the stability of the output for the given
input (instance). Here, 'stability of the output' means that: cards with the
same value appear in the output in the same order as they do in the input
(instance).  [{"input": "6\n D 3\n H 2\n D 1\n S 3\n D 2\n C 1", "output": "Not stable\n D 1\n C 1\n D 2\n H 2\n D 3\n S 3"}, {"input": "2\n S 1\n H 1", "output": "Stable\n S 1\n H 1"}] 
In the first line, print the stability ("Stable" or "Not stable") of this
output.
In the following lines, print the arranged cards in the same manner of that of
the input.  s142345588  Accepted  p02277  The first line contains an integer _n_ , the number of cards.
_n_ cards are given in the following lines. Each card is given in a line and
represented by a pair of a character and an integer separated by a single
space.  if __name__ == "__main__":
import sys
input = sys.stdin.readline
MAX = 100000
SENTINEL = 2000000000
class Card:
def __init__(self, suit, value):
self.suit = suit
self.value = value
def merge(A, n, left, mid, right):
n1 = mid  left
n2 = right  mid
L = [Card(None, None) for _ in range(n1 + 1)]
R = [Card(None, None) for _ in range(n2 + 1)]
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1].value = SENTINEL
R[n2].value = SENTINEL
i, j = 0, 0
for k in range(left, right):
if L[i].value <= R[j].value:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, n, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, n, left, mid)
mergeSort(A, n, mid, right)
merge(A, n, left, mid, right)
def swap(a, i, j):
# list aのi番目の要素とj番目の要素を交換する関数
k = a[j]
a[j] = a[i]
a[i] = k
def partition(A, p, r):
x = A[r]
i = p  1
for j in range(p, r):
if A[j].value <= x.value:
i += 1
swap(A, i, j)
swap(A, i + 1, r)
return i + 1
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, p, q  1)
quickSort(A, q + 1, r)
n = int(input())
A = [Card(None, None) for _ in range(n)]
B = [Card(None, None) for _ in range(n)]
for i in range(n):
suit, value = input().split()
A[i].suit = suit
B[i].suit = suit
A[i].value = int(value)
B[i].value = int(value)
mergeSort(A, n, 0, n)
quickSort(B, 0, n  1)
for i in range(n):
if A[i].suit != B[i].suit:
print("Not stable")
break
else:
print("Stable")
for b in B:
print(b.suit, b.value)
 Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card
consists of a part of a suit (S, H, C or D) and an number. Write a program
which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p1
3 for j = p to r1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q1)
4 run Quicksort(A, q+1, r)
Here, A is an array which represents a deck of cards and comparison operations
are performed based on the numbers.
Your program should also report the stability of the output for the given
input (instance). Here, 'stability of the output' means that: cards with the
same value appear in the output in the same order as they do in the input
(instance).  [{"input": "6\n D 3\n H 2\n D 1\n S 3\n D 2\n C 1", "output": "Not stable\n D 1\n C 1\n D 2\n H 2\n D 3\n S 3"}, {"input": "2\n S 1\n H 1", "output": "Stable\n S 1\n H 1"}] 
In the first line, print the stability ("Stable" or "Not stable") of this
output.
In the following lines, print the arranged cards in the same manner of that of
the input.  s118675930  Accepted  p02277  The first line contains an integer _n_ , the number of cards.
_n_ cards are given in the following lines. Each card is given in a line and
represented by a pair of a character and an integer separated by a single
space.  from copy import copy
def merge(arr, left, middle, right):
L = arr[left:middle]
L.append([None, float("inf")])
R = arr[middle:right]
R.append([None, float("inf")])
iterL, iterR = iter(L), iter(R)
l, r = next(iterL), next(iterR)
for index in range(left, right):
if l[1] <= r[1]:
arr[index] = l
l = next(iterL)
else:
arr[index] = r
r = next(iterR)
def merge_sort(arr, left, right):
if left + 1 < right:
pivot = (left + right) // 2
merge_sort(arr, left, pivot)
merge_sort(arr, pivot, right)
merge(arr, left, pivot, right)
def partition(arr, start, end):
criteria = arr[end][1]
idx1 = start
for idx2 in range(start, end):
if arr[idx2][1] <= criteria:
arr[idx1], arr[idx2] = arr[idx2], arr[idx1]
idx1 += 1
arr[idx1], arr[end] = arr[end], arr[idx1]
return idx1
def quick_sort(arr, start, end):
if start < end:
pivot = partition(arr, start, end)
quick_sort(arr, start, pivot  1)
quick_sort(arr, pivot + 1, end)
num = int(input())
arr = []
for index in range(num):
sign, number = input().split()
arr.append([sign, int(number)])
arr1 = copy(arr)
arr2 = copy(arr)
merge_sort(arr1, 0, num)
quick_sort(arr2, 0, num  1)
print("Stable" if arr1 == arr2 else "Not stable")
for sign, number in arr2:
print(sign + " " + str(number))
 Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card
consists of a part of a suit (S, H, C or D) and an number. Write a program
which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p1
3 for j = p to r1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q1)
4 run Quicksort(A, q+1, r)
Here, A is an array which represents a deck of cards and comparison operations
are performed based on the numbers.
Your program should also report the stability of the output for the given
input (instance). Here, 'stability of the output' means that: cards with the
same value appear in the output in the same order as they do in the input
(instance).  [{"input": "6\n D 3\n H 2\n D 1\n S 3\n D 2\n C 1", "output": "Not stable\n D 1\n C 1\n D 2\n H 2\n D 3\n S 3"}, {"input": "2\n S 1\n H 1", "output": "Stable\n S 1\n H 1"}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s431988288  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  S = str(input())
print("A" if S.islower() else "a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s488229934  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  a, b = map(int, input().split())
print(a * b)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s627040532  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  n, k = input().split()
k = int(k)
# print(n,k)
p = [int(s) for s in input().split()]
p.sort()
# print(p)
# print(k)
p2 = p[0:k]
# print(p2)
s = sum(p)
# print(s)
print(sum(p2))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s309929004  Accepted  p02627  Input is given from Standard Input in the following format:
α  print("Aa"[ord(input()) > 95])
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s351771041  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print("B" if input().islower() else "A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s444056405  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  while True:
aw = input()
if (
aw == "q"
or "a"
or "z"
or "w"
or "s"
or "x"
or "e"
or "d"
or "c"
or "r"
or "f"
or "v"
or "t"
or "g"
or "b"
or "y"
or "h"
or "n"
or "u"
or "j"
or "m"
or "i"
or "k"
or "l"
or "o"
or "p"
):
print("a")
else:
print("A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s523930860  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  num = int(input())
d = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 10,
"k": 11,
"l": 12,
"m": 13,
"n": 14,
"o": 15,
"p": 16,
"q": 17,
"r": 18,
"s": 19,
"t": 20,
"u": 21,
"v": 22,
"w": 23,
"x": 24,
"y": 25,
"z": 0,
}
op_d = {}
for i, j in d.items():
op_d[j] = i
ans = ""
for i in list(range(0, 12))[::1]:
if int(num / (26**i)) == 0:
pass
else:
ans += op_d[int(num / (26**i))]
num = num % 26**i
print(ans)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s356654369  Accepted  p02627  Input is given from Standard Input in the following format:
α  print("a" if ord(input()) > 90 else "A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s966512331  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print("A" if (input().islower()) else "a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s645990424  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  L = set("A", "B")
print(L)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s758645869  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print("B") if input().islower() else print("A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s742853748  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print(input())
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s330574019  Accepted  p02627  Input is given from Standard Input in the following format:
α  print(chr(65 + (input() > "Z") * 32))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s342900613  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print(chr(ord(input()) + 32))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s666622625  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  kotae = str(input())
print(kotae.swapcase())
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s078443149  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print("a" if input() > "A" else "A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s728878493  Accepted  p02627  Input is given from Standard Input in the following format:
α  S = lambda: input()
I = lambda: int(input())
L = lambda: list(map(int, input().split()))
LS = lambda: list(map(str, input().split()))
a = S()
print("A" if a.isupper() else "a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s759496176  Accepted  p02627  Input is given from Standard Input in the following format:
α  import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int((x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**10
S = input()
if S.islower():
print("a")
else:
print("A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s679363297  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  def pokryj(plansza, x, y):
koszt = 0
if 2 * x >= y:
for i in range(len(plansza)  1):
if plansza[i] == "." and plansza[i + 1] == ".":
plansza[i] == "x"
plansza[i + 1] == "x"
koszt += y
elif plansza[i] == ".":
plansza[i] == "x"
koszt += x
else:
for i in range(len(plansza)  1):
if plansza[i] == ".":
plansza[i] == "x"
koszt += x
return koszt
print(pokryj("x.x.x.x..", 1, 2))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s104153163  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  n = int(input())
c = 0
n1 = 0
n1 += n
for i in range(1, 12):
a = n1  26 ** (i)
c += 1
if a <= 0:
break
n1 = n1  26 ** (i)
a = ""
for i in range(c):
if n // 26 ** (c  i  1) >= 26:
alpha = 26
n = n  26 ** (c  i)
else:
alpha = n // 26 ** (c  i  1)
n = n % 26 ** (c  i  1)
a += chr(96 + alpha)
print(a)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s147954234  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  m = input()
if (
m == "A"
or m == "B"
or m == "Q"
or m == "W"
or m == "E"
or m == "R"
or m == "T"
or m == "Y"
or m == "U"
or m == "I"
or m == "O"
or m == "P"
or m == "S"
or m == "D"
or m == "F"
or m == "G"
or m == "H"
or m == "J"
or m == "K"
or m == "L"
or m == "Z"
or m == "X"
or m == "C"
or m == "V"
or m == "B"
or m == "N"
or m == "M"
):
print("A")
if (
m == "a"
or m == "b"
or m == "q"
or m == "w"
or m == "e"
or m == "r"
or m == "t"
or m == "y"
or m == "u"
or m == "i"
or m == "o"
or m == "p"
or m == "s"
or m == "d"
or m == "f"
or m == "g"
or m == "h"
or m == "j"
or m == "k"
or m == "l"
or m == "Z"
or m == "x"
or m == "c"
or m == "v"
or m == "b"
or m == "n"
or m == "m"
):
print("a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s698026813  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  a, b = map(int, input().split())
mylist = input().split()
mylist.sort()
c = 0
for i in range(b  1):
c = c + int(mylist[i  1])
print(c)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s763917155  Accepted  p02627  Input is given from Standard Input in the following format:
α  print("a" if input() in list("abcdefghijklmnopqrstuvwxyz") else "A")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s340713150  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  print("Aa"[ord(open(0)) > 95])
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s755351383  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  input()
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s447613318  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  a = input()
dic = {
"A": "a",
"B": "b",
"C": "c",
"D": "d",
"E": "e",
"F": "f",
"G": "g",
"H": "h",
"I": "i",
"J": "j",
"K": "k",
"L": "l",
"M": "m",
"N": "n",
"O": "o",
"P": "p",
"Q": "q",
"R": "r",
"S": "s",
"T": "t",
"U": "u",
"V": "v",
"W": "w",
"X": "x",
"Y": "y",
"Z": "z",
}
if a in list(dic.keys()):
print(dic[a])
exit()
print(a)
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s668270506  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print(str.swapcase(input()))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s691256385  Accepted  p02627  Input is given from Standard Input in the following format:
α  a = input()
if a == "A":
print("A")
elif a == "B":
print("A")
elif a == "C":
print("A")
elif a == "D":
print("A")
elif a == "E":
print("A")
elif a == "E":
print("A")
elif a == "F":
print("A")
elif a == "G":
print("A")
elif a == "H":
print("A")
elif a == "I":
print("A")
elif a == "J":
print("A")
elif a == "K":
print("A")
elif a == "L":
print("A")
elif a == "M":
print("A")
elif a == "N":
print("A")
elif a == "O":
print("A")
elif a == "P":
print("A")
elif a == "Q":
print("A")
elif a == "R":
print("A")
elif a == "S":
print("A")
elif a == "T":
print("A")
elif a == "U":
print("A")
elif a == "V":
print("A")
elif a == "W":
print("A")
elif a == "X":
print("A")
elif a == "Y":
print("A")
elif a == "Z":
print("A")
else:
print("a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s573832272  Accepted  p02627  Input is given from Standard Input in the following format:
α  #!python3.8
# * coding: utf8 *
# abc171/abc171_a
import sys
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
a = i2s()
print("A" if a.isupper() else "a")
return
main()
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s814261086  Accepted  p02627  Input is given from Standard Input in the following format:
α  a = input()
if (
a == "A"
or a == "B"
or a == "C"
or a == "D"
or a == "E"
or a == "F"
or a == "G"
or a == "H"
or a == "I"
or a == "J"
or a == "K"
or a == "L"
or a == "M"
or a == "N"
or a == "O"
or a == "P"
or a == "Q"
or a == "R"
or a == "S"
or a == "T"
or a == "U"
or a == "V"
or a == "W"
or a == "X"
or a == "Y"
or a == "Z"
):
print("A")
else:
print("a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s975288215  Runtime Error  p02627  Input is given from Standard Input in the following format:
α  N, K = map(int, input().split())
p = list(map(int, input().split()))
print(sum(sorted(p)[:K]))
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s428052204  Wrong Answer  p02627  Input is given from Standard Input in the following format:
α  print("aA"[input().islower()])
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s750093066  Accepted  p02627  Input is given from Standard Input in the following format:
α  a = input()
B = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P","Q", "R","S","T","U","V","W","X","Y","Z"]
b = ["a","b", "c","d","e", "f","g", "h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if a in B:
print("A")
else:
print("a")  Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s044866322  Accepted  p02627  Input is given from Standard Input in the following format:
α  print(["a", "A"][input().isupper()])
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
If \alpha is uppercase, print `A`; if it is lowercase, print `a`.
* * *  s497711093  Accepted  p02627  Input is given from Standard Input in the following format:
α  strr = input()
if (
strr == "A"
or strr == "B"
or strr == "C"
or strr == "D"
or strr == "E"
or strr == "F"
or strr == "G"
or strr == "H"
or strr == "I"
or strr == "J"
or strr == "K"
or strr == "L"
or strr == "N"
or strr == "M"
or strr == "O"
or strr == "P"
or strr == "Q"
or strr == "R"
or strr == "S"
or strr == "T"
or strr == "U"
or strr == "V"
or strr == "W"
or strr == "X"
or strr == "Y"
or strr == "Z"
):
print("A")
else:
print("a")
 Statement
An uppercase or lowercase English letter \alpha will be given as input. If
\alpha is uppercase, print `A`; if it is lowercase, print `a`.  [{"input": "B", "output": "A\n \n\n`B` is uppercase, so we should print `A`.\n\n* * *"}, {"input": "a", "output": "a\n \n\n`a` is lowercase, so we should print `a`."}] 
Print the number of ways modulo $10^9+7$ in a line.  s670408233  Accepted  p02332  $n$ $k$
The first line will contain two integers $n$ and $k$.  import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int((x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
EPS = 10**10
class ModTools:
"""階乗・逆元用のテーブルを構築する"""
def __init__(self, MAX, MOD):
MAX += 1
self.MAX = MAX
self.MOD = MOD
factorial = [1] * MAX
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
factorial[i] = factorial[i  1] * i % MOD
inverse = [1] * MAX
inverse[MAX  1] = pow(factorial[MAX  1], MOD  2, MOD)
for i in range(MAX  2, 1, 1):
inverse[i] = inverse[i + 1] * (i + 1) % MOD
self.fact = factorial
self.inv = inverse
def nCr(self, n, r):
"""組み合わせ"""
if n < r:
return 0
r = min(r, n  r)
numerator = self.fact[n]
denominator = self.inv[r] * self.inv[n  r] % self.MOD
return numerator * denominator % self.MOD
def nHr(self, n, r):
"""重複組み合わせ"""
return self.nCr(r + n  1, r)
def nPr(self, n, r):
"""順列"""
if n < r:
return 0
return self.fact[n] * self.inv[n  r] % self.MOD
def div(self, x, y):
"""MOD除算"""
return x * pow(y, self.MOD  2, self.MOD) % self.MOD
N, K = MAP()
mt = ModTools(max(N, K) + 1, MOD)
ans = mt.nPr(K, N) % MOD
print(ans)
 You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box can contain at most one ball.
Note that you must print this count modulo $10^9+7$.  [{"input": "2 3", "output": "6"}, {"input": "3 2", "output": "0"}, {"input": "100 100", "output": "437918130"}] 
Print the number of ways modulo $10^9+7$ in a line.  s491479256  Accepted  p02332  $n$ $k$
The first line will contain two integers $n$ and $k$.  a, b = map(int, input().split())
m = 10**9 + 7
if a > b:
print(0)
else:
r = 1
for i in range(b  a + 1, b + 1):
r *= i
r %= m
print(r)
 You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box can contain at most one ball.
Note that you must print this count modulo $10^9+7$.  [{"input": "2 3", "output": "6"}, {"input": "3 2", "output": "0"}, {"input": "100 100", "output": "437918130"}] 
Print the number of ways modulo $10^9+7$ in a line.  s825421683  Accepted  p02332  $n$ $k$
The first line will contain two integers $n$ and $k$.  class Twelvefold: # n <= 1000程度
def __init__(self, n, mod):
self.mod = mod
self.fct = [0 for _ in range(n + 1)]
self.inv = [0 for _ in range(n + 1)]
self.stl = [[0 for j in range(n + 1)] for i in range(n + 1)]
self.bel = [[0 for j in range(n + 1)] for i in range(n + 1)]
self.prt = [[0 for j in range(n + 1)] for i in range(n + 1)]
self.fct[0] = 1
self.inv[0] = 1
self.stl[0][0] = 1
self.bel[0][0] = 1
for i in range(n):
self.fct[i + 1] = self.fct[i] * (i + 1) % mod
self.inv[n] = pow(self.fct[n], mod  2, mod)
for i in range(n)[::1]:
self.inv[i] = self.inv[i + 1] * (i + 1) % mod
for i in range(n):
for j in range(n):
self.stl[i + 1][j + 1] = self.stl[i][j] + (j + 1) * self.stl[i][j + 1]
self.stl[i + 1][j + 1] %= mod
for i in range(n):
for j in range(n):
self.bel[i + 1][j + 1] = (
self.bel[i + 1][j] + self.stl[i + 1][j + 1] % mod
)
self.bel[i + 1][j + 1] %= mod
for j in range(n):
self.prt[0][j] = 1
for i in range(n):
for j in range(n):
if i  j >= 0:
self.prt[i + 1][j + 1] = self.prt[i + 1][j] + self.prt[i  j][j + 1]
else:
self.prt[i + 1][j + 1] = self.prt[i + 1][j]
self.prt[i + 1][j + 1] %= mod
def solve(
self,
element,
subset,
equate_element=False,
equate_subset=False,
less_than_1=False,
more_than_1=False,
):
assert not less_than_1 or not more_than_1
n = element
k = subset
a = equate_element
b = equate_subset
c = less_than_1
d = more_than_1
id = a * 3 + b * 6 + c + d * 2
tw = [
self.tw1,
self.tw2,
self.tw3,
self.tw4,
self.tw5,
self.tw6,
self.tw7,
self.tw8,
self.tw9,
self.tw10,
self.tw11,
self.tw12,
]
return tw[id](n, k)
def tw1(self, n, k):
return pow(k, n, self.mod)
def tw2(self, n, k):
if k  n < 0:
return 0
return self.fct[k] * self.inv[k  n] % self.mod
def tw3(self, n, k):
return self.stl[n][k] * self.fct[k] % self.mod
def tw4(self, n, k):
if k == 0:
return 0
return self.fct[n + k  1] * self.inv[n] * self.inv[k  1] % self.mod
def tw5(self, n, k):
if k  n < 0:
return 0
return self.fct[k] * self.inv[n] * self.inv[k  n] % self.mod
def tw6(self, n, k):
if n  k < 0 or k == 0:
return 0
return self.fct[n  1] * self.inv[k  1] * self.inv[n  k]
def tw7(self, n, k):
return self.bel[n][k]
def tw8(self, n, k):
if k  n < 0:
return 0
return 1
def tw9(self, n, k):
return self.stl[n][k]
def tw10(self, n, k):
return self.prt[n][k]
def tw11(self, n, k):
if k  n < 0:
return 0
return 1
def tw12(self, n, k):
if n  k < 0:
return 0
return self.prt[n  k][k]
n, k = map(int, input().split())
t = Twelvefold(1000, 10**9 + 7)
print(t.solve(n, k, 0, 0, 1, 0))
 You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box can contain at most one ball.
Note that you must print this count modulo $10^9+7$.  [{"input": "2 3", "output": "6"}, {"input": "3 2", "output": "0"}, {"input": "100 100", "output": "437918130"}] 
Print "1" or "0" in a line.  s869501713  Wrong Answer  p02298  g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counterclockwise visit of them.  n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
edges = [p1  p0 for p0, p1 in zip(points, points[1:] + [points[0]])]
prev = edges[0]
while edges:
edge = edges.pop()
if edge.real * prev.imag  prev.real * edge.imag < 1e6:
print(0)
break
prev = edge
else:
print(1)
 IsConvex
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise.
Here, in a convex polygon, all interior angles are less than or equal to 180
degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.  [{"input": "4\n 0 0\n 3 1\n 2 3\n 0 3", "output": "1"}, {"input": "5\n 0 0\n 2 0 \n 1 1\n 2 2\n 0 2", "output": "0"}] 
Print "1" or "0" in a line.  s643525663  Accepted  p02298  g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counterclockwise visit of them.  n = int(input())
vec = []
for i in range(n):
vec += [list(map(int, input().split()))]
vec += [vec[0]]
vec += [vec[1]]
Sum = 0
def cross(a, b):
return a[0] * b[1]  a[1] * b[0]
def ab(a, b):
c = (b[0]  a[0], b[1]  a[1])
return c
def check(a, b, c):
if cross(ab(a, b), ab(a, c)) >= 0:
return 1
else:
return 0
for a, b, c in zip(vec[0:2], vec[1:1], vec[2:]):
cnt = check(a, b, c)
if cnt == 0:
break
print(cnt)
 IsConvex
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise.
Here, in a convex polygon, all interior angles are less than or equal to 180
degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.  [{"input": "4\n 0 0\n 3 1\n 2 3\n 0 3", "output": "1"}, {"input": "5\n 0 0\n 2 0 \n 1 1\n 2 2\n 0 2", "output": "0"}] 
Print the answers in order, with space in between.
* * *  s569971509  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  print("1 3 5 4 3 3 3 3 1 0")
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s038859216  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  def s0():
return input()
def s1():
return input().split()
def s2(n):
return [input() for x in range(n)]
def s3(n):
return [input().split() for _ in range(n)]
def s4(n):
return [[x for x in s] for s in s2(n)]
def n0():
return int(input())
def n1():
return [int(x) for x in input().split()]
def n2(n):
return [int(input()) for _ in range(n)]
def n3(n):
return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):
return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b, yes="Yes", no="No"):
print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n, m, k = n1()
AB = n3(m)
CD = n3(k)
G = nx.Graph()
G.add_edges_from(AB)
friend = {i: [] for i in range(1, n + 1)}
for i, j in AB:
friend[i].append(j)
friend[j].append(i)
block = {i: [] for i in range(1, n + 1)}
for i, j in CD:
block[i].append(j)
block[j].append(i)
ans = []
for i in range(1, n + 1):
g = nx.single_source_shortest_path(G, source=i)
f_kouho = set(g.keys())
tmp = 1
for j in f_kouho:
if (not j in friend[i]) and (not j in block[i]):
tmp += 1
ans.append(tmp)
print(*ans)
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s837746507  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  """
Friend Suggestions
"""
import sys
input = lambda: sys.stdin.readline().rstrip()
class Vertex:
"""A Vertex is a node in a graph."""
def __init__(self, label=""):
self.label = label
def __repr__(self):
return f"V{self.label}"
__str__ = __repr__
class Edge(tuple):
"""An Edge is a list of two vertices."""
def __new__(cls, *vs):
"""The Edge constructor takes two vertices."""
if len(vs) != 2:
raise ValueError("Edges must connect exactly two vertices.")
return tuple.__new__(cls, vs)
def __repr__(self):
return f"Edge_{repr(self[0])}_{repr(self[1])}"
__str__ = __repr__
class Graph(dict):
"""A Graph is a dictionary of dictionaries.
For vertices a and b, graph[a][b] maps
to the edge that connects a>b, if it exists."""
def __init__(self, vs, es):
"""Creates a new graph.
vs: list of vertices;
es: list of edges.
"""
super().__init__()
for v in vs:
self.add_vertex(v)
for e in es:
self.add_edge(e)
def add_vertex(self, v):
"""Add a vertex to the graph."""
self[v] = {}
def add_edge(self, e):
"""Adds and edge to the graph by adding an entry in both directions."""
v, w = e
self[v][w] = e
self[w][v] = e
def vertices(self):
"""returns a list of the vertices in graph"""
vs = []
for v in self.keys():
vs.append(v)
return vs
def out_vertices(self, v):
"""returns a list of adjacent vertices of the (v)"""
return self[v].keys()
def out_edges(self, v):
"""returns a list of edges connected to the (v)"""
return self[v].values()
def is_connected(self):
"""returns True if the Graph is conneted and False otherwise"""
vertices = self.vertices()
closed = self.BFS(vertices[0])
return len(vertices) == len(closed)
def closed_vertices(self, v):
return self.BFS(v)
def BFS(self, v):
"""search graph by a BFS: breadthfirstsearch"""
worklist = [v]
closed = []
while worklist:
visited = worklist.pop(0)
closed.append(visited)
vs = self.out_vertices(visited)
vs = [v for v in vs if not (v in closed or v in worklist)]
worklist.extend(vs)
return closed
def main():
N, M, K = map(int, input().split())
ans = [1] * N
friend = [list(map(int, input().split())) for _ in range(M)]
blocks = [list(map(int, input().split())) for _ in range(K)]
nodes = [Vertex(str(v)) for v in range(N)]
edges = [Edge(nodes[edge[0]  1], nodes[edge[1]  1]) for edge in friend]
g = Graph(nodes, edges)
for i, v in enumerate(nodes):
closed_graph_list = [str(x) for x in g.closed_vertices(v)]
closed_graph_list.remove(str(v))
connected_vertices = [str(x) for x in list(g.out_vertices(v))]
candidates = list(set(closed_graph_list)  set(connected_vertices))
ans[i] = candidates
for block_rel in blocks:
block_a = block_rel[0]  1
block_b = block_rel[1]  1
if f"V{block_b}" in ans[block_a]:
ans[block_a].remove(f"V{block_b}")
if f"V{block_a}" in ans[block_b]:
ans[block_b].remove(f"V{block_a}")
print(*[len(i) for i in ans])
if __name__ == "__main__":
main()
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s657080801  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  from collections import deque, Counter
import sys
N_MAX = 100000 + 5
sys.setrecursionlimit(N_MAX)
N, M, K = map(int, sys.stdin.readline().rstrip().split())
fr = [[] for _ in range(N)] # 友達関係
for _ in range(M):
a, b = map(int, sys.stdin.readline().rstrip().split())
fr[a  1].append(b  1)
fr[b  1].append(a  1)
bl = [[] for _ in range(N)] # ブロック関係
for _ in range(K):
a, b = map(int, sys.stdin.readline().rstrip().split())
bl[a  1].append(b  1)
bl[b  1].append(a  1)
gr = [0] * N # 友達候補グループ
# ## BFS ## #
def bfs(u, num):
q = deque()
q.append(u)
while q:
u = q.popleft()
for v in fr[u]:
if gr[v] == 0: # state を確認
gr[v] = num # state を変更
q.append(v)
num = 1
for i in range(N):
if gr[i] == 0:
bfs(i, num)
num += 1
# print(gr)
gr_num = Counter(gr) # グループの人数を数えておく
# グループの中から、友達でも
ans = []
for i in range(N):
kouho_suu = gr_num[gr[i]]
for f in fr[i]:
if gr[i] == gr[f]:
kouho_suu = 1
for b in bl[i]:
if gr[i] == gr[b]:
kouho_suu = 1
kouho_suu = 1
ans.append(kouho_suu)
print(*ans)
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s705088646  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
l1 = []
l2 = []
l3 = []
for i in range(m):
if s[i][0] == 1:
l1.append(s[i])
elif s[i][0] == 2:
l2.append(s[i])
elif s[i][0] == 3:
l3.append(s[i])
l1 = list(map(list, set(map(tuple, l1))))
l2 = list(map(list, set(map(tuple, l2))))
l3 = list(map(list, set(map(tuple, l3))))
check = 0
if len(l1) > 1 or len(l2) > 1 or len(l3) > 1: # 同じ桁に違う数
check += 1
if n == 3 or n == 2:
if len(l1) > 0 and l1[0][1] == 0: # 二桁三桁の時最初が０
check += 1
if n == 3:
if len(l1) == 0:
l1.append([1, 1])
if len(l2) == 0:
l2.append([2, 0])
if len(l3) == 0:
l3.append([3, 0])
if n == 2:
if len(l1) == 0:
l1.append([1, 1])
if len(l2) == 0:
l2.append([2, 0])
if n == 1:
if len(l1) == 0:
l1.append([1, 0])
if check >= 1:
print(1)
else:
ans = []
if len(l1) > 0:
ans.append(l1[0][1])
if len(l2) > 0:
ans.append(l2[0][1])
if len(l3) > 0:
ans.append(l3[0][1])
print(int("".join(map(str, ans))))
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s130857790  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  import sys
from collections import deque
# 再帰関数は非常にダメダメですねぇ
N, M, K = map(int, input().split())
friend = [list(map(int, input().split())) for _ in range(M)]
block = [list(map(int, input().split())) for _ in range(K)]
sys.setrecursionlimit(2 * N)
# print(friend)
# print(block)
graph = [[] for _ in range(N)]
bgraph = [[] for _ in range(N)]
cnt = []
for i in range(M):
ii, jj = friend[i]
graph[ii  1].append(jj  1)
graph[jj  1].append(ii  1)
for i in range(K):
ii, jj = block[i]
bgraph[ii  1].append(jj  1)
bgraph[jj  1].append(ii  1)
# print(graph)
# print(bgraph)
seen = [False for _ in range(N)]
def dfs(i):
# if i not in bgraph[j]:
# seen[i]= True
# else:
# seen[i]="block"
# if graph[i]:
# for nec in graph[i]:
# if seen[nec] == False:
# dfs(nec,j)
seen[i] = True
que = deque([i])
while que:
neci = que.pop()
for nec in graph[neci]:
if seen[nec] == False:
if nec not in bgraph[i]:
seen[nec] = True
else:
seen[nec] = "block"
que.append(nec)
for i_n in range(N):
seen = [False for _ in range(N)]
dfs(i_n)
# print(seen)
cnt.append(seen.count(True)  1  len(graph[i_n]))
print(*cnt)
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s562479430  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  from collections import deque
n, m, k = list(map(int, input().split()))
friends = [tuple(map(int, input().split())) for _ in range(m)]
block = [tuple(map(int, input().split())) for _ in range(k)]
relation_d = {}
for i in range(1, n + 1):
relation_d[str(i)] = set()
for a, b in friends:
relation_d[str(a)].add(str(b))
relation_d[str(b)].add(str(a))
block_d = {}
for i in range(1, n + 1):
block_d[str(i)] = set()
for a, b in block:
block_d[str(a)].add(str(b))
block_d[str(b)].add(str(a))
for i in range(1, n + 1):
visited = set()
candidates = set()
dq = deque(list(relation_d[str(i)]))
while dq:
for j in range(len(dq)):
node = dq.popleft()
if not node in relation_d[str(i)]:
candidates.add(node)
if not node in visited:
dq.extend(relation_d[node])
visited.add(node)
print(len(candidates  block_d[str(i)]  set(str(i))), end=" ")
# print(relation_d[str(i)], block_d[str(i)], relation_d[str(i)]block_d[str(i)])
# print(len(candidatesblock_d[str(i)]))
# print(len(memberrelation_d[str(i)]block_d[str(i)])1, end=" ")
# print(n1len(relation_d[str(i)]block_d[str(i)]), end=" ")
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s386410283  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  n, m, k = map(int, input().split())
S = [[i, 100001, []] for i in range(1, n + 1)]
count = 0
for num in range(0, m + k):
i1, i2 = map(int, input().split())
a = S[i1  1][1]
b = S[i2  1][1]
a_1, a_2 = S[i1  1][1], []
b_1, b_2 = S[i2  1][1], []
t = min(a, b)
if t == 100001 and num < m:
a_1 = b_1 = count
count += 1
elif num < m:
a_1 = b_1 = t
if max(a, b) != 100001:
xc = [x[1] for x in S]
indexes = [j + 1 for j, x in enumerate(xc) if x == max(a, b)]
for f in range(len(indexes)):
S[indexes[f]  1][1:] = [t, S[indexes[f]  1][2]]
a_2 = S[i1  1][2]
b_2 = S[i2  1][2]
a_2.append(i2)
b_2.append(i1)
S[i1  1][1:] = [a_1, a_2]
S[i2  1][1:] = [b_1, b_2]
friend = [0] * n
for i in range(0, count):
xc = [x[1] for x in S]
indexes = [j + 1 for j, x in enumerate(xc) if x == i]
for z in range(len(indexes)):
S[indexes[z]  1][2].append(S[indexes[z]  1][0])
V = S[indexes[z]  1][2] # +indexes[:z]
result = set(indexes)  set(V)
S[indexes[z]  1][2].append(z)
friend[indexes[z]  1] = str(len(result))
# print(indexes)
print(" ".join(friend))
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s679060115  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  from collections import deque
n, m, k = list(map(int, input().split()))
friendship = {}
for i in range(m):
a, b = list(map(int, input().split()))
if a in friendship.keys():
friendship[a].append(b)
else:
friendship[a] = [b]
if b in friendship.keys():
friendship[b].append(a)
else:
friendship[b] = [a]
block = {}
for j in range(k):
c, d = list(map(int, input().split()))
if c in block.keys():
block[c].append(d)
else:
block[c] = [d]
if d in block.keys():
block[d].append(c)
else:
block[d] = [c]
ans = [0] * n
for i in range(n):
print(i + 1)
person = i + 1
checked_person = set()
checked_person.add(person)
if person in friendship.keys():
candidate = deque(friendship[person])
while len(candidate) > 0:
c = deque.popleft(candidate)
checked_person.add(c)
if c not in friendship[person]:
if person in block.keys():
if c not in block[person]:
ans[i] += 1
else:
ans[i] += 1
if c in friendship.keys():
for p in friendship[c]:
if p not in checked_person and p not in candidate:
candidate.append(p)
else:
continue
answer = ""
for i in range(len(ans)):
answer += str(ans[i])
if i != n  1:
answer += " "
print(answer)
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s517133290  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  import queue
q = queue.Queue()
n, m, k = map(int, input().split())
friend = [list(map(int, input().split())) for i in range(m)]
block = [list(map(int, input().split())) for i in range(k)]
suggestions = [] # 友達候補
def Strand(now): # 繋がり検索
for o in range(m):
if friend[o][0] == now:
if friend[o][1] not in Q:
q.put(friend[o][1])
Q.append(friend[o][1])
if friend[o][1] == now:
if friend[o][0] not in Q:
q.put(friend[o][0])
Q.append(friend[o][0])
for i in range(n):
now = i # 現在地
count = 0
Q = [i] # 発見済み
Strand(i)
F = [] # 人iのフレンドリスト
for j in range(m):
if friend[j][0] == i:
F.append(friend[j][1])
if friend[j][1] == i:
F.append(friend[j][0])
B = [] # 人iのブロックリスト
for l in range(k):
if block[l][0] == i:
B.append(block[l][1])
if block[l][1] == i:
B.append(block[l][0])
while not q.empty():
if i != 0:
for o in range(m):
if friend[o][0] == now:
if friend[o][1] not in Q:
q.put(friend[o][1])
Q.append(friend[o][1])
if friend[o][1] == now:
if friend[o][0] not in Q:
q.put(friend[o][0])
Q.append(friend[o][0])
now = q.get()
if (now not in F) and (now not in B):
count += 1
suggestions.append(count)
print(" ".join(map(str, suggestions)))
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s054749833  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  import sys
N, M, K = map(int, sys.stdin.readline().split())
setList = [set(list(map(int, sys.stdin.readline().split()))) for _ in range(M + K)]
li = []
i = 1
for s in setList:
j = 2
while i < N:
while j <= N:
if s != {i, j}:
li.append(i)
li.append(j)
j += 1
i += 1
n = 1
while n <= N:
print(li.count(n), end="")
n += 1
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s774942065  Runtime Error  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  N, M, K = map(int, input().split())
friend = [list(map(int, input().split())) for i in range(M)]
block = [list(map(int, input().split())) for i in range(K)]
result = []
FG = [[] for i in range(N + 1)]
BG = [[] for i in range(N + 1)]
for i in range(M):
a = friend[i][0]
b = friend[i][1]
FG[a].append(b)
FG[b].append(a)
for i in range(K):
a = block[i][0]
b = block[i][1]
BG[a].append(b)
BG[b].append(a)
result = [0] * (N + 1)
flag = [0] * (N + 1)
W = []
for i in range(1, N + 1):
W.append(i)
W = set(W)
def dfs(i):
if flag[i] == 1:
return
else:
group.append(i)
flag[i] = 1
for j in range(len(FG[i])):
dfs(FG[i][j])
while len(W) != 0:
w = list(W)
point = w[0]
group = []
if FG[point] != 0:
dfs(point)
S = len(group)
for j in range(S):
m = group[j]
FB = set(FG[m] + BG[m])
SG = set(group)
fc = SG  FB
result[m] = len(fc)  1
else:
flag[point] = 1
SG = {point}
W = W  SG
print(*result[1:])
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s992226651  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]
CD = [list(map(int, input().split())) for i in range(K)]
AB.sort()
CD.sort()
friend = [N  1] * N
anti = []
ans = []
count = 1
cnt = 1
# print(AB)
# print(CD)
m = 0
n = 0
while m < M:
friend[AB[m][0]  1] = 1
friend[AB[m][1]  1] = 1
m += 1
while n < K:
friend[CD[n][0]  1] = 1
friend[CD[n][1]  1] = 1
n += 1
"""for i in range(M1):
if AB[i][0]==AB[i+1][0]:
count+=1
else:
friend[AB[i][0]]=count
count=1
for j in range(K1):
if CD[j][0]==CD[j+1][0]:
cnt+=1
else:
friend[CD[j][0]]=cnt
cnt=1
while True:
if len(friend)<N:
friend.append([0,0])
break
while True:
if len(anti)<K:
anti.append([0,0])
break"""
print(*friend)
"""while m<len(friend):
if friend[m]==
print(ans)"""
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s341136008  Wrong Answer  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  used = []
w = []
def dfs(v, num):
used[v] = num
for x in w[v]:
if used[x] == 0:
dfs(x, num)
n, m, k = (int(i) for i in input().split())
for i in range(n):
w.append([])
for j in range(m):
u, v = (int(i) for i in input().split())
u = 1
v = 1
w[u].append(v)
w[v].append(u)
block = []
for j in range(k):
u, v = (int(i) for i in input().split())
u = 1
v = 1
block.append([u, v])
for i in range(n):
used.append(0)
# cnt_comp = 0;
# for i in range(n):
# if used[i] == 0:
# cnt_comp += 1;
# dfs(i, cnt_comp);
# cnt = [0 for i in range(cnt_comp)];
#
# for i in range(n):
# cnt[used[i]  1] += 1;
#
# res = [0 for i in range(n)];
# for i in range(n):
# res[i] = cnt[used[i]  1]  1;
# #print(res);
# for x in block:
# if used[x[0]] == used[x[1]]:
# res[x[0]] = 1;
# res[x[1]] = 1;
# #print(res);
# for i in range(n):
# for v in w[i]:
# if used[v] == used[i]:
# res[i] = 1;
#
# #print(cnt);
#
# for i in res:
# print(i, end=" ");
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
Print the answers in order, with space in between.
* * *  s896908606  Accepted  p02762  Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K  from sys import stdin
def getval():
n, m, k = map(int, stdin.readline().split())
a = [list(map(int, stdin.readline().split())) for i in range(m)]
c = [list(map(int, stdin.readline().split())) for i in range(k)]
return n, m, k, a, c
def main(n, m, k, a, c):
# Compute all members' friends
friends = [[] for i in range(n)]
for i in a:
friends[i[0]  1].append(i[1]  1)
friends[i[1]  1].append(i[0]  1)
# Group all members in the isolated "friend groups"
frgroups = []
visited = [False for i in range(n)]
for i in range(n):
if visited[i]:
continue
q = [i]
temp = [i]
visited[i] = True
while q:
idx = q.pop(0)
adj = friends[idx]
for j in adj:
if visited[j]:
continue
visited[j] = True
q.append(j)
temp.append(j)
frgroups.append(temp)
# Number all members with their friend groups respectively
groups = [1 for i in range(n)]
for i in range(len(frgroups)):
for j in frgroups[i]:
groups[j] = i
# For each member, refer to the friend groups of blocked peope
# Compute ans accordingly
ans = [len(frgroups[groups[i]])  1  len(friends[i]) for i in range(n)]
for i in c:
if groups[i[0]  1] == groups[i[1]  1]:
ans[i[0]  1] = 1
ans[i[1]  1] = 1
s = str(ans[0])
for i in range(1, n):
s += " " + str(ans[i])
print(s)
if __name__ == "__main__":
n, m, k, a, c = getval()
main(n, m, k, a, c)
 Statement
An SNS has N users  User 1, User 2, \cdots, User N.
Between these N users, there are some relationships  M _friendships_ and K
_blockships_.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User
A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User
C_i and User D_i.
We define User a to be a _friend candidate_ for User b when all of the
following four conditions are satisfied:
* a \neq b.
* There is not a friendship between User a and User b.
* There is not a blockship between User a and User b.
* There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L  1.
For each user i = 1, 2, ... N, how many friend candidates does it have?  [{"input": "4 4 1\n 2 1\n 1 3\n 3 2\n 3 4\n 4 1", "output": "0 1 0 1\n \n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there\nis no friendship or blockship between User 2 and 4. Thus, User 4 is a friend\ncandidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has\none friend candidate.\n\n* * *"}, {"input": "5 10 0\n 1 2\n 1 3\n 1 4\n 1 5\n 3 2\n 2 4\n 2 5\n 4 3\n 5 3\n 4 5", "output": "0 0 0 0 0\n \n\nEveryone is a friend of everyone else and has no friend candidate.\n\n* * *"}, {"input": "10 9 3\n 10 1\n 6 7\n 8 2\n 2 5\n 8 4\n 7 3\n 10 9\n 6 4\n 5 8\n 2 6\n 7 5\n 3 1", "output": "1 3 5 4 3 3 3 3 1 0"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s198962528  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  s=list(input())
if s.count('K')==1 and s.count('I')==1 and s.count('H')==1 ands.count('B')==1 ands.count('R')==1:
print('YES')
else:
print('NO')  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s004233696  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  from collections import Counter
import itertools
N = int(input())
D = list(map(int, input().split()))
M = Counter(D)
if max(M.values()) > 2:
print(0)from collections import Counter
import itertools
N = int(input())
D = list(map(int, input().split()))
M = Counter(D)
if max(M.values()) > 2:
print(0)
else:
D = [[x, 24x] for x in D]
generator = list(itertools.product([0, 1], repeat=N))
D_gen = [[D[i][g[i]] for i in range(N)] for g in generator]
ans = 0
for d in D_gen:
tmp = [0] + sorted(d) + [24]
s = 13
for i in range(N+1):
s = min(s, tmp[i+1]tmp[i])
ans = max(ans, s)
print(ans)
elif 0 in D:
print(0)
else:
D = [[x, 24x] for x in D]
generator = list(itertools.product([0, 1], repeat=N))
D_gen = [[D[i][g[i]] for i in range(N)] for g in generator]
ans = 0
for d in D_gen:
tmp = [0] + sorted(d) + [24]
s = 13
for i in range(N+1):
s = min(s, tmp[i+1]tmp[i])
ans = max(ans, s)
print(ans)
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s505771815  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  #!/usr/bin/env python3
#CODE FESTIVAL 2017 Final A
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
lst = ['A','K','I','H','B','R']
for i in range(len(s)):
if s[i] not in lst:
print('NO')
quit()
a = s.count('A')
t = ''
for i in range(len(s)):
if s[i] != 'A':
t += s[i]
if 'KIHBR' not in t or a > 4 or 'KIH' not in s:
print('NO')
quit()
if t.count('K') != 1 or t.count('I') != 1 or t.count('H') != 1 or t.count('B') != 1 or t.count('R') != 1:
print('NO')
quit()
a = 0
for i in range(len(s)):
if s[i] == 'K':
if s[:i].count('A') > 1:
print('NO')
quit()
if s[i] == 'H':
for j in range(i+1.len(s)):
if s[j] == 'B':
if s[i:j].count('A') > 1:
print('NO')
quit()
if s[i] == 'B':
for j in range(i+1,len(s)):
if s[j] == 'R':
if s[i:j].count('A') > 1:
print('NO')
quit()
if s[i] == 'R':
if s[i:].count('A') > 1:
print('NO')
quit()
print('YES')
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s010188020  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  S = input().strip()
K = S.find('K')
I = S.find('I')
H = S.find('H')
B = S.find('B')
R = S.find('R')
if S.find('AA'):
print('NO')
exit()
if K in [0, 1] and I >= 0 and H >= 0 and B >= 0 and R >= 0 and \
IK in [0, 1] and HI in [0, 1] and BH in [0, 1] and RB in [0, 1] and:
print('YES')
else:
print('NO')  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s173664553  Wrong Answer  p03523  Input is given from Standard Input in the following format:
S  # coding: utf8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop, heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
# import numpy as np
alphabet = "abcdefghijklmnopqrstuvwxyz"
mod = int(10**9 + 7)
inf = int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find:
def __init__(self, n):
self.n = n
self.P = [a for a in range(N)]
self.rank = [0] * n
def find(self, x):
if x != self.P[x]:
self.P[x] = self.find(self.P[x])
return self.P[x]
def same(self, x, y):
return self.find(x) == self.find(y)
def link(self, x, y):
if self.rank[x] < self.rank[y]:
self.P[x] = y
elif self.rank[y] < self.rank[x]:
self.P[y] = x
else:
self.P[x] = y
self.rank[y] += 1
def unite(self, x, y):
self.link(self.find(x), self.find(y))
def size(self):
S = set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_power(a, b): # aはbの累乗数か
now = b
while now < a:
now *= b
if now == a:
return True
else:
return False
def bin_(num, size):
A = [0] * size
for a in range(size):
if (num >> (size  a  1)) & 1 == 1:
A[a] = 1
else:
A[a] = 0
return A
def get_facs(n, mod_=0):
A = [1] * (n + 1)
for a in range(2, len(A)):
A[a] = A[a  1] * a
if mod > 0:
A[a] %= mod_
return A
def comb(n, r, mod, fac):
if n  r < 0:
return 0
return (fac[n] * pow(fac[n  r], mod  2, mod) * pow(fac[r], mod  2, mod)) % mod
def next_comb(num, size):
x = num & (num)
y = num + x
z = num & (~y)
z //= x
z = z >> 1
num = y  z
if num >= (1 << size):
return False
else:
return num
def get_primes(n, type="int"):
A = [True] * (n + 1)
A[0] = False
A[1] = False
for a in range(2, n + 1):
if A[a]:
for b in range(a * 2, n + 1, a):
A[b] = False
if type == "bool":
return A
B = []
for a in range(n + 1):
if A[a]:
B.append(a)
return B
def is_prime(num):
if num <= 2:
return False
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
def ifelse(a, b, c):
if a:
return b
else:
return c
def join(A, c=" "):
n = len(A)
A = list(map(str, A))
s = ""
for a in range(n):
s += A[a]
if a < n  1:
s += c
return s
def factorize(n, type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b += 1
if n > 1:
list_.append(n)
if type_ == "dict":
dic = {}
for a in list_:
if a in dic:
dic[a] += 1
else:
dic[a] = 1
return dic
elif type_ == "list":
return list_
else:
return None
def floor_(n, x=1):
return x * (n // x)
def ceil_(n, x=1):
return x * ((n + x  1) // x)
def hani(x, min_, max_):
ret = x
if x < min_:
ret = min_
if x > max_:
ret = max_
return ret
def seifu(x):
return x // abs(x)
###################################################
def main():
s = "AKIHABARA"
ss = input()
f = True
if len(list(set(s)  set(ss))) != 1 or list(set(s)  set(ss))[0] != "A":
f = False
if set(ss)  set(s):
f = False
YN(f)
main()
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s321975475  Wrong Answer  p03523  Input is given from Standard Input in the following format:
S  print("YES" if input().replace("A", "P").replace("A", "") == "KIHBR" else "NO")
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s018476786  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  #!/usr/bin/env python
import re
s = input()
STR = 'AKIHABARA'
if len(s) > len(STR):
print('NO')
exit()
regex = re.compile('A?KIHA?BA?RA?')
mo = regex.search(s)
if mo == None:
print('NO')
else:
print('YES')
~  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s422206582  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  S = input()
if len(S) >= 10:
print("NO")
else:
if S == "AKIHABARA":
print("YES")
elif S == "KIHABARA":
print("YES")
elif S == "AKIHBARA":
print("YES")
elif S == "AKIHABRA":
print("YES")
elif S == "AKIHABR":
print("YES")
elif S == "KIHBARA":
print("YES")
elif S == "KIHABRA":
print("YES")
elif S == "KIHABAR":
print("YES")
elif S == "AKIHBRA":
print("YES")
elif S == "AKIHABR":
print("YES")
elif S == "KIHBRA":
print("YES")
elif S == "KIHBAR":
print("YES")
elif S == "AKIHBR":
print("YES")
elif S == "KIHBR":
print("YES")
else;
print("NO")  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s828137339  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  s = input()
AKB = KIHBR
tmp = 0
count = 0
for i in range(len(s)):
if s[i] == "A" and count < 4:
count += 1
elif s[i] == AKB[tmp]:
tmp += 1
if count <= 4 and tmp = 5:
print("YES")
else:
print("NO")  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s781451572  Wrong Answer  p03523  Input is given from Standard Input in the following format:
S  print("YES" if input().replace("A", "") == "KIHBR" else "NO")
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s156678615  Accepted  p03523  Input is given from Standard Input in the following format:
S  a = ["KIH", "B", "R", ""]
ans = []
aaa = []
for i in range(16):
b = ""
for j, k in enumerate(a):
if (i >> j) & 1:
b += "A"
b += k
ans.append(b)
print("YES" if input() in ans else "NO")
 Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s818973652  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  A="AKIHABARA"
s=input()
n=len(s)
na=len(A)
i=0
j=0
while i<n j<na1:
if s[i]==A[j]:
i+=1; j+=1
elif s[i]!=A[j] and A[j]=="A":
j+=1
else:
break
if j==n1:
print("YES")
else:
print("NO")  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print
`NO`.
* * *  s498727540  Runtime Error  p03523  Input is given from Standard Input in the following format:
S  s = input()
for i in range(len(s)):
if s[i] == "K" ans i == 0:
s = s[:i] + "A" + s[i:]
elif s[i] == "H" and s[i+1] != "A":
s = s[:i] + "A" + s[i:]
elif s[i] == "B" and s[i+1] != "A":
s = s[:i] + "A" + s[i:]
elif s[i] == "R" and s[i+1] != "A":
s = s[:i] + "A" + s[i:]
if s == "AKIHABARA":
print("YES")
else:
print("NO")  Statement
You are given a string S.
Takahashi can insert the character `A` at any position in this string any
number of times.
Can he change S into `AKIHABARA`?  [{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s553796704  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  # FT Robot_2
s = input()
x, y = map(int, input().split())
L = []
stack = 0
p = [0]
q = [0]
for i in range(len(s)):
if s[i] == "F":
stack = stack + 1
else:
L.append(stack)
stack = 0
if stack != 0:
L.append(stack)
for i in range(len(L)):
if i == 0:
p = [L[i]]
elif i % 2 == 0:
while len(p) < 2 ** (i // 2):
p.append(p[0] + L[i])
p.append(p[0]  L[i])
p.remove(p[0])
elif i % 2 == 1:
while len(q) < 2 ** (i // 2 + 1):
q.append(q[0] + L[i])
q.append(q[0]  L[i])
q.remove(q[0])
if x in p and y in q:
print("Yes")
else:
print("No")
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s913390265  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, 1, 0, 1], [1, 0, 1, 0]
def inside(y: int, x: int, H: int, W: int) > bool:
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b  1) // b
YES = "Yes"
NO = "No"
def check(x, nums):
x = abs(x)
dp = [False] * (x + 1)
dp[0] = True
for y in nums:
tmp = [False] * (x + 1)
for i in range(len(dp)):
if i + y < len(tmp):
tmp[i + y] = dp[i]
if i  y >= 0:
tmp[i  y] = dp[i]
dp = tmp
return dp[x]
def solve(s, x, y):
type_num = [(k, len(list(g))) for k, g in groupby(s)]
if s[0] == "F":
x = type_num[0][1]
type_num.pop(0)
h, v = [], []
now = 0
for t, n in type_num:
if t == "F":
if now == 0:
h.append(n)
else:
v.append(n)
else:
if n % 2 != 0:
now = (now + 1) % 2
return YES if check(x, h) and check(y, v) else NO
def main():
s = input()
x, y = map(int, input().split())
print(solve(s, x, y))
if __name__ == "__main__":
main()
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s842365615  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  # * coding: utf8 *
from collections import Counter
from itertools import product
def inpl():
return tuple(map(int, input().split()))
S = input()
x, y = inpl()
M = []
d = 0
for s in S:
if s == "F":
d += 1
else:
M.append(d)
d = 0
M.append(d)
Cx = Counter(M[2::2])
Cy = Counter(M[1::2])
Lx = []
Ly = []
for k, v in Cx.items():
if k == 0:
pass
else:
Lx.append(list(range(k * v, k * v + 1, 2 * k)))
for k, v in Cy.items():
if k == 0:
pass
else:
Ly.append(list(range(k * v, k * v + 1, 2 * k)))
def bfss(Ls, t, f):
N = set([f])
for L in Ls:
nN = set(([n + l for n, l in product(N, L)]))
N = nN
if t in N:
return True
else:
return False
if bfss(Lx, x, M[0]) and bfss(Ly, y, 0):
print("Yes")
else:
print("No")
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s401545062  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  def f(m, l):
tmpm = set()
for x in m:
tmpm.add(x + l)
tmpm.add(x  l)
return tmpm
s = input() + "T"
x, y = map(int, input().split())
while s and s[0] == "F":
x = 1
s = s[1:]
ss = [{0}, {0}]
mode = 0
l = 0
for i in range(len(s)):
if s[i] == "F":
l += 1
else:
ss[mode] = f(ss[mode], l)
mode ^= 1
l = 0
print("Yes" if x in ss[0] and y in ss[1] else "No")
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s869023833  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
s = input()
[x, yy] = i2()
t = []
y = []
k = 0
for i in range(len(s)):
if s[i] == "T":
if len(t) == len(y):
y.append(k)
else:
t.append(k)
k = 0
else:
k += 1
if s[1] == "F":
if len(t) == len(y):
y.append(k)
else:
t.append(k)
dx = [0 for i in range(8001)]
dy = [0 for i in range(8001)]
dx[0] = 1
dy[0] = 1
t.sort()
y.sort()
t = t[::1]
y = y[::1]
for i in t:
for j in range(8001):
if j + i <= 8000:
dy[j + i] = dy[j]
if j  i >= 0:
dy[j  i] = dy[j]
for i in y:
for j in range(8001):
if j + i <= 8000:
dx[j + i] = dx[j]
if j  i >= 0:
dx[j  i] = dx[j]
if dy[abs(yy)] * dx[abs(x)]:
print("Yes")
else:
print("No")
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s528230035  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  s = str(input())
x, y = map(int, input().split())
n = 8000
fs = list(map(len, s.split("T")))
x = fs[0]
dx = []
dy = []
for i in range(1, len(fs)):
if fs[i] == 0:
continue
if i % 2 == 0:
dx.append(fs[i])
else:
dy.append(fs[i])
dpx = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpy = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpx[0][2 * n] = True
dpy[0][2 * n] = True
for i in range(len(dx)):
for j in range(4 * n + 1):
if dpx[i % 2][j]:
if 0 <= j  dx[i]:
dpx[(i + 1) % 2][j  dx[i]] = True
if j + dx[i] <= 4 * n:
dpx[(i + 1) % 2][j + dx[i]] = True
for i in range(len(dy)):
for j in range(4 * n + 1):
if dpy[i % 2][j]:
if 0 <= j  dy[i]:
dpy[(i + 1) % 2][j  dy[i]] = True
if j + dy[i] <= 4 * n:
dpy[(i + 1) % 2][j + dy[i]] = True
ix = 2 * n + x
iy = 2 * n + y
if (
0 <= ix <= 4 * n
and dpx[len(dx) % 2][ix]
and 0 <= iy <= 4 * n
and dpy[len(dy) % 2][iy]
):
print("Yes")
else:
print("No")
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s329507979  Runtime Error  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  n = len(input())
mp, res = {}, 0
for el in list(map(int, input().split())):
mp[el] = mp.get(el, 0) + 1
for key, val in mp:
if key > val:
res += val
elif key < val:
res += val  key
print(res)
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s242920476  Accepted  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  from collections import defaultdict
N = int(input())
As = map(int, input().split())
counts = defaultdict(int)
for a in As:
counts[a] += 1
total = 0
for n, c in counts.items():
if n < c:
total += c  n
elif n > c:
total += c
print(total)
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * *  s342995441  Accepted  p03489  Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N  n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(0)
answer = 0
i = 0
counter = 1
while i <= n  1:
if a[i] == a[i + 1]:
counter += 1
i += 1
else:
if counter != a[i]:
if counter > a[i]:
answer += counter  a[i]
i += 1
counter = 1
else:
answer += counter
i += 1
counter = 1
else:
i += 1
counter = 1
print(answer)
 Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence.  [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] 
Print the minimum possible total cost incurred.
* * *  s134359508  Wrong Answer  p03173  Input is given from Standard Input in the following format:
N
a_1 a_2 \ldots a_N  #!/usr/bin/env python3
# from collections import defaultdict
# from heapq import heappush, heappop
from itertools import accumulate
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10**9 + 1 # sys.maxsize # float("inf")
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, XS):
accum = list(accumulate(XS)) + [0]
@lru_cache(maxsize=None)
def sub(L, R):
# debug(": L,R", L, R)
if L == R:
return 0
ret = INF
for x in range(L, R):
v = sub(L, x) + sub(x + 1, R)
if v < ret:
ret = v
# debug("loop: ", XS[L:x+1], XS[x+1: R+1], v)
# debug(": ret, ", ret, accum[R]  accum[L  1])
return ret + accum[R]  accum[L  1]
return sub(0, N  1)
def main():
# parse input
N = int(input())
XS = list(map(int, input().split()))
print(solve(N, XS))
# tests
T0 = """
2
10 20
"""
def test_T0():
"""
>>> as_input(T0)
>>> main()
30
"""
T01 = """
3
10 20 30
"""
def test_T01():
"""
>>> as_input(T01)
>>> main()
90
"""
T1 = """
4
10 20 30 40
"""
def test_T1():
"""
>>> as_input(T1)
>>> main()
190
"""
T2 = """
5
10 10 10 10 10
"""
def test_T2():
"""
>>> as_input(T2)
>>> main()
120
"""
# add tests above
def _test():
import doctest
doctest.testmod()
def as_input(s):
"use in test, use given string as input file"
import io
global read, input
f = io.StringIO(s.strip())
def input():
return bytes(f.readline(), "ascii")
def read():
return bytes(f.read(), "ascii")
USE_NUMBA = False
if (USE_NUMBA and sys.argv[1] == "ONLINE_JUDGE") or sys.argv[1] == "c":
print("compiling")
from numba.pycc import CC
cc = CC("my_module")
cc.export("solve", solve.__doc__.strip().split()[0])(solve)
cc.compile()
exit()
else:
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if (USE_NUMBA and sys.argv[1] != "p") or sys.argv[1] == "numba":
# p: pure python mode
# if not p, import compiled module
from my_module import solve # pylint: disable=all
elif sys.argv[1] == "t":
print("testing")
_test()
sys.exit()
elif sys.argv[1] != "p" and len(sys.argv) == 2:
# input given as file
input_as_file = open(sys.argv[1])
input = input_as_file.buffer.readline
read = input_as_file.buffer.read
main()
 Statement
There are N slimes lining up in a row. Initially, the ith slime from the left
has a size of a_i.
Taro is trying to combine all the slimes into a larger slime. He will perform
the following operation repeatedly until there is only one slime:
* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.
Find the minimum possible total cost incurred.  [{"input": "4\n 10 20 30 40", "output": "190\n \n\nTaro should do as follows (slimes being combined are shown in bold):\n\n * (**10** , **20** , 30, 40) \u2192 (**30** , 30, 40)\n * (**30** , **30** , 40) \u2192 (**60** , 40)\n * (**60** , **40**) \u2192 (**100**)\n\n* * *"}, {"input": "5\n 10 10 10 10 10", "output": "120\n \n\nTaro should do, for example, as follows:\n\n * (**10** , **10** , 10, 10, 10) \u2192 (**20** , 10, 10, 10)\n * (20, **10** , **10** , 10) \u2192 (20, **20** , 10)\n * (20, **20** , **10**) \u2192 (20, **30**)\n * (**20** , **30**) \u2192 (**50**)\n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32bit integer type.\n\n* * *"}, {"input": "6\n 7 6 8 6 1 1", "output": "68\n \n\nTaro should do, for example, as follows:\n\n * (7, 6, 8, 6, **1** , **1**) \u2192 (7, 6, 8, 6, **2**)\n * (7, 6, 8, **6** , **2**) \u2192 (7, 6, 8, **8**)\n * (**7** , **6** , 8, 8) \u2192 (**13** , 8, 8)\n * (13, **8** , **8**) \u2192 (13, **16**)\n * (**13** , **16**) \u2192 (**29**)"}] 
Print the minimum possible total cost incurred.
* * *  s684135606  Accepted  p03173  Input is given from Standard Input in the following format:
N
a_1 a_2 \ldots a_N  # dp[i][j]  minimum cost from i to j
INF = 1e18 + 5
n = int(input())
arr = [int(x) for x in input().split()]
dp = [[0 for _ in range(n)] for _ in range(n)]
def range_sum(arr, L, R):
s = 0
for i in range(L, R + 1):
s += arr[i]
return s
for L in reversed(range(n)):
for R in range(L, n):
if L == R:
dp[L][R] = 0
else:
dp[L][R] = INF
s = range_sum(arr, L, R)
# try every possible middle
for mid in range(L, R):
dp[L][R] = min(dp[L][R], dp[L][mid] + dp[mid + 1][R] + s)
print(dp[0][n  1])
"""
int main() {
const int INF = 1e9+7;
int n;
scanf("%d", &n);
vector<int> arr(n);
vector<vector<ll>> dp(n, vector<ll>(n, 1));
vector<vector<int>> mids(n, vector<int>(n));
vector<ll> pref_sums(n+1);
ll pref_sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
dp[i][i] = 0;
}
for (int i = 0; i <= n; i++) {
pref_sum += arr[i];
pref_sums[i] = pref_sum;
}
for (int length = 1; length < n; length++) {
for (int left = 0; left+length < n; left++) {
int right = left + length;
//cout << left << " " << right << endl;
for (int mid = left; mid < right; mid++) {
ll left_cost = dp[left][mid];
ll right_cost = dp[mid+1][right];
ll range_sum = pref_sums[right]  (left1 < 0 ? 0 : pref_sums[left1]);
ll my_cost = left_cost + right_cost + range_sum;
//cout << total << endl;
/*
if (total < dp[left][right]) {
// update chosen mid & min value
dp[left][right] = my_cost;//total;
//mids[left][right] = mid;
}
*/
if (dp[left][right] == 1) {
dp[left][right] = my_cost;
}
else {
dp[left][right] = min(dp[left][right], my_cost);
}
}
}
}
/*
vector<pair<int, int>> v; // (start, end)
v.push_back({0, n1});
ll ans = 0; //dp[0][n1]; // the last one
while (!v.empty()) {
pair<int, int> cur = v.back();
v.pop_back();
if (cur.second  cur.first + 1 >= 2) { // interval at least two
ans += dp[cur.first][cur.second];
int mid = mids[cur.first][cur.second];
cout << "L: " << cur.first << " R: " << cur.second << " Total: " << dp[cur.first][cur.second] << " mid: " << mid << endl;
v.push_back({cur.first, mid});
v.push_back({mid+1, cur.second});
}
}
*/
/*
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int mid = i; mid <= j; mid++) {
ll cur = dp[i][mid];
if (mid+1 <= j) {
cur += dp[mid+1][j];
}
dp[i][j] = min(dp[i][j], cur);
}
}
}
*/
//printf("%lld", ans);
printf("%lld", dp[0][n1]);
return 0;
}
"""
 Statement
There are N slimes lining up in a row. Initially, the ith slime from the left
has a size of a_i.
Taro is trying to combine all the slimes into a larger slime. He will perform
the following operation repeatedly until there is only one slime:
* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.
Find the minimum possible total cost incurred.  [{"input": "4\n 10 20 30 40", "output": "190\n \n\nTaro should do as follows (slimes being combined are shown in bold):\n\n * (**10** , **20** , 30, 40) \u2192 (**30** , 30, 40)\n * (**30** , **30** , 40) \u2192 (**60** , 40)\n * (**60** , **40**) \u2192 (**100**)\n\n* * *"}, {"input": "5\n 10 10 10 10 10", "output": "120\n \n\nTaro should do, for example, as follows:\n\n * (**10** , **10** , 10, 10, 10) \u2192 (**20** , 10, 10, 10)\n * (20, **10** , **10** , 10) \u2192 (20, **20** , 10)\n * (20, **20** , **10**) \u2192 (20, **30**)\n * (**20** , **30**) \u2192 (**50**)\n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32bit integer type.\n\n* * *"}, {"input": "6\n 7 6 8 6 1 1", "output": "68\n \n\nTaro should do, for example, as follows:\n\n * (7, 6, 8, 6, **1** , **1**) \u2192 (7, 6, 8, 6, **2**)\n * (7, 6, 8, **6** , **2**) \u2192 (7, 6, 8, **8**)\n * (**7** , **6** , 8, 8) \u2192 (**13** , 8, 8)\n * (13, **8** , **8**) \u2192 (13, **16**)\n * (**13** , **16**) \u2192 (**29**)"}] 
Print the minimum possible total cost incurred.
* * *  s835221074  Wrong Answer  p03173  Input is given from Standard Input in the following format:
N
a_1 a_2 \ldots a_N  import array as ar
def getInt():
return int(input())
def getIntList():
return [int(x) for x in input().split()]
def zeros(n):
return [0] * n
def zeros2(n, m):
return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
def getIntLines(n):
return [int(input()) for i in range(n)]
def getIntMat(n, m): # n行に渡って、1行にm個の整数
mat = zeros((n, m))
for i in range(n):
mat[i] = getIntList()
return mat
class Debug:
def __init__(self):
self.debug = True
def off(self):
self.debug = False
def dmp(self, x, cmt=""):
if self.debug:
if cmt != "":
print(cmt, ": ", end="")
print(x)
return x
def prob_N(): # Grid 1 AC 10 TLE 6
d = Debug()
d.off()
N = getInt()
A = getIntList()
d.dmp((N), "N")
d.dmp((A), "A")
dp = ar.array("q", [0] * (N  1))
for i in range(N  1):
dp[i] = A[i] + A[i + 1]
d.dmp(dp, "dp")
cost = 0
for i in range(N  2):
mn = min(dp)
cost += mn
idx = dp.index(mn)
# d.dmp((idx,A,dp),'idx,A,dp')
if idx > 0:
dp[idx  1] += A[idx + 1]
A[idx + 1] += A[idx]
if idx < len(dp)  1:
dp[idx + 1] += A[idx]
else:
dp[idx] += A[idx]
dp.pop(idx)
A.pop(idx)
# d.dmp((mn,idx),'mn,idx')
# d.dmp((A,dp,cost), 'A,dp,cost')
return cost + dp[0]
ans = prob_N()
if ans is None:
pass
elif type(ans) == tuple and ans[0] == 1: # 1,ans
for elm in ans[1]:
print(elm)
else:
print(ans)
 Statement
There are N slimes lining up in a row. Initially, the ith slime from the left
has a size of a_i.
Taro is trying to combine all the slimes into a larger slime. He will perform
the following operation repeatedly until there is only one slime:
* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.
Find the minimum possible total cost incurred.  [{"input": "4\n 10 20 30 40", "output": "190\n \n\nTaro should do as follows (slimes being combined are shown in bold):\n\n * (**10** , **20** , 30, 40) \u2192 (**30** , 30, 40)\n * (**30** , **30** , 40) \u2192 (**60** , 40)\n * (**60** , **40**) \u2192 (**100**)\n\n* * *"}, {"input": "5\n 10 10 10 10 10", "output": "120\n \n\nTaro should do, for example, as follows:\n\n * (**10** , **10** , 10, 10, 10) \u2192 (**20** , 10, 10, 10)\n * (20, **10** , **10** , 10) \u2192 (20, **20** , 10)\n * (20, **20** , **10**) \u2192 (20, **30**)\n * (**20** , **30**) \u2192 (**50**)\n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32bit integer type.\n\n* * *"}, {"input": "6\n 7 6 8 6 1 1", "output": "68\n \n\nTaro should do, for example, as follows:\n\n * (7, 6, 8, 6, **1** , **1**) \u2192 (7, 6, 8, 6, **2**)\n * (7, 6, 8, **6** , **2**) \u2192 (7, 6, 8, **8**)\n * (**7** , **6** , 8, 8) \u2192 (**13** , 8, 8)\n * (13, **8** , **8**) \u2192 (13, **16**)\n * (**13** , **16**) \u2192 (**29**)"}] 
Print the minimum possible total cost incurred.
* * *  s839589257  Runtime Error  p03173  Input is given from Standard Input in the following format:
N
a_1 a_2 \ldots a_N  import fileinput
def solve_slimes(slimes):
slime_union_table = [0] * len(slimes) * len(slimes)
slime_cost_table = [0] * len(slimes) * len(slimes)
for i in range(len(slimes)):
slime_union_table[i] = slimes[i]
for gap in range(1, len(slimes)):
for li in range(len(slimes)  gap):
split_size = slime_union_table[li] + slime_union_table[li + 1 + (gap  1) * len(slimes)]
slime_union_table[li + gap * len(slimes)] = split_size
for split in range(0, gap):
split_cost = slime_cost_table[li + split * len(slimes)] + slime_cost_table[li + split + 1 + (gap  split  1) * len(slimes)] + split_size
if slime_cost_table[li + gap * len(slimes)] == 0:
slime_cost_table[li + gap * len(slimes)] = split_cost
else:
slime_cost_table[li + gap * len(slimes)] = min(
split_cost,
slime_cost_table[li + gap * len(slimes)]
)
return slime_cost_table[len(slimes) * (len(slimes)  1)]
inp = fileinput.FileInput()
inp.readline()
slimes = [int(v) for v in inp.readline().split()]
print(solve_slimes(slimes)  Statement
There are N slimes lining up in a row. Initially, the ith slime from the left
has a size of a_i.
Taro is trying to combine all the slimes into a larger slime. He will perform
the following operation repeatedly until there is only one slime:
* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.
Find the minimum possible total cost incurred.  [{"input": "4\n 10 20 30 40", "output": "190\n \n\nTaro should do as follows (slimes being combined are shown in bold):\n\n * (**10** , **20** , 30, 40) \u2192 (**30** , 30, 40)\n * (**30** , **30** , 40) \u2192 (**60** , 40)\n * (**60** , **40**) \u2192 (**100**)\n\n* * *"}, {"input": "5\n 10 10 10 10 10", "output": "120\n \n\nTaro should do, for example, as follows:\n\n * (**10** , **10** , 10, 10, 10) \u2192 (**20** , 10, 10, 10)\n * (20, **10** , **10** , 10) \u2192 (20, **20** , 10)\n * (20, **20** , **10**) \u2192 (20, **30**)\n * (**20** , **30**) \u2192 (**50**)\n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32bit integer type.\n\n* * *"}, {"input": "6\n 7 6 8 6 1 1", "output": "68\n \n\nTaro should do, for example, as follows:\n\n * (7, 6, 8, 6, **1** , **1**) \u2192 (7, 6, 8, 6, **2**)\n * (7, 6, 8, **6** , **2**) \u2192 (7, 6, 8, **8**)\n * (**7** , **6** , 8, 8) \u2192 (**13** , 8, 8)\n * (13, **8** , **8**) \u2192 (13, **16**)\n * (**13** , **16**) \u2192 (**29**)"}] 
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
 Downloads last month
 3