id stringlengths 14 117 | description stringlengths 29 13k | code stringlengths 10 49.8k | test_samples dict | source class label 3
classes | prompt stringlengths 391 104k |
|---|---|---|---|---|---|
939_A. Love Triangle_35916 | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i.
We call a love triangle a situation in which plane A likes plane... | n=int(input())
a=list(map(int,input().split()))
for i in range(n):
if a[a[a[i]-1]-1]==i+1:
print('YES')
exit(0)
print('NO')
| {
"input": [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n",
"100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane wit... |
964_C. Alternating Sum_35920 | You are given two integers a and b. Moreover, you are given a sequence s_0, s_1, ..., s_{n}. All values in s are integers 1 or -1. It's known that sequence is k-periodic and k divides n+1. In other words, for each k ≤ i ≤ n it's satisfied that s_{i} = s_{i - k}.
Find out the non-negative remainder of division of ∑ _{i... | n, a, b, k = map(int, input().split() )
s = input()
mod = (int)( 1e9 + 9 )
ans = 0
t = (int)( (n + 1) / k )
def modInverse(a):
return pow(a, mod - 2, mod)
i = 0
for ind in range( len(s) ):
first = ( pow(a, n - i, mod ) * pow( b, i, mod ) ) % mod
num = ( pow( b, k, mod ) * modInverse( pow(a, k, mod... | {
"input": [
"2 2 3 3\n+-+\n",
"4 1 5 1\n-\n",
"743329 973758 92942 82\n++----+-++++----+--+++---+--++++-+-+---+++++--+--+++++++--++-+++----+--+++++-+--+-\n",
"403493428 317461491 556701240 1\n-\n",
"938449224 59852396 219719125 1\n-\n",
"5 1 1 6\n++---+\n",
"234179195 430477711 115381398 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers a and b. Moreover, you are given a sequence s_0, s_1, ..., s_{n}. All values in s are integers 1 or -1. It's known that sequence is k-periodic and k divides... |
991_D. Bishwock_35924 | Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent square... | def main():
a, b = [i for i in input()], [i for i in input()]
l = len(a)
c = 0
for i in range(l - 1):
if a[i] == '0':
if b[i] == '0':
if a[i + 1] == '0':
c += 1
a[i], b[i], a[i + 1] = 1, 1, 1
elif b[i + 1] == '0'... | {
"input": [
"0XXX0\n00000\n",
"0X0X0\n0X0X0\n",
"00\n00\n",
"00X00X0XXX0\n0XXX0X00X00\n",
"X\n0\n",
"00000000\nXXXXXXXX\n",
"XX\nXX\n",
"00\nX0\n",
"000\n00X\n",
"X0000X\n00000X\n",
"000X00XX0XX0X00X0XX0XXXX00XXX0X00000000XXX0XXXXXXX0X00X00XX00X0XXX00000XXXX0XX00X00XXX00X0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
... |
p02619 Introduction to Heuristics Contest - Scoring_35937 | You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,... | D=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for i in range(D)]
t=[int(input()) for i in range(D)]
d=[0]*(26)
v=[0]*(D+1)
for i in range(D):
v[i]=s[i][t[i]-1]
d[t[i]-1]=-1
sb=0
for j in range(26):
d[j]+=1
sb+=d[j]*c[j]
... | {
"input": [
"5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of t... |
p02750 Social Infrastructure Information Systems Division Hitachi Programming Contest 2020 - Manga Market_35941 | There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.
It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.
If Takahashi reaches Store i at time t, he can do shopping the... | import sys
readline = sys.stdin.buffer.readline
INF = 10**18+3
N, T = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(N)]
ABzero = [b for a, b in AB if a == 0]
ABnonzero = [(a, b) for a, b in AB if a]
ABnonzero.sort(key = lambda x: (x[1]+1)/x[0])
dp = [0]
for a, b in ABnonzero:... | {
"input": [
"1 3\n0 3",
"5 21600\n2 14\n3 22\n1 3\n1 10\n1 9",
"3 7\n2 0\n3 2\n0 3",
"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15",
"1 3\n0 0",
"5 21600\n2 14\n3 22\n1 3\n0 10\n1 9",
"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 9",
"1 0\n1 -1",
"7 149\n0 25\n3 10\n2 4\n2 20\n3 22... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.
It takes Takahashi one unit of time ... |
p02885 AtCoder Beginner Contest 143 - Curtain_35945 | The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)
We will close the window so as to minimize the total horizontal length of the uncovered part of the window. Fin... | a,b=map(int,input().split())
print(a-2*b if a-2*b>=0 else 0) | {
"input": [
"20 30",
"12 4",
"20 15",
"27 30",
"16 4",
"45 18",
"45 20",
"35 7",
"72 20",
"72 21",
"126 21",
"20 7",
"98 21",
"39 11",
"181 21",
"45 11",
"20 8",
"181 6",
"85 11",
"20 5",
"181 9",
"17 5",
"194 9",
"3 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to ... |
p03020 AtCoder Grand Contest 034 - Manhattan Max Matching_35948 | Snuke is playing with red and blue balls, placing them on a two-dimensional plane.
First, he performed N operations to place red balls. In the i-th of these operations, he placed RC_i red balls at coordinates (RX_i,RY_i). Then, he performed another N operations to place blue balls. In the i-th of these operations, he ... | import sys
from collections import deque
def min_cost_flow(links, links_from, s, t, flow, n2):
remain = flow
result = 0
INF = 10 ** 12
predecessors = [0] * n2 # link_id
while remain:
# print(remain)
distances = [INF] * n2
updated = [False] * n2
distances[s] = 0
... | {
"input": [
"3\n0 0 1\n2 2 1\n0 0 2\n1 1 1\n1 1 1\n3 3 2",
"10\n582463373 690528069 8\n621230322 318051944 4\n356524296 974059503 6\n372751381 111542460 9\n392867214 581476334 6\n606955458 513028121 5\n882201596 791660614 9\n250465517 91918758 3\n618624774 406956634 6\n426294747 736401096 5\n974896051 888765... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke is playing with red and blue balls, placing them on a two-dimensional plane.
First, he performed N operations to place red balls. In the i-th of these operations, he placed RC_... |
p03160 Educational DP Contest - Frog 1_35952 | There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |... | N = int(input())
H = [0]+list(map(int, input().split()))
C = [10**10] + [0]*N
for i in range(2,N+1):
C[i] = min(C[i-1]+abs(H[i-1]-H[i]), C[i-2]+abs(H[i-2]-H[i]))
print(C[-1]) | {
"input": [
"6\n30 10 60 10 60 50",
"4\n10 30 40 20",
"2\n10 10",
"6\n30 10 60 10 60 57",
"4\n10 14 40 20",
"2\n18 10",
"4\n5 14 40 20",
"2\n33 10",
"6\n30 12 60 10 60 9",
"2\n9 10",
"6\n30 12 60 17 60 9",
"2\n9 18",
"6\n30 12 60 33 60 9",
"6\n30 12 60 33 60 18... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following ac... |
p03303 SoundHound Inc. Programming Contest 2018 -Masters Tournament- - Acrostic_35956 | You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
Constraints
* 1 \leq w \leq |S| \leq 1000
* S consists of lowercase E... | S = list(input())
w = int(input())
ans = S[::w]
for a in ans:
print(a, end="")
print()
| {
"input": [
"lllll\n1",
"abcdefgh\n3",
"souuundhound\n2",
"lllll\n2",
"abcdefgh\n4",
"dnuohdnuuuos\n2",
"llmll\n2",
"dnuoodnuuuhs\n2",
"llmll\n4",
"accdefgh\n5",
"dnuoodnuuuhs\n4",
"llmll\n6",
"hgfedcca\n5",
"dnuoodnuuuhs\n7",
"dnuoodnuuuhs\n1",
"llmll\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating... |
p03463 AtCoder Grand Contest 020 - Move and Win_35960 | A game is played on a strip consisting of N cells consecutively numbered from 1 to N.
Alice has her token on cell A. Borys has his token on a different cell B.
Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or... | n, a, b = map(int, input().split())
print('Alice' if (a - b - 1) % 2 == 1 else 'Borys') | {
"input": [
"58 23 42",
"2 1 2",
"5 2 4",
"9 23 42",
"8 2 4",
"3 1 2",
"9 23 18",
"3 2 2",
"8 2 3",
"9 23 23",
"0 2 2",
"7 2 3",
"9 44 23",
"0 2 1",
"7 2 5",
"9 44 0",
"0 0 1",
"7 1 5",
"9 38 0",
"0 1 1",
"7 1 4",
"1 38 0",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A game is played on a strip consisting of N cells consecutively numbered from 1 to N.
Alice has her token on cell A. Borys has his token on a different cell B.
Players take turns, A... |
p03781 AtCoder Regular Contest 070 - Go Home_35965 | There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be a... | import math
X = int(input())
low_N = (-1 + (1 + 8 * X)**0.5) / 2
high_N = (1 + (1 + 8 * X)**0.5) / 2
if low_N % 1 == 0:
print(int(low_N))
else:
print(math.floor(high_N)) | {
"input": [
"6",
"11",
"2",
"12",
"4",
"19",
"24",
"10",
"1",
"3",
"40",
"50",
"29",
"69",
"105",
"173",
"200",
"227",
"349",
"60",
"108",
"135",
"89",
"607",
"312",
"979",
"235",
"291",
"366",
"14... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at ... |
p03951 AtCoder Grand Contest 006 - Prefix and Suffix_35969 | Snuke is interested in strings that satisfy the following conditions:
* The length of the string is at least N.
* The first N characters equal to the string s.
* The last N characters equal to the string t.
Find the length of the shortest string that satisfies the conditions.
Constraints
* 1≤N≤100
* The lengths o... | N = int(input())
s = input()
t = input()
x = s+t
for i in range(N):
if (s[i:N] == t[0:N-i]):
x = s + t[N-i:N]
break
print(len(x)) | {
"input": [
"3\nabc\ncde",
"1\na\nz",
"4\nexpr\nexpr",
"3\nabc\ncce",
"1\na\n{",
"4\nexpr\nexpq",
"3\ncba\ncec",
"4\nexpr\nrxep",
"3\nabc\ncec",
"1\n`\nz",
"4\nexpr\nepxq",
"1\n`\n{",
"4\nexpr\npexq",
"3\nbca\ncec",
"1\n`\n|",
"4\nexpr\nqxep",
"3\nb... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke is interested in strings that satisfy the following conditions:
* The length of the string is at least N.
* The first N characters equal to the string s.
* The last N character... |
p00041 Expression_35973 | Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that gives an answer of 10 according to the following conditions. Also, if there are multiple answers, only the first answer found will be ou... | from itertools import permutations, product
import sys
readline = sys.stdin.readline
write = sys.stdout.write
P = [
"((%d %s %d) %s (%d %s %d))",
"(%d %s (%d %s (%d %s %d)))",
"(((%d %s %d) %s %d) %s %d)",
"((%d %s (%d %s %d)) %s %d)",
"(%d %s ((%d %s %d) %s %d))",
]
def solve():
*X, = map(int, ... | {
"input": [
"8 7 9 9\n4 4 4 4\n5 5 7 5\n0 0 0 0",
"8 7 9 9\n4 4 4 4\n5 5 3 5\n0 0 0 0",
"8 7 9 9\n4 4 4 4\n5 5 1 5\n0 0 0 0",
"8 7 9 11\n4 4 4 4\n5 5 3 5\n0 0 0 0",
"8 7 9 5\n4 4 3 4\n5 5 7 2\n0 0 0 0",
"8 7 8 9\n4 4 4 0\n5 5 7 2\n0 0 0 0",
"8 7 9 11\n4 4 4 4\n5 5 7 5\n0 0 0 0",
"8 7 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that... |
p00173 Haunted House_35977 | Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many visitors come from the neighborhood these days.
Therefore, the sc... | while True:
try:a,b,c=input().split()
except:break
b,c=map(int,[b,c])
print(a,b+c,b*200+c*300)
| {
"input": [
"1a 132 243\n1c 324 183\n1f 93 199\n2b 372 163\n2c 229 293\n2e 391 206\n3a 118 168\n3b 263 293\n3d 281 102",
"1a 132 243\n1c 324 183\n1f 93 199\n2b 372 163\n2c 229 346\n2e 391 206\n3a 118 168\n3b 263 293\n3d 281 102",
"1a 132 243\n1c 324 183\n1f 93 199\n3b 372 163\n2c 229 346\n2e 391 206\n3a ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or... |
p00502 Hot days_35982 | problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of cl... | def solve():
from sys import stdin
f_i = stdin
D, N = map(int, f_i.readline().split())
T = tuple(int(f_i.readline()) for i in range(D))
clothes = [tuple(map(int, f_i.readline().split())) for i in range(N)]
clothes.sort(key=lambda x: x[2])
candidate = []
for t in T:
... | {
"input": [
"3 4\n31\n27\n35\n20 25 30\n23 29 90\n21 35 60\n28 33 40",
"3 4\n34\n27\n35\n20 25 30\n23 29 90\n21 35 60\n28 33 40",
"3 4\n31\n27\n35\n20 25 30\n35 29 90\n21 35 60\n28 33 40",
"3 4\n34\n40\n35\n20 25 30\n23 29 90\n21 69 60\n28 33 40",
"3 4\n31\n27\n35\n20 25 30\n23 29 90\n21 35 60\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the... |
p00686 Where's Your Robot?_35986 | You have full control over a robot that walks around in a rectangular field paved with square tiles like a chessboard. There are m columns of tiles from west to east, and n rows of tiles from south to north (1 <= m, n <= 100). Each tile is given a pair of coordinates, such as (i, j), where 1 <= i <= m and 1 <= j <= n.
... | while True:
col, row = map(int, input().split())
if col == 0:
break
else:
robot = [1, 1]
direction = "up"
while True:
str = input()
if str == "STOP":
print(robot[0], robot[1])
break
elif str == "LEFT":
... | {
"input": [
"6 5\nFORWARD 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 2\nSTOP\n3 1\nFORWARD 2\nSTOP\n0 0",
"6 5\nFORWARD 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 2\nSTOP\n5 1\nFORWARD 2\nSTOP\n0 0",
"6 5\nFORWARD 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 3\nSTOP\n3 1\nFORWARD 2\nSTOP\n0 0",
"6 6\nFORDARW 1\nRIGHT\nFORW... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have full control over a robot that walks around in a rectangular field paved with square tiles like a chessboard. There are m columns of tiles from west to east, and n rows of ti... |
p00828 Make a Sequence_35990 | Your company’s next product will be a new game, which is a three-dimensional variant of the classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length.
People believe that it is fun to play the game, but they still cannot fix the values of s... | import sys
sys.setrecursionlimit(1000000000)
input=lambda : sys.stdin.readline().rstrip()
dx=[1,1,0,-1,1,1,0,-1,-1,-1,0,1,0]
dy=[0,1,1,1,0,1,1,1,0,-1,-1,-1,0]
dz=[0,0,0,0,1,1,1,1,1,1,1,1,1]
while True:
n,m,q=map(int,input().split())
if n==m==q==0:
break
field=[[[-1 for i in range(n)]for i in range... | {
"input": [
"3 3 3\n1 1\n1 1\n1 1\n3 3 7\n2 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n2 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1\n2 2\n0 0 0",
"3 3 3\n1 1\n1 1\n1 1\n3 3 7\n2 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n0 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your company’s next product will be a new game, which is a three-dimensional variant of the classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), a... |
p00959 Medical Checkup_35994 | Problem C Medical Checkup
Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on.
Students are now forming a long queue, waiting for the checkup to start. Students are also numbered 1, 2, 3, and so on, from the top of the queue. They have to under... | n, t = map(int, input().split())
s = x = y = 0
for i in range(n):
h = int(input())
s, x, y = s+x, h, max(h, y)
print(max((t-x-s)//y+2,1)) | {
"input": [
"3 20\n5\n7\n3",
"3 20\n5\n11\n3",
"3 20\n5\n11\n6",
"3 20\n1\n11\n6",
"3 20\n1\n3\n6",
"3 20\n1\n3\n3",
"3 25\n1\n3\n3",
"3 35\n1\n3\n3",
"3 35\n1\n3\n4",
"3 55\n1\n3\n4",
"3 55\n1\n3\n0",
"3 55\n1\n4\n0",
"3 55\n2\n4\n0",
"3 20\n7\n7\n3",
"3 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem C Medical Checkup
Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on.
Students are now forming a l... |
p01228 Rhythm Machine_35998 | Advanced Computer Music (ACM) sold a rhythm machine that plays music according to a pre-programmed rhythm. At one point, ACM was trying to develop and sell a new rhythm machine. While ACM's old product could only play one sound at a time, the new product was able to play up to eight sounds at the same time, which was t... | def shorten(s):
f = 1
while f:
l = len(s) // 2
while f:
f = 0
if l % 2 == 0:
for i in range(l):
if s[2 * i:2 * i + 2] != "00" and i % 2:break
else:
f = 1
t = ""
... | {
"input": [
"5\n2\n01000100\n00020202\n2\n0102\n00000810\n1\n0200020008000200\n5\n0001\n000001\n0000000001\n00000000000001\n0000000000000000000001\n1\n000000",
"5\n2\n01000100\n00020202\n2\n0102\n00000810\n1\n0200020008000200\n5\n0001\n000001\n0000000011\n00000000000001\n0000000000000000000001\n1\n000000",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Advanced Computer Music (ACM) sold a rhythm machine that plays music according to a pre-programmed rhythm. At one point, ACM was trying to develop and sell a new rhythm machine. While... |
p01362 Dice Room_36001 | You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to call for help, so you have to escape on yours own. However, almost every room in the house has some kind of puzzles and you cannot move to n... | from collections import deque
def main():
I = {
1: ((6, 0), (2, 1), (5, 2), (4, 3)),
2: ((6, 3), (3, 1), (5, 3), (1, 3)),
3: ((6, 2), (4, 1), (5, 0), (2, 3)),
4: ((6, 1), (1, 1), (5, 1), (3, 3)),
5: ((1, 0), (2, 0), (3, 0), (4, 0)),
6: ((1, 2), (2, 2), (3, 2), (4, 2))... | {
"input": [
"...\n...\n.*.\n...\n...\n.*.\n...\n...\n...\n...\n...\n.*.\n...\n...\n.*.\n...\n...\n...\n\n...\n.*.\n...\n*..\n...\n..*\n*.*\n*.*\n*.*\n*.*\n.*.\n*.*\n*..\n.*.\n..*\n*.*\n...\n*.*\n\n...\n.*.\n.*.\n...\n.**\n*..\n...\n...\n.*.\n.*.\n...\n*..\n..*\n...\n.**\n...\n*..\n...",
"...\n...\n.*.\n...\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to cal... |
p01844 Land Inheritance_36007 | F --Land inheritance
Problem Statement
One $ N $ brother was discussing the inheritance of his parents. The vast heritage left by their parents included vast lands. The land has a rectangular shape extending $ H $ km from north to south and $ W $ km from east to west. This land is managed in units of 1 km square, 1 k... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def rotate(H, W, R0):
R1 = [[0]*H for i in range(W)]
for i in range(H):
for j in range(W):
R1[W-1-j][i] = R0[i][j]
return R1
def make(H, W, R0):
R1 = [[0]*(W+1) for i in range(H+1)]
for i in range(H):
c = 0... | {
"input": [
"3 3 2\n1 2 2\n3 1 0\n0 4 3",
"3 3 2\n1 2 2\n3 1 0\n1 4 3",
"3 3 2\n1 2 2\n1 1 0\n1 4 3",
"3 3 2\n1 2 2\n1 1 0\n1 2 3",
"1 3 2\n2 2 2\n1 1 0\n1 2 3",
"1 3 0\n1 3 2\n1 2 -1\n1 2 3",
"1 3 2\n2 3 3\n1 1 0\n1 2 3",
"3 4 2\n1 2 2\n3 1 0\n0 4 6",
"3 3 1\n1 2 2\n4 1 0\n1 4 3"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
F --Land inheritance
Problem Statement
One $ N $ brother was discussing the inheritance of his parents. The vast heritage left by their parents included vast lands. The land has a r... |
p02126 Ball_36011 | Problem
There are $ N $ balls, each with its own color and value.
There are $ C $ types of ball colors from $ 1 $ to $ C $, and each color has an upper limit on the number of balls that can be selected.
Maximize the total value you get when choosing at most $ M $ balls in total.
Constraints
The input satisfies the f... | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, M, C = inpl()
L = {i+1:v for i, v in enumerate(inpl())}
balls = []
for _ in range(N):
c, w = inpl()
balls.append([w, c])
balls = sorted(balls, reverse=True)
i = 0
count = 0
ans = 0
for i in range(N):
w, c = balls[i]
if coun... | {
"input": [
"22 7 26\n11 14 15 3 11 7 16 17 1 4 2 19 4 14 16 16 3 13 17 12 7 11 2 20 12 22\n6 10\n1 3\n13 1\n16 5\n4 1\n20 7\n18 4\n26 6\n9 1\n12 2\n21 1\n21 7\n18 1\n14 5\n24 5\n6 1\n3 1\n2 5\n21 2\n7 6\n10 9\n15 7",
"3 3 2\n1 1\n1 1\n1 100\n2 10",
"3 3 3\n1 0 1\n1 1\n2 100\n3 1",
"22 7 26\n11 14 15... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There are $ N $ balls, each with its own color and value.
There are $ C $ types of ball colors from $ 1 $ to $ C $, and each color has an upper limit on the number of balls t... |
p02266 Areas on the Cross-Section Diagram_36015 | Areas on the Cross-Section Diagram
Your task is to simulate a flood damage.
For a given cross-section diagram, reports areas of flooded sections.
<image>
Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the abov... | def cross_section_diagram():
down = []
edge = []
pool = []
for i, c in enumerate(input()):
if c == '\\':
down.append(i)
elif c == '/' and down:
left = down.pop()
area = i - left
while edge:
if edge[-1] < left:
break
edge.pop()
area += pool.pop()
edge.append(left)
pool.appen... | {
"input": [
"\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\",
"\\\\//",
"\\/_/\\_/\\\\_\\\\\\__///\\\\/_/\\\\\\\\/\\/_\\///\\\\",
"]\\//",
"\\/_/\\_/\\\\_/\\\\__///\\\\/_/\\\\\\\\/\\/_\\/\\/\\\\",
"\\/_/\\_/\\\\_/\\\\__///\\\\/_/\\[\\\\0\\/_\\/\\/\\\\",
"-/\\]",
"\\/_/\\_/\\\\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Areas on the Cross-Section Diagram
Your task is to simulate a flood damage.
For a given cross-section diagram, reports areas of flooded sections.
<image>
Assume that rain is fal... |
p02414 Matrix Multiplication_36019 | Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ res... | n,m,l = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
B = [list(map(int,input().split())) for j in range(m)]
C = [[0 for k in range(l)]for i in range(n)]
for i in range(n) :
for k in range(l) :
for j in range(m) :
C[i][k] = C[i][k] + A[i][j] * B[j][k]
for i in range(n):
... | {
"input": [
"3 2 3\n1 2\n0 3\n4 5\n1 2 1\n0 3 2",
"3 2 3\n1 2\n0 3\n4 5\n1 2 1\n1 3 2",
"3 2 3\n1 2\n1 3\n4 5\n1 2 1\n1 3 2",
"3 2 3\n1 2\n2 3\n4 5\n1 2 1\n1 3 2",
"3 2 3\n1 2\n2 3\n4 5\n1 2 2\n1 3 2",
"3 2 3\n1 2\n3 3\n4 5\n1 2 2\n1 3 2",
"3 2 3\n1 1\n3 3\n4 5\n1 2 2\n1 3 2",
"3 2 3\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the f... |
1042_D. Petya and Array_36031 | Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.
Now he wonders what is the number of segments in his arra... | maxn = 2*10**5 + 5
bit = [0]*(maxn)
def add(idx):
idx += 1
while idx < maxn:
bit[idx] += 1
idx += idx & -idx
def sm(idx):
idx += 1
tot = 0
while idx > 0:
tot += bit[idx]
idx -= idx & -idx
return tot
n,t = map(int,input().split())
a = list(map(int,input().spli... | {
"input": [
"5 4\n5 -1 3 4 -1\n",
"3 0\n-1 2 -3\n",
"4 -1\n-2 1 -2 3\n",
"1 -999999999\n-999999999\n",
"10 -196228170\n-181402541 328251238 624722764 682518931 783857631 969228879 547715844 -149364638 823684584 833196798\n",
"1 1000000000\n1000000000\n",
"1 902894468\n700839779\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment ... |
1065_C. Make It Equal_36035 | There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i.
Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make towe... | #########################################################################################################\
#########################################################################################################
###################################The_Apurv_Rathore#####################################################
#... | {
"input": [
"4 5\n2 3 4 5\n",
"5 5\n3 1 2 2 4\n",
"5 10\n2 2 2 2 3\n",
"4 4\n1 1 1 1\n",
"1 1\n1\n",
"5 5\n1 1 1 1 1\n",
"1 5\n5\n",
"4 5\n4 4 4 4\n",
"2 100\n5 5\n",
"2 2\n2 2\n",
"2 2\n3 3\n",
"4 5\n3 3 3 4\n",
"3 4\n3 3 3\n",
"1 4\n1\n",
"5 5\n3 3 3 3 3\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i.
Let's define ... |
1088_A. Ehab and another construction problem_36039 | Given an integer x, find 2 integers a and b such that:
* 1 ≤ a,b ≤ x
* b divides a (a is divisible by b).
* a ⋅ b>x.
* a/b<x.
Input
The only line contains the integer x (1 ≤ x ≤ 100).
Output
You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in... |
n=int(input())
if n>=3 and n%2==1:
print(n-1,2)
elif n>=2 and n%2==0:
print(n,2)
else:
print(-1) | {
"input": [
"1\n",
"10\n",
"82\n",
"49\n",
"35\n",
"79\n",
"92\n",
"57\n",
"100\n",
"75\n",
"56\n",
"41\n",
"16\n",
"25\n",
"8\n",
"74\n",
"90\n",
"44\n",
"13\n",
"64\n",
"70\n",
"7\n",
"9\n",
"4\n",
"72\n",
"69\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given an integer x, find 2 integers a and b such that:
* 1 ≤ a,b ≤ x
* b divides a (a is divisible by b).
* a ⋅ b>x.
* a/b<x.
Input
The only line contains the integer ... |
1107_A. Digits Sequence Dividing_36043 | You are given a sequence s consisting of n digits from 1 to 9.
You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the ... | for _ in range(int(input())):
n = int(input())
z = input()
if n==2 and z[0]>=z[1]:
print("NO")
else:
print("YES")
print(2)
print(z[0],z[1::]) | {
"input": [
"4\n6\n654321\n4\n1337\n2\n33\n4\n2122\n",
"2\n2\n45\n2\n67\n",
"21\n3\n123\n3\n123\n3\n123\n3\n123\n3\n123\n3\n213\n3\n123\n3\n123\n3\n123\n3\n321\n3\n123\n3\n321\n3\n132\n3\n322\n3\n321\n3\n341\n3\n123\n3\n421\n3\n421\n3\n421\n3\n421\n",
"1\n4\n9999\n",
"1\n4\n5234\n",
"4\n6\n65... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence s consisting of n digits from 1 to 9.
You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you... |
1136_A. Nastya Is Reading a Book_36047 | After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.
Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi... | n=int(input())
p=[]
for x in range(n):
a,b=list(map(int,input().split()))
sam=list(range(a,b+1))
p.append(sam)
kam=int(input())
for x in p:
if kam in x:
print(n-p.index(x))
break
| {
"input": [
"3\n1 4\n5 9\n10 12\n9\n",
"1\n1 7\n4\n",
"3\n1 3\n4 7\n8 11\n2\n",
"1\n1 5\n1\n",
"19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n13\n",
"3\n1 3\n4 7\n8 11\n1\n",
"2\n1 2\n3 4\n3\n",
"1\n1 2\n1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contai... |
1154_E. Two Teams_36051 | There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose ... | import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i, a in enumerate(A):
B.append((a, i+1))
B.sort()
#print(B)
bit = [0]*(n+1)
def bit_query(i, bit):
res = 0
while i > 0:
... | {
"input": [
"5 1\n2 4 5 3 1\n",
"7 1\n7 2 1 3 5 4 6\n",
"5 1\n2 1 3 5 4\n",
"5 2\n2 4 5 3 1\n",
"100 7\n89 100 24 91 95 84 22 64 69 52 76 99 62 93 82 57 72 21 26 27 9 32 71 96 17 2 4 40 41 50 55 60 36 14 70 11 68 74 80 98 75 15 94 29 63 66 38 3 25 28 79 13 97 16 1 39 33 12 30 49 90 10 87 18 42 20... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.
The i-th student has ... |
1176_C. Lose it!_36055 | You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.
Your task is to remove the minimum number of elements to make this array good.
An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15... | _=int(input())
a=list(map(int,input().split()))
b=[4,8,15,16,23,42]
c=[0]*6
for i in range(len(a)):
x = b.index(a[i])
if x == 0:
c[0] +=1
elif c[x-1]!=0:
c[x-1]-=1
c[x]+=1
print(len(a)-6*c[5]) | {
"input": [
"5\n4 8 15 16 23\n",
"15\n4 8 4 8 15 16 8 16 23 15 16 4 42 23 42\n",
"12\n4 8 4 15 16 8 23 15 16 42 23 42\n",
"1\n4\n",
"123\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.
Your task is to remove the minimum number of elements to make t... |
1195_B. Sport Mafia_36059 | Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remainin... | n,x=map(int,input().split())
formula=0
i=0
if(n==1):
print(0)
else:
formula=1000000
while(abs(n-(i+formula))!=x):
i=i+1
formula=(i*(i+1))//2
print(abs(n-i))
| {
"input": [
"1 1\n",
"3 2\n",
"9 11\n",
"5 0\n",
"107 3295\n",
"999997 811911683\n",
"999993 417284432\n",
"999999 675660078\n",
"1001 102283\n",
"106 634\n",
"239239 142219520\n",
"999998 551232762\n",
"1000000 485392454\n",
"999992 159231858\n",
"103 1976... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for... |
1234_D. Distinct Characters Queries_36063 | You are given a string s consisting of lowercase Latin letters and q queries for this string.
Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} ... s_r. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top".
There are two types of queries:
... | import sys
def upd(bit, idx, inc):
while idx < len(bit):
bit[idx] += inc
idx += idx & -idx
def query(bit, idx):
ret = 0
while idx > 0:
ret += bit[idx]
idx -= idx & -idx
return ret
if __name__ == '__main__':
input = sys.stdin.readline
inp = list(input().strip... | {
"input": [
"dfcbbcfeeedbaea\n15\n1 6 e\n1 4 b\n2 6 14\n1 7 b\n1 12 c\n2 6 8\n2 1 6\n1 7 c\n1 2 f\n1 10 a\n2 7 9\n1 10 a\n1 14 b\n1 1 f\n2 1 11\n",
"abacaba\n5\n2 1 4\n1 4 b\n1 5 b\n2 4 6\n2 1 7\n",
"aaab\n1\n2 4 4\n",
"abacaba\n5\n2 1 4\n1 4 b\n1 5 b\n2 4 6\n2 2 7\n",
"abab\n1\n2 4 4\n",
"df... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s consisting of lowercase Latin letters and q queries for this string.
Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} ... s_r. F... |
1253_C. Sweets Eating_36067 | Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer a_i.
Yui loves sweets, but she can eat at most m sweets each day for health reasons.
Days are 1-indexed (numbered 1, 2, 3, …). Eating the sweet i at the d-t... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
f = [0] * 1000000
sum = [0] * 1000000
for i in range(n):
sum[i] = sum[i - 1] + a[i]
for i in range(n):
f[i] = f[i - m] + sum[i]
print(f[i], end = " ")
| {
"input": [
"1 1\n7\n",
"9 2\n6 19 3 4 4 2 6 7 8\n",
"5 5\n98816 43061 167639 85627 15007\n",
"2 1\n135072 38422\n",
"3 1\n134186 63312 172492\n",
"5 1\n132416 80387 164336 78116 99081\n",
"2 2\n51200 19970\n",
"5 2\n15840 196527 169082 107594 191438\n",
"3 2\n50314 12156 18453\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer a_i.
Yui loves sweet... |
1277_B. Make Them Odd_36071 | There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c.
For example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the move.
You need to find the minimal number of moves for transformin... | for _ in range(int(input())):
n=int(input())
a=[int(y) for y in input().split()]
a=sorted(a)
a=a[::-1]
d={}
count=0
for i in range(n):
d[a[i]]=0
for i in range(n):
if(d[a[i]] == 0):
s=a[i]
while(a[i]%2==0):
a[i]/=2
... | {
"input": [
"4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n",
"4\n6\n40 6 40 3 20 1\n1\n2020\n4\n2 4 8 16\n3\n3 1 7\n",
"4\n6\n22 6 40 3 20 1\n1\n2020\n4\n2 4 8 16\n3\n3 1 7\n",
"4\n6\n37 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n",
"4\n6\n22 6 40 3 20 1\n1\n2038\n4\n2 4 8 30\n1\n3 1 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c.
For example, if a=[6,8,12,6,3,12] and ... |
1320_C. World of Darkraft: Battle for Azathoth_36074 | Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier a_i and is worth ca_i coins, and armor set j has defense... | # quick input by @c1729 and @pajenegod
import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from bisect import bisect_right
from operator import itemgetter
class SegmTree:
'''
- increment on interval
- get max on interval
'''
def __init__(self, size):
N = 1
h =... | {
"input": [
"2 3 3\n2 3\n4 7\n2 4\n3 2\n5 11\n1 2 4\n2 1 6\n3 4 6\n",
"4 4 5\n5 10\n6 2\n10 3\n9 5\n7 7\n4 3\n9 2\n3 6\n7 1 6\n8 3 2\n2 6 9\n3 8 2\n1 2 9\n",
"3 3 3\n6 1010\n9 1153\n9 1159\n9 1150\n7 1058\n9 1159\n7 3 172\n10 3 167\n6 6 160\n",
"1 2 1\n2 2\n2 1\n2 2\n1 1 1\n",
"10 10 10\n51 87\n6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
Roma has a choice to buy exactly one of n different... |
133_A. HQ9+_36078 | HQ9+ is a joke programming language which has only four one-character instructions:
* "H" prints "Hello, World!",
* "Q" prints the source code of the program itself,
* "9" prints the lyrics of "99 Bottles of Beer" song,
* "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q"... | s=input()
flag=0
for i in range(len(s)):
if(s[i]=='H' or s[i]=='Q' or s[i]=='9'):
print('YES')
flag=1
break
if flag==0:
print('NO') | {
"input": [
"Codeforces\n",
"Hi!\n",
"!3YPv@2JQ44@)R2O_4`GO\n",
"Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5\n",
"U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8\n",
"UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp\n",
"!0WKT:$O\n",
"!:!{~=9*\\P;Z6F?HC5GadFz)>... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
HQ9+ is a joke programming language which has only four one-character instructions:
* "H" prints "Hello, World!",
* "Q" prints the source code of the program itself,
* "9" prin... |
1361_B. Johnny and Grandmaster_36081 | Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems.
The boy has found an online judge with tasks divided by topics they cover. ... | import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | {
"input": [
"4\n5 2\n2 3 4 4 3\n3 1\n2 10 1000\n4 5\n0 1 1 100\n1 8\n89\n",
"1\n20 22328\n2572 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"1\n25 2\n2 3 4 6 7 9 12 13 15 22 23 24 26 30 37 40 41 42 43 44 45 51 52 1000000 1\n",
"1\n17 2\n30 26 22 21 18 16 13 12 10 8 7 6 5 4 3 0 0\n",
"1\n67 2\n100 99... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that... |
1381_C. Mastermind_36085 | In the game of Mastermind, there are two players — Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive.
When Bob guesses a code, Alice tells him some information about ... | from sys import stdin, stdout
from collections import defaultdict
from heapq import heapify, heappop, heappush
def solve():
n, s, y = map(int, stdin.readline().split())
a = stdin.readline().split()
d = defaultdict(list)
for i, x in enumerate(a):
d[x].append(i)
for i in range(1, n + 2):
... | {
"input": [
"7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n",
"7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n",
"6\n1 0 0\n1\n1 0 0\n2\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the game of Mastermind, there are two players — Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exact... |
1401_D. Maximum Distributed Tree_36089 | You are given a tree that consists of n nodes. You should label each of its n-1 edges with an integer in such way that satisfies the following conditions:
* each integer must be greater than 0;
* the product of all n-1 numbers should be equal to k;
* the number of 1-s among all n-1 integers must be minimum po... | import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
dic={}
dico={}
for i in range(1,n+1):
dic[i]=[]
dico[i]=[]
for i in range(n-1):
x,y=map(int,input().split())
dic[x].append(y)
dic[y].append(x)
dico[x].append(y)
di... | {
"input": [
"3\n4\n1 2\n2 3\n3 4\n2\n2 2\n4\n3 4\n1 3\n3 2\n2\n3 2\n7\n6 1\n2 3\n4 6\n7 3\n5 1\n3 6\n4\n7 5 13 3\n",
"4\n3\n3 1\n2 1\n4\n22861 20707 59627 9293\n3\n3 1\n1 2\n6\n15767 40973 20807 24419 46439 33757\n3\n3 2\n1 2\n6\n16493 54493 10799 37529 59743 30529\n3\n3 1\n2 1\n1\n42961\n",
"1\n4\n1 2\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree that consists of n nodes. You should label each of its n-1 edges with an integer in such way that satisfies the following conditions:
* each integer must be g... |
1446_B. Catching Cheaters_36095 | You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequence of strings C and D.
You believe that only some part of the ... | n, m = map(int, input().split())
a = input()
b = input()
res = 0
dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
if a[i - 1] == b[j - 1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2)
dp[i][j] = max(dp[i][j], max(dp[i - 1][j], d... | {
"input": [
"7 7\nuiibwws\nqhtkxcn\n",
"4 5\nabba\nbabab\n",
"8 10\nbbbbabab\nbbbabaaaaa\n",
"11 18\naaaagaaxaxa\naiaiiaaaaiaaiaaaaa\n",
"12 17\nqqqqqqgqqgqq\nqqqgqqqggqqqlqqqq\n",
"6 9\nvvvkvv\nvgkkvvvgg\n",
"153 205\nssasssszzessssseazzssssassaskasassesssseszzazzaassassslsasasszszeaeeaa... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C|... |
1470_B. Strange Definition_36099 | Let us call two integers x and y adjacent if (lcm(x, y))/(gcd(x, y)) is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not.
Here gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y, and lcm(x, y) denotes the [least comm... | from sys import stdin
dct = {i:i for i in range(1000001)}
for i in range(2, 1001):
for j in range(1, (10 ** 6) // (i ** 2) + 1):
dct[(i ** 2) * j] = j
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
elements = map(int, stdin.readline().split())
q = int(stdin.readline())
dct2 = {}
for i in... | {
"input": [
"2\n4\n6 8 4 2\n1\n0\n6\n12 3 20 5 80 1\n1\n1\n",
"1\n5\n1 1 3 3 1\n1\n4294967296\n",
"1\n40\n1 3 5 6 2 10 7 10 4 2 10 10 6 1 1 8 1 3 7 2 9 10 4 2 4 1 9 1 1 4 1 7 8 1 7 9 3 10 7 1\n40\n1\n7\n0\n5\n1\n9\n9\n2\n0\n5\n7\n7\n3\n10\n4\n6\n0\n9\n0\n8\n5\n5\n3\n3\n6\n5\n1\n10\n8\n8\n3\n1\n1\n4\n7\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let us call two integers x and y adjacent if (lcm(x, y))/(gcd(x, y)) is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not.
Here gcd(x, y) denotes the [greates... |
1497_A. Meximization_36103 | You are given an integer n and an array a_1, a_2, …, a_n. You should reorder the elements of the array a in such way that the sum of MEX on prefixes (i-th prefix is a_1, a_2, …, a_i) is maximized.
Formally, you should find an array b_1, b_2, …, b_n, such that the sets of elements of arrays a and b are equal (it is equ... | #fi = open("task1.txt")
#def input():
# return fi.readline()
T = int(input())
for _ in range(T):
n = int(input())
a = [int(x) for x in input().split()]
nums = [0 for _ in range(101)]
for el in a:
nums[el] += 1
result = []
for i in range(101):
if nums[i] >= 1:
result += [str(i)]
nums[i] -= 1
else:
... | {
"input": [
"3\n7\n4 2 0 1 3 3 7\n5\n2 2 8 6 9\n1\n0\n",
"1\n1\n2\n",
"1\n100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"1\n1\n4\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer n and an array a_1, a_2, …, a_n. You should reorder the elements of the array a in such way that the sum of MEX on prefixes (i-th prefix is a_1, a_2, …, a_i) ... |
174_B. File List_36110 | Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin lett... | s=input()
n=len(s)
a=s.find('.')
b=s.rfind('.')
from sys import exit
if a==b==-1:print('NO');exit()
if a==0 or n-b-1==0:print('NO');exit()
if not 0<a<9 or not 0<n-b-1<4:print('NO');exit()
s2=s[a+1:b+1]
res=[s[:a+1]]
app=res.append
length,item=0,''
for i,x in enumerate(s2):
if x=='.':
if not 1<length<12:prin... | {
"input": [
"read.meexample.txtb.cpp\n",
"version.infontldrcontestdata.zip\n",
"ph..qlr.pt\n",
"aa.aa.aaaabbbbccc.ddd.ee\n",
"akymwh\n",
".abcde.cpp\n",
".abc.cpp\n",
".c.v.hpehh\n",
"double..dot\n",
"badabaca.mor\n",
"a.b.c\n",
"thisislongfilename\n",
"abc.abcde\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the B... |
194_C. Cutting Figure_36114 | You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected.
A set of painted squares is called connected, if for every two s... | n, m = map(int, input().split())
p, s = [], {}
x = 0
for i in range(n):
for j, q in enumerate(input()):
if q != '#': continue
s[(i, j)] = x
p.append([])
if (i, j - 1) in s:
p[x] += [x - 1]
p[x - 1] += [x]
if (i - 1, j) in s:
y = s[(i - 1, j... | {
"input": [
"5 5\n#####\n#...#\n#####\n#...#\n#####\n",
"5 4\n####\n#..#\n#..#\n#..#\n####\n",
"3 3\n###\n#.#\n###\n",
"2 2\n.#\n.#\n",
"2 2\n.#\n##\n",
"2 5\n#####\n##.##\n",
"2 2\n##\n#.\n",
"5 3\n###\n###\n.#.\n###\n###\n",
"1 2\n##\n",
"5 7\n.#####.\n.#...#.\n###.###\n#.#.... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum nu... |
218_C. Ice Skating_36118 | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | #start the code from here
n=int(input())
global parent
parent=[i for i in range(n)]
# n is total number of nodes
# finding parent of a node
def find(w):
global parent
if parent[w]==w:
return w
else:
return find(parent[w])
def union(a,b):
global parent
w=find(a)
y=find(b)
if w==y:
return
parent[y]=w
... | {
"input": [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n",
"7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924\n",
"3\n1 1\n1 2\n2 2\n",
"6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3\n",
"23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands i... |
241_G. Challenging Balloons_36122 | Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..... | print(302)
print("0 1000000")
coord, rad = 17321*2, 300
for i in range(300):
print(coord, rad)
coord, rad = coord+600, rad-1
print("1000000 1000000")
| {
"input": [
""
],
"output": [
"302\n0 500000\n24495 300\n25094 299\n25691 298\n26286 297\n26879 296\n27470 295\n28059 294\n28646 293\n29231 292\n29814 291\n30395 290\n30974 289\n31551 288\n32126 287\n32699 286\n33270 285\n33839 284\n34406 283\n34971 282\n35534 281\n36095 280\n36654 279..."
]
} | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assi... |
267_A. Subtractions_36126 | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | for i in range(int(input())):
a,b=map(int,input().split())
sm=0
while a and b:
sm+=a//b
t=b
b=a%b
a=t
print(sm) | {
"input": [
"2\n4 17\n7 987654321\n",
"20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one numb... |
290_A. Mysterious strings_36130 |
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding | ans = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267]
print(ans[int(input())])
| {
"input": [
"8\n",
"2\n",
"29\n",
"12\n",
"40\n",
"43\n",
"10\n",
"11\n",
"60\n",
"50\n",
"61\n",
"17\n",
"9\n",
"59\n",
"14\n",
"64\n",
"48\n",
"28\n",
"58\n",
"51\n",
"30\n",
"32\n",
"34\n",
"33\n",
"3\n",
"37\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
... |
316_A1. Special Task_36134 | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get th... | hint = input()
seen = []
if 'A' <= hint[0] <= 'J':
num = 9
seen = [hint[0]]
elif '0' <= hint[0] <= '9':
num = 1
elif hint[0] == '?':
num = 9
for l in hint[1:]:
if 'A' <= l <= 'J':
if not l in seen:
num *= 10 - len(seen)
seen += [l]
elif l == '?':
num *= ... | {
"input": [
"1?AA\n",
"AJ\n",
"?C\n",
"?H2?H\n",
"9???\n",
"??JG?\n",
"HH???\n",
"B??C?\n",
"IG5IJ\n",
"5???\n",
"?J?5?\n",
"3??\n",
"??C?C\n",
"7\n",
"IJ?GH\n",
"CB?\n",
"BB?C?\n",
"H1I??\n",
"???2\n",
"CB\n",
"?BCB?\n",
"GJH2?\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the be... |
384_C. Milking cows_36142 | Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of mi... | n = int(input())
lis = list(map(int,input().split()))
ans=b=0
for i in range(n-1,-1,-1):
if lis[i]==1:
ans+=b
else:
b+=1
print(ans) | {
"input": [
"5\n1 0 1 0 1\n",
"4\n0 0 1 0\n",
"2\n0 1\n",
"2\n1 0\n",
"4\n1 1 1 1\n",
"1\n0\n",
"2\n0 0\n",
"50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\n",
"1\n1\n",
"2\n1 1\n",
"100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left... |
405_B. Domino Effect_36146 | Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes... | n = int(input())
s = input()+'R'
r = 0
flag = 'L'
a = 0
for _ in range(n+1):
if s[_] == '.':
a+=1
elif s[_] == 'L':
if flag =='L':
a = 0
else:
if a%2==1:
r+=1
a = 0
flag = 'L'
else:
if flag =='L':
r +... | {
"input": [
"14\n.L.R...LR..L..\n",
"5\nR....\n",
"1\n.\n",
"2\n.R\n",
"200\n....R..LRLR......LR..L....R..LR.L....R.LR.LR..LR.L...R..L.R.......LR..LRL.R..LR.LRLR..LRLRL....R..LR...LR.L..RL....R.LR..LR..L.R.L...R.LR.....L.R....LR..L.R...L..RLRL...RL..R..L.RLR......L..RL....R.L.\n",
"9\n.......... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Ch... |
432_C. Prime Swaps_36150 | You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
* choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);
* swap the elements on positi... | def sieve(n):
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
n = int(input())
prime = [True for i in range(n+2)]
prime[0]=0
prime[1]=0
sieve(n+1)
aa=[0]*(n+1)
for i in range(n+1):
if prime[i]:
a... | {
"input": [
"3\n3 2 1\n",
"2\n1 2\n",
"4\n4 2 3 1\n",
"3\n1 3 2\n",
"4\n3 4 1 2\n",
"3\n3 1 2\n",
"10\n10 9 8 7 6 5 4 3 2 1\n",
"8\n1 3 5 7 8 6 4 2\n",
"3\n1 2 3\n",
"2\n2 1\n",
"100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to ap... |
454_E. Little Pony and Summer Sun Celebration_36154 | Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration.
<im... | """
Codeforces Contest 259 Div 1 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
# Read N and M from problem statement.
n,m = read()
# Set up an adjacency list for each vertex.
edges = [[] for _ in range(n+1)]
for i in range(m):
a,b = read()
edges[a].append... | {
"input": [
"2 0\n0 0\n",
"5 7\n1 2\n1 3\n1 4\n1 5\n3 4\n3 5\n4 5\n0 1 0 1 0\n",
"3 2\n1 2\n2 3\n1 1 1\n",
"10 10\n1 2\n1 3\n3 4\n3 5\n6 1\n7 6\n8 7\n9 7\n10 1\n2 4\n0 1 0 1 1 0 0 1 1 0\n",
"4 2\n1 2\n3 4\n0 0 0 1\n",
"3 1\n2 3\n0 1 1\n",
"2 0\n1 1\n",
"2 0\n1 0\n",
"10 10\n1 2\n3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn he... |
477_C. Dreamoon and Strings_36157 | Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates <image> that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible.
More formally... | s, p = input(), input()
n, m = len(s) + 1, len(p)
d = [[0] * n for t in range(n)]
for x in range(1, n):
i, j = x, m
while i and j:
j -= s[i - 1] == p[j - 1]
i -= 1
if not j:
for y in range(i + 1): d[x][y + x - i - m] = d[i][y] + 1
for y in range(x): d[x][y] = max(d[x][y], d[x - 1... | {
"input": [
"aaaaa\naa\n",
"axbaxxb\nab\n",
"abxxxaxbxaxxxba\naba\n",
"ababababababababa\naba\n",
"aaaaaaaaaaa\nb\n",
"a\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates <image> that is defined as the maximal... |
4_D. Mysterious Present_36160 | Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height o... | inputi = [int(i) for i in input().split(" ")]
amt = inputi[0]
cardW = inputi[1]
cardH = inputi[2]
envelopes = []
cur_amt = 1
for i in range(amt):
inputi = [int(i) for i in input().split(" ")]
if inputi[0] > cardW and inputi[1] > cardH:
envelopes.append((inputi[0],inputi[1],inputi[0]*inputi[1], cur_amt))... | {
"input": [
"3 3 3\n5 4\n12 11\n9 8\n",
"2 1 1\n2 2\n2 2\n",
"5 13 13\n4 4\n10 10\n7 7\n1 1\n13 13\n",
"4 12 140\n172 60\n71 95\n125 149\n53 82\n",
"5 1000 998\n5002 5005\n5003 5004\n5003 5002\n5002 5001\n5002 5002\n",
"3 5 5\n6 2\n7 8\n10 2\n",
"3 500 789\n56 32\n64 42\n74 55\n",
"2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence o... |
525_C. Ilya and Sticks_36163 | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi... | n = int(input())
rects = [int(s) for s in input().split()]
rects.sort()
sumsquare = 0
stash = []
i = len(rects) - 1
while i > 0:
if rects[i] - rects[i-1] == 1 or rects[i] == rects[i-1]:
if len(stash) == 2:
sumsquare += stash[0]*stash[1]
stash.clear()
stash.append(rects[i-1])
rects.pop()
rects.pop()
... | {
"input": [
"4\n2 4 4 2\n",
"4\n2 2 3 5\n",
"4\n100003 100004 100005 100006\n",
"7\n2 2 2 2 2 2 2\n",
"21\n580 3221 3987 2012 35 629 1554 654 756 2254 4307 2948 3457 4612 4620 4320 1777 556 3088 348 1250\n",
"6\n3 4 5 100 101 102\n",
"69\n2367 2018 3511 1047 1789 2332 1082 4678 2036 4108 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its... |
550_D. Regular Bridge_36167 | An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.
Build a connected undirected k-regular graph containing at least one bridge, or else state that such gra... | def nextEdge():
global v
for i in range(1, v + 1):
for j in range(i + 1, v + 1):
yield (i, j)
k = int(input())
if k % 2 == 0:
print("NO")
elif k == 1:
print("YES", "2 1", "1 2", sep = "\n")
else:
n = 2 * k + 4
m = k * (k + 2)
print("YES")
print(n, m, sep = " ")
... | {
"input": [
"1\n",
"30\n",
"68\n",
"22\n",
"66\n",
"26\n",
"98\n",
"82\n",
"70\n",
"60\n",
"6\n",
"18\n",
"84\n",
"46\n",
"62\n",
"74\n",
"34\n",
"12\n",
"50\n",
"54\n",
"52\n",
"28\n",
"78\n",
"56\n",
"40\n",
"4\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split... |
59_C. Title_36173 | Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not contain... | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
k = int(input())
a = list(input().rstrip())
n = len(a)
unused = [1] * k
def ng():
print('IMPOSSIBLE')
exit()
try:
for i in range(n):
if a[i] == '?' and a[n - i - 1] != '?':
... | {
"input": [
"3\na?c\n",
"2\na??a\n",
"2\n?b?a\n",
"26\nabcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba\n",
"26\n?b????g????l?????rs???????s?f?ceiww??ok????u??qwm???q?fu??wkkoh??wie??f???yx?vuts?q??nm?????g??dc??\n",
"2\nababaaaababaaaababba... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among other... |
621_A. Wet Shark and Odd and Even_36177 | Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.
Input
The first line of the ... | n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ls=set(l)
lss=list(ls)
lss.sort()
c=0
for i in range(len(lss)):
if lss[i]%2!=0:
c=lss[i]
break
if s%2==0:
print(s)
else:
print(s-c) | {
"input": [
"5\n999999999 999999999 999999999 999999999 999999999\n",
"3\n1 2 3\n",
"4\n2 3 7 7\n",
"4\n3 2 5 7\n",
"1\n4\n",
"3\n7 4 4\n",
"2\n1 4\n",
"15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59\n",
"2\n2 3\n",
"3\n5 3 1\n",
"1\n1\n",
"15\n59 96 34 48 8 72 67 90 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value fo... |
66_D. Petya and His Friends_36183 | Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.
Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is e... | import math
def checkprime(n):
if(n==1):
return 0
i=2
while(i*i<=n):
if(n%i==0):
return 0
i+=1
return 1
primes=[]
primes.append(0)
i=1
while(i<=1000):
if(checkprime(i)==1):
primes.append(i)
i+=1
n=int(input())
if(n==2):
print(-1)
exit(0)
res=[]
i=1
while(i<=n):
product=1
j=i
while(j<i+n-1):
if(j... | {
"input": [
"4\n",
"3\n",
"8\n",
"34\n",
"49\n",
"39\n",
"12\n",
"30\n",
"10\n",
"18\n",
"43\n",
"20\n",
"17\n",
"44\n",
"43\n",
"18\n",
"19\n",
"20\n",
"21\n",
"2\n",
"32\n",
"22\n",
"24\n",
"47\n",
"27\n",
"23\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.
Let us remind you the definit... |
691_A. Fashion in Berland_36187 | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | n = int(input())
a = list(map(int,input().split()))
c = a.count(0)
if (c>1 or c<1) and n>1 :
print('NO')
elif n==1 and c==1:
print('NO')
else:
print('YES')
| {
"input": [
"3\n1 0 0\n",
"3\n1 0 1\n",
"10\n0 0 0 0 0 0 0 0 0 0\n",
"231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only o... |
716_A. Crazy Computer_36191 | ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then ever... | """
second a and then the next word at second b, then if b - a ≤ c,
just the new word is appended to other words on the screen.
If b - a > c, then everything on the screen disappears and after that the word
you have typed appears on the screen.
"""
num1 = input()
num2 = input()
a = []
b = []
def get_the_data(co... | {
"input": [
"6 1\n1 3 5 7 9 10\n",
"6 5\n1 3 8 14 19 20\n",
"2 1000000000\n1 1000000000\n",
"2 1\n1 100\n",
"5 5\n1 7 12 13 14\n",
"3 5\n1 10 20\n",
"1 1\n1000000000\n",
"2 1\n1 2\n",
"3 1\n1 2 10\n",
"3 10\n1 2 3\n",
"2 1\n2 100\n",
"3 10\n2 2 3\n",
"6 1\n1 4 5 7 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second a a... |
736_C. Ostap and Tree_36194 | Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.
Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no m... | def main():
n, k = map(int, input().split())
cnt = [[[0] * 21 for _ in (0, 1)] for _ in range(n + 1)]
edges, mod = [[] for _ in range(n + 1)], 1000000007
for _ in range(n - 1):
u, v = map(int, input().split())
edges[u].append(v)
edges[v].append(u)
def dfs(u, f):
cnt[... | {
"input": [
"2 1\n1 2\n",
"7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"2 0\n1 2\n",
"4 1\n1 2\n2 3\n3 4\n",
"10 5\n6 4\n4 1\n7 5\n8 7\n2 6\n3 6\n8 6\n10 3\n4 9\n",
"10 4\n9 6\n10 8\n9 2\n7 10\n3 7\n7 9\n10 4\n1 7\n9 5\n",
"10 9\n1 2\n3 1\n6 10\n6 1\n10 9\n4 5\n7 1\n5 6\n8 5\n",
"10 2\n7 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.
Ostap's tree now has n vert... |
760_C. Pavel and barbecue_36198 | Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.
Pavel has a plan: a permutation p and a sequence b1, b2, ... | n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(b[i] for i in range(n))
if s % 2 == 0:
ans = 1
else:
ans = 0
visited = [0] * n
ptr = 0
start = 1
visited[0] = 1
q = 1
c = 1
while q < n:
start = p[start - 1]
if visited[start - 1] == 1:
c += 1
... | {
"input": [
"4\n4 3 2 1\n0 1 1 1\n",
"3\n2 3 1\n0 0 0\n",
"3\n1 3 2\n0 0 1\n",
"3\n1 3 2\n0 1 0\n",
"3\n3 1 2\n0 0 0\n",
"2\n1 2\n0 0\n",
"3\n2 1 3\n0 0 0\n",
"3\n1 2 3\n1 0 0\n",
"1\n1\n0\n",
"3\n3 1 2\n1 1 0\n",
"3\n3 1 2\n1 1 1\n",
"3\n3 2 1\n1 1 0\n",
"3\n1 2 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two di... |
875_A. Classroom Watch_36209 | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi... |
n = int(input())
res = []
def sum_digits(x):
return sum([int(i) for i in x])
for i in range(max(0, n - 80), n):
# print(sum_digits(str(i)))
if i + sum_digits(str(i)) == n:
res.append(i)
print(len(res))
if len(res) != 0:
for r in sorted(res):
print(r) | {
"input": [
"21\n",
"20\n",
"75\n",
"1000000000\n",
"100\n",
"999999979\n",
"39\n",
"3\n",
"101\n",
"10\n",
"100000001\n",
"9\n",
"66\n",
"11\n",
"999999994\n",
"1\n",
"2014\n",
"2\n",
"37\n",
"110\n",
"71\n",
"6\n",
"1000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher ... |
899_F. Letters Removing_36213 | Petya has a string of length n consisting of small and large English letters and digits.
He performs m operations. Each operation is described with two integers l and r and a character c: Petya removes from the string all characters c on positions between l and r, inclusive. It's obvious that the length of the string ... | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
class FenwickTree:
def __init__(self, x):
"""transform list into BIT"""
self.bit = x
for i in range(len(x)):
j = i | (i + 1)
if j < len(x):
x[j] += x[i]
def update(self, id... | {
"input": [
"3 2\nA0z\n1 3 0\n1 1 z\n",
"10 4\nagtFrgF4aF\n2 5 g\n4 9 F\n1 5 4\n1 7 a\n",
"4 2\nabac\n1 3 a\n2 2 c\n",
"9 5\naAAaBBccD\n1 4 a\n5 6 c\n2 3 B\n4 4 D\n2 3 A\n",
"30 5\nkR87ctl81OsbekSKwUATCwSPKssjio\n16 25 0\n16 19 W\n6 12 K\n4 23 k\n28 29 z\n",
"10 10\nhRZQK137KY\n1 10 V\n8 10 g... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya has a string of length n consisting of small and large English letters and digits.
He performs m operations. Each operation is described with two integers l and r and a charact... |
920_B. Tea Queue_36217 | Recently n students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
i-th stude... | if __name__ == '__main__':
cin = input
t = int(cin())
while t > 0:
n = int(cin())
a, cnt = [0] * n, 0
for i in range(n):
l, r = map(int, cin().split())
if r >= cnt + max(l - cnt, 1):
cnt += max(l - cnt, 1)
a[i] += cnt
p... | {
"input": [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n",
"1\n5\n1 1\n1 2\n1 5\n1 1\n1 1\n",
"1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently n students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink som... |
976_E. Well played!_36223 | Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types ... | import sys
read=lambda:map(int,sys.stdin.buffer.readline().split())
n,a,b=read()
v=[tuple(read()) for _ in range(n)]
ans=0
if b>0:
c=[v[x][0]-v[x][1] for x in range(n)]
w,r=list(range(n)),[0]*n
w.sort(key=lambda x:c[x],reverse=True)
for i in range(n): r[w[i]]=i
f=True;s=0;m=min(n,b)
for i in range(m):
k=c[w[i]]... | {
"input": [
"2 1 1\n10 15\n6 1\n",
"3 0 3\n10 8\n7 11\n5 2\n",
"1 0 0\n2 1\n",
"2 11 1\n1 4\n1 5\n",
"4 8 1\n9 9\n7 6\n2 4\n6 10\n",
"2 13 2\n208637 682633\n393097 724045\n",
"2 1 2\n20 1\n22 23\n",
"1 0 200000\n1 42\n",
"2 3 14\n28 5\n32 47\n",
"3 1 1\n10 9\n8 6\n7 5\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of ... |
996_C. Tesla_36227 | Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be repre... | n, k = list(map(int, input().split()))
table = []
for row in range(4):
table.append(list(map(int, input().split())))
moves = []
def make_move(start,finish):
moves.append((table[start[0]][start[1]], finish[0]+1, finish[1]+1))
table[finish[0]][finish[1]] = table[start[0]][start[1]]
table[start[0]][start... | {
"input": [
"1 2\n1\n1\n2\n2\n",
"4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n",
"1 2\n1\n2\n1\n2\n",
"2 3\n0 2\n0 1\n3 2\n3 1\n",
"37 22\n0 18 0 0 0 16 0 0 0 0 1 21 0 0 0 4 0 15 0 8 0 0 0 0 0 0 0 9 14 0 0 0 22 0 0 3 0\n0 0 0 0 0 21 0 0 2 0 0 0 0 0 0 13 0 0 0 0 0 0 22 12 9 15 11 8 0 16 0 0 0 0 0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the diffe... |
p02649 Tokio Marine & Nichido Fire Insurance Programming Contest 2020 - O(rand)_36240 | Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied:
* The bitwise AND of the chosen numbers is S.
* The bitwise OR of the chosen numbers is T.
C... | def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
cmb=[[0 for i in range(51)] for j in range(51)]
cmb[0][0]=1
for i in range(51):
for j in range(51):
... | {
"input": [
"3 3 0 3\n1 2 3",
"5 3 1 7\n3 4 9 1 5",
"5 4 0 15\n3 4 9 1 5",
"3 3 0 3\n0 2 3",
"5 4 0 15\n3 6 9 1 5",
"3 3 0 6\n0 2 3",
"5 4 1 15\n3 11 1 0 5",
"5 3 1 7\n3 4 9 0 5",
"5 4 0 15\n3 4 9 1 1",
"5 4 0 15\n3 6 1 1 8",
"5 5 1 7\n3 4 9 1 5",
"5 5 1 7\n3 4 11 1 5"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that t... |
p02778 AtCoder Beginner Contest 154 - I miss you..._36244 | Given is a string S. Replace every character in S with `x` and print the result.
Constraints
* S is a string consisting of lowercase English letters.
* The length of S is between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
S
Output
Replace every character in S with ... | s = input()
print('x' * (len(s))) | {
"input": [
"sardine",
"xxxx",
"gone",
"sardnie",
"xxwx",
"gpne",
"sardnif",
"wxwx",
"gpnd",
"findras",
"wwxx",
"gpnc",
"findrbs",
"xxww",
"fpnc",
"frndibs",
"wwyx",
"cnpf",
"frndics",
"wwzx",
"dnpf",
"fqndics",
"wvzx",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is a string S. Replace every character in S with `x` and print the result.
Constraints
* S is a string consisting of lowercase English letters.
* The length of S is between 1 ... |
p02913 AtCoder Beginner Contest 141 - Who Says a Pun?_36248 | Given is a string S of length N.
Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.
More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:
... | n = int(input())
s = input()
l1 = l2 = length = 0
while l2 + length < n:
if s[l1 : l2] in s[l2:]:
length = l2 - l1
l2 += 1
else:
l1 += 1
l2 = l1 + length + 1
print(length) | {
"input": [
"13\nstrangeorange",
"2\nxy",
"5\nababa",
"13\nstrangeoranfe",
"2\nwy",
"5\n`baba",
"5\nabac`",
"13\nefnaroegnarts",
"2\nvy",
"5\nabab`",
"13\nefnarotgnares",
"2\nyx",
"13\nserangtoranfe",
"2\nxz",
"5\n`caba",
"13\nseraogtoranfe",
"2\nzx... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is a string S of length N.
Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.
More formally, find the m... |
p03049 diverta 2019 Programming Contest - AB Substrings_36252 | Snuke has N strings. The i-th string is s_i.
Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
Constraints
* 1 \leq N \leq 10^{4}
* 2 \leq |s_i| \leq 10
* s_i consists of uppercase English letters.
In... | import re
n = int(input())
a = 0
b = 0
ab = 0
cnt = 0
for i in range(n):
s = input()
tmp = re.findall(r'AB',s)
ab += len(tmp)
if s[0] == "B":
b += 1
if s[-1] == "A":
a += 1
if s[0] == "B" and s[-1] == "A":
cnt += 1
if a == b and a == cnt and a > 0:
print(a-1+ab)
el... | {
"input": [
"9\nBEWPVCRWH\nZZNQYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA",
"7\nRABYBBE\nJOZ\nBMHQUVA\nBPA\nISU\nMCMABAOBHZ\nSZMEHMA",
"3\nABCA\nXBAZ\nBAD",
"9\nBEWPVCRWH\nZQNZYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA",
"7\nEBBYBAR\nJOZ\nBMHQUVA\nBPA\nISU\nM... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has N strings. The i-th string is s_i.
Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `... |
p03337 AtCoder Beginner Contest 098 - Add Sub Mul_36258 | You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
Constraints
* -1000 \leq A,B \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the largest value among A+B, A-B and A \times B.
Examples
Inp... | A, B = map(int, input().split())
M = max(A+B,A-B,A*B)
print(M) | {
"input": [
"0 0",
"3 1",
"4 -2",
"0 -1",
"6 1",
"0 -2",
"6 0",
"9 1",
"3 0",
"9 0",
"4 0",
"-2 2",
"5 0",
"17 -1",
"20 -1",
"37 -1",
"38 -1",
"-4 -2",
"38 -2",
"-2 1",
"-4 2",
"-4 1",
"-6 -2",
"3 5",
"5 5",
"-7 2... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
Constraints
* -1000 \leq A,B \leq 1000
* All values in input are integers.
Input
Input is... |
p03499 AtCoder Regular Contest 086 - Smuggling Marbles_36261 | Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i.
Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one mar... | n, = map(int, input().split())
p = [-1] + [*map(int, input().split())]
MOD = 10**9+7
dp = [[] for _ in range(n+1)]
dep = [0]*(n+1)
nxt = [0]*(n+1)
for v in range(n,0,-1):
_,nxt[p[v]],dep[p[v]] = sorted([nxt[p[v]],dep[p[v]],dep[v]+1])
tot = [0]*(dep[0]+1)
for i in range(n+1): tot[dep[i]] += 1
def merge(p,v):
... | {
"input": [
"2\n0 0",
"31\n0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23",
"5\n0 1 1 0 4",
"2\n0 1",
"31\n0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 3 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23",
"5\n0 1 1 0 3",
"31\n0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 3 3 6 12 10 12 16 5 3 20 1 25 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i.
Beside... |
p03658 AtCoder Beginner Contest 067 - Snake Toy_36265 | Snuke has N sticks. The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
Constraints
* 1 \leq K \leq N \leq 50
* 1 \leq l_i \leq 50
... | N,K=map(int,input().split(' '))
print(sum(sorted(list(map(int,input().split(' '))))[::-1][:K])) | {
"input": [
"15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45",
"5 3\n1 2 3 4 5",
"15 14\n49 26 27 21 41 7 42 35 7 5 5 36 39 1 45",
"5 5\n1 2 3 4 5",
"15 14\n49 26 27 21 33 7 42 35 7 5 5 36 39 1 45",
"5 5\n2 2 3 4 5",
"15 14\n49 26 27 26 33 7 42 35 7 5 5 36 39 1 45",
"5 3\n2 2 3 4 5",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has N sticks. The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the indi... |
p03814 AtCoder Beginner Contest 053 - A to Z String_36269 | Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s).
Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends w... | N = input()
a = N.find("A")
z = N.rfind("Z")
print(z - a + 1) | {
"input": [
"HASFJGHOGAKZZFEGA",
"ZABCZ",
"QWERTYASDFZXCV",
"HASFJGHOGAK[ZFEGA",
"ZAACZ",
"AGEFZKKAGOHH[FSAH",
"IBAG[IHNGFKKZSFGB",
"ZCAAZ",
"QWERTAFSDXZXCV",
"ZCAZB",
"AIEFZGKAFOFGJZSAH",
"I@SCIGHEA[KFGOKZA",
"ICAF[IHNGFKZKSFGB",
"QWARTEFSDXZXCV",
"AGEFZJG... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s).
Find the greatest length o... |
p00071 Bombs Chain_36274 | There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb).
| □ | □ | □ | □ | □ | □ | □ | □
--- | --- | --- | --- | --- | --- | --- | ---
□ | □ | □ | □ | □ | □ | □ | □
□ | □ | □ | □ | □ | □ | □ | □
□ | □ | □ | □ | □ | □ | □ | □
□... | def e(x,y):
A[y][x]='0'
for d in range(-3,4):
0<=x+d<8and'1'==A[y][x+d]and e(x+d,y)
0<=y+d<8and'1'==A[y+d][x]and e(x,y+d)
for i in range(int(input())):
print(f'Data {i+1}:');input()
A=[list(input())for _ in[0]*8]
e(int(input())-1,int(input())-1)
for r in A:print(*r,sep='')
| {
"input": [
"2\n\n00010010\n00000100\n10001001\n00100010\n01000000\n00001000\n10100010\n01010010\n2\n5\n\n00010010\n00000100\n10001001\n00100010\n01000000\n00001000\n10100010\n01010010\n2\n5",
"2\n\n00010010\n00000100\n10001001\n00100010\n01000000\n00001000\n10100010\n01010010\n2\n5\n\n00010010\n00000100\n10... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb).
| □ | □ | □ | □ | □ | □ | □ | □
... |
p00203 A New Plan of Aizu Ski Resort_36278 | Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift.
Let's create a program for the oil tree shop that outputs the number of pa... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203
"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline
def solve(field):
BLANK, OBSTACLE, JUMP = 0, 1, 2
ans = 0 # ??????????????°???????????°
dy... | {
"input": [
"5 5\n0 0 0 0 1\n2 1 0 2 0\n1 0 0 1 1\n0 2 1 2 0\n0 1 0 0 0\n5 5\n0 0 1 0 0\n2 1 0 2 0\n1 0 0 1 1\n0 2 1 2 0\n0 1 0 0 0\n15 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can ... |
p00359 Dungeon_36281 | Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the rig... | w, h, n = map(int, input().split())
xys = sorted([list(map(int, input().split())) for _ in range(n)])
y_max = [0]
for _, y in reversed(xys):
y_max.append(max(y_max[-1], y))
xs = [0] + [x for x, _ in xys]
print(min([xs[i] + y_max[n - i] for i in range(n + 1)]))
| {
"input": [
"5 4 4\n0 3\n1 1\n2 2\n2 3",
"6 6 5\n2 1\n5 2\n3 3\n1 4\n1 5",
"8 8 4\n6 0\n7 0\n0 6\n0 7",
"5 4 4\n0 3\n1 1\n3 2\n2 3",
"6 6 5\n2 1\n5 2\n3 3\n2 4\n1 5",
"8 8 4\n12 0\n7 0\n0 6\n0 7",
"6 6 5\n2 1\n5 2\n1 3\n2 4\n1 5",
"10 4 2\n0 3\n1 1\n3 3\n2 3",
"5 4 4\n0 3\n1 1\n2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus t... |
p00570 Stove_36283 | JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors.
On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + ... | n, k = map(int, input().split())
li = [int(input()) for i in range(n)]
diff = []
for j in range(n-1):
diff.append(li[j+1]-li[j]-1)
diff.sort(reverse=True)
print(n+sum(diff[k-1:]))
| {
"input": [
"3 2\n1\n3\n6",
"3 2\n1\n3\n11",
"3 2\n0\n3\n11",
"3 3\n1\n3\n14",
"3 2\n0\n4\n11",
"2 2\n0\n3\n20",
"3 2\n1\n6\n16",
"3 2\n0\n4\n1",
"3 1\n0\n3\n11",
"3 2\n-2\n4\n11",
"3 2\n0\n6\n1",
"3 1\n1\n6\n18",
"3 1\n-1\n4\n11",
"2 1\n1\n0\n20",
"3 2\n1\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there ar... |
p00717 Polygonal Line Search_36287 | Multiple polygonal lines are given on the xy-plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template.
A polygonal line consists of several line segments parallel to x-axis or y-axis. It is defined by a list of xy-coordinates of vertices from th... | # -*- coding: utf-8 -*-
def main():
N = int(input())
while N:
lines = []
for _ in range(N+1):
tmp = []
M = int(input())
x0, y0 = map(int, input().split())
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
... | {
"input": [
"5\n5\n0 0\n2 0\n2 1\n4 1\n4 0\n5\n0 0\n0 2\n-1 2\n-1 4\n0 4\n5\n0 0\n0 1\n-2 1\n-2 2\n0 2\n5\n0 0\n0 -1\n2 -1\n2 0\n4 0\n5\n0 0\n2 0\n2 -1\n4 -1\n4 0\n5\n0 0\n2 0\n2 1\n4 1\n4 0\n4\n4\n-60 -75\n-60 -78\n-42 -78\n-42 -6\n4\n10 3\n10 7\n-4 7\n-4 40\n4\n-74 66\n-74 63\n-92 63\n-92 135\n4\n-12 22\n-12 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Multiple polygonal lines are given on the xy-plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template.
A pol... |
p01120 Tally Counters_36292 | <!--
Problem D
-->
Tally Counters
A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value.
<image> Fig. D-1 Tally Cou... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve(C, N, M, range = range, min = min):
K = N // 4 + 1
S = [0]*K
T = [0]*K
U = [0]*(K+1)
for i in range(N-1):
U[0] = 10**18
for j in range(K):
U[j+1] = min(U[j], S[j])
k = K-1
ci = C[i... | {
"input": [
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 10 100\n5 10000\n4971 7482 1238 8523 1823\n3287 9013 9812 297 1809\n0 0",
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 10 100\n5 10000\n4971 7482 1238 8523 1823\n3287 9013 9928 297 1809\n0 0",
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 14 100\n5 10000\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
<!--
Problem D
-->
Tally Counters
A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is ... |
p01419 On or Off_36296 | Saving electricity is very important!
You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 unit of time for you to move to the next room (that is, the grid adja... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"3 3 5\n...\n.##\n..#\n1 1 1\n1 0 0\n1 1 0\n3 3 3\n3 0 0\n3 3 0\n5 4 5\n4 0 0\n5 4 0\n1 0\n2 1\n0 2\n2 0\n0 0",
"1 3 2\n...\n1 1 1\n1 2 1\n1 1 1\n0 0\n0 2",
"5 5 10\n.###\n....\n.#\n..#.#\n....\n0 12 0 0 0\n0 4 3 2 10\n0 0 0 99 0\n11 13 0 2 0\n0 1 1 2 1\n0 4 0 0 0\n0 13 8 2 4\n0 0 0 16 0\n1 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Saving electricity is very important!
You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the offic... |
p01735 Optimal alpha beta pruning_36301 | Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluat... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
*P, = map(int, readline().split())
G = []
prt = [0]*N
for i in range(N):
k, *t = map(int, readline().split())
G.append([e-1 for e in t])
for e in t... | {
"input": [
"3\n0 1 1\n2 2 3\n0\n0",
"3\n0 2 1\n2 2 3\n0\n0",
"3\n0 2 2\n2 2 3\n0\n0",
"3\n-1 2 2\n2 2 3\n0\n0",
"3\n-1 2 0\n2 2 3\n0\n0",
"3\n0 1 2\n2 2 3\n0\n0",
"3\n-1 1 2\n2 2 3\n0\n0",
"3\n-1 2 0\n2 2 3\n0\n1",
"3\n-1 2 1\n2 2 3\n0\n1",
"3\n-1 1 1\n2 2 3\n0\n1",
"3\n-... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows h... |
p02295 Cross Point_36307 | For given two segments s1 and s2, print the coordinate of the cross point of them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
* The given segments have a cross point and are not in parallel.
Input
The... | def dot(a, b):
return a.real * b.real + a.imag * b.imag
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def cross_point(p0,p1,p2,p3):
base=p3-p2
d1=abs(cross(base,p0-p2))
d2=abs(cross(base,p1-p2))
t=d1/(d1+d2)
ans= p0+(p1-p0)*t
return ans.real,ans.imag
n = int(input())
for i in range(n):
... | {
"input": [
"3\n0 0 2 0 1 1 1 -1\n0 0 1 1 0 1 1 0\n0 0 1 1 1 0 0 1",
"3\n0 0 2 0 2 1 1 -1\n0 0 1 1 0 1 1 0\n0 0 1 1 1 0 0 1",
"3\n0 0 2 0 2 2 1 -1\n0 0 1 1 0 1 1 0\n0 0 1 1 1 0 0 1",
"3\n0 0 2 0 2 2 0 -1\n0 0 1 1 0 1 1 0\n0 0 1 1 1 0 0 1",
"3\n0 0 2 0 2 1 0 -1\n0 0 1 1 0 1 1 0\n0 0 1 1 1 0 0 1",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For given two segments s1 and s2, print the coordinate of the cross point of them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.
Constraints
* 1 ≤... |
p02442 Lexicographical Comparison_36310 | Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}$ lexicographically.
Constraints
* $1 \leq n, m \leq 1,000$
* $0 \leq a_i, b_i \leq 1,000$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$m$
$b_0 \; b_1, ..., \; b_{m-1}$
The num... | input()
a = list(map(int, input().split(' ')))
input()
b = list(map(int, input().split(' ')))
print(1 if a<b else 0)
| {
"input": [
"3\n1 1 2\n4\n1 1 2 2",
"3\n1 2 3\n2\n2 4",
"4\n5 4 7 0\n5\n1 2 3 4 5",
"3\n1 1 2\n4\n1 2 2 2",
"4\n1 4 3 1\n4\n0 4 5 4 2",
"3\n1 4 3\n2\n2 4",
"4\n0 4 7 0\n5\n1 2 3 4 5",
"3\n1 1 2\n4\n1 3 2 2",
"3\n1 4 3\n2\n2 2",
"4\n0 4 7 0\n5\n1 2 3 4 1",
"3\n1 1 2\n4\n1 3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}$ lexicographically.
Constraints
* $1 \leq n, m \leq 1,000$
* $0 \leq a_i, b_i \leq 1... |
1015_C. Songs Compression_36320 | Ivan has n songs on his phone. The size of the i-th song is a_i bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty.
Ivan wants to copy all n songs to the flash drive. He can compress the songs. If he compresses the i-th song, the size of the i-th song reduce... | n,m = input().split()
n=int(n)
m=int(m)
songs=list()
for i in range(n):
songs.append([int(c) for c in input().split()])
def sumList(lista,inx):
sum=0
for i in range(len(lista)):
sum+=lista[i][inx]
return sum
songs=sorted(songs,key=lambda x: x[1]-x[0])
suma = sumList(songs,0)
for i in ra... | {
"input": [
"4 16\n10 8\n7 4\n3 1\n5 4\n",
"4 21\n10 8\n7 4\n3 1\n5 4\n",
"1 2\n3 1\n",
"3 7\n2 1\n2 1\n2 1\n",
"1 1000000000\n1000000000 999999999\n",
"1 3\n2 1\n",
"4 10\n2 1\n2 1\n2 1\n2 1\n",
"1 999999999\n1000000000 999999999\n",
"2 100\n2 1\n3 2\n",
"1 1\n3 2\n",
"1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ivan has n songs on his phone. The size of the i-th song is a_i bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty.
Ivan ... |
1039_A. Timetable_36324 | There are two bus stops denoted A and B, and there n buses that go from A to B every day. The shortest path from A to B takes t units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route.
At each station one can find a sorted list of moments of time when a... | def read():
return list(map(int, input().split(' ')))
def fail():
print('No')
exit(0)
n, t = read()
aa = read()
xx = read()
res = [0] * n
prevX = 0
prevV = -10
for i in range(n):
x = xx[i] - 1
if x < prevX or x < i:
fail()
prevX = x
res[i] = prevV = max(aa[i + 1] + t if x > i els... | {
"input": [
"2 1\n1 2\n2 1\n",
"3 10\n4 6 8\n2 2 3\n",
"2 1000000000\n999999999 1000000000\n1 2\n",
"2 1000000000\n99999999 1000000000\n1 1\n",
"2 1000000000\n1 1000000000\n2 2\n",
"2 10\n4 5\n2 2\n",
"2 2\n4 5\n1 2\n",
"2 1000000000\n130296385 1000000000\n1 1\n",
"3 19\n4 6 8\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are two bus stops denoted A and B, and there n buses that go from A to B every day. The shortest path from A to B takes t units of time but some buses might take longer paths. M... |
1061_C. Multiplicity_36328 | You are given an integer array a_1, a_2, …, a_n.
The array b is called to be a subsequence of a if it is possible to remove some elements from a to get b.
Array b_1, b_2, …, b_k is called to be good if it is not empty and for every i (1 ≤ i ≤ k) b_i is divisible by i.
Find the number of good subsequences in a modulo... | import math
def nextDiv(a):
ret = []
i = 1;
while (i*i <= a):
if (a%i == 0):
ret.append(i)
j = a//i
if (i != j):
ret.append(j)
i += 1
return reversed(ret)
MOD = int(1e9+7)
def solve(n, lis):
dp = [0] * (max(lis)+1)
dp[0] = 1
... | {
"input": [
"2\n1 2\n",
"5\n2 2 1 22 14\n",
"13\n313494 586155 96820 472596 340986 799976 416813 725571 487013 603301 832 626376 583769\n",
"1\n519612\n",
"5\n325539 329221 106895 882089 718673\n",
"15\n513046 683844 914823 764255 815301 790234 184972 93547 388028 211665 554415 713159 183950 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer array a_1, a_2, …, a_n.
The array b is called to be a subsequence of a if it is possible to remove some elements from a to get b.
Array b_1, b_2, …, b_k is ... |
1083_B. The Fair Nut and Strings_36331 | Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time.
Then, he lost his sheet with strings. He remembers that all written strings were lexicog... | d = {'a': 0, 'b': 1}
def process(s, t, k):
n = len(s)
answer = 0
D = 0
final_i = n
for i in range(n):
d1 = d[s[i]]
d2 = d[t[i]]
D = 2*(D)+d2-d1
if D+1 < k:
answer+=(D+1)
else:
final_i = i
break
answer+=k*(n-final_i)
... | {
"input": [
"2 4\naa\nbb\n",
"4 5\nabbb\nbaaa\n",
"3 3\naba\nbba\n",
"100 1000000000\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbaabaabbb\nbaaaaaaaaababbbbaaabbbbbababbbbabbbabbaaaaabaabbaabbbbabaaaabbaaaabaaabaabbbabbbbbbbbabaaabbababbabb\n",
"100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written s... |
1102_D. Balanced Ternary String_36335 | You are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.
Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a ternary string ... | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
# sys.setrecursionlimit(1000000)
mod = 998244353
n=int(data())
s=da... | {
"input": [
"6\n000000\n",
"3\n121\n",
"6\n120110\n",
"6\n211200\n",
"12\n000022220000\n",
"3\n122\n",
"12\n111111111111\n",
"12\n012012222000\n",
"6\n002202\n",
"3\n022\n",
"3\n020\n",
"3\n211\n",
"60\n122202011021020021110110101221221001221010101110221212112211\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.
Your task is to replace minimum nu... |
1130_D1. Toy Train (Simplified)_36339 | This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at... | from collections import defaultdict as dd
n,m=[int(i) for i in input().split(' ')]
a=[]
b=[]
def fnx(i,j):
if i<j:
return(j-i)
else:
return(n-i+j)
def fnr(r):
if r%n==0:
return(n)
else:
return(r%n)
for i in range(m):
x,y=[int(i) for i in input().split(' ')]
a.a... | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"50 20\n45 33\n44 7\n31 41\n45 12\n3 13\n18 17\n3 39\n31 11\n31 1\n44 7\n44 23\n18 46\n44 1\n45 6\n31 22\n18 13\n31 22\n45 8\n45 17\n18 43\n",
"3 2\n3 1\n1 3\n",
"3 1\n1 2\n",
"3 3\n1 2\n3 2\n2 3\n",
"20 5\n3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.
Alice received a set of Toy Train™ from Bo... |
1190_B. Tokitsukaze, CSL and Stone Game_36346 | Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if... | def find(A):
from collections import defaultdict
A=sorted(A)
N=len(A)
dic=defaultdict(int)
for i in range(N):
dic[A[i]]+=1
checked=[]
count=set([])
for x in A:
if dic[x]>2:
return "cslnb"
if dic[x]==2:
count.add(x)
y=x-1
... | {
"input": [
"2\n2 2\n",
"2\n1 0\n",
"1\n0\n",
"3\n2 3 1\n",
"4\n2 2 1 0\n",
"3\n2 3 3\n",
"3\n22534187 22534186 22534186\n",
"9\n8004 5687 1235 8004 5687 1235 999 789555 1222235\n",
"14\n6 66 89 84 89 66 123456 98745 3685 21457 15987 36528 14578 98633\n",
"2\n3 0\n",
"5\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves... |
1228_E. Another Filling the Grid_36352 | You have n × n square grid and an integer k. Put an integer in each cell while satisfying the conditions below.
* All numbers in the grid should be between 1 and k inclusive.
* Minimum number of the i-th row is 1 (1 ≤ i ≤ n).
* Minimum number of the j-th column is 1 (1 ≤ j ≤ n).
Find the number of ways to ... | def Solve(n,k):
mod = 10**9+7
max_n = 10**4
#precalcular los factoriales
fac = [1] + [0] * max_n
fac_i = [1] + [0] * max_n
for i in range(1,n+1):
fac[i] = fac[i-1] * (i) % mod
fac_i[i] = fac_i[i- 1] * pow(i,mod-2,mod) % mod
#calculo de las combinaciones con factorial inverso
def... | {
"input": [
"123 456789\n",
"2 2\n",
"220 51931060\n",
"250 1000000000\n",
"236 1\n",
"242 558095993\n",
"216 639704712\n",
"206 1\n",
"10 19549\n",
"3 212096267\n",
"218 325181815\n",
"216 104981514\n",
"218 548318195\n",
"244 315404017\n",
"1 3\n",
"2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have n × n square grid and an integer k. Put an integer in each cell while satisfying the conditions below.
* All numbers in the grid should be between 1 and k inclusive.
* ... |
1270_E. Divide Points_36356 | You are given a set of n≥ 2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups A and B, such that the following condition holds:
For every two points P and Q, write the [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) between them o... | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
"""
created by shhuan at 2019/12/30 21:55
"""
N = int(input())
A = []
for i in range(N):
x, y = map(int, input().split())
A.append((x, y))
def dist... | {
"input": [
"3\n0 0\n0 1\n1 0\n",
"2\n-1000000 -1000000\n1000000 1000000\n",
"3\n-2 1\n1 1\n-1 0\n",
"6\n2 5\n0 3\n-4 -1\n-5 -4\n1 0\n3 -1\n",
"4\n0 1\n0 -1\n1 0\n-1 0\n",
"3\n792878 200978\n-5870 -263790\n-134681 900147\n",
"10\n793236 -477199\n-793236 477199\n-287060 607089\n287060 -607... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set of n≥ 2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups A and B, such that the following condit... |
1293_C. NEKO's Maze Game_36360 | [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive)
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a 2 × n rectangle grid. NEKO... | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
n, q = [int(item) for item in input().split()]
block = [[0] * (n + 6) for _ in range(2)]
wall = 0
for _ in range(q):
x, y = [int(item) - 1 for item in input().split()]
y += 3
invx = (x + 1) % 2
if block[x][y]:
block[x][y] = 0
... | {
"input": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"76183 37\n1 68009\n2 68008\n2 68008\n2 51883\n1 51882\n2 51883\n2 51881\n2 51881\n2 51881\n2 51881\n2 68008\n2 68008\n2 68008\n2 68008\n2 51881\n2 40751\n2 51881\n2 51881\n2 51881\n2 2204\n1 40750\n2 40751\n2 62512\n2 68008\n2 68008\n2 40749\n2 33598\n2 40749\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or... |
1313_C1. Skyscrapers (easy version)_36364 | This is an easier version of the problem. In this version n ≤ 1000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company ... | import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import *
from collections import defaultdict, deque, Counter
import math, string
from heapq import *
from operator import add
from itertools import accumulate
BUFSIZE = 8192
sys.setrecursionlimit(10 ** 5)
class FastIO(IOBase):
... | {
"input": [
"3\n10 6 8\n",
"5\n1 2 3 2 1\n",
"1\n1\n",
"6\n4 1 2 3 2 1\n",
"7\n6 2 2 6 5 7 7\n",
"6\n3 2 1 7 3 7\n",
"5\n1 1 4 2 2\n",
"100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an easier version of the problem. In this version n ≤ 1000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the constru... |
1335_F. Robots on a Grid_36368 | There is a rectangular grid of size n × m. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell (i, j) is c_{i, j}. You are also given a map of directions: for each cell, there is a direction s_{i, j} which is one of the four characters 'U', 'R', 'D' and 'L'.
* If s_{i, j} is 'U' then t... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sy... | {
"input": [
"3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n",
"3\n1 2\n01\nRL\n3 3\n000\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n",
"3\n1 2\n01\nRL\n3 3\n011\n101\n110\nRLL\nDLD\nULL\n3 3\n010\n000\n000\nRRD\nRLD\nULL\n",
"3\n1 2\n01\nRL\n3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a rectangular grid of size n × m. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell (i, j) is c_{i, j}. You are also given a map of direction... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.