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 |
|---|---|---|---|---|---|
p03312 AtCoder Regular Contest 100 - Equal Cut_20324 | Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the ma... | N=int(input())
A=list(map(int,input().split()))
from itertools import accumulate
C=[0]+list(accumulate(A))
l,r=1,3
x=10**16
for m in range(2,N-1):
a,b,c,d=C[l],C[m]-C[l],C[r]-C[m],C[N]-C[r]
while l<m-1 and abs(C[m]-C[l+1]*2)<abs(a-b):
l+=1
a,b=C[l],C[m]-C[l]
while r<N-1 and abs(C[N]-C[r+1]*2... | {
"input": [
"10\n10 71 84 33 6 47 23 25 52 64",
"7\n1 2 3 1000000000 4 5 6",
"5\n3 2 4 1 2",
"10\n10 71 113 33 6 47 23 25 52 64",
"7\n1 2 3 1100000000 4 5 6",
"5\n3 2 4 2 2",
"10\n10 102 113 33 6 47 23 25 52 64",
"7\n1 2 3 1100000000 4 5 2",
"10\n10 102 113 60 6 47 23 25 52 64",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be ... |
p03469 AtCoder Beginner Contest 085 - Already 2018_20328 | On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date col... | s=input()
print("2018/"+s[5:]) | {
"input": [
"2017/01/07",
"2017/01/31",
"2017/01/06",
"2017/01/32",
"2017/01//7",
"2010/01/77",
"2010/01/76",
"2016/01/70",
"2016/01/80",
"2017/01/21",
"2017/01/33",
"2017/01/16",
"2017/01/22",
"2016/01/07",
"2010/01/87",
"2017/01/20",
"2010/01/75",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be ... |
p03631 AtCoder Beginner Contest 070 - Palindromic Number_20332 | You are given a three-digit positive integer N.
Determine whether N is a palindromic number.
Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
Constraints
* 100≤N≤999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output... | N = input()
print('Yes' if N == N[-1::-1] else 'No') | {
"input": [
"812",
"575",
"123",
"559",
"676",
"665",
"179",
"129",
"371",
"344",
"158",
"654",
"435",
"278",
"467",
"1293",
"143",
"1865",
"3151",
"808",
"731",
"406",
"208",
"182",
"357",
"300",
"1035",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a three-digit positive integer N.
Determine whether N is a palindromic number.
Here, a palindromic number is an integer that reads the same backward as forward in decima... |
p03789 AtCoder Grand Contest 011 - Increasing Numbers_20335 | We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are not.
Snuke has an integer N. Find the minimum number of increasi... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・1,11,111,...に分解して9個ずつまとめる
・9倍して考える。9N+x の digit sum <= x となる最小のxが知りたい
・xが満たせばx+1も満たすので、二分探索できる
"""
N = [x - ord('0') for x in map(int,read().rstrip())][::-1]
# とりあえず 9 倍
N = [9 * x for x in N] + [... | {
"input": [
"123456789",
"80",
"7204647845201772120166980358816078279571541735614841625060678056933503",
"20170312",
"150346839",
"73",
"3704579452095997258280591217784156184311155893966777597430447796450532",
"19664274",
"22",
"427137435587252121464618920693144725991555722532... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left.... |
p03957 CODE FESTIVAL 2016 qual C - CF_20339 | This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way.
You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtai... | import re
print("YNeos"[re.match(".*C.*F.*",input())==None::2])
| {
"input": [
"CF",
"CODEFESTIVAL",
"FCF",
"FESTIVALCODE",
"FC",
"CODDFESTIVAL",
"FCE",
"IESTFVALCODE",
"DF",
"DODDFESTIVAL",
"FCD",
"EDOCLAVFTSEI",
"EF",
"LAVITSEFDDOD",
"DCF",
"EFOCLAVDTSEI",
"FD",
"KAVITSEFDDOD",
"CFD",
"ECOFLAVDTSEI",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other s... |
p00049 Blood Groups_20343 | Create a program that reads the attendance numbers of students in a class and the data that stores the ABO blood group and outputs the number of people for each blood type. There are four types of ABO blood types: A, B, AB, and O.
Input
A comma-separated pair of attendance numbers and blood types is given over mult... | from collections import Counter
import sys
d=Counter([i.split(",")[1].strip() for i in sys.stdin])
[print(d[i]) for i in ["A","B","AB","O"]]
| {
"input": [
"1,B\n2,A\n3,B\n4,AB\n5,B\n6,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A",
"1,B\n2,A\n3,B\n4,AB\n5,B\n5,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A",
"1,B\n2,B\n3,B\n4,AB\n5,B\n6,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A",
"1,B\n2,A\n3,B\n4,AB\n5,A\n6,O\n7,A\n8,O\n9,AB\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Create a program that reads the attendance numbers of students in a class and the data that stores the ABO blood group and outputs the number of people for each blood type. There are ... |
p00179 Mysterious Worm_20347 | Dr. A of the Aizu Institute of Biological Research discovered a mysterious insect on a certain southern island. The shape is elongated like a hornworm, but since one segment is shaped like a ball, it looks like a beaded ball connected by a thread. What was strange was that there were many variations in body color, and ... | from collections import deque
def new_color(s, i, rgb):
for color in rgb:
if color != s[i] and color != s[i + 1]:
break
return s[:i] + color * 2 + s[i + 2:]
def solve(s):
length = len(s)
monos = ["r" * length, "g" * length, "b" * length]
if s in monos:
print(0)
return
dic = {s:0}
rgb =... | {
"input": [
"rbgrg\nrbbgbbr\nbgr\nbgrbrgbr\nbggrgbgrr\ngbrggrbggr\nrrrrr\nbgbr\n0",
"rbgrg\nrbbgbbr\nbgr\nrgbbrgbr\nbggrgbgrr\ngbrggrbggr\nrrrrr\nbgbr\n0",
"rbgrg\ngbbrbbr\ngbr\nrgbbrgbr\nrrgbgrggb\ngbrggrbggr\nrrrrr\nbgbr\n0",
"rbgrg\nrbbgbbr\nbgr\nbgbrrgbr\nbggrgbgrr\ngbrggrbggr\nrrrrr\nbgbr\n0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dr. A of the Aizu Institute of Biological Research discovered a mysterious insect on a certain southern island. The shape is elongated like a hornworm, but since one segment is shaped... |
p00335 Pancake_20350 | At the pancake shop you work for, pancake dough is lined up in a row on an elongated iron plate and baked. Pancakes can be completed by turning them over with a spatula several times. How many times you turn it over to complete it depends on the pancake.
Since the spatula is large, two adjacent pancakes will be turned... | n = int(input())
pancake = list(map(int, input().split()))
ans = 10**9
for i in range(4):
cnt = [0] * n
cnt[0] += i
for j in range(n-1):
diff = pancake[j] - cnt[j]
if diff > 0:
cnt[j] += diff
cnt[j+1] += diff
diff = pancake[n-1] - cnt[n-1]
if diff > 0:
... | {
"input": [
"3\n0 3 0",
"3\n1 2 1",
"3\n0 6 0",
"3\n0 2 1",
"3\n1 4 1",
"3\n0 11 -1",
"3\n0 10 -1",
"3\n1 7 2",
"3\n0 5 -1",
"3\n0 3 -1",
"3\n2 8 -2",
"3\n2 14 -2",
"3\n2 17 -2",
"3\n1 32 -1",
"3\n1 57 -1",
"3\n0 72 2",
"3\n0 0 0",
"3\n1 0 0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At the pancake shop you work for, pancake dough is lined up in a row on an elongated iron plate and baked. Pancakes can be completed by turning them over with a spatula several times.... |
p00526 Illumination_20354 | Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleep... | N = int(input())
*A, = map(int, input().split())
for i in range(N): A[i] ^= i&1
B = []
prev = A[0]; cnt = 0
for i in range(N):
if prev != A[i]:
B.append(cnt)
cnt = 1
else:
cnt += 1
prev = A[i]
B.append(cnt)
if len(B) == 1:
print(B[0])
elif len(B) == 2:
print(B[0] + B[1])
else... | {
"input": [
"10\n1 1 0 0 1 0 1 1 1 0",
"10\n1 1 0 0 0 0 1 1 1 0",
"10\n1 1 0 0 0 0 1 1 1 1",
"10\n1 1 0 0 0 0 1 2 1 1",
"10\n1 1 0 0 -1 0 1 2 1 1",
"10\n1 1 0 0 -1 1 1 2 1 1",
"10\n1 1 0 0 -1 2 1 2 1 2",
"10\n-1 1 1 1 1 -1 -21 1 1 15",
"10\n1 1 0 0 -1 1 1 2 1 2",
"10\n1 1 0 0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row... |
p00693 Cyber Guardian_20358 | In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing atrocious crackers wherever you are, unless being disconnected. You have to protect yourselves against their attacks.
Counting upon you... | # AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u
import re
while True:
n, m = map(int, input().split())
if (n|m) == 0: break
rule, ans = [], []
for i in range(n):
g, s, d = input().split()
rule.append((g[0] == 'p', re.compile((s+d).replace("?", "\d"))))
for i in range(m):
s, d, m = input().split()
sd... | {
"input": [
"2 5\npermit 192168?? ?12??34?\ndeny 19216899 012343?5\n19216711 11233340 HiIamACracker\n19216891 01234345 Hello\n19216899 01234345 HiIamAlsoACracker\n19216809 11200340 World\n00000000 99999999 TheEndOfTheWorld\n1 2\npermit 12345678 23456789\n19216891 01234345 Hello\n12345678 23456789 Hello\n0 0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing... |
p00834 Inherit the Spheres_20361 | In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres.
<image>
Figure 1: A strange o... | from collections import defaultdict, deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
C0 = [list(map(int, readline().split())) for i in range(N)]
U = [1]*N
D = defaultdict(list)
for i in range(N):
xi,... | {
"input": [
"3\n95 20 180 18\n125 20 185 18\n40 27 195 10\n1\n5 5 5 4\n2\n5 5 5 4\n5 5 5 3\n2\n5 5 5 4\n5 7 5 3\n16\n2338 3465 29034 710\n1571 14389 25019 842\n1706 8015 11324 1155\n1899 4359 33815 888\n2160 10364 20511 1264\n2048 8835 23706 1906\n2598 13041 23679 618\n1613 11112 8003 1125\n1777 4754 25986 929\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid sph... |
p00966 String Puzzle_20363 | Problem J String Puzzle
Amazing Coding Magazine is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try!
The puzzle in the latest issue ... | from bisect import bisect
n, a, b, q = map(int, input().split())
W = [input().split() for i in range(a)]
X = [int(x) for x, c in W]
C = [c for x, c in W]
P = [list(map(int, input().split())) for i in range(b)]
Y = [y for y, h in P] + [n+1]
D = [0]*b
for i in range(b):
y0, h = P[i]; y1 = Y[i+1]
l = y1 - y0
... | {
"input": [
"9 4 5 4\n3 C\n4 I\n7 C\n9 P\n2 1\n4 0\n6 2\n7 0\n8 4\n8\n1\n9\n6",
"9 4 5 3\n3 C\n4 I\n7 C\n9 P\n2 1\n4 0\n6 2\n7 0\n8 4\n8\n1\n9\n6",
"9 4 5 3\n3 C\n4 I\n9 C\n9 P\n2 1\n4 1\n6 2\n7 0\n8 4\n8\n1\n9\n6",
"9 4 5 4\n3 C\n4 I\n7 C\n9 P\n4 1\n4 0\n6 2\n7 0\n8 4\n8\n1\n9\n6",
"9 4 1 2\n6 C... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem J String Puzzle
Amazing Coding Magazine is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for pro... |
p01368 Merry Christmas_20369 | International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at specified time of December 24. Although same Santa can deliver two or more presents, because it takes time to move between houses, two or more... | 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 2 3\n0 1 10\n1 2 10\n0 0\n1 10\n2 0\n3 2 4\n0 1 10\n1 2 10\n0 0\n1 10\n2 20\n0 40\n10 10 10\n0 1 39\n2 3 48\n3 5 20\n4 8 43\n3 9 10\n8 9 40\n3 4 5\n5 7 20\n1 7 93\n1 3 20\n0 0\n1 100000000\n2 100\n3 543\n4 500\n5 400\n6 300\n7 200\n8 100\n9 100\n0 0 0",
"3 2 3\n0 1 10\n1 2 10\n0 0\n1 10\n2 0\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at speci... |
p01550 Card_20372 | Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time.
For example, if you have 1 and 2, you will get 4 numbers 1, 2, 12, 21 so the total number is 36. Even if the same numbers are produced ... | import sys
read = sys.stdin.read
write = sys.stdout.write
def solve():
MOD = 10**9 + 7
N, *A = map(int, read().split())
L = 10**5
fact = [1]*(L+1)
rfact = [1]*(L+1)
r = 1
for i in range(1, L+1):
fact[i] = r = r * i % MOD
rfact[L] = r = pow(fact[L], MOD-2, MOD)
for i in rang... | {
"input": [
"2\n1\n2",
"4\n0\n4\n7\n8",
"2\n1\n11",
"2\n2\n2",
"4\n0\n4\n2\n8",
"2\n2\n11",
"2\n2\n0",
"4\n0\n4\n2\n10",
"2\n2\n22",
"2\n1\n0",
"4\n1\n4\n2\n10",
"2\n2\n9",
"4\n1\n4\n0\n10",
"2\n1\n9",
"4\n1\n4\n0\n12",
"2\n0\n9",
"2\n0\n15",
"2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time.... |
p01706 Reverse a Road II_20375 | Problem Statement
JAG Kingdom is a strange kingdom such that its $N$ cities are connected only by one-way roads. The $N$ cities are numbered $1$ through $N$. ICPC (International Characteristic Product Corporation) transports its products from the factory at the city $S$ to the storehouse at the city $T$ in JAG Kingdom... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
self.D = {}
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = ... | {
"input": [
"4 4 1 4\n1 2\n3 1\n4 2\n3 4\n7 8 1 7\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 7\n7 6\n6 4 5 2\n1 2\n1 3\n4 5\n5 6\n10 21 9 10\n9 1\n9 2\n9 3\n9 4\n10 1\n10 2\n10 3\n10 4\n1 5\n2 5\n2 6\n3 6\n3 7\n4 7\n4 8\n1 8\n5 10\n6 10\n7 10\n10 8\n10 9\n2 15 1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem Statement
JAG Kingdom is a strange kingdom such that its $N$ cities are connected only by one-way roads. The $N$ cities are numbered $1$ through $N$. ICPC (International Char... |
p02273 Koch Curve_20382 | Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of... | import math
def koch(d,x1,y1,x2,y2):
if d == 0:
return
xs = (2*x1+x2)/3
ys = (2*y1+y2)/3
xt = (x1+2*x2)/3
yt = (y1+2*y2)/3
xu = (xt-xs)*math.cos(math.pi/3) - (yt-ys)*math.sin(math.pi/3) + xs
yu = (xt-xs)*math.sin(math.pi/3) + (yt-ys)*math.cos(math.pi/3) + ys
koch(d-1,x1,y1,x... | {
"input": [
"2",
"1",
"4",
"0",
"6",
"3",
"5",
"3",
"0",
"4",
"6",
"5"
],
"output": [
"0.00000000 0.00000000\n11.11111111 0.00000000\n16.66666667 9.62250449\n22.22222222 0.00000000\n33.33333333 0.00000000\n38.88888889 9.62250449\n33.33333333 19.24500897\n44.444... | 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 an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve i... |
p02420 Shuffle_20386 | Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character co... | while 1:
s = input()
if s == "-": break
for _ in range(int(input())):
h = int(input())
s = s[h:] + s[:h]
print(s)
| {
"input": [
"aabc\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-",
"aaac\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-",
"caaa\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-",
"caaa\n3\n1\n2\n2\nvxxyz\n2\n3\n4\n-",
"ca`a\n3\n1\n2\n2\nvwxyz\n2\n3\n4\n-",
"caaa\n3\n1\n0\n2\nvwxyz\n2\n3\n4\n-",
"caaa\n3\n1\n-1\n2\nvwxyz\n2\n3\n4\n-",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to t... |
1010_C. Border_20396 | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | from math import gcd
n, k = map(int, input().split())
A = list(map(int, input().split()))
g = 0
for ai in A:
g = gcd(g, ai)
s = set()
x = 0
while True:
d = (g*x) % k
if d not in s:
s.add(d)
else:
break
x += 1
print(len(s))
print(*sorted(s))
| {
"input": [
"3 10\n10 20 30\n",
"2 8\n12 20\n",
"2 300\n3 10\n",
"60 30\n10 30 45 15 25 60 10 40 35 25 5 40 35 40 15 5 15 35 10 60 25 15 60 10 30 10 5 25 10 15 60 20 30 5 50 50 40 20 55 40 35 15 15 10 60 40 50 50 30 15 25 45 35 40 15 5 5 20 60 45\n",
"1 8\n6\n",
"30 30\n11 23 7 30 13 6 25 29 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every touris... |
109_C. Lucky Tree_20406 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of... | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
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" ... | {
"input": [
"4\n1 2 4\n1 3 47\n1 4 7447\n",
"4\n1 2 4\n3 1 2\n1 4 7\n",
"2\n2 1 1000000000\n",
"2\n1 2 7\n",
"9\n1 2 1\n1 3 7\n3 4 19\n3 5 2\n4 6 46\n7 4 25\n5 8 64\n5 9 73\n",
"7\n1 2 47\n1 3 9\n3 7 7\n3 4 2\n3 5 4\n3 6 1\n",
"9\n1 2 7\n1 3 12\n4 1 2\n4 5 4\n4 6 47\n4 7 9\n5 8 2\n5 9 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, ... |
1120_C. Compress String_20410 | Suppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.
To compress the string, you have to represent s as a concatenation of several non-empty strings: s = t_{1} t_{2} … t_{k}. The i-th of these strings should be encode... | def f(x):
z=[0 for i in range(len(x))]
l=0
r=0
for i in range(1,len(x)):
if i<=r:
z[i]=min(z[i-l],r-i+1)
while i+z[i]<len(x) and x[z[i]]==x[i+z[i]]:
z[i]+=1
if i+z[i]-1>r:
l,r=i,i+z[i]-1
return z
a=list(map(int,input('').split()))
n,a,b=a[0... | {
"input": [
"4 1 1\nabcd\n",
"4 10 1\naaaa\n",
"3 3 1\naba\n",
"134 4 64\nabaayaaabaaaabaaaaapaaaaaabaapajaapaaanasaabaaaaaaaaabaaaataaarabaaaadaaaaaabaaaaaacaaaaabaaaaaaaaaaaaabaaaaaaaaaaaiaabsaaaaaaaaaaaaaa\n",
"79 1 2\nfifchfihhhfbijhhifcefgfjifdfchfdfjegiddhfagdhfiffhfijghdifbhfafedhdfcififcf... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Suppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.
To compress the string, you... |
1169_A. Circle Metro_20416 | The circle line of the Roflanpolis subway has n stations.
There are two parallel routes in the subway. The first one visits stations in order 1 → 2 → … → n → 1 → 2 → … (so the next stop after station x is equal to (x+1) if x < n and 1 otherwise). The second route visits stations in order n → (n-1) → … → 1 → n → (n-1) ... | n,a,x,b,y=map(int,input().split(" "))
flag =1
while a!=x and b!=y:
a = a+ 1
b = b-1
if(a==n+1):
a = 1
if(b==0):
b=n
if(a==b):
flag =0
print('YES')
break;
if flag==1:
print ('NO')
| {
"input": [
"5 1 4 3 2\n",
"10 2 1 9 10\n",
"10 2 4 7 3\n",
"5 3 2 4 1\n",
"4 4 2 1 3\n",
"5 5 1 2 3\n",
"5 4 5 3 1\n",
"8 1 4 5 6\n",
"53 10 34 1 48\n",
"60 1 50 51 49\n",
"5 5 1 2 4\n",
"4 4 2 3 1\n",
"10 9 10 5 8\n",
"4 2 1 4 3\n",
"13 1 9 2 13\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The circle line of the Roflanpolis subway has n stations.
There are two parallel routes in the subway. The first one visits stations in order 1 → 2 → … → n → 1 → 2 → … (so the next s... |
1187_C. Vasya And Array_20420 | Vasya has an array a_1, a_2, ..., a_n.
You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≤ t_i ≤ 1, 1 ≤ l_i < r_i ≤ n) and it means:
* if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order;
* if t_i... | """609C"""
# import math
# import sys
def main():
n,m = map(int,input().split())
l = []
s = []
r = []
d = [0]*n
for _ in range(m):
a,b,c = map(int,input().split())
s.append(a)
b-=1
l.append(b)
c-=1
r.append(c)
if a==1:
d[b]+=1
d[c]-=1
dx = [-1]*(n-1)
add = 0
for i in range(n):
add+=d[i]
... | {
"input": [
"7 4\n1 1 3\n1 2 5\n0 5 6\n1 6 7\n",
"4 2\n1 1 4\n0 2 3\n",
"5 2\n0 1 5\n1 1 4\n",
"7 3\n1 1 4\n1 4 6\n0 1 7\n",
"5 4\n0 1 2\n1 2 3\n0 3 4\n1 4 5\n",
"10 2\n0 1 4\n1 1 4\n",
"7 2\n1 1 4\n0 4 5\n",
"5 3\n0 1 3\n1 2 4\n0 4 5\n",
"4 3\n1 1 2\n0 2 3\n0 3 4\n",
"7 5\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has an array a_1, a_2, ..., a_n.
You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≤ t_i ≤ 1, 1 ≤ l_... |
1206_B. Make Product Equal One_20424 | You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation:
Choose one of these numbers and add or subtract 1 from it.
In particular, we can apply this operation to the same number several times.
We want to make the product of all these numbers equal to 1, in other wo... | def func(lst):
prod = 1
for item in lst:
if item!=0:
prod = prod*item
return prod
w = int(input())
a=list(map(int,input().split()))
count=0
count1=0
for i,item in enumerate(a):
if item<0 and item !=-1:
count+=abs(item+1)
a[i]=-1
if item>0 and... | {
"input": [
"5\n-5 -3 5 3 0\n",
"4\n0 0 0 0\n",
"2\n-1 1\n",
"4\n-3 -3 -3 1\n",
"5\n-1 -1 -1 0 0\n",
"3\n-525187879 0 425880698\n",
"4\n-1 0 0 0\n",
"5\n0 0 -1 -1 -1\n",
"21\n-302243520 63294374 -424314405 -870258491 110759377 321300735 569988467 -852033606 -987112183 -475943648 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation:
Choose one of these numbers and add or subtract 1 from it.
In particular... |
1249_B1. Books Exchange (easy version)_20430 | The only difference between easy and hard versions is constraints.
There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ... | import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.... | {
"input": [
"6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3\n",
"20\n6\n4 5 6 3 2 1\n7\n1 4 3 6 5 2 7\n10\n4 6 8 2 5 7 3 1 9 10\n6\n4 5 2 3 1 6\n2\n1 2\n7\n4 2 3 7 1 6 5\n10\n3 6 2 8 4 1 7 9 10 5\n3\n1 3 2\n4\n4 3 1 2\n2\n2 1\n1\n1\n1\n1\n5\n1 5 2 3 4\n9\n5 2 8 7 1 6 3 9 4\n6\n2 5 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to ... |
128_B. String_20435 | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The le... | from heapq import *
l=input()
k=int(input())
n=len(l)
if k>n*(n+1)/2:
print("No such line.")
quit()
ss=[(l[i],i) for i in range(n)]
heapify(ss)
while k:
k-=1
t=heappop(ss)
if k==0:
print(t[0])
else:
if t[1]<n-1:
heappush(ss,(t[0]+l[t[1]+1],t[1]+1))
... | {
"input": [
"abc\n5\n",
"abab\n7\n",
"aa\n2\n",
"llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there ex... |
1332_C. K-Complete Word_20439 | Word s of length n is called k-complete if
* s is a palindrome, i.e. s_i=s_{n+1-i} for all 1 ≤ i ≤ n;
* s has a period of k, i.e. s_i=s_{k+i} for all 1 ≤ i ≤ n-k.
For example, "abaaba" is a 3-complete word, while "abccba" is not.
Bob is given a word s of length n consisting of only lowercase Latin letters a... | import sys
input=sys.stdin.readline
t=int(input())
def find(no):
global par
if par[no]==no:
return no
par[no]=find(par[no])
return par[no]
for _ in range(t):
n,k=map(int,input().split())
s=[ord(i)-97 for i in input()]
par=[i for i in range(n)]
vis=[0 for i in range(n)]
f... | {
"input": [
"4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n",
"4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotononstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n",
"4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 3\nw... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Word s of length n is called k-complete if
* s is a palindrome, i.e. s_i=s_{n+1-i} for all 1 ≤ i ≤ n;
* s has a period of k, i.e. s_i=s_{k+i} for all 1 ≤ i ≤ n-k.
For examp... |
1352_F. Binary String Reconstruction_20443 | For some binary string s (i.e. each character s_i is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 2 were written. For each pair (substring of length 2), the number of '1' (ones) in it was calculated.
You are given three numbers:
* n_0 — th... | for testcase in range(int(input())):
n0, n1, n2 = map(int, input().split())
if n1 == 0:
if n0:
ans = "0" * (n0 + 1)
else:
ans = "1" * (n2 + 1)
else:
ans = ["0" * (n0 + 1), "1" * (n2 + 1)]
for i in range(n1 - 1):
ans.append(str(i & 1))
... | {
"input": [
"7\n1 3 5\n1 1 1\n3 9 3\n0 1 0\n3 1 2\n0 0 3\n2 0 0\n",
"7\n1 3 5\n1 1 1\n3 9 3\n0 1 0\n3 1 2\n0 0 3\n2 0 0\n",
"1\n11 10 9\n",
"7\n1 3 5\n1 1 1\n3 9 3\n0 1 0\n3 1 1\n0 0 3\n2 0 0\n",
"1\n11 10 17\n",
"7\n1 3 5\n1 1 1\n3 9 3\n0 1 0\n3 2 2\n0 0 3\n2 0 0\n",
"7\n1 3 5\n1 1 1\n3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For some binary string s (i.e. each character s_i is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 2 were w... |
1372_D. Omkar and Circle_20447 | Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given n nonnegative integers a_1, a_2, ..., a_n arranged in a circle, where n must be odd (ie. n-1 is divisible by 2). Formally, for all i such that 2 ≤ i ≤ n, the elements a_{i - 1} and a_... | n = int(input())
a = [int(x) for x in input().split()]
if n == 1:
print(a[0])
exit()
evens = [a[0]]
odds = [a[1]]
for i in range(2,n):
if i % 2 == 0:
evens.append(evens[-1]+a[i])
else:
odds.append(odds[-1] + a[i])
# print(evens)
# print(odds)
maxi = 0
for i in range(len(evens)):
score = evens[i]
if i == 0:
... | {
"input": [
"3\n7 10 2\n",
"1\n4\n",
"51\n3 3 2 3 1 1 3 1 0 2 1 3 1 3 0 2 0 0 1 1 2 0 3 3 1 3 0 3 0 3 0 0 0 0 0 0 0 3 0 3 1 2 1 1 0 2 1 1 1 0 0\n",
"79\n4 2 2 0 1 9 7 4 8 10 3 2 5 1 10 3 2 1 6 1 1 5 3 4 5 2 0 5 10 1 5 2 9 8 2 8 3 5 8 6 8 3 1 8 4 9 8 4 8 6 1 4 8 7 5 9 6 10 1 1 7 6 0 9 7 2 10 2 4 9 8 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given n nonnegative integers a_1, a_2, ..., a_n arra... |
1395_C. Boboniu and Bit Operations_20451 | Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers a_1,a_2,…,a_n and b_1,b_2,…,b_m.
For each i (1≤ i≤ n), you're asked to choose a j (1≤ j≤ m) and let c_i=a_i\& b_j, where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise... | from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
from collections import deque
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
z=[]
ma=0
for i in a:
x=float("infinity")
for j in b:
x=min(i&j,x)
ma=max(x,ma)
for i i... | {
"input": [
"7 6\n1 9 1 9 8 1 0\n1 1 4 5 1 4\n",
"4 2\n2 6 4 0\n2 4\n",
"8 5\n179 261 432 162 82 43 10 38\n379 357 202 184 197\n",
"54 12\n435 115 422 469 19 176 292 395 273 217 160 343 277 500 124 360 315 59 2 477 465 138 175 392 146 438 4 96 231 182 257 183 51 117 430 125 167 107 238 66 236 96 319 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers a_1,a_2,…,a_n and b_1,b_2,…,b_m.
For each i (1≤ i≤ n), you'r... |
1419_E. Decryption_20455 | An agent called Cypher is decrypting a message, that contains a [composite number](https://en.wikipedia.org/wiki/Composite_number) n. All divisors of n, which are greater than 1, are placed in a circle. Cypher can choose the initial order of numbers in the circle.
In one move Cypher can choose two adjacent numbers in ... | from sys import stdin, stdout
# 6
# 2 3 6
# 30
# 2,3,5
# 2 30 6 3 15 5 10
# 2 - (30) - 6 - 3 - 15 - 5 - 10
# P1 - (x*P1) - P1P2 - P2 - (x*P2) - P2P3 - P3 - (x*P3) - P1P3
def decryption(n):
r1 = []
r2 = 0
factor_a = getfactor(n)
prime_a = getprime(n)
hs = set()
prime_dic = {}
#print(fa... | {
"input": [
"3\n6\n4\n30\n",
"1\n18\n",
"1\n9\n",
"3\n6\n2\n30\n",
"1\n22\n",
"1\n13\n",
"3\n6\n2\n5\n",
"1\n21\n",
"1\n29\n",
"1\n38\n",
"1\n34\n",
"1\n47\n",
"1\n61\n",
"1\n75\n",
"1\n17\n",
"3\n6\n2\n50\n",
"1\n42\n",
"1\n62\n",
"1\n23\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An agent called Cypher is decrypting a message, that contains a [composite number](https://en.wikipedia.org/wiki/Composite_number) n. All divisors of n, which are greater than 1, are ... |
1437_F. Emotional Fishermen_20459 | n fishermen have just returned from a fishing vacation. The i-th fisherman has caught a fish of weight a_i.
Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (each fisherman shows his fish exactly once, so, formally, the order of sh... | from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
a = map(int, input().split())
mod = 998244353
d = defaultdict(int)
for x in a:
d[x] += 1
d[0] = 0
b = list(d.items())
b.sort()
m = len(b)
ba = [0] * m
cn = [0] * (m + 1)
k = h = 0
for i, x in enumerate(b):
while h < m and... | {
"input": [
"4\n4 3 2 1\n",
"8\n42 1337 13 37 420 666 616 97\n",
"3\n4 2 1\n",
"4\n1 1 4 9\n",
"2\n500000000 1000000000\n",
"2\n500000001 1000000000\n",
"2\n1 1\n",
"10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\n",
"2\n300... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
n fishermen have just returned from a fishing vacation. The i-th fisherman has caught a fish of weight a_i.
Fishermen are going to show off the fish they caught to each other. To do ... |
1462_D. Add to Neighbour and Remove_20463 | Polycarp was given an array of a[1 ... n] of n integers. He can perform the following operation with the array a no more than n times:
* Polycarp selects the index i and adds the value a_i to one of his choice of its neighbors. More formally, Polycarp adds the value of a_i to a_{i-1} or to a_{i+1} (if such a neighbo... | def check(sm):
cur = 0
for i in range(n):
cur += lis[i]
if cur == sm: cur = 0
elif cur > sm: return False
return cur == 0
t = int(input())
s = ""
for i in range(t):
n = int(input())
lis = [*map(int, input().split())]
sm = sum(lis)
ans = -1
for j in range(n, 0, -... | {
"input": [
"4\n5\n3 1 6 6 2\n4\n1 2 2 1\n3\n2 2 2\n4\n6 3 2 1\n",
"1\n13\n1 2 3 2 1 3 2 1 2 65 12 1 1\n",
"50\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp was given an array of a[1 ... n] of n integers. He can perform the following operation with the array a no more than n times:
* Polycarp selects the index i and adds the v... |
1487_E. Cheap Dinner_20467 | Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of dri... | MAX_VAL = 2 ** 31
def prepare_values(vals):
zipped_vals = list(zip(vals, range(1, len(vals) + 1)))
zipped_vals.sort()
pairs = [(old_i, i) for i, (val, old_i) in enumerate(zipped_vals, 1)]
return zipped_vals, dict(pairs)
def renumber_ids(dic, l):
return [dic[x] for x in l]
def get_first_absent(... | {
"input": [
"1 1 1 1\n1\n1\n1\n1\n1\n1 1\n0\n0\n",
"4 3 2 1\n1 2 3 4\n5 6 7\n8 9\n10\n2\n1 2\n1 1\n2\n3 1\n3 2\n1\n1 1\n",
"5 5 5 5\n836 776 809 618 397\n121 629 373 169 333\n589 439 410 388 446\n936 472 433 647 791\n25\n1 2\n4 5\n5 4\n4 1\n3 5\n5 2\n2 4\n3 4\n3 3\n3 2\n4 4\n4 3\n1 1\n1 4\n5 1\n2 3\n1 5\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy... |
1511_B. GCD Length_20471 | You are given three integers a, b and c.
Find two positive integers x and y (x > 0, y > 0) such that:
* the decimal representation of x without leading zeroes consists of a digits;
* the decimal representation of y without leading zeroes consists of b digits;
* the decimal representation of gcd(x, y) without... | for _ in range(int(input())):
a,b,c=map(int,input().split())
x=(10**(a-c)+1)*(10**(c-1))
y=10**(b-1)
print(x,y) | {
"input": [
"4\n2 3 1\n2 2 2\n6 6 2\n1 1 1\n",
"4\n2 3 1\n2 2 2\n6 6 2\n1 1 1\n",
"9\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"9\n1 1 1\n2 4 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"9\n1 1 1\n2 4 2\n3 5 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given three integers a, b and c.
Find two positive integers x and y (x > 0, y > 0) such that:
* the decimal representation of x without leading zeroes consists of a digit... |
1538_G. Gift Set_20475 | Polycarp has x of red and y of blue candies. Using them, he wants to make gift sets. Each gift set contains either a red candies and b blue candies, or a blue candies and b red candies. Any candy can belong to at most one gift set.
Help Polycarp to find the largest number of gift sets he can create.
For example, if x... | import sys,io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda: map(int,input().split())
O = []
for _ in range(int(input())):
x,y,a,b = read()
if a==b:
O.append(str(min(x,y)//a))
continue
if a<b: a,b = b,a
d = a-b
L = [0,(x+y)//(a+b)+1]
while L[1]-L[0... | {
"input": [
"9\n10 12 2 5\n1 1 2 2\n52 311 13 27\n1000000000 1000000000 1 1\n1000000000 1 1 1000000000\n1 1000000000 1000000000 1\n1 2 1 1\n7 8 1 2\n4 1 2 3\n",
"9\n10 12 2 5\n1 2 2 2\n52 311 13 27\n1000000000 1000000000 1 1\n1000000000 1 1 1000000000\n1 1000000000 1000000000 1\n1 2 1 1\n7 8 1 2\n4 1 2 3\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has x of red and y of blue candies. Using them, he wants to make gift sets. Each gift set contains either a red candies and b blue candies, or a blue candies and b red candie... |
165_B. Burning Midnight Oil_20479 | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as <image> lines, drinks another cup of tea, then he writes <... | """
Solution to the 706B problem on CodeForces.
"""
import sys
import math
def binary_search(k, target):
beg, end = 1, target
while beg + 1 < end:
number = (beg + end) // 2
if (lambda_function(target, k, number)):
end = number
else:
beg = number
if (lambda_fu... | {
"input": [
"7 2\n",
"59 9\n",
"948889213 9\n",
"246 10\n",
"7998332 2\n",
"689973 7\n",
"75584551 2\n",
"37212 2\n",
"6578 2\n",
"92153348 9\n",
"2959379 4\n",
"1000000000 3\n",
"1000000000 10\n",
"11 2\n",
"177583558 10\n",
"1000000000 9\n",
"1000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: f... |
186_C. Plant_20483 | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | N = int(input())
result = (pow(2, N, int(1e9 + 7)) * (pow(2, N, int(1e9 + 7)) + 1)) % int(1e9+7)
result = (result * pow(2, int(1e9+5), int(1e9+7))) % int(1e9+7)
print(result)
| {
"input": [
"1\n",
"2\n",
"615812227854199662\n",
"563324730406715801\n",
"856674609788912527\n",
"349993003033420740\n",
"15\n",
"148049062285906746\n",
"989464295\n",
"6\n",
"252509053898415171\n",
"1312148742261680\n",
"269587448053313253\n",
"93135650170321... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides int... |
207_D5. The Beaver's Problem - 3_20487 | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | print('2') | {
"input": [
"24000\nN.Y. BANK DISCOUNT BORROWINGS 169 MLN DLRS\nNEW YORK, April 9 - The eight major New York City banks had\ndaily average borrowings of 169 mln dlrs from the Federal\nReserve in the week ended April 8, a Fed spokesman said.\nA Fed spokesman said that all of the borrowings were made\nyesterday by... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorti... |
281_C. Rectangle Puzzle_20495 | You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side tha... | import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
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... | {
"input": [
"1 1 45\n",
"6 4 30\n",
"90002 994645 176\n",
"100 100 0\n",
"520648 189225 167\n",
"852428 738707 49\n",
"100 100 30\n",
"135646 480909 0\n",
"560489 381720 91\n",
"129842 930245 115\n",
"314304 429528 163\n",
"507487 609004 180\n",
"646084 979010 45\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle'... |
304_B. Calendar_20499 | Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year... | import sys
import datetime
y1, m1, d1 = map(int, input().split(':'))
y2, m2, d2 = map(int, input().split(':'))
print(abs((datetime.date(y1, m1, d1) - datetime.date(y2, m2, d2)).days))
| {
"input": [
"1900:01:01\n2038:12:31\n",
"1996:03:09\n1991:11:12\n",
"1986:08:24\n1926:04:13\n",
"1910:01:11\n1987:02:08\n",
"1996:02:01\n1996:01:27\n",
"2015:10:17\n1966:07:12\n",
"2000:02:28\n2000:02:28\n",
"1993:08:25\n1985:02:16\n",
"1973:03:18\n1932:11:07\n",
"1934:01:09\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Greg... |
330_C. Purification_20503 | You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the ro... | n = int(input())
grid = [input() for line in range(n)]
total = sum([ln.count('.') for ln in grid])
rowsWSpcN = len([True for ln in grid if '.' in ln])
colsWSpcN = len([True for col in range(n) if '.' in [ln[col] for ln in grid]])
rowsWSpc = [ln.count('.') for ln in grid]
colsWSpc = [[ln[col] for ln in grid].count('.') ... | {
"input": [
"3\nEEE\nE..\nE.E\n",
"3\n.E.\nE.E\n.E.\n",
"5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE\n",
"1\n.\n",
"6\n.EEEEE\n.EEEEE\n......\n......\n......\nEEEEEE\n",
"3\nEEE\n..E\n...\n",
"3\nE..\nEEE\nE..\n",
"17\nEE...E.EE.EE..E..\nE.....EE..E..E..E\nEEEE.EEEE..E..E.E\n.E.E.EEE.EEEEE..... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The... |
352_A. Jeff and Digits_20507 | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number ... | import collections
n = int(input())
l = list(map(int,input().split()))
s = ""
if 0 in l:
c1 = collections.Counter(l)
s+=('0'*c1[0])
x = (c1[5]//9)*9
s = ('5'*x) + s
print(int(s))
else:
print(-1)
| {
"input": [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n",
"4\n5 5 5 5\n",
"23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0\n",
"101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible numbe... |
376_B. I.O.U._20511 | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | n,m = map(int, input().split())
debt=[0]*(n+1)
for i in range(m):
a,b,c = map(int, input().split())
debt[a]-=c
debt[b]+=c
ans=0
for i in debt:
if i>0:
ans+=i
print(ans)
| {
"input": [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n",
"3 0\n",
"100 48\n1 56 6\n2 42 3\n3 52 1\n9 50 8\n10 96 8\n11 39 2\n12 51 6\n12 68 7\n13 40 5\n14 18 10\n14 70 6\n15 37 4\n15 38 8\n15 82 6\n15 85 5\n16 48 4\n16 50 9\n16 71 9\n17 18 3\n17 100 10\n20 73 3\n22 32 9\n22 89 9\n23 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not orga... |
447_C. DZY Loves Sequences_20519 | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | """
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppp... | {
"input": [
"6\n7 2 3 1 5 6\n",
"2\n1000000000 1000000000\n",
"3\n5 1 3\n",
"5\n1 2 5 3 4\n",
"3\n5 3 5\n",
"3\n100 5 10\n",
"8\n1 2 3 4 1 5 6 7\n",
"10\n17 99 23 72 78 36 5 43 95 9\n",
"6\n2 3 5 5 6 7\n",
"4\n1 4 3 4\n",
"4\n5 1 2 3\n",
"6\n1 2 1 2 4 5\n",
"1\n42\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of ... |
469_D. Two Sets_20522 | Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:
* If number x belongs to set A, then number a - x must also belong to set A.
* If number x belongs to set B, then number b - x must also belong to set B.
Hel... | class DisjointSet:
def __init__(self, n):
self._fa = list(range(n))
def union(self, x, y):
x = self.get_father(x)
y = self.get_father(y)
self._fa[x] = y
return y
def get_father(self, x):
y = self._fa[x]
if self._fa[y] == y:
return y
... | {
"input": [
"4 5 9\n2 3 4 5\n",
"3 3 4\n1 2 4\n",
"2 2 3\n1 2\n",
"100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 29... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:
* If number x belongs to se... |
542_E. Playing on Graph_20529 | Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.
Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge. As a res... | def solve():
n, m = input().split()
n = int(n)
m = int(m)
global maxValue
maxValue = n*2
graph = [[] for _ in range(0, n)]
edges = []
diameters = []
for _ in range(0, m):
u, v = input().split()
u = int(u)-1
v = int(v)-1
edges.append(v)
graph[u]... | {
"input": [
"4 2\n1 3\n2 4\n",
"4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n",
"1 0\n",
"1000 4\n100 200\n200 300\n300 400\n400 100\n",
"59 24\n40 3\n14 10\n17 5\n40 15\n22 40\n9 40\n46 41\n17 24\n20 15\n49 46\n17 50\n14 25\n8 14\n11 36\n59 40\n7 36\n16 46\n20 35\n20 49\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.
Vova has a non-directed graph consisting of n vertices and m edges wit... |
56_A. Bar_20533 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ... | a=['ABSINTH','BEER','BRANDY','CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
l=0
for i in range(int(input())):
x=input()
try:
if(int(x)<18):
l+=1
except:
if(x in a):
l+=1
print(l) | {
"input": [
"5\n18\nVODKA\nCOKE\n19\n17\n",
"4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW\n",
"1\n0\n",
"3\nWHISKEY\n3\nGIN\n",
"4\nSAKE\nSAKE\n13\n2\n",
"2\n0\n17\n",
"2\n2\nGIN\n",
"4\n813\nIORBQITQXMPTFAEMEQ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n p... |
612_C. Replace To Make Regular Bracket Sequence_20539 | You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
stack = []
res = 0
for c in s:
if c in '(<[{':
stack.append(c)
else:
if not stack:
print('Impossible')
break
last = stack.pop()
if last + c not in ('[]', '()', '<>', '{}'):
res += 1
else:
if stack:
print('Impossible')
... | {
"input": [
"{()}[]\n",
"[<}){}\n",
"]]\n",
"[<}){}\n",
"(([{>}{[{[)]]>>]\n",
"[[[[[[[[\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 are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by anot... |
632_C. The Smallest String Concatenation_20543 | You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation.
Input
The first line contains integer n — the number of strings (... | from functools import cmp_to_key
def comparator(a,b):
return -1 if a+b <= b+a else 1
def smallest_string(str_list):
return "".join(sorted(str_list, key=cmp_to_key(comparator)))
if __name__ == '__main__':
n = int(input())
str_list = []
for _ in range(n):
s = input()
str_list.append... | {
"input": [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n",
"10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc\n",
"13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtv... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the ... |
750_B. New Year and North Pole_20552 | In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the N... | n = int(input())
x = 0
y = 0
fl = True
for i in range(n):
ar = input().split()
d = int(ar[0])
if fl:
if x == 0 and ar[1] != 'South':
fl = False
if x == 20000 and ar[1] != 'North':
fl = False
if ar[1][0] == 'S':
if x + d > 20000:
fl ... | {
"input": [
"2\n15000 South\n4000 East\n",
"5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n",
"4\n50 South\n50 North\n15000 South\n15000 North\n",
"2\n1000 North\n1000 South\n",
"5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n",
"3\n20000 South\n10 East\n200... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilom... |
818_G. Four Melodies_20558 | Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, and recently she had recorded two tracks that became very popular. Now she has got a lot of fans who are waiting for new tracks.
This t... | import sys
n = int(sys.stdin.readline())
a = [0] + [int(i) for i in sys.stdin.readline().split()]
dp = [[0]*(n + 1) for i in range(n + 1)]
ans = 0
maxnum = [0] * (10**5 + 2)
maxmod = [0] * 7
for y in range(n + 1):
maxmod = [0] * 7
for ai in a:
maxnum[ai] = 0
for i in range(y):
max... | {
"input": [
"5\n1 3 5 7 2\n",
"5\n1 3 5 7 9\n",
"20\n26 5 4 29 39 3 5 16 36 18 36 11 16 8 36 4 15 37 25 13\n",
"4\n8 6 8 1\n",
"6\n2 7 8 6 5 7\n",
"4\n3 2 3 1\n",
"4\n15 11 28 17\n",
"7\n9 12 12 1 8 12 12\n",
"16\n19 9 4 4 9 21 10 18 27 9 5 3 6 12 21 18\n",
"17\n16 26 6 8 6 25... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, ... |
844_C. Sorting by Subsequences_20562 | You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequence is... | n = int(input())
a = list(map(int, input().split()))
a = sorted(range(n), key=lambda i: a[i])
s = []
for i in range(n):
if a[i] + 1:
l = []
s.append(l)
while a[i] + 1:
l.append(i + 1)
a[i], i = -1, a[i]
print(len(s))
for l in s:
print(len(l), *l)
| {
"input": [
"6\n83 -75 -49 11 37 62\n",
"6\n3 2 1 6 5 4\n",
"2\n1 2\n",
"50\n39 7 45 25 31 26 50 11 19 37 8 16 22 33 14 6 12 46 49 48 29 27 41 15 34 24 3 13 20 47 9 36 5 43 40 21 2 38 35 42 23 28 1 32 10 17 30 18 44 4\n",
"2\n2 1\n",
"10\n3 7 10 1 9 5 4 8 6 2\n",
"3\n3 2 1\n",
"20\n36... | 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 a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting intege... |
913_C. Party Lemonade_20571 | A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci r... | n = input().split()
l = int(n[1])
n = int(n[0])
c = input().split()
cperl = []
for i in range(n):
c[i] = int(c[i])
cperl.append([(c[i])/2**i, 2**i, i])
cperl.sort()
f = False
nl = [0]
nc = [0]
i = 0
while not f:
p = nl[i]
nl[i] += cperl[i][1] * ((l-p)//cperl[i][1])
nc[i] += c[cperl[i][2]] * ((l-p)//... | {
"input": [
"4 12\n20 30 70 90\n",
"5 787787787\n123456789 234567890 345678901 456789012 987654321\n",
"4 3\n10000 1000 100 10\n",
"4 3\n10 100 1000 10000\n",
"30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 167... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite sto... |
935_C. Fifa and Fafa_20575 | Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by... | import math
i,x1,y1,x2,y2=input().split()
R=int(i)
x=int(x1)
y=int(y1)
xx=int(x2)
yy=int(y2)
a=(x-xx)*(x-xx)
b=(y-yy)*(y-yy)
d=math.sqrt(a+b)
flag=0
if a+b >= R*R:
print(x,end=" ")
print(y,end=" ")
print(R)
flag=1
elif flag!=1 and d!=0:
r=(d+R)/2
t=xx + r*(x-xx)/d
u=yy + r*(y-yy)/d
print... | {
"input": [
"10 5 5 5 15\n",
"5 3 3 1 1\n",
"82 1928 -30264 2004 -30294\n",
"8318 -2198 35161 3849 29911\n",
"11 9899 34570 9895 34565\n",
"75 -66998 89495 -66988 89506\n",
"4189 -24915 61224 -28221 65024\n",
"1 0 0 0 0\n",
"100000 83094 84316 63590 53480\n",
"10 1 1 1 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can acce... |
961_B. Lecture Sleep_20579 | Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th m... | from collections import Counter
def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
print(solve(n, k, a, t))
def solve(n, k, a, t):
minsum = sum(ai for ai, ti in zip(a,t) if ti == 1)
inc = sum(ai for ai, ti in zip(a[:k], t[... | {
"input": [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n",
"4 2\n4 5 6 8\n1 0 1 0\n",
"9 8\n3 3 7 7 1 9 10 7 1\n1 1 1 1 1 1 1 1 1\n",
"4 3\n6 5 9 6\n1 1 0 1\n",
"10 4\n9 5 6 4 3 9 5 1 10 7\n0 0 0 0 0 0 1 0 0 1\n",
"10 5\n3 5 9 2 5 9 3 8 8 1\n0 1 1 1 0 1 0 0 0 0\n",
"2 1\n3 4\n0 0\n",
"2 1\n3 2\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it i... |
989_A. A Blend of Springtime_20583 | When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" ... | s=input()
f=False
for i in range(len(s)-2):
t=s[i:i+3]
if 'A' in t and 'B' in t and 'C' in t:
f=True
if f:
print('YES')
else:
print('NO') | {
"input": [
"AA..CB\n",
".BAC.\n",
"CACCBAA.BC\n",
"AAABC\n",
"ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB\n",
"AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC\n",
"AAAAABABAAAAA\n",
"............................................ | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already ... |
p02599 AtCoder Beginner Contest 174 - Range Set Query_20597 | We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq ... | import sys
input=sys.stdin.readline
n,q=map(int,input().split())
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
l[i].append(i)
l.sort(key=lambda x:x[1])
L=[-1]*(5*10**5+1)
class Bit:
def __init__(self,n):
self.size=n
self.tree=[0]*(n + 1)
self.... | {
"input": [
"4 3\n1 2 1 3\n1 3\n2 4\n3 3",
"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8",
"10 10\n4 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8",
"4 1\n1 2 1 3\n1 3\n2 4\n3 3",
"4 2\n1 2 1 3\n1 3\n2 4\n3 3",
"4 3\n1 1 1 3\n1 3\n2 4\n3... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many differe... |
p02730 AtCoder Beginner Contest 159 - String Palindrome_20601 | A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:
* S is a palindrome.
* Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.
* The string consisting of the (N+3)/2-st through N-th charact... | s=input()
n=len(s)
s1=s[:n//2]
s2=s[n//2+1:]
if s1==s2 and s1==s1[::-1]:
print("Yes")
else:
print("No") | {
"input": [
"akasaka",
"atcoder",
"level",
"akas`ka",
"redocta",
"llvee",
"akas`ja",
"rfdocta",
"elvle",
"ak`saja",
"redodta",
"elvld",
"`k`saja",
"derodta",
"elvdl",
"ajas`k`",
"dreodta",
"eludl",
"aj`sak`",
"treodda",
"ldule",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:
* S is a palindrome.
* Let N be the length of S. The strin... |
p02863 AtCoder Beginner Contest 145 - All-you-can-eat_20605 | Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot or... | n, t = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]
items.sort()
ma = items[-1][0]
dp = [0] * (t+ma)
for a, b in items:
for i in range(t+ma-1, a-1, -1):
if i-a < t:
dp[i] = max(dp[i], dp[i-a] + b)
print(max(dp))
| {
"input": [
"3 60\n10 10\n10 20\n10 30",
"10 100\n15 23\n20 18\n13 17\n24 12\n18 29\n19 27\n23 21\n18 20\n27 15\n22 25",
"3 60\n30 10\n30 20\n30 30",
"2 60\n10 10\n100 100",
"3 74\n10 10\n10 20\n10 30",
"10 100\n15 23\n20 18\n13 17\n47 12\n18 29\n19 27\n23 21\n18 20\n27 15\n22 25",
"3 60\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the... |
p02998 AtCoder Beginner Contest 131 - Must Be Rectangular!_20609 | There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at... | import sys
input = sys.stdin.readline
M = 10**5
n = int(input())
G = [[] for _ in range(2*M+1)]
for _ in range(n):
x, y = map(int, input().split())
G[x].append(y+M)
G[y+M].append(x)
seen = [False]*(2*M+1)
def dfs(v):
stack = [v]
seen[v] = True
cnt_x, cnt_y = 0, 0
while stack:
v = stack.pop()
if v... | {
"input": [
"3\n1 1\n5 1\n5 5",
"9\n1 1\n2 1\n3 1\n4 1\n5 1\n1 2\n1 3\n1 4\n1 5",
"2\n10 10\n20 20",
"3\n1 1\n5 1\n5 4",
"9\n1 1\n2 1\n3 1\n4 1\n7 1\n1 2\n1 3\n1 4\n1 5",
"2\n10 10\n20 1",
"9\n1 1\n3 1\n3 1\n4 1\n7 1\n1 2\n2 3\n1 4\n1 5",
"9\n1 1\n3 1\n3 1\n4 1\n7 1\n2 2\n2 3\n1 4\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b,... |
p03139 NIKKEI Programming Contest 2019 - Subscribers_20613 | We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:
* Question 1: Are you subscribing to Newspaper X?
* Question 2: Are you subscribing to Newspaper Y?
As the result, A respondents answered "yes" to Question 1, and B respondents answer... | n,a,b=map(int,input().split())
and_=min(a,b)
or_=max(0, a+b-n)
print(and_, or_) | {
"input": [
"10 7 5",
"100 100 100",
"10 3 5",
"10 2 5",
"100 100 000",
"10 1 5",
"101 110 000",
"101 110 100",
"101 100 100",
"100 110 100",
"000 110 100",
"0 2 1",
"000 100 100",
"0 3 1",
"16 1 22",
"000 100 000",
"0 3 2",
"16 1 42",
"1 3 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:
* Question 1: Are you subscribing to Newspaper X?... |
p03283 AtCoder Beginner Contest 106 - AtCoder Express 2_20617 | In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i). Takahashi the king is interested in the following Q matters:
* The ... | n,m,q=map(int,input().split())
a=[[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
x,y=map(int,input().split())
a[x-1][y-1]+=1
for j in range(n):
for k in range(1,n):
a[j][k]=a[j][k]+a[j][k-1]
for l in range(q):
ans=0
L,R=map(int,input().split())
for g in range(L-1,R):
ans+=a[g][... | {
"input": [
"10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10",
"2 3 1\n1 1\n1 2\n2 2\n1 2",
"10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10",
"10 3 2\n1 5\n2 8\n7 10\n1 7\n3 3",
"10 3 2\n1 10\n2 8\n7 10\n1 7\n3 10",
"10 10 10\n1 6\n2 9\n4 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses M trains, and the tra... |
p03438 AtCoder Petrozavodsk Contest 001 - Two Arrays_20621 | You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.
Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two ac... | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=sum(b)-sum(a)
y=0
for i in range(n):
if a[i]<b[i]:
y+=-((a[i]-b[i])//2)
print("No" if x<y else "Yes") | {
"input": [
"5\n3 1 4 1 5\n2 7 1 8 2",
"5\n2 7 1 8 2\n3 1 4 1 5",
"3\n1 2 3\n5 2 2",
"5\n3 1 6 1 5\n2 7 1 8 2",
"3\n1 2 2\n5 2 2",
"5\n2 8 1 8 2\n3 1 4 1 5",
"5\n3 1 7 1 5\n2 7 1 8 2",
"5\n2 8 1 8 2\n5 1 4 1 5",
"3\n1 2 2\n4 2 2",
"5\n3 1 8 1 5\n2 7 1 8 2",
"5\n2 8 1 8 2\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b... |
p03597 AtCoder Beginner Contest 074 - Bichrome Cells_20625 | We have an N \times N square grid.
We will paint each square in the grid either black or white.
If we paint exactly A squares white, how many squares will be painted black?
Constraints
* 1 \leq N \leq 100
* 0 \leq A \leq N^2
Inputs
Input is given from Standard Input in the following format:
N
A
Outputs
Print... | N = int(input()) ** 2
A = int(input())
print(str(N - A)) | {
"input": [
"3\n4",
"19\n100",
"10\n0",
"3\n2",
"19\n110",
"10\n-1",
"3\n3",
"10\n1",
"3\n0",
"10\n2",
"3\n1",
"10\n-2",
"3\n6",
"10\n3",
"3\n5",
"10\n-4",
"3\n-1",
"10\n-8",
"3\n7",
"10\n-13",
"3\n-2",
"10\n-5",
"3\n-3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have an N \times N square grid.
We will paint each square in the grid either black or white.
If we paint exactly A squares white, how many squares will be painted black?
Constra... |
p00021 Parallelism_20631 | There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the fir... | num=int(input())
for i in range (num):
info=list(map(float,input().split()))
info=list(map(lambda x:int(x*10**6),info))
if info[2]==info[0]:
if info[6]==info[4]:
print("YES")
else:
print("NO")
elif info[6]==info[4]:
if info[2]==info[0]:
print("... | {
"input": [
"2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0",
"2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.0 5.0 7.0 9.0",
"2\n0.943552035027174 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.541356008746918 5.95543610948743 7.0 9.233114893271... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those ... |
p00152 Bowling_20635 | I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 ... | while 1:
m = int(input())
if m == 0:
break
result = []
for _ in range(m):
datas = list(map(int, input().split()))
student = datas.pop(0)
score = 0
frame = 1
while 1:
if frame == 10:
while datas != []:
score... | {
"input": [
"3\n1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0\n1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9\n1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n4\n3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10\n3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1\n3335 10 10 10 10 10 10 10 10 10 10 10 10\n3340 8 2 7 3 6 4 8 2 8 2 9 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order ... |
p00473 Dividing Snacks_20640 | problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy e... |
n = int(input())
dp = [float('inf')]*(n+1)
dp[0] = 0
cost = [int(input()) for _ in range(n-1)]
for i in range(1,n):
for j in range(i):
if dp[i-j]+cost[i-1] < dp[j]: dp[j] = dp[i-j]+cost[i-1]# = min(dp[j],dp[i-j]+cost[i-1])
if dp[j]+cost[i-1] < dp[i-j]: dp[i-j] = dp[j]+cost[i-1]# = min(dp[i-j],dp[j]... | {
"input": [
"6\n1\n8\n12\n6\n2",
"6\n1\n4\n12\n6\n2",
"6\n1\n7\n12\n6\n2",
"6\n1\n4\n3\n5\n3",
"6\n1\n0\n5\n4\n1",
"6\n0\n0\n5\n0\n1",
"6\n0\n7\n11\n5\n3",
"6\n1\n0\n5\n4\n2",
"6\n0\n0\n5\n-1\n1",
"6\n1\n14\n11\n3\n2",
"6\n2\n8\n17\n6\n2",
"6\n-1\n0\n14\n-1\n6",
"6... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total... |
p00665 Everything Starts With Your Vote_20643 | There is the word heuristics. It's a relatively simple approach that usually works, although there is no guarantee that it will work. The world is full of heuristics because it is simple and powerful.
Some examples of heuristics include: In an anime program, the popularity of a character is proportional to the total a... | import sys
input = sys.stdin.readline
while True:
n, m, k, l = map(int, input().split())
if n == 0:
break
ranking = []
for _ in range(n):
name, x = input().split()
x = int(x)
ranking.append([x, name])
ranking.sort(key=lambda x:(-x[0], x[1]))
favs = {input().strip() for _ in range(m)}
fa... | {
"input": [
"4 1 3 4\nyskwcnt 16\nakzakr 7\ntsnukk 12\nfnmyi 13\nakzakr\n4 1 3 5\nakzakr 7\ntsnukk 12\nfnmyi 13\nyskwcnt 16\nakzakr\n4 2 2 1\nakzakr 4\ntsnukk 6\nyskwcnt 6\nfnmyi 12\nakzakr\nfnmyi\n5 2 3 28\nknmmdk 6\nskrkyk 14\ntmemm 14\nakmhmr 15\nmksyk 25\nknmmdk\nskrkyk\n5 2 3 11\ntmemm 12\nskrkyk 18\nknmmdk... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is the word heuristics. It's a relatively simple approach that usually works, although there is no guarantee that it will work. The world is full of heuristics because it is sim... |
p00939 Bringing Order to Disorder_20648 | Example
Input
20
Output
4 | def solve():
D = input()
N = len(D)
*DI, = map(int, D)
su = sum(DI)
pd = 1
for d in D:
pd *= int(d) + 1
memo = [{} for i in range(N)]
def dfs0(i, s, p):
key = (s, p)
if i == N:
return s > 0 or (s == 0 and p < pd)
if key in memo[i]:
... | {
"input": [
"20",
"35",
"13",
"12",
"1",
"0",
"33",
"55",
"18",
"4",
"2",
"21",
"50",
"15",
"3",
"34",
"31",
"5",
"-8",
"6",
"19",
"7",
"36",
"17",
"-15",
"16",
"26",
"-9",
"32",
"22",
"27",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
20
Output
4
### Input:
20
### Output:
4
### Input:
35
### Output:
42
### Code:
def solve():
D = input()
N = len(D)
*DI, = map(int, D)
su = sum(D... |
p01072 Plants_20651 | Problem
Gaccho owns a field separated by W horizontal x H vertical squares. The cell in the x-th column and the y-th row is called the cell (x, y). Only one plant with a height of 0 cm is planted on the land of some trout, and nothing is planted on the land of other trout.
Gaccho sprinkles fertilizer on the field at ... | #!/usr/bin/env python3
import itertools
import math
def main():
w, h, t = map(int, input().split())
p = int(input())
fert = []
for _ in range(p):
x, y, _ = map(int, input().split())
fert.append((y, x))
stage = [list(map(int, input().split())) for _ in range(h)]
for r, c in ite... | {
"input": [
"2 3 4\n2\n0 0 0\n1 1 3\n1 0\n0 0\n0 0",
"3 8 6\n6\n0 4 3\n2 5 3\n0 2 3\n2 2 5\n1 1 3\n2 2 1\n1 1 1\n1 1 1\n1 1 1\n1 0 1\n0 1 1\n1 1 0\n1 0 1\n0 1 0",
"8 3 3\n7\n0 1 1\n5 1 0\n4 0 2\n3 2 0\n3 1 1\n3 0 1\n5 1 1\n1 0 1 1 0 0 1 0\n0 0 1 1 0 1 0 1\n0 1 0 0 0 1 0 1",
"3 3 3\n5\n2 0 0\n0 1 0\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Gaccho owns a field separated by W horizontal x H vertical squares. The cell in the x-th column and the y-th row is called the cell (x, y). Only one plant with a height of 0 ... |
p01680 Everlasting -One-_20658 | Problem Statement
"Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play.
In this game, a character is characterized by attributes. There are $N$ attributes in this game, numbered $1$ through $N$. Each attribute takes... | from collections import deque
MOD = 10**9 + 7
while 1:
N, M = map(int, input().split())
if N == M == 0:
break
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
que = deque()
used = [0]*N
r = 0;... | {
"input": [
"3 2\n1 2\n2 3\n5 0\n100000 0\n0 0",
"3 2\n1 2\n2 3\n2 0\n100000 0\n0 0",
"3 2\n1 2\n2 3\n3 0\n100000 0\n0 0",
"5 2\n1 2\n2 3\n5 0\n100000 0\n0 0",
"3 2\n1 2\n2 3\n4 0\n100000 0\n0 0",
"5 2\n1 2\n2 3\n2 0\n100000 0\n0 0",
"5 2\n1 2\n2 1\n2 0\n100000 0\n0 0",
"5 2\n1 2\n2 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem Statement
"Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play.
In thi... |
p01824 Surface Area of Cubes_20661 | Example
Input
2 2 2 1
0 0 0
Output
24 | 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**10
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": [
"2 2 2 1\n0 0 0",
"2 2 2 0\n0 0 0",
"2 1 2 0\n-1 -1 0",
"2 0 2 0\n-1 0 0",
"4 2 2 0\n0 0 1",
"3 1 2 0\n-1 0 -1",
"1 2 1 0\n-2 -1 0",
"2 2 3 0\n-1 -1 -1",
"1 1 4 0\n0 1 -1",
"3 2 0 0\n-1 -1 -1",
"1 0 1 0\n0 1 -1",
"1 -1 1 0\n0 1 -1",
"1 0 0 0\n0 0 -1",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
2 2 2 1
0 0 0
Output
24
### Input:
2 2 2 1
0 0 0
### Output:
24
### Input:
2 2 2 0
0 0 0
### Output:
24
### Code:
import math,string,itertools,fractions,heapq,c... |
p02246 15 Puzzle_20666 | The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space.
In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below.
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
You can move a piece toward the empty space a... | import heapq
distance = (
(0,1,2,3,1,2,3,4,2,3,4,5,3,4,5,6),
(1,0,1,2,2,1,2,3,3,2,3,4,4,3,4,5),
(2,1,0,1,3,2,1,2,4,3,2,3,5,4,3,4),
(3,2,1,0,4,3,2,1,5,4,3,2,6,5,4,3),
(1,2,3,4,0,1,2,3,1,2,3,4,2,3,4,5),
(2,1,2,3,1,0,1,2,2,1,2,3,3,2,3,4),
... | {
"input": [
"1 2 3 4\n6 7 8 0\n5 10 11 12\n9 13 14 15",
"0 2 3 4\n6 7 8 0\n5 10 11 12\n9 13 14 15",
"0 4 3 0\n6 7 8 0\n5 10 11 12\n9 13 14 15",
"0 4 3 0\n6 7 8 0\n5 10 11 12\n9 13 14 0",
"0 2 3 8\n6 7 0 0\n5 10 11 12\n9 13 14 15",
"0 2 3 0\n6 7 4 0\n5 10 11 12\n9 13 14 15",
"0 0 3 1\n6 7 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space.
In this problem, the space is represented by 0 and pieces are rep... |
p02392 Range_20670 | Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
Constraints
* 0 ≤ a, b, c ≤ 100
Input
Three integers a, b and c separated by a single space are given in a line.
Output
Print "Yes" or "No" in a line.
Examples
Input
1 3 8
Output
Yes
Input
3 8 1
Output... | a,b,c = map(int,(input().split()))
if(a < b and b < c):
print("Yes")
else:
print("No")
| {
"input": [
"1 3 8",
"3 8 1",
"1 6 8",
"3 7 1",
"1 6 9",
"3 7 2",
"1 9 9",
"3 7 3",
"1 9 2",
"2 7 3",
"1 6 2",
"3 9 3",
"0 6 2",
"3 8 3",
"-1 6 2",
"5 8 3",
"-1 0 2",
"5 13 3",
"-1 -1 2",
"5 13 5",
"-1 -1 1",
"1 3 0",
"3 8 0"... | 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 three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
Constraints
* 0 ≤ a, b, c ≤ 100
Input
Three integers a, b and c separated by ... |
1015_F. Bracket Substring_20680 | You are given a bracket sequence s (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of... | def add(a,b):
if a+b>=mod:
return (a+b)%mod
return a+b
n=int(input())*2
s=input()
d=[[0,0] for i in range(len(s)+1)]
aux=''
for i in range(len(s)):
if s[i]=='(':
d[i][1]=i+1
x=aux+')'
for j in range(1,i+2):
if x[j::] ==s[0:len(x)-j]:
d[i][0]=len(x[... | {
"input": [
"2\n(((\n",
"3\n(()\n",
"5\n()))()\n",
"100\n((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((\n",
"9\n(\n",
"100\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 bracket sequence s (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.
A regular bracket sequence is a bracket seq... |
1062_A. A Prank_20686 | JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a_1, a_2, ..., a_n of integers, such that 1 ≤ a_1 < a_2 < … < a_n ≤ 10^3, and then went to the bathroom.
JATC decided to prank his friend by erasing some consecutive elements in the array. Since he... | n = int(input())
l = [*map(int, input().split())]
res = i = 0
while i < n:
j = i + 1
while j < n and l[j] - l[j - 1] == 1:
j += 1
res = max(res, j - i - 2 + int(l[i] == 1) + int(l[j - 1] == 1000))
# print(res, i, j)
i = j
print(min(res, n - 1)) | {
"input": [
"3\n998 999 1000\n",
"5\n1 2 3 4 5\n",
"6\n1 3 4 5 6 9\n",
"95\n34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 688 689 690 691 692 693 694 695 696... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a_1, a_2, ..., a_n of integers, such that 1 ≤ a_1 < a_2 < … <... |
1103_B. Game with modulo_20691 | This is an interactive problem.
Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers (x, y). Petya will answer him:
* "x", if (x mod a) ≥ (y mod a). ... | import sys
def ask(x, y):
print("?", x, y)
return input() == "y"
while input() == "start":
if not ask(0, 1):
print("! 1")
continue
d = 1
while ask(d, d * 2):
d *= 2
r = d
l = d // 2
while l + 1 < r:
m = (l + r) // 2
if ask(m, m * 2):
... | {
"input": [
"start\nx\nx\nstart\nx\nx\ny\nstart\nx\nx\ny\ny\nend\n",
"100\n103\n130\n138\n126\n157\n164\n185\n120\n109\n137\n123\n147\n124\n178\n183\n155\n146\n169\n156\n153\n196\n152\n145\n110\n184\n168\n170\n177\n190\n128\n108\n182\n102\n101\n159\n150\n117\n106\n187\n194\n167\n151\n171\n195\n127\n115\n192\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem.
Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the fo... |
1131_B. Draw!_20695 | You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is «x:y», then after the goal it will change to "x+1:y" or "x:y+1". What is the l... | n=int(input())
arr= []
arr.append((0,0))
ans = 1
for _ in range(n):
a,b=map(int,input().split())
arr.append((a,b))
for i in range(1,n+1):
preva = arr[i-1][0]
prevb = arr[i-1][1]
cura = arr[i][0]
curb = arr[i][1]
if preva == cura and prevb==curb:
pass
elif preva==prevb:
an... | {
"input": [
"3\n0 0\n0 0\n0 0\n",
"1\n5 4\n",
"3\n2 0\n3 1\n3 4\n",
"6\n0 0\n0 1\n1 1\n8 7\n8 8\n9 9\n",
"1\n1000000000 0\n",
"10\n0 1\n3 2\n3 3\n3 4\n3 4\n4 4\n6 5\n7 7\n8 7\n8 8\n",
"7\n0 1\n1 1\n1 2\n1 2\n9 9\n9 9\n9 9\n",
"9\n1 0\n4 2\n4 4\n4 5\n4 5\n7 6\n7 7\n9 9\n9 9\n",
"1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the scor... |
1151_D. Stas and the Queue at the Buffet_20699 | During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is on position i. Each student i is characterized by two numbers — a_i and b_i. Dissatisfaction of the person i equals the product of a_i b... | # Why do we fall ? So we can learn to pick ourselves up.
t = int(input())
ss = []
for _ in range(0,t):
a,b = map(int,input().split())
ss.append([b-a,a,b])
ss = sorted(ss)
s = 0
for i in range(1,t+1):
s += ss[i-1][1]*(i-1)+ss[i-1][2]*(t-i)
print(s) | {
"input": [
"10\n5 10\n12 4\n31 45\n20 55\n30 17\n29 30\n41 32\n7 1\n5 5\n3 15\n",
"3\n4 2\n2 3\n6 1\n",
"4\n2 4\n3 3\n7 1\n2 3\n",
"1\n55 60\n",
"10\n36 3\n33 39\n17 11\n31 33\n50 15\n50 50\n18 22\n43 43\n4 12\n29 17\n",
"30\n61 23\n30 93\n4 18\n34 97\n63 77\n45 95\n51 13\n41 8\n86 19\n38 24... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is... |
1173_C. Nauuo and Cards_20703 | Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n... | n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=[0]
mini=n+1
for i in range(0,len(arr2)):
if arr2[i]<mini and arr2[i]!=0:
mini=arr2[i]
if mini==n+1:
print(len(arr1))
exit()
q=n+1
a=0
b=0
m=0
for i in range(0,len(arr2)):
if mini==arr2[i]:
q=int... | {
"input": [
"3\n0 2 0\n1 0 3\n",
"11\n0 0 0 5 0 0 0 4 0 0 11\n9 2 6 0 8 1 7 0 3 0 10\n",
"3\n0 2 0\n3 0 1\n",
"3\n0 0 0\n2 3 1\n",
"12\n0 0 1 0 3 0 0 4 0 0 0 2\n7 0 9 8 6 12 0 5 11 10 0 0\n",
"5\n0 0 0 0 0\n1 2 3 5 4\n",
"5\n0 0 3 0 0\n1 2 0 4 5\n",
"19\n0 0 0 0 0 0 0 0 0 18 17 16 15 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they wer... |
122_C. Lucky Sum_20710 | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let next(x) be the minimum lucky number which is larger than or equals x. Petya is interested what i... | li=set()
def addi(n):
if n>10**10+1:
return
li.add(n)
addi(n*10+4)
addi(n*10+7)
addi(4)
addi(7)
li=list(set(li))
li.sort()
#print(len(li))
l,r=map(int,input().split())
ans=0
for x in li:
#print(x)
if x>=r:
#print("l",l)
ans+=x*(r-l+1)
#print("ans",ans)
br... | {
"input": [
"7 7\n",
"2 7\n",
"369 852\n",
"3 4\n",
"77 77\n",
"77777440 77777444\n",
"854444 985555\n",
"6 77\n",
"7 777777774\n",
"12 47\n",
"47444 1000000000\n",
"1 2\n",
"49 49\n",
"1000000000 1000000000\n",
"474 747\n",
"1 1000000\n",
"98754588... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, ... |
1251_B. Binary Palindromes_20714 | A palindrome is a string t which reads the same backward as forward (formally, t[i] = t[|t| + 1 - i] for all i ∈ [1, |t|]). Here |t| denotes the length of a string t. For example, the strings 010, 1001 and 0 are palindromes.
You have n binary strings s_1, s_2, ..., s_n (each s_i consists of zeroes and/or ones). You ca... | Q = int(input())
for q in range(Q):
n = int(input())
arr = [input() for i in range(n)]
lens = [len(i) % 2 for i in arr]
counts = [i.count('1') for i in arr]
if sum(counts) % 2 == 0:
print(n)
else:
if 1 in lens:
print(n)
else:
print(n - 1)
| {
"input": [
"4\n1\n0\n3\n1110\n100110\n010101\n2\n11111\n000001\n2\n001\n11100111\n",
"1\n3\n1\n0111101111000000110001110101\n10001111001101011000001110000101101110001111\n",
"1\n33\n10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n1\n10\n",
"1\n4\n110101\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A palindrome is a string t which reads the same backward as forward (formally, t[i] = t[|t| + 1 - i] for all i ∈ [1, |t|]). Here |t| denotes the length of a string t. For example, the... |
1294_A. Collecting Coins_20719 | Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that ... | import sys
T = int(sys.stdin.readline())
for _ in range(T):
a, b, c, n = map(int , sys.stdin.readline().split())
if not (a+b+c+n)%3 and max(a, b, c)<=(a+b+c+n)//3:
print('YES')
else:
print('NO') | {
"input": [
"5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3\n",
"1\n3 798 437 1804\n",
"1\n1 1 1 1111\n",
"1\n3 1170 437 1804\n",
"5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n001 101 101 3\n",
"1\n2 1 2 1111\n",
"5\n7 3 2 8\n100 101 102 105\n3 2 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has retur... |
1315_A. Dead Pixel_20723 | Screen resolution of Polycarp's monitor is a × b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 ≤ x < a, 0 ≤ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows — from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which ... | t=int(input())
for _ in range(t):
a,b,x,y=map(int,input().split())
print(max(max(a-1-x,x)*b,max(b-1-y,y)*a)) | {
"input": [
"6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 1 0 0\n5 10 3 9\n10 10 4 8\n",
"6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 2 0 0\n5 10 3 9\n10 10 4 8\n",
"6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 2 0 0\n4 10 3 9\n10 10 4 8\n",
"6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n4 2 0 0\n5 10 3 9\n10 10 4 8\n",
"6\n8 8 0 0\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Screen resolution of Polycarp's monitor is a × b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 ≤ x < a, 0 ≤ y < b). You can consider colum... |
1359_A. Berland Poker_20729 | The game of Berland poker is played with a deck of n cards, m of which are jokers. k players play this game (n is divisible by k).
At the beginning of the game, each player takes n/k cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he... | def main_function():
from sys import stdin
from sys import stdout
from math import ceil
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
n, m, k = map(int, input().split())
if m <= n//k:
print(f'{m}\n')
else:
print(f'{n//k... | {
"input": [
"4\n8 3 2\n4 2 4\n9 6 3\n42 0 7\n",
"1\n48 20 4\n",
"1\n49 7 7\n",
"1\n50 50 50\n",
"1\n48 10 4\n",
"4\n8 3 2\n4 2 4\n12 6 3\n42 0 7\n",
"1\n48 7 4\n",
"1\n48 3 6\n",
"4\n8 3 2\n4 3 4\n15 6 3\n7 0 9\n",
"1\n49 9 7\n",
"4\n12 3 2\n4 2 4\n9 6 3\n42 0 7\n",
"4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The game of Berland poker is played with a deck of n cards, m of which are jokers. k players play this game (n is divisible by k).
At the beginning of the game, each player takes n/k... |
1379_C. Choosing flowers_20733 | Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly n flowers.
Vladimir went to a flower shop, and he was amazed to see that there are m types of flowers being sold there, and there is unlimited supply of flowers of each type. Vladimir wants to choose flowers ... | from sys import stdin
import math
from bisect import bisect_right
input = stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split(" "))
a = []
xs = []
ans = 0
for i in range(m):
x, y = map(int, input().split(" "))
a.append((y, x))
xs.append(x)
garbage... | {
"input": [
"2\n4 3\n5 0\n1 4\n2 2\n\n5 3\n5 2\n4 2\n3 1\n",
"1\n7 7\n875211518 78149272\n372527826 28528254\n777595365 608227558\n861586350 722262664\n996903444 323312570\n299704754 233926739\n778198166 197484491\n",
"1\n7 7\n10122721 121764855\n397678435 423586551\n203091798 455230154\n500000000 409776... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly n flowers.
Vladimir went to a flower shop, and he was amazed to see tha... |
139_A. Petr and Book_20737 | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Som... | n=int(input())
l=list(map(int,input().split()))
i=0
while(n>0):
if i==7:
i=0
n -= l[i]
if n>0:
i+=1
print(i+1)
| {
"input": [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n",
"5\n1 0 1 0 1 0 1\n",
"7\n2 1 1 1 1 1 0\n",
"1000\n1 0 0 0 0 0 0\n",
"1\n0 0 0 0 0 1 0\n",
"77\n11 11 11 11 11 11 10\n",
"28\n1 2 3 4 5 6 7\n",
"509\n105 23 98 0 7 0 155\n",
"1000\n100 100 100 100 100 100 100\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages.
Petr decided to start reading it starting from the next day, that is, fr... |
1468_F. Full Turn_20744 | There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i).
At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn.
It is said... | import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buf... | {
"input": [
"3\n2\n0 0 0 1\n1 0 2 0\n3\n0 0 1 1\n1 1 0 0\n1 0 2 0\n6\n0 0 0 1\n1 0 1 2\n2 0 2 3\n3 0 3 -5\n4 0 4 -5\n5 0 5 -5\n",
"1\n5\n0 0 1 1\n2 2 10 10\n-10 -10 23 23\n-5 -5 -7 -7\n1 2 3 4\n",
"4\n2\n0 0 1 1\n5 5 6 6\n2\n0 0 -1 1\n-5 5 -6 6\n2\n0 0 1 -1\n5 -5 6 -6\n2\n0 0 -1 -1\n-5 -5 -6 -6\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i).
At the same moment of time, all persons will s... |
1492_E. Almost Fault-Tolerant Database_20747 | You are storing an integer array of length m in a database. To maintain internal integrity and protect data, the database stores n copies of this array.
Unfortunately, the recent incident may have altered the stored information in every copy in the database.
It's believed, that the incident altered at most two elemen... | def solvetestcase():
n,m = [int(e) for e in input().split(" ")]
db = []
for _ in range(n):
db.append([int(e) for e in input().split(" ")])
return solve_helper(n,m,db)
def solve_helper(n,m,db, start=True):
found_candidate = -1
max_diffs = 0
for i in range(1,n):
diffs = [j fo... | {
"input": [
"3 4\n1 10 10 100\n1 1 1 100\n10 100 1 100\n",
"10 7\n1 1 1 1 1 1 1\n1 1 1 1 1 1 2\n1 1 1 1 1 2 2\n1 1 1 1 2 2 1\n1 1 1 2 2 1 1\n1 1 2 2 1 1 1\n1 2 2 1 1 1 1\n2 2 1 1 1 1 1\n2 1 1 1 1 1 1\n1 1 1 1 1 1 1\n",
"2 5\n2 2 1 1 1\n1 1 2 2 2\n",
"4 4\n622256560 220089420 26256618 988502414\n63223... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are storing an integer array of length m in a database. To maintain internal integrity and protect data, the database stores n copies of this array.
Unfortunately, the recent inc... |
1515_F. Phoenix and Earthquake_20750 | Phoenix's homeland, the Fire Nation had n cities that were connected by m roads, but the roads were all destroyed by an earthquake. The Fire Nation wishes to repair n-1 of these roads so that all the cities are connected again.
The i-th city has a_i tons of asphalt. x tons of asphalt are used up when repairing a road... | from collections import deque
class UnionFind:
def __init__(self, n): self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]: a = self.parent[a]
while acopy != a: self.parent[acopy], acopy = a, self.parent[acopy]
return a
... | {
"input": [
"2 1 2\n0 1\n1 2\n",
"5 4 1\n0 0 0 4 0\n1 2\n2 3\n3 4\n4 5\n",
"2 1 2\n1 1\n1 2\n",
"5 6 5\n0 9 4 0 10\n1 2\n1 3\n2 3\n3 4\n1 4\n4 5\n",
"3 3 3\n2 2 2\n1 2\n2 3\n1 3\n",
"3 3 1\n0 0 1\n1 2\n2 3\n1 3\n",
"3 3 2\n1 1 1\n1 2\n2 3\n1 3\n",
"11 10 1000000\n2000001 2000001 20000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Phoenix's homeland, the Fire Nation had n cities that were connected by m roads, but the roads were all destroyed by an earthquake. The Fire Nation wishes to repair n-1 of these roads... |
1542_E1. Abnormal Permutation Pairs (easy version)_20753 | This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved.
A permutation of 1, 2, …, n is a sequence of n integers, where each integer from 1 to n appears exactly once. For example, [2,3,1,4] i... |
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
... | {
"input": [
"4 403458273\n",
"10 802030518\n",
"29 170254369\n",
"18 341796022\n",
"26 930971393\n",
"21 335521569\n",
"15 102513046\n",
"25 752887969\n",
"7 941492387\n",
"16 985629174\n",
"24 869771841\n",
"23 691688417\n",
"19 519879446\n",
"20 452405440\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved... |
16_E. Fish_20756 | n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ... | # Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10**4)
def main():
n=int(input())
prob=[]
for _ in range(n):
prob.append(list(map(float,input().split())))
dp=[-1 for _ in range... | {
"input": [
"2\n0 0.5\n0.5 0\n",
"5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0\n",
"1\n0.000\n",
"4\n0 0.5 0.5 0.5\n0.5 0 0.5 0.5\n0.5 0.5 0 0.5\n0.5 0.5 0.5 0\n",
"8\n0.000 0.147 0.783 0.224 0.220 0.651 0.453 0.209\n0.853 0.000 0.246 0.076 0.018 0.349 0.896 0.... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet,... |
190_C. STL_20760 | Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer... |
###pyrival template for fast IO
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
... | {
"input": [
"3\npair pair int int int\n",
"1\npair int\n",
"9\npair int int int pair pair int int int int int pair pair pair pair pair pair int\n",
"2\npair int int\n",
"4\npair pair pair int int int int\n",
"5\npair pair pair pair int int int int int\n",
"10\npair int int int pair pair p... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs ofte... |
214_C. Game_20764 | Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.... | n = int(input())
h = [int(q) - 1 for q in input().split()]
u = [set([int(q) - 1 for q in input().split()][1:]) for i in range(n)]
t = 1e9
def g():
for i in p:
if h[i] == k and not v[i]:
return i
for k in range(3):
p = list(range(n))
d = -1
v = [q.copy() for q in u]
while p:
... | {
"input": [
"1\n1\n0\n",
"5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0\n",
"22\n2 3 2 3 3 2 1 2 3 3 1 3 1 1 2 2 3 3 1 3 2 2\n0\n1 8\n1 22\n1 12\n0\n1 14\n0\n0\n0\n2 22 14\n1 12\n0\n0\n0\n0\n0\n0\n0\n0\n1 16\n1 13\n0\n",
"30\n1 3 3 3 2 3 1 3 3 3 3 2 3 1 3 2 1 1 1 1 2 3 2 1 1 3 3 2 2 2\n0\n1 20\n0\n1 7\n2 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may pro... |
263_A. Beautiful Matrix_20770 | You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | mat = []
for x in range(0, 5):
a = list(map(int, input().split()))
mat.append(a)
for i in a:
if i == 1:
row = a.index(1)
col = mat.index(a)
print(abs(row - 2) + abs(col - 2)) | {
"input": [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n",
"0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by nu... |
287_A. IQ Test_20774 | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the p... | # Description of the problem can be found at http://codeforces.com/problemset/problem/287/A
l_l = list([input() for _ in range(4)])
dx = [ 0, 0, 1, 1]
dy = [ 0, -1, -1, 0]
for i in range(3):
for j in range(3):
t = 0
for z in range(4):
t += (-1 if l_l[i + dy[z]][j + dx[z]] == "#" e... | {
"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... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of ... |
312_A. Whose sentence is it?_20778 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | import re
n = int(input())
for i in range(n):
s = input()
rainbow = re.search(r"\Amiao\.", s)
freda = re.search(r"lala\.\Z", s)
if rainbow and not freda:
print("Rainbow's")
elif freda and not rainbow:
print("Freda's")
else:
print("OMG>.< I don't know!")
| {
"input": [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n",
"10\nmiao.Plala.\nDVm,VYslala.\nmiao.rlala.\nmiao.,KQNL.fO_.QRc\nUBLCKEUePlala.\nIouS.Alala.\nmiao.lala.\nmiao.rlala.\nEJZwRJeKlala.\nmiao.Olala.\n",
"10\nduClyjMIPsEuWmx_Ce.byVoizYlTM,sF\nuZHsNip_,Mwtg,FZjM_Lz... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his ... |
334_D. Chips_20782 | Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')... | {
"input": [
"3 0\n",
"4 3\n3 1\n3 2\n3 3\n",
"3 1\n2 2\n",
"999 0\n",
"6 5\n2 6\n5 2\n4 3\n6 6\n2 5\n",
"5 1\n3 2\n",
"6 5\n2 6\n6 5\n3 1\n2 2\n1 2\n",
"2 3\n1 2\n2 1\n2 2\n",
"5 5\n3 2\n1 4\n5 1\n4 5\n3 1\n",
"1000 0\n",
"5 1\n2 3\n",
"5 5\n2 2\n5 3\n2 3\n5 1\n4 4\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not cor... |
380_C. Sereja and Brackets_20788 | Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers li, ri (1 ≤ li ≤ ri ≤ n). The answer to the i-th query is the length of the maximum correct bracket subsequence of... | import sys
input = sys.stdin.readline
s = input()
M = int(input())
def next_pow_2(n):
p = 1
while p < n:
p <<= 1
return p
def represented_range(node, size):
l = node
r = node
while l < size:
l = 2*l
r = 2*r + 1
return l-size, r-size
class SegTree:
def __in... | {
"input": [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n",
"(()((((()(())((((((((()((((((()((((\n71\n15 29\n17 18\n5 26\n7 10\n16 31\n26 35\n2 30\n16 24\n2 24\n7 12\n15 18\n12 13\n25 30\n1 30\n12 13\n16 20\n6 35\n20 28\n18 23\n9 31\n12 35\n14 17\n8 16\n3 10\n12 33\n7 19\n2 33\n7 17\n21 27\n10 30... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is des... |
401_B. Sereja and Contests_20792 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot... | import math
x,k=map(int,input().split(" "))
given=[0 for x in range(x-1)]
for _ in range(k):
a=list(map(int,input().split(" ")))
if a[0]==2:
given[a[1]-1]=1
else:
given[a[2]-1]=1
given[a[1]-1]=1
cmax=0
for y in range(x-1):
if given[y]==0:
cmax=cmax+1
pp=0
t=0
ss=x-1
while... | {
"input": [
"10 0\n",
"3 2\n2 1\n2 2\n",
"9 3\n1 2 3\n2 8\n1 4 5\n",
"48 35\n1 17 18\n2 20\n1 7 8\n2 13\n1 1 2\n2 23\n1 25 26\n1 14 15\n2 3\n1 45 46\n1 35 36\n2 47\n1 27 28\n2 30\n1 5 6\n2 11\n2 9\n1 32 33\n2 19\n2 24\n2 16\n1 42 43\n1 21 22\n2 37\n2 34\n2 40\n2 31\n2 10\n2 44\n2 39\n2 12\n2 29\n2 38... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.