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 |
|---|---|---|---|---|---|
313_B. Ilya and Queries_17486 | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n)... |
s=input()
n=len(s)
m=int(input())
a=[0]*(n+1)
for i in range(n-1):
a[i+1]=a[i]+(s[i]==s[i+1])
ans=""
for i in range(m):
l,r=map(int,input().split())
ans+=str(a[r-1]-a[l-1])+" "
print(*ans.split(),sep="\n")
| {
"input": [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n",
"#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3\n",
"#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4\n",
".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3\n",
"#.\n1\n1 2\n",
"#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s1s2... sn (n is the length of the... |
402_C. Searching for Graph_17498 | Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:
* the graph contains exactly 2n + p edges;
* the graph doesn't contain self-loops and multiple edges;
* for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges.
A sub... | for _ in range(int(input())):
n, p = map(int, input().split())
p += 2 * n
for i in range(n):
for j in range(i + 1, n):
if p == 0:
break
print(i + 1, j + 1)
p -= 1
| {
"input": [
"1\n6 0\n",
"5\n24 1\n23 1\n22 1\n21 1\n20 1\n",
"5\n24 0\n24 0\n24 0\n24 0\n24 0\n",
"5\n24 0\n23 0\n24 1\n23 1\n22 0\n",
"5\n6 0\n5 0\n7 0\n8 0\n9 0\n",
"5\n24 0\n23 0\n22 0\n21 0\n24 1\n",
"5\n19 1\n18 1\n17 1\n16 1\n15 1\n",
"5\n10 1\n11 1\n12 1\n13 1\n14 1\n",
"1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:
* the graph contains exactly 2n + p edges;
* the graph doesn't contain self-loo... |
42_D. Strange town_17502 | Volodya has recently visited a very odd town. There are N tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) assigned to it and all prices are distinct. But the most striking thing about this town is that each city sightseeing to... | #codeforces 42d: strange town: math, constructive algorithm
def readGen(trans):
while 1:
for x in input().split():
yield(trans(x))
readint=readGen(int)
n=next(readint)
def constructRow(n):
can=[1 for i in range(1001)]
b=[0 for i in range(n+1)]
b[2]=1
b[3]=2
can[1]=0
can[2]=0
for k in range(4,n+1):
b[k... | {
"input": [
"3\n",
"17\n",
"11\n",
"18\n",
"4\n",
"13\n",
"15\n",
"14\n",
"19\n",
"14\n",
"10\n",
"5\n",
"12\n",
"13\n",
"12\n",
"7\n",
"18\n",
"15\n",
"17\n",
"10\n",
"19\n",
"16\n",
"20\n",
"20\n",
"6\n",
"9\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Volodya has recently visited a very odd town. There are N tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price ... |
452_B. 4-point polyline_17506 | You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segment... | n, m = map(int, input().split())
a = ([[0, 1], [0, m], [0, 0], [0, m - 1]], [[1, 0], [n, 0], [0, 0], [n - 1, 0]], \
[[0, 1], [n, m], [0, 0], [n, m - 1]], [[1, 0], [n, m], [0, 0], [n - 1, m]], \
[[0, 0], [n, m], [0, m], [n, 0]], [[0, 0], [n, m], [n, 0], [0, m]])
for x in max(a, key = lambda a: (len(set(map(tup... | {
"input": [
"0 10\n",
"1 1\n",
"9 3\n",
"3 2\n",
"2 4\n",
"5 3\n",
"555 1\n",
"1000 3\n",
"6 5\n",
"987 567\n",
"1000 500\n",
"3 1\n",
"10 100\n",
"2 1\n",
"955 956\n",
"1 5\n",
"4 4\n",
"3 4\n",
"6 4\n",
"20 10\n",
"1000 20\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 rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections ... |
474_F. Ant colony_17510 | Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.
In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices betwe... | from math import gcd
class SegTree:
def __init__(self, arr = None, length = None):
"""
Creates a segment tree. If arr (a list) is given, length is ignored,
and we build a segment tree with underlying array arr. If no list is
given, length (an int) must be given, and we build a segme... | {
"input": [
"5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n",
"5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n",
"5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n",
"5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n2 5\n",
"5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n4 5\n",
"5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n3 5\n",
"5\n1 3 4 4 2\n4\n1 3\n2 5\n1 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.
In order to make his dinner more interesting, Mole or... |
522_A. Reposts_17516 | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | leng = int(input())
names = ["POLYCARP", 1]
others = []
max = 1
for i in range(leng):
x, y= map(str, input().split(' reposted '))
others.append(x.upper())
others.append(y.upper())
for i in range(0, leng*2, 2):
if others[i+1] in names:
num = names[names.index(others[i+1]) + 1] + 1
names.append(others[i])
name... | {
"input": [
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n",
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted w... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. S... |
549_C. The Game Of Parity_17520 | There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities left.
The ... | n,k=[int(i) for i in input().split()]
l=[int(i) for i in input().split()]
no=0
for i in l:
no+=i%2
ne=n-no
if n==k:
if no%2:
print("Stannis")
else:
print("Daenerys")
else:
if no<=(n-k)//2:
print("Daenerys")
else:
if no%2:
if (n-k)%2 and ne<=(n-k)//2 and ne%2... | {
"input": [
"3 1\n1 2 1\n",
"6 3\n5 20 12 7 14 101\n",
"3 1\n2 2 1\n",
"2 2\n67427 727097\n",
"3 3\n767153 643472 154791\n",
"3 3\n814664 27142 437959\n",
"1 1\n107540\n",
"6 3\n346 118 330 1403 5244 480\n",
"7 4\n11 3532 99 3512 12 8 22\n",
"3 3\n349371 489962 45420\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it... |
597_C. Subsequences_17526 | For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing ... | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def update(tree,pos,diff,si):
pos += si-1
while pos:
tree[pos] += diff
pos >>= 1
def query(tree,l,r,si):
ans,l,r = 0,l+si-1,r+si-1
while l < r:
if l&1:
ans += ... | {
"input": [
"5 2\n1\n2\n3\n5\n4\n",
"10 2\n6\n10\n9\n7\n1\n2\n8\n5\n4\n3\n",
"100 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
F... |
618_E. Robot Arm_17529 | Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0) is colored blue for all segments. Thus, the blue endpoint of the i-th segm... | from cmath import rect
import sys
import math
from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y):
self.function = function
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in range(self... | {
"input": [
"5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1\n",
"1 1\n2 1 302\n",
"50 50\n1 41 261\n2 47 324\n1 41 256\n1 31 339\n2 23 116\n2 44 184\n2 32 115\n1 40 301\n2 40 303\n1 29 309\n2 49 348\n2 47 356\n1 41 263\n2 42 276\n1 45 135\n1 33 226\n2 31 166\n1 50 171\n2 47 166\n2 50 284\n2 25 324\n2 48 307\n2 41 176... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The en... |
690_B1. Recover Polygon (easy)_17536 | The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.
Heidi knows that the lair can be represented as a rectangle on a lattice, with si... | n = int(input())
aux = []
grid = []
flag = True
ans = -1
um = 0
dois = 0
quatro = 0
while(n):
n-=1
x = str(int(input()))
if(x!='0'):
aux.append(x)
for i in aux:
txt = ''
for j in i:
if(j!='0'):
txt+=j
grid.append(txt... | {
"input": [
"6\n000000\n000000\n012100\n024200\n012100\n000000\n",
"8\n00000000\n00001210\n00002420\n00002020\n00001210\n00000000\n00000000\n00000000\n",
"7\n0000000\n0000000\n0000000\n1122210\n0244420\n0122210\n0000000\n",
"7\n0000000\n0012210\n0024420\n0012210\n0000000\n0000000\n0000000\n",
"6\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know wher... |
779_D. String Game_17545 | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain ... | s = input()
t = input()
a = list(map(int, input().split()))
def ok(n):
bad = set()
for i in range(n):
bad.add(a[i] - 1)
pt = 0
ps = 0
while pt < len(t) and ps < len(s):
if ps in bad:
ps += 1
else:
if t[pt] == s[ps]:
ps += 1
... | {
"input": [
"bbbabb\nbb\n1 6 3 4 2 5\n",
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her bro... |
827_A. String Reconstruction_17550 | Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.
Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more... | from sys import stdin, stdout
sze = 10 ** 6 + 1
n = int(stdin.readline())
challengers = []
strings = []
sze = 10 ** 6 + 1
cnt = [[] for i in range(sze)]
for i in range(n):
s = stdin.readline().strip().split()
num = int(s[1])
values = list(map(int, s[2:]))
strings.append(s[0])
for j in r... | {
"input": [
"3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n",
"3\nab 1 1\naba 1 3\nab 2 3 5\n",
"1\na 1 3\n",
"18\nabacab 2 329 401\nabadabacabae 1 293\nbacab 1 2\nabacabadabacabaga 1 433\nc 1 76\nbaca 1 26\ndab 1 72\nabagabaca 1 445\nabaea 1 397\ndabac 1 280\nab 2 201 309\nca 1 396\nabacabadab 1 497\nac 1 451\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old... |
849_A. Odds and Ends_17554 | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subse... | n = int(input())
a = list(map(int,input().split()))
if n % 2 == 0 or a[0] % 2 == 0 or a[-1] % 2 == 0:
print("NO")
else:
print("YES") | {
"input": [
"4\n3 9 9 3\n",
"3\n4 3 1\n",
"5\n1 0 1 5 1\n",
"3\n1 3 5\n",
"4\n1 0 1 1\n",
"2\n10 10\n",
"5\n1 3 2 4 5\n",
"2\n1 1\n",
"4\n1 1 2 1\n",
"6\n1 2 3 5 6 7\n",
"100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to ... |
897_C. Nephren gives a riddle_17561 | What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about i... | import sys
sys.setrecursionlimit(1500)
s1 = "What are you doing at the end of the world? Are you busy? Will you save us?"
a = "What are you doing while sending \""
b = "\"? Are you busy? Will you send \""
c = "\"?"
ans = ""
def solve(n, k):
if n == 0:
if k >= len(s1):
return "."
else:... | {
"input": [
"10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n",
"3\n1 1\n1 2\n1 111111111111\n",
"5\n0 69\n1 194\n1 139\n0 47\n1 66\n",
"10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, ... |
918_D. MADMAX_17565 | As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower... | # int(input())
# [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(20000)
def go(v,w,last):
if game[v][w][last] >= 0: return(game[v][w][last])
flag = 0
move = 0
for p in edges_out[v]:
if p[1] >= last:
move = 1
if not go(w,p[0],p[1]):
fl... | {
"input": [
"5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n",
"4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n",
"100 1\n92 93 p\n",
"3 2\n1 3 l\n2 1 v\n",
"2 1\n1 2 q\n",
"8 20\n2 4 a\n1 8 a\n1 2 v\n8 4 h\n1 7 w\n5 4 h\n2 8 h\n7 4 i\n4 3 w\n6 8 l\n1 4 v\n1 3 g\n5 3 b\n1 6 a\n7 3 w\n6 4 f\n6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at gam... |
940_D. Alena And The Heater_17569 | "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:
b1 = b2 = b3... | import sys
n = int(input())
A = input().split()
A = [int(i) for i in A]
S = input()
L = -1000000000
R = 1000000000
for i in range(4, n):
if S[i - 1] == S[i - 2] == S[i - 3] == S[i - 4] == '0' and S[i] == '1':
L = max(max(A[i], A[i - 1], A[i - 2], A[i - 3], A[i - 4]) + 1, L)
elif S[i - 1] == S[i - 2] ... | {
"input": [
"5\n1 2 3 4 5\n00001\n",
"10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n",
"99\n-94 -97 -95 -99 94 98 91 95 90 -98 -92 -93 -91 -100 84 81 80 89 89 70 76 79 69 74 -80 -90 -83 -81 -80 64 60 60 60 68 56 50 55 50 57 39 47 47 48 49 37 31 34 38 34 -76 -71 -70 -76 -70 23 21 24 29 22 -62 -65 -63 -60 -6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The a... |
96_A. Football_17573 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | entrada = input()
vez = -1
total = 0
perigo = False
for i in range(len(entrada)):
aux = int(entrada[i])
if(vez == aux):
total += 1
if(total == 7):
perigo = True
else:
total = 1
vez = aux
if(perigo):
print("YES")
else:
print("NO")
| {
"input": [
"1000000001\n",
"001001\n",
"111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010\n",
"1111100111\n",
"10101011111111111111111111111100\n",
"11110110011000100111100111101101011111110100010101011011111101110110110111\n",
"10000000\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted ... |
994_A. Fingerprints_17577 | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = ''
for i in a:
if i in b:
ans = ans + str(i) + ' '
print(ans)
| {
"input": [
"4 4\n3 4 1 0\n0 1 7 9\n",
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6\n",
"8 2\n7 2 9 6 1 0 3 4\n6 3\n",
"10 2\n4 9 6 8 3 0 1 5 7 2\n0 1\n",
"8 2\n7 4 8 9 2 5 6 1\n6 4\n",
"10 1\n9 0 8 1 7 4 6 5 2 3\n0\n",
"3 6\n1 2 3\n4 5 6 1 2 3\n",
"3 7\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a seq... |
p02633 AtCoder Grand Contest 046 - Takahashikun The Strider_17591 | Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:
* Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise.
Constraints
* 1 \leq X \leq ... | from math import gcd
X=int(input())
g=gcd(X,360)
print((360)//(g)) | {
"input": [
"90",
"1",
"155",
"2",
"297",
"408",
"643",
"810",
"928",
"1780",
"33",
"70",
"4",
"1368",
"1035",
"222",
"12",
"180",
"760",
"54",
"690",
"285",
"684",
"2640",
"60",
"1080",
"107",
"77",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the follow... |
p02764 AtCoder Beginner Contest 157 - Yakiniku Optimization Problem_17595 | Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), wher... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdi... | {
"input": [
"10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n449 310 57\n-656 -204 11\n-270 76 40\n184 170 16",
"4 3\n-1 0 3\n0 0 3\n1 0 2\n1 1 40",
"10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n102 310 57\n-656 -204 11\n-270 76 40\n184... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its... |
p02899 AtCoder Beginner Contest 142 - Go to School_17599 | Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including... | n,*a= map(int,open(0).read().split())
b=[0]*n
for i in range(n):
b[a[i]-1]=i+1
print(*b) | {
"input": [
"5\n1 2 3 4 5",
"3\n2 3 1",
"8\n8 2 7 3 4 5 6 1",
"3\n1 3 2",
"5\n2 1 3 4 5",
"3\n1 2 3",
"3\n3 2 1",
"3\n2 1 3",
"3\n3 1 2",
"3\n-1 3 -2",
"8\n8 2 7 3 5 4 6 1",
"3\n-2 2 3",
"3\n-2 3 2",
"3\n-2 -1 3",
"3\n-1 -2 0",
"3\n-2 3 -1",
"3\n0 -... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different... |
p03034 AtCoder Beginner Contest 128 - Frog Jump_17603 | There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written.
You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows:
* 1. Choose... | import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_, input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().... | {
"input": [
"6\n0 10 -7 -4 -13 0",
"5\n0 2 5 1 0",
"11\n0 -4 0 -99 31 14 -15 -39 43 18 0",
"6\n0 10 -7 -4 -5 0",
"5\n0 2 5 0 0",
"11\n0 -4 0 -99 31 14 -15 -39 43 24 0",
"6\n0 2 -7 -1 -5 0",
"11\n0 -4 0 -99 31 13 -15 -39 64 24 0",
"6\n0 4 -7 -1 -3 0",
"6\n0 4 -7 -1 -1 0",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate ... |
p03175 Educational DP Contest - Independent Set_17607 | There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be pa... |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
"""
OPT[node][BLACK] = product(OPT[child[i]][WHITE])
OPT[node][WHITE] = product(OPT[child[i]][WHITE|BLACK])
"""
N = read_int()
G = [[] for _ in range(N)]
... | {
"input": [
"3\n1 2\n2 3",
"10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7",
"1",
"4\n1 2\n1 3\n1 4",
"10\n8 5\n10 8\n6 7\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7",
"10\n8 3\n10 8\n6 7\n1 5\n4 8\n2 10\n3 6\n9 2\n1 3",
"10\n8 5\n10 8\n6 7\n1 5\n4 8\n2 10\n3 6\n9 2\n2 7",
"10\n8 5\n10 8\n6 7\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white... |
p03323 AtCoder Beginner Contest 100 - Happy Birthday!_17611 | E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces, respectively,
when they found a note attached to the cake saying that "the same person should not t... | a,b = map(int,input().split())
print("Yay!"if a<=8 and b <=8 else ':(') | {
"input": [
"11 4",
"8 8",
"5 4",
"11 6",
"0 8",
"5 1",
"11 5",
"0 9",
"8 1",
"13 5",
"0 18",
"8 0",
"18 5",
"0 17",
"14 1",
"18 8",
"0 31",
"14 2",
"18 4",
"-1 31",
"10 2",
"18 1",
"-1 54",
"10 4",
"25 1",
"-2 54... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just ... |
p03477 AtCoder Beginner Contest 083 - Libra_17615 | A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and pl... | a,b,c,d = map(int, input().split())
ans = "Balanced"
if a+b > c+d: ans = "Left"
elif a+b < c+d: ans = "Right"
print(ans) | {
"input": [
"3 8 7 1",
"1 7 6 4",
"3 4 5 2",
"0 8 7 1",
"1 7 6 8",
"5 4 5 2",
"0 8 3 1",
"1 1 6 8",
"2 4 5 2",
"0 16 3 1",
"0 1 6 8",
"2 3 5 2",
"0 25 3 1",
"0 1 6 3",
"4 3 5 2",
"1 25 3 1",
"-1 1 6 3",
"4 3 8 2",
"2 25 3 1",
"-1 0 6 3",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if ... |
p03642 AtCoder Regular Contest 080 - Prime Flip_17618 | There are infinitely many cards, numbered 1, 2, 3, ... Initially, Cards x_1, x_2, ..., x_N are face up, and the others are face down.
Snuke can perform the following operation repeatedly:
* Select a prime p greater than or equal to 3. Then, select p consecutive cards and flip all of them.
Snuke's objective is to h... | import itertools
from math import sqrt
def chunk(a):
i = 0
res = []
while i < len(a):
res.append(a[i])
while i != len(a) - 1 and a[i + 1] == a[i] + 1:
i += 1
res.append(a[i] + 1)
i += 1
return res
def augment(g, src, dest):
o = [None] * len(g)
q = [(s... | {
"input": [
"2\n4 5",
"2\n1 10000000",
"9\n1 2 3 4 5 6 7 8 9",
"2\n3 5",
"2\n3 8",
"2\n-1 -1",
"2\n3 7",
"2\n3 13",
"2\n4 3",
"2\n2 5",
"2\n5 8",
"2\n3 11",
"2\n1 13",
"2\n6 3",
"2\n1 5",
"2\n7 8",
"2\n3 17",
"2\n4 6",
"2\n7 10",
"2\n3 2... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are infinitely many cards, numbered 1, 2, 3, ... Initially, Cards x_1, x_2, ..., x_N are face up, and the others are face down.
Snuke can perform the following operation repeat... |
p03799 AtCoder Regular Contest 069 - Scc Puzzle_17622 | Snuke loves puzzles.
Today, he is working on a puzzle using `S`- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below:
9b0bd546db9f28b4093d417b8f274124.png
Snuke decided to create as many `Scc` groups as possible by putting together one ... | S,C = map(int,input().split())
p = min(S,C//2)
C -= p*2
ans = p + C//4
print(ans) | {
"input": [
"12345 678901",
"1 6",
"12345 267141",
"1 4",
"12345 263982",
"5656 263982",
"0 8",
"10389 263982",
"0 12",
"10389 232248",
"0 20",
"10389 85698",
"0 28",
"10389 18349",
"10389 5425",
"10389 728",
"10389 750",
"3 11",
"5394 668",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke loves puzzles.
Today, he is working on a puzzle using `S`- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in t... |
p03968 AtCoder Regular Contest 062 - Building Cubes with AtCoDeer_17625 | AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the 1000 colors, which are represented by the integers 0 between 999. The top-left, top-right, bottom-right and bottom-left ... | from collections import defaultdict
N, = map(int, input().split())
def normal(xs):
return tuple(min((xs[j:] + xs[:j] for j in range(1, 5))))
dd = defaultdict(int)
cc = dict()
norm = dict()
ss = []
for _ in range(N):
xs = list(map(int, input().split()))
cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]
... | {
"input": [
"6\n0 1 2 3\n0 4 6 1\n1 6 7 2\n2 7 5 3\n6 4 5 7\n4 0 3 5",
"6\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"8\n0 0 0 0\n0 0 1 1\n0 1 0 1\n0 1 1 0\n1 0 0 1\n1 0 1 0\n1 1 0 0\n1 1 1 1",
"6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n2 7 5 3\n6 4 5 7\n4 0 3 5",
"8\n0 0 1 0\n0 0 1 1\n0 1 0 1\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is paint... |
p00057 The Number of Area_17629 | If you draw a few infinitely long straight lines on an infinitely wide plane, this plane will be divided into several areas. For example, if you draw a straight line, the plane will be divided into two areas. Even if you draw the same number of straight lines, the number of areas obtained will differ depending on how y... | while 1:
try:
n = int(input())
except:break
ans = (0.5 * n * n) + (0.5 * n) + 1
print(round(ans))
| {
"input": [
"1\n3",
"1\n5",
"1\n0",
"1\n1",
"1\n2",
"1\n4",
"1\n8",
"1\n13",
"1\n6",
"1\n25",
"1\n9",
"1\n45",
"1\n14",
"1\n24",
"1\n27",
"1\n12",
"1\n10",
"1\n11",
"1\n19",
"1\n17",
"1\n22",
"1\n48",
"1\n68",
"1\n32",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
If you draw a few infinitely long straight lines on an infinitely wide plane, this plane will be divided into several areas. For example, if you draw a straight line, the plane will b... |
p00188 Search_17633 | "Search" is an operation to obtain the desired information from a large amount of information. Familiar examples include "finding your own exam number from a large number of exam numbers" when announcing your success, or "finding Taro Aizu's phone number" from your phone book. This search operation is also widely used ... | while True:
n = int(input())
if n == 0: break
a = [int(input()) for _ in range(n)]
k = int(input())
l, r, c = 0, n-1, 0
while l <= r:
c += 1
m = (l+r) >> 1
if k == a[m]:
break
elif k < a[m]:
r = m-1
else:
l = m+1
pri... | {
"input": [
"7\n11\n15\n23\n36\n51\n61\n86\n51\n4\n1\n2\n3\n5\n4\n0",
"7\n11\n15\n0\n36\n51\n61\n86\n51\n4\n1\n2\n3\n5\n4\n0",
"7\n11\n15\n0\n42\n51\n61\n86\n51\n4\n1\n2\n4\n5\n4\n0",
"7\n11\n8\n-2\n53\n51\n17\n109\n42\n4\n1\n0\n3\n1\n0\n0",
"7\n11\n15\n0\n42\n51\n61\n86\n61\n4\n1\n2\n4\n5\n4\n0"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
"Search" is an operation to obtain the desired information from a large amount of information. Familiar examples include "finding your own exam number from a large number of exam numb... |
p00343 Sevens_17636 | There is "7 rows" in the game using playing cards. Here we consider a game that simplifies it. Arrange 7 using 13 cards with numbers 1 to 13 written on each. In the match, the game progresses as follows with only two players.
1. Place 7 cards in the "field".
2. Six remaining cards will be randomly distributed to the t... | n = int(input())
for i in range(n):
F = set(map(int, input().split()))
fl = min(F); fr = max(F)
G = {i for i in range(1, 14)} - F - {7}
gl = min(G); gr = max(G)
memo = {}
def dfs(s, t, u):
if (s, t, u) in memo:
return memo[s, t, u]
T = [G, F][u]
res = 0
... | {
"input": [
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 2 3 6 9 11",
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 3 3 6 9 11",
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 3 5 10 5\n1 3 3 6 9 11",
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 6 8\n1 2 3 5 10 11\n1 3 3 6 9 11"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is "7 rows" in the game using playing cards. Here we consider a game that simplifies it. Arrange 7 using 13 cards with numbers 1 to 13 written on each. In the match, the game pr... |
p00539 JOI Park_17640 | JOI Park
In preparation for the Olympic Games in IOI in 20XX, the JOI Park in IOI will be developed. There are N squares in JOI Park, and the squares are numbered from 1 to N. There are M roads connecting the squares, and the roads are numbered from 1 to M. The road i (1 ≤ i ≤ M) connects the square Ai and the square ... | from heapq import heappush, heappop
INF = 10 ** 20
n, m, c = map(int, input().split())
edges = [[] for _ in range(n)]
edges_dict = {}
d_cost = 0
for _ in range(m):
a, b, d = map(int, input().split())
a -= 1
b -= 1
edges[a].append((b, d))
edges[b].append((a, d))
edges_dict[(a, b)] = d
d_cost += d
dist = ... | {
"input": [
"5 5 2\n2 3 1\n3 1 2\n2 4 3\n1 2 4\n2 5 5",
"5 5 2\n2 3 1\n3 1 2\n1 4 3\n1 2 4\n2 5 5",
"5 5 2\n2 3 1\n3 1 4\n1 4 3\n1 2 4\n2 5 5",
"5 0 2\n2 3 1\n3 1 4\n1 2 2\n1 2 4\n2 5 5",
"5 5 2\n2 3 1\n3 1 4\n1 4 3\n1 2 4\n1 5 5",
"5 5 2\n2 3 1\n3 1 2\n2 4 3\n1 2 4\n2 5 7",
"5 2 2\n2 3 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
JOI Park
In preparation for the Olympic Games in IOI in 20XX, the JOI Park in IOI will be developed. There are N squares in JOI Park, and the squares are numbered from 1 to N. There ... |
p00701 Pile Up!_17643 | There are cubes of the same size and a simple robot named Masato. Initially, all cubes are on the floor. Masato can be instructed to pick up a cube and put it on another cube, to make piles of cubes. Each instruction is of the form `pick up cube A and put it on cube B (or on the floor).'
When he is to pick up a cube, ... | while(1):
m=int(input())
if m==0: break
#root, before, next, top, rank
A=[[i for i in range(m+1)],[0 for i in range(m+1)],[0 for i in range(m+1)],[i for i in range(m+1)],[1 for i in range(m+1)]]
while(1):
I,J=map(int, input().split())
if I==0: break
if I==J:
... | {
"input": [
"3\n1 3\n2 0\n0 0\n4\n4 1\n3 1\n1 2\n0 0\n5\n2 1\n3 1\n4 1\n3 2\n1 1\n0 0\n0",
"3\n1 3\n2 0\n0 0\n4\n4 1\n3 1\n1 0\n0 0\n5\n2 1\n3 1\n4 1\n3 2\n1 1\n0 0\n0",
"3\n1 3\n2 0\n0 0\n4\n4 1\n3 1\n1 2\n0 0\n5\n2 2\n3 1\n4 1\n3 2\n1 1\n0 0\n0",
"3\n1 3\n2 0\n0 0\n4\n1 1\n3 1\n1 2\n0 0\n5\n2 1\n3 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are cubes of the same size and a simple robot named Masato. Initially, all cubes are on the floor. Masato can be instructed to pick up a cube and put it on another cube, to make... |
p00842 Network Mess_17646 | Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate how computers and switches are connected. Since he is a programmer, he is very reluctant to move throughout the office and examine c... | def solve():
from sys import stdin
f_i = stdin
# function to update distance between switch and computer
def dfs(sw_id, prev, dist):
switch[sw_id].append(dist)
for next_sw in adj[sw_id]:
if next_sw != prev:
dfs(next_sw, sw_id, dist + 1)
while Tru... | {
"input": [
"4\n 0 2 2 2\n 2 0 2 2\n 2 2 0 2\n 2 2 2 0\n4\n 0 2 4 4\n 2 0 4 4\n 4 4 0 2\n 4 4 2 0\n2\n 0 12\n 12 0\n0",
"4\n0 2 2 2\n2 0 2 2\n2 2 0 2\n2 2 2 0\n4\n0 2 4 4\n2 0 4 4\n4 4 0 2\n4 4 2 0\n2\n0 12\n12 0\n0",
"4\n 0 2 2 2\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illust... |
p01106 Folding a Ribbon_17652 | Folding a Ribbon
Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it ove... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def rdp_trace(n: int, i: int) -> list:
def loop(n: int, i: int) -> list:
if n == 1:
return []
if i <= n // 2:
rval = loop(n // 2, (n // 2) - i + 1)
rval.append(i)
return rval
else:
rva... | {
"input": [
"3 3 2\n12 578 2214\n59 471605241352156968 431565444592236940\n0 0 0",
"3 3 2\n12 578 1435\n59 471605241352156968 431565444592236940\n0 0 0",
"3 3 2\n12 578 1954\n59 471605241352156968 431565444592236940\n0 0 0",
"3 3 2\n12 785 2214\n59 471605241352156968 431565444592236940\n0 0 0",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Folding a Ribbon
Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ... |
p01721 Wave Attack_17659 | The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end.
If you select a corner of the room and take the coordinate system so that the width direction is the x-axis and the depth direction is the ... | def solve():
w, h, v, t, x, y, p, q = map(int, input().split())
def count(a, b):
res = 0
C = v*t
ky = 0
while 1:
B = b + 2*h*ky
D = C**2 - (B - y)**2
if D < 0:
break
SQ = D**.5 + 1e-7
k0 = int((x - a - SQ... | {
"input": [
"2 3 1000 1000 1 1 1 2",
"10 10 1 11 3 3 7 7",
"10 10 1 10 3 3 7 7",
"2 3 1001 1000 1 1 1 2",
"16 10 1 10 3 3 7 7",
"2 3 1001 1000 1 2 1 2",
"16 10 1 10 3 3 2 7",
"2 3 1000 1000 1 2 1 2",
"2 3 1000 1000 1 2 0 2",
"2 3 1000 1010 1 2 0 2",
"16 10 0 7 3 3 2 8",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end.
If... |
p01859 Match Peas War_17663 | B: Nakajima, let's do that! --Match Peas War -
problem
Nakajima "Uhh ..."
Isono "Nakajima, are you okay?"
Nakajima "... I feel like I was having an unpleasant dream."
Isono "What kind of dream do you have?"
Nakajima "Dream to play infinitely"
Isono "I don't know what it means. Well, Nakajima, let's do that!"
Na... | li, ri = map(int, input().split())
ln, rn = map(int, input().split())
ISONO = True
NAKAJIMA = False
def search(li, ri, ln, rn, turn):
if li == None and ri == None:
return False
if ln == None and rn == None:
return True
if turn == ISONO:
ret = False
if li and ln:
ret = ret or search(li, ri,... | {
"input": [
"3 2\n2 2",
"3 2\n2 3",
"5 1\n2 3",
"3 2\n1 2",
"3 2\n1 3",
"4 2\n1 3",
"2 2\n2 2",
"5 2\n2 3",
"3 1\n1 2",
"3 3\n1 3",
"4 3\n1 3",
"2 2\n4 2",
"3 1\n1 0",
"3 2\n1 5",
"2 2\n4 1",
"2 1\n2 3",
"3 2\n2 5",
"0 2\n4 2",
"2 0\n2 3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
B: Nakajima, let's do that! --Match Peas War -
problem
Nakajima "Uhh ..."
Isono "Nakajima, are you okay?"
Nakajima "... I feel like I was having an unpleasant dream."
Isono "What... |
p02140 Gridgedge_17667 | Problem
There is a grid of $ R \ times C $ squares with $ (0, 0) $ in the upper left and $ (R-1, C-1) $ in the lower right. When you are in a square ($ e $, $ f $), from there $ (e + 1, f) $, $ (e-1, f) $, $ (e, f + 1) $, $ (e) , f-1) $, $ (e, 0) $, $ (e, C-1) $, $ (0, f) $, $ (R-1, f) $ can be moved at a cost of $ 1 ... | from collections import deque
R,C,ay,ax,by,bx = map(int,input().split())
MOD = INF = 10**9+7
dists = [[INF]*C for i in range(R)]
dists[ay][ax] = 0
ptns = [[0]*C for i in range(R)]
ptns[ay][ax] = 1
q = deque([(0,ax,ay)])
dxs = [1,0,-1,0]
dys = [0,1,0,-1]
ans_d = None
while q:
d,x,y = q.popleft()
if ans_d is not... | {
"input": [
"5 5 0 0 4 4",
"1 1 0 0 0 0",
"1 10 0 0 0 9",
"2 2 0 0 1 1",
"421 435 196 169 388 9",
"2 2 0 0 0 1",
"421 435 196 169 388 5",
"1 2 0 0 0 0",
"421 435 196 91 388 9",
"5 6 0 0 4 4",
"1 10 0 1 0 9",
"421 435 196 169 388 12",
"421 435 196 169 388 10",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There is a grid of $ R \ times C $ squares with $ (0, 0) $ in the upper left and $ (R-1, C-1) $ in the lower right. When you are in a square ($ e $, $ f $), from there $ (e +... |
p02281 Tree Walk_17670 | Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either
* contains no nodes, or
* is composed of three disjoint sets of nodes:
- a root node.
- a binary tree called its left subtree.
- a binary tree called its right subtree.
Your task is to write a program ... | def preorder(tree, now):
if now == -1:
return []
else:
left = tree[now][0]
right = tree[now][1]
return [now] + preorder(tree, left) + preorder(tree, right)
def inorder(tree, now):
if now == -1:
return []
else:
left = tree[now][0]
right = tree[now... | {
"input": [
"9\n0 1 4\n1 2 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1",
"9\n0 1 4\n1 2 5\n2 -1 -1\n3 -1 -1\n4 3 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1",
"9\n0 2 4\n1 1 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1",
"9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either
* contains no nodes, or
* is composed of three disjoint sets of node... |
p02428 Enumeration of Subsets II_17673 | You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a ... | if __name__ == "__main__":
bit = int(input())
k, *E = map(lambda x: int(x), input().split())
m = sum(1 << e for e in E)
if (0 == m):
print(f"0:")
for d in range(1, 1 << bit):
if (d & m == m):
print(f"{d}: ", end="")
print(" ".join([str(elem) for elem in range... | {
"input": [
"4\n2 0 2",
"4\n2 1 2",
"4\n2 1 3",
"4\n0 0 2",
"4\n1 1 2",
"4\n1 0 2",
"4\n2 1 0",
"4\n1 2 0",
"4\n2 0 3",
"4\n2 2 0",
"4\n1 3 2",
"4\n2 2 3",
"4\n0 0 3",
"4\n0 0 1",
"4\n0 -1 1",
"4\n0 1 2",
"4\n1 0 3",
"4\n1 1 0",
"4\n0 -1 3",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we... |
1007_B. Pave the Parallelepiped_17683 | You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same d... | from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3., 1., 2., 2., 2., 1.] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1.
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(... | {
"input": [
"4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n",
"10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n",
"10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n",
"1\n100000 100000 100000\n",
"10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c an... |
1030_B. Vasya and Cornfield_17687 | Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n).
<image> An example of a cornfield with n = 7 and d = 2.
Vasya also knows that there are m grasshoppers near the fie... | n,d = map(int,input().split())
m = int(input())
x = []
y = []
k = 2*n-d
for i in range(m):
a = list(map(int,input().split()))
x.append(a[0])
y.append(a[1])
for i in range(m):
if x[i] >= 0 and x[i] <= n and y[i] >= 0 and y[i] <= n:
if y[i] <= d + x[i] and y[i] >= x[i] - d and y[i] >= -x[i]+d and y[i] <= -x[i... | {
"input": [
"7 2\n4\n2 4\n4 1\n6 3\n4 5\n",
"8 7\n4\n4 4\n2 8\n8 1\n6 1\n",
"2 1\n50\n1 0\n0 1\n0 1\n1 2\n0 1\n0 1\n0 1\n0 1\n1 0\n1 2\n2 1\n1 0\n1 2\n1 2\n2 1\n0 1\n0 1\n1 2\n0 1\n0 1\n1 2\n0 1\n2 1\n1 2\n0 1\n2 1\n2 1\n1 2\n1 0\n0 1\n2 1\n1 0\n2 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n0 1\n2 1\n1 0\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n -... |
1075_A. The King's Race_17692 | On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column.
The white ki... | a=int(input())
n, m=map(int, input().split())
mh=min(abs(1-n),abs(1-m))
mb=min(abs(a-n),abs(a-m))
if mh<=mb:
print("White")
else:
print("Black") | {
"input": [
"4\n2 3\n",
"5\n3 5\n",
"2\n2 2\n",
"878602530892252875\n583753601575252768 851813862933314387\n",
"982837494536444311\n471939396014493192 262488194864680421\n",
"778753534913338583\n547836868672081726 265708022656451521\n",
"100000000000000000\n50000000000000001 5000000000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of... |
1096_B. Substring Removal_17696 | You are given a string s of length n consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to calculate the number of ways to remove exactly one substring from thi... | n=int(input())
s=input()
cntl=1
cntr=1
for i in range(1,len(s)):
if(s[0]==s[i]):
cntl+=1
else:
break
for i in range(n-2,-1,-1):
if(s[n-1]==s[i]):
cntr+=1
else:
break
if(s[0]!=s[n-1]):
ans=(cntl+cntr+1)%998244353
print(ans)
else:
ans=((cntl+1)*(cntr+1))%998244353
print(ans) | {
"input": [
"7\naacdeee\n",
"2\naz\n",
"4\nabaa\n",
"23\nszsqqwareupmhkxlqwdtgbn\n",
"7\nabcdaaa\n",
"5\nabcde\n",
"24\nbxstlxalhkcaguyydabgpyts\n",
"420\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s of length n consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring ... |
1117_C. Magic Ship_17700 | You a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x_2, y_2).
You know the weather forecast — the string s of length n, consisting only of letters U, D, L and R. The letter corresponds t... | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | {
"input": [
"0 3\n0 0\n3\nUDD\n",
"0 0\n4 6\n3\nUUU\n",
"0 0\n0 1\n1\nL\n",
"0 1\n2 1\n1\nR\n",
"0 0\n0 1\n2\nLU\n",
"0 0\n1000000000 1000000000\n2\nDR\n",
"1 0\n0 0\n2\nLU\n",
"0 0\n1000000010 1000000000\n2\nDR\n",
"0 -1\n0 1\n1\nL\n",
"0 0\n1 1\n2\nLU\n",
"0 0\n1 2\n2\nL... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (... |
1143_E. Lynyrd Skynyrd_17704 | Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n.
Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the ... | # 注意array cache順序 QQ
from math import log, floor
"""
class RMQ:
'''
maximum version rmq
query: max([l, r])
'''
def __init__(self, nums):
size = floor(log(len(nums)) // log(2)) + 1
self.nums = [nums]
for i in range(1, size):
last = self.nums[-1]
... | {
"input": [
"2 4 3\n2 1\n1 1 2 2\n1 2\n2 3\n3 4\n",
"3 6 3\n2 1 3\n1 2 3 1 2 3\n1 5\n2 6\n3 5\n",
"1 1 1\n1\n1\n1 1\n",
"2 4 3\n2 1\n1 1 2 2\n1 2\n2 2\n3 4\n",
"3 6 3\n2 1 3\n1 2 3 1 2 3\n1 6\n2 6\n3 5\n",
"2 4 3\n2 1\n1 1 2 2\n1 2\n2 4\n3 4\n",
"2 4 3\n2 1\n1 2 2 2\n1 2\n2 4\n3 4\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n.
Lynyrd and... |
1163_D. Mysterious Code_17708 | During a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string c consisting of lowercase English characters and asterisks ("*"), where each of the asterisks denotes an unreadable character. Excited wi... | import sys
from array import array # noqa: F401
from typing import List, Tuple, TypeVar, Generic, Sequence, Union # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def build_next_table(s):
s = '*' + s + '*'
n = len(s) - 1
kmp = [0] * (n + 1)
next_table = [[0] * 26 fo... | {
"input": [
"***\ncc\nz\n",
"*****\nkatie\nshiro\n",
"*a*\nbba\nb\n",
"caat\ncaat\na\n",
"kljab**abs\nab\nba\n",
"***********************************************************************************************************************************************************************\ngcoldfocap... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string ... |
1243_E. Sum Balance_17715 | Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are k boxes numbered from 1 to k. The i-th box contains n_i integer numbers. The integers can be negative. All of the integers are distinct.
Ujan is lazy, so he will do the following reordering of the numbe... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
k = int(input())
d = {}
aa = []
sa = []
for i in range(k):
ni, *a = map(int, input().split())
for ai in a:
d[ai] = i
aa.append(a)
sa.append(sum(a))
s = sum(sa)
if s%k != 0:
print("No")
exit()
s //= k
def calc_... | {
"input": [
"2\n2 -10 10\n2 0 -20\n",
"2\n2 3 -2\n2 -1 5\n",
"4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n",
"1\n1 0\n",
"2\n2 1 2\n10 0 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 589934621\n",
"3\n1 20\n2 30 40\n3 50 60 80\n",
"5\n10 -251 650 475 -114 364 -75754... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are k boxes numbered from 1 to k. The i-th box contains n_i integer nu... |
1263_D. Secret Passwords_17719 | One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of n passwords — strings, consists of small Latin letters.
Hacker went home and started preparing to... | from sys import stdin
inp = lambda: stdin.readline().strip()
n = int(inp())
def dfs(visited, graph, node):
if not visited[node]:
visited[node] = True
for neighbour in graph[node]:
dfs(visited, graph, neighbour)
adj = [set() for x in range(26)]
visited = [True]*26
for i in range(n):
... | {
"input": [
"1\ncodeforces\n",
"3\nab\nbc\nabc\n",
"4\na\nb\nab\nd\n",
"3\nac\nbde\nbc\n",
"5\nyyyyyyyyyyyyyyyyyyyyyyyyyyy\nxxxxxx\nzz\nzzzzzzzzzzz\nzzzzzzzzzz\n",
"3\nab\ncd\nda\n",
"2\nab\nad\n",
"5\nnznnnznnnnznnnnznzznnnznnznnnnnnnzzn\nljjjjlljlllllj\nduuuudududduuuuududdddduduudd... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and... |
1304_B. Longest Palindrome_17724 | Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.
Gildong lo... | n,m=map(int,input().split())
a=[input() for x in range(n)]
z=[]
p=[]
for x in range(n):
for y in range(x+1,n):
if a[x]==a[y][::-1]:
z.append((x,y))
if a[x]==a[x][::-1]:
p.append(x)
if x==n-1:
if a[x]==a[x][::-1]:
p.append(x)
ans=''
for x in z:
ans+... | {
"input": [
"4 2\noo\nox\nxo\nxx\n",
"3 5\nhello\ncodef\norces\n",
"3 3\ntab\none\nbat\n",
"9 4\nabab\nbaba\nabcd\nbcde\ncdef\ndefg\nwxyz\nzyxw\nijji\n",
"17 14\ntzmqqlttfuopox\ndlgvbiydlxmths\ndxnyijdxjuvvej\nnfxqnqtffqnojm\nrkfvitydhceoum\ndycxhtklifleqe\nldjflcylhmjxub\nurgabqqfljxnps\nshtmxld... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "no... |
1328_C. Ternary XOR_17728 | A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation ⊙ of two ternary n... | from sys import stdout, stdin
read = stdin.readline
write = stdout.write
t = int(read())
for _ in range(t):
n = int(read())
x = read()
a, b = ['1'], ['1']
a_gt_b = False
for d in x[1:-1]:
if d == '1':
if not a_gt_b:
a_gt_b = True
a.append('1')
... | {
"input": [
"4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n"
],
"output": [
"11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n"
]
} | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftm... |
1348_C. Phoenix and Distribution_17732 | Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and re... | import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for CASES in range(int(input())):
sys.stdout.write(" ".join(map(str,ans))+"\n")
'''
inf = 100000000000000000 # 1e17
mod = 998244353
for CASES in range(int(input())):
... | {
"input": [
"6\n4 2\nbaba\n5 2\nbaacb\n5 3\nbaacb\n5 3\naaaaa\n6 4\naaxxzz\n7 1\nphoenix\n",
"9\n8 2\nchefspam\n11 7\nmonkeyeight\n8 2\nvcubingx\n6 1\namazed\n4 4\nhebs\n8 1\narolakiv\n9 7\nhidavidhu\n33 33\ngosubtovcubingxheneedssubscribers\n7 4\nhiimbad\n",
"9\n8 2\nchefspam\n11 7\nmonkeyeight\n8 2\nvc... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter o... |
1369_A. FashionabLee_17736 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis a... | t= int(input())
for i in range (t):
g= int(input())
if(g%4==0):
print("YES")
else:
print("NO")
| {
"input": [
"4\n3\n4\n12\n1000000000\n",
"4\n3\n4\n12\n1010000000\n",
"4\n3\n4\n12\n1010000001\n",
"4\n3\n4\n11\n1110000000\n",
"4\n3\n7\n12\n1010000001\n",
"4\n3\n1\n11\n1110000000\n",
"4\n4\n7\n12\n1010000001\n",
"4\n2\n4\n19\n1010000110\n",
"4\n2\n7\n19\n1010000110\n",
"4\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rot... |
1413_C. Perform Easily_17742 | After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j.
Tayuya wants to play a melody of n notes. Each note can be play... | import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
a.sort()
n=int(input())
b=list(map(int,input().split()))
b.sort()
res=[]
for i in range(6):
for j in range(n):
res.append([b[j]-a[i],j])
res.sort()
ans=10**18
r=0
c=0
cnt=[0]*n
for l in range(n*6):
while c!=n and r<6*n:
cnt[res... | {
"input": [
"1 4 100 10 30 5\n6\n101 104 105 110 130 200\n",
"1 1 2 2 3 3\n7\n13 4 11 12 11 13 12\n",
"5 4 7 6 4 1\n10\n19 16 18 12 16 15 16 20 16 14\n",
"11 16 12 20 12 13\n10\n21 21 21 21 21 21 21 21 21 21\n",
"1 1 1 96 99 100\n3\n101 146 175\n",
"158260522 877914575 602436426 24979445 8616... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fr... |
1455_C. Ping-pong_17746 | Alice and Bob play ping-pong with simplified rules.
During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return.
The one ... | import sys
import math
from collections import defaultdict,deque
input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
def main():
t=int(input())
for _ in range(t):
alice,bob=inar()
print(alice-1,bob)
if __name__ == '__main__':
main()
| {
"input": [
"3\n1 1\n2 1\n1 7\n",
"3\n1 1\n2 1\n96342 7\n",
"1\n99899 99899\n",
"1\n99899 100000\n",
"1\n1000000 1\n",
"1\n99999 100000\n",
"12\n1 1\n2 1\n1 7\n1 1\n2 1\n1 7\n1 1\n2 1\n1 7\n1 1\n2 1\n1 7\n",
"1\n1000000 1000000\n",
"2\n1000000 1\n1 1000000\n",
"1\n8627 2007\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob play ping-pong with simplified rules.
During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hit... |
1506_C. Double-ended Strings_17752 | You are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in any order:
* if |a| > 0 (the length of the string a is greater than zero), delete the first character of the string a, that is, replace a with a_2 a_3 … a_n;
* if |a| > 0, delete the las... | rn=lambda:int(input())
rns=lambda:map(int,input().split())
rl=lambda:list(map(int,input().split()))
rs=lambda:input()
YN=lambda x:print('YES') if x else print('NO')
mod=10**9+7
for _ in range(rn()):
a=rs()
b=rs()
aset=set()
aset.add('')
for i in range(len(a)):
for j in range(i,len(a)+1):
... | {
"input": [
"5\na\na\nabcd\nbc\nhello\ncodeforces\nhello\nhelo\ndhjakjsnasjhfksafasd\nadjsnasjhfksvdafdser\n",
"5\na\na\nabcc\nbc\nhello\ncodeforces\nhello\nhelo\ndhjakjsnasjhfksafasd\nadjsnasjhfksvdafdser\n",
"5\na\na\nabcc\nbc\nhello\ncodeforces\nhello\nhelo\ndhjakjsnasjhfksafasd\nadjsnasjhgksrdafdsev\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in any order:
* if |a| > 0 (the length of the string a ... |
152_B. Steps_17756 | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangu... | n, m = [int(z) for z in input().split()]
x, y = [int(z) for z in input().split()]
k = int(input())
res = 0
i = 0
while i < k:
dx, dy = [int(z) for z in input().split()]
if dx == 0:
s = (m - y) // dy if dy > 0 else (1 - y) // dy
elif dy == 0:
s = (n - x) // dx if dx > 0 else (1 - x) // dx
... | {
"input": [
"10 10\n1 2\n1\n-1 0\n",
"4 5\n1 1\n3\n1 1\n1 1\n0 -2\n",
"10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5\n",
"1 1\n1 1\n1\n1 1\n",
"20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n20 3\n-1 -16\n0 2\n-1 1\n20 0\n-1 1\n",
"3 3\n2 2\n1\n2 0\n",
"1000 20... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decide... |
160_D. Edges in MST_17759 | You are given a connected weighted undirected graph without any loops and multiple edges.
Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertexes. The weight of a tree is defined as the sum of weights of the edges that the... | import sys
from math import inf
from collections import defaultdict
class disjoinSet(object):
def __init__(self,n):
self.father = [x for x in range(0,n+1)]
self.rank = [0 for x in range(0,n+1)]
def setOf(self, x):
if(self.father[x] != x):
self.father[x] = self.setOf(se... | {
"input": [
"3 3\n1 2 1\n2 3 1\n1 3 2\n",
"4 5\n1 2 101\n1 3 100\n2 3 2\n2 4 2\n3 4 1\n",
"3 3\n1 2 1\n2 3 1\n1 3 1\n",
"5 8\n2 5 3\n4 1 3\n3 4 7\n3 1 9\n1 2 6\n5 3 7\n2 4 7\n4 5 9\n",
"10 15\n6 5 805980\n1 6 805980\n7 8 805980\n4 9 805980\n4 1 805980\n3 6 805980\n6 9 805980\n8 10 805980\n3 1 805... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a connected weighted undirected graph without any loops and multiple edges.
Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph ... |
180_A. Defragmentation_17763 | In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m recorded files, the i-th file occupies clusters with numbers ai, 1, ai, 2, ..., ai, ni. These clusters are not necessarily located consecuti... | import sys
n, m, *inp = map(int, sys.stdin.read().split())
inp.reverse()
f = [[0 for x in range(201)] for y in range(201)] #2D Array
c = [(0,0)]*201
f_size = [0]*201
def putData(f_id, s_id, c_id):
global f, c
f[f_id][s_id] = c_id
c[c_id] = (f_id, s_id)
for f_id in range(1, m+1):
f_size[f_id] = in... | {
"input": [
"7 2\n2 1 3\n3 2 4 5\n",
"7 2\n2 1 2\n3 3 4 5\n",
"7 3\n1 7\n2 6 5\n3 4 3 2\n",
"100 30\n8 62 50 93 34 82 24 87 65\n2 64 86\n3 91 42 88\n2 76 7\n2 35 63\n3 78 84 15\n4 90 46 73 9\n4 74 13 95 58\n3 71 59 55\n2 4 31\n1 19\n1 10\n2 45 23\n2 27 69\n4 12 66 44 22\n1 36\n2 67 2\n2 77 54\n4 96 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m rec... |
203_B. Game on Paper_17767 | One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.
He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the p... | import math
from sys import stdin
from math import ceil
import sys
if __name__ == '__main__':
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
moves = [[0] * (n + 4) for _ in range(n + 4)]
for i in range(m):
listOfMoves = list(map(int, input().split()))
x = li... | {
"input": [
"4 11\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n3 3\n4 1\n",
"4 12\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n4 2\n4 1\n3 1\n",
"1 1\n1 1\n",
"1000 1\n542 374\n",
"4 12\n2 2\n1 1\n3 3\n3 4\n1 2\n1 3\n1 4\n2 1\n3 2\n2 3\n3 1\n4 1\n",
"2 1\n1 1\n",
"1000 10\n1000 1000\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.
He took a checkered white square piece of paper, consisting ... |
228_A. Is your horseshoe on the other hoof?_17771 | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | l=list(map(int,input().split()))
i=list(set(l))
print(abs(len(i)-len(l))) | {
"input": [
"7 7 7 7\n",
"1 7 3 3\n",
"2 2 2 1\n",
"3491663 217797045 522540872 715355328\n",
"28442865 741657755 978106882 978106882\n",
"240458500 511952208 240458500 511952208\n",
"133315691 265159773 734556507 265159773\n",
"255635360 732742923 798648949 883146723\n",
"8117086... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different col... |
251_D. Two Sets_17775 | Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to g... | base = [-1] * 60
how = [-1] * 60
who = [-1] * 60
n = int(input())
arr = list(map(int, input().split()))
x = 0
for a in arr:
x ^= a
mapper = [-1] * 60
ind = 59
ind_start = bin(x).count('1') - 1
for bit in reversed(range(60)):
if (1 << bit) & x :
mapper[bit] = ind_start
ind_start -= 1
else... | {
"input": [
"3\n1000000000000 1000000000000 1000000000000\n",
"8\n1 1 2 2 3 3 4 4\n",
"6\n1 2 3 4 5 6\n",
"10\n1 2 1 0 0 1 100 1 3 1\n",
"2\n1024 2048\n",
"5\n0 0 1 3 128\n",
"2\n123456789123456789 123456789123456789\n",
"17\n1 2 3 4 5 6 7 8 9 10 11 12 13 13 13 17 16\n",
"30\n285 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with lit... |
29_B. Traffic Lights_17781 | A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on fo... | # n=int(input())
l,d,v,g,r=map(int,input().split())
z=d/v
y=(l-d)/v
temp=z
light=True
x=0
# print(z,y)
while(1):
if(x%2==0):
if(temp>=g):
temp-=g
light=False
else:
break
else:
if(temp>=r):
temp-=r
light=True
else:
... | {
"input": [
"5 4 3 1 1\n",
"2 1 3 4 5\n",
"1000 999 1000 1000 1\n",
"1000 999 1 1000 1000\n",
"1000 999 1000 1 1000\n",
"2 1 1 1 1000\n",
"1000 1 1 1000 1\n",
"29 12 569 939 259\n",
"1000 999 1 1 1000\n",
"1000 1 1000 1 1000\n",
"1000 1 1000 1000 1\n",
"2 1 1000 1 1\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0,... |
347_C. Alice and Bob_17787 | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di... | from sys import *
from math import *
from string import *
from operator import *
from functools import *
from fractions import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
##... | {
"input": [
"3\n5 6 7\n",
"2\n5 3\n",
"2\n2 3\n",
"2\n1 2\n",
"10\n1 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991\n",
"2\n6 2\n",
"4\n2 3 15 30\n",
"2\n4 6\n",
"10\n72 96 24 66 6 18 12 30 60 48\n",
"2\n1 1000000000\n",
"2\n10 4\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then th... |
370_D. Broken Monitor_17791 | Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.
Innocentius is touch-typing a program that pain... | #!/usr/bin/python3
def readln(): return list(map(int, input().split()))
import sys
def exit():
print(-1)
sys.exit()
n, m = readln()
mon = [list(input()) for _ in range(n)]
hor = [i for i in range(n) if mon[i] != ['.'] * m]
rmon = list(zip(*mon))
ver = [j for j in range(m) if rmon[j] != ('.',) * n]
mini = hor[... | {
"input": [
"4 8\n..w..w..\n........\n........\n..w..w..\n",
"5 6\n......\n.w....\n......\n..w...\n......\n",
"2 4\n....\n.w..\n",
"2 6\nw..w.w\n...w..\n",
"1 3\n.w.\n",
"8 10\n..........\n..........\n.....w....\n.w........\n..........\n....w.....\n..........\n..........\n",
"1 2\nww\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual comput... |
392_A. Blocked Points_17795 | Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
* the Euclidean distance between A and B is one unit and neither A nor B is blocked;
* or there is some inte... | from math import sqrt, floor
def calc(n):
if n == 0:
return 1
# y = n
# x = 1
# c = 0
# while x - y < 0:
# if x ** 2 + y ** 2 <= n ** 2:
# c += 1
# x += 1
# continue
# if x ** 2 + y ** 2 > n ** 2:
# y -= 1
x = floor(sqrt(n... | {
"input": [
"2\n",
"1\n",
"3\n",
"34714265\n",
"31975828\n",
"16\n",
"46340\n",
"12\n",
"39099999\n",
"10\n",
"46341\n",
"15012490\n",
"9\n",
"15\n",
"11\n",
"6\n",
"39999996\n",
"39999997\n",
"3107977\n",
"17590047\n",
"24562258\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-con... |
415_B. Mashmokh and Tokens_17799 | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
from sys import stdin
from math import floor
n, a, b = arr_inp(1)
arr = arr_inp(1)
... | {
"input": [
"1 1 1\n1\n",
"3 1 2\n1 2 3\n",
"5 1 4\n12 6 11 9 1\n",
"1 1 1000000000\n1000000000\n",
"1 1 1000000000\n999999999\n",
"10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999\n",
"1 2 1000000000\n1000000000\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Th... |
464_A. No to Palindromes!_17805 | Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st... | n, p = map(int, input().split())
s = list(ord(i) - 97 for i in input())
for i in range(n - 1, -1, -1):
for j in range(s[i] + 1, p):
if (i < 1 or j != s[i - 1]) and (i < 2 or j != s[i - 2]):
s[i] = j
for i in range(i + 1, n):
for j in range(p):
if ... | {
"input": [
"3 4\ncba\n",
"4 4\nabcd\n",
"3 3\ncba\n",
"6 3\nacbacb\n",
"30 7\ncedcfedcfgcfgcbadcadgfaegfacgf\n",
"1 26\no\n",
"1 2\na\n",
"3 26\nyzx\n",
"333 5\nedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedced... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguo... |
510_D. Fox And Jumping_17811 | Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
There are also n cards, each card has 2 attributes: length li and cost ci. If she pays ci dollars then she can apply i-th card. After app... | import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data():... | {
"input": [
"3\n100 99 9900\n1 1 1\n",
"8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026\n",
"7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10\n",
"5\n10 20 30 40 50\n1 1 1 1 1\n",
"1\n1\n1\n",
"39\n692835 4849845 22610 1995 19019 114 6270 15 85085 27170... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
... |
560_A. Currency System in Geraldion_17817 | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | n=int(input())
l=list(map(int,input().split()));print(1 if 1 not in l else -1)
| {
"input": [
"5\n1 2 3 4 5\n",
"10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\n",
"1\n1\n",
"10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\n",
"1\n1000000\n",
"1\n2\n",
"2\n3 2\n",
"50\n110876 835020 859879 999908 712969 788264 287153 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens ... |
586_C. Gennady the Dentist_17821 | Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
n = int(input())
C = [list(map(int,input().split())) for i in range(0,n)]
ans = []
for i in range(n):
v, d, p = C[i]
if p >= 0:
count = 0
d0 = 0
for j in range(i + 1, n):
if C[j][2] >= 0:
C[j][2] -= max(0,v - c... | {
"input": [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n",
"10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6\n",
"1\n1 1 1\n",
"10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42\n",
"10\n10 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the recep... |
608_D. Zuma_17825 | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ... | from sys import stdin
n=int(input())
s=list(map(int,stdin.readline().strip().split()))
dp=[[-1 for i in range(501)] for j in range(500)]
def sol(i,j):
if i>j:
return 0
if i==j:
return 1
if dp[i][j]!=-1:
return dp[i][j]
x=502
if s[i]==s[i+1]:
x=min(x,sol(i+2,j)+1)
... | {
"input": [
"3\n1 2 3\n",
"7\n1 4 4 2 3 2 1\n",
"3\n1 2 1\n",
"50\n22 19 14 22 20 11 16 28 23 15 3 23 6 16 30 15 15 10 24 28 19 19 22 30 28 1 27 12 12 14 17 30 17 26 21 26 27 1 11 23 9 30 18 19 17 29 11 20 29 24\n",
"50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones i... |
656_B. Scrambled_17832 | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ... | n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
days = 0
for day in range(1, 100001):
for index in range(n):
if day % m[index] == r[index]:
days += 1
break
print(days / 100000)
| {
"input": [
"2\n2 3\n1 0\n",
"1\n2\n0\n",
"1\n15\n1\n",
"1\n7\n5\n",
"1\n6\n3\n",
"2\n10 14\n2 5\n",
"16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
"1\n16\n15\n",
"3\n6 14 7\n4 2 0\n",
"2\n13 3\n6 0\n",
"12\n8 5 5 12 12 14 14 16 5 11... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg d... |
67_B. Restoration of the Permutation_17836 | Let A = {a1, a2, ..., an} be any permutation of the first n natural numbers {1, 2, ..., n}. You are given a positive integer k and another sequence B = {b1, b2, ..., bn}, where bi is the number of elements aj in A to the left of the element at = i such that aj ≥ (i + k).
For example, if n = 5, a possible A is {5, 1, 4... | s = input()
l = s.split()
n = int(l[0])
k = int(l[1])
s = input()
l = s.split()
b = [-1]
for i in range(1, n + 1):
b.append(int(l[i - 1]))
for i in range(1, n + 1):
j = 1
while b[j] != 0:
j += 1
b[j] -= 1
print(j, end = ' ')
for t in range(1, n + 1):
if j - k >= t:
... | {
"input": [
"5 2\n1 2 1 0 0\n",
"4 2\n1 0 0 0\n",
"13 2\n1 2 3 4 5 4 3 2 1 0 0 0 0\n",
"20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0\n",
"20 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\n",
"10 10\n0 0 0 0 0 0 0 0 0 0\n",
"10 3\n4 2 4 2 1 0 1 0 0 0\n",
"20 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let A = {a1, a2, ..., an} be any permutation of the first n natural numbers {1, 2, ..., n}. You are given a positive integer k and another sequence B = {b1, b2, ..., bn}, where bi is ... |
702_B. Powers of Two_17840 | You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).
Input
The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers ... | # @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-20 23:46
# @url:https://codeforc.es/problemset/problem/702/B
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
BUFSIZE = 8192
class Fa... | {
"input": [
"3\n1 1 1\n",
"4\n7 3 2 1\n",
"2\n1 1\n",
"10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607\n",
"1\n2\n",
"10\n6 6 7 3 9 14 15 7 2 2\n",
"100\n3 6 12 1 16 4 9 5 4 4 5 8 12 4 6 14 5 1 2 2 2 1 7 1 9 10 6 13 7 8 3 11 8 11 7 5 15 6 14 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).
Input
The... |
724_C. Ray Tracing_17844 | There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle.
Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.
At... | def main():
nx, my, k = list(map(int, input().strip().split()))
my *= 2
nx *= 2
diags = [[] for i in range(nx + my)]
answers = [-1] * k
for i in range(k):
x,y = list(map(int, input().strip().split()))
def add(x, y, i):
diag_index = nx + (y - x)
diags[diag_index].append( (x,y,i) )
add(x, y, i)
ad... | {
"input": [
"3 3 4\n1 1\n1 2\n2 1\n2 2\n",
"3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n",
"7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n",
"10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n3 3\n2 8\n5 5\n6 3\n3 1\n",
"3 3 4\n1 1\n1 0\n2 1\n2 2\n",
"10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n3 3\n2 8\n5 6\n6 3\n3 1\n",
"3 4 6\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the ... |
746_C. Tram_17848 | The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point... | def codeforces(max_point, start, finish, tram_speed, legs_speed,
tram_point, direction):
if tram_point == start:
time_to_start = 0
elif start > tram_point:
if direction == 1:
time_to_start = (start - tram_point) * tram_speed
else:
direction = -direc... | {
"input": [
"4 2 4\n3 4\n1 1\n",
"5 4 0\n1 2\n3 1\n",
"50 10 30\n1 50\n10 1\n",
"1000 913 474\n34 162\n566 -1\n",
"1000 394 798\n155 673\n954 -1\n",
"10 4 8\n1 5\n4 -1\n",
"40 31 14\n628 1000\n36 1\n",
"5 4 1\n1 100\n4 -1\n",
"4 2 4\n3 4\n2 1\n",
"20 5 19\n163 174\n4 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the sta... |
769_C. Cycle In Maze_17852 | The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In... | import math
from collections import deque
def main():
n, m, k = list(map(int, input().split()))
grid = ["" for _ in range(n)]
x, y = 0, 0
for i in range(n):
grid[i] = input()
if 'X' in grid[i]:
x, y = i, grid[i].index('X')
if k % 2 == 1:
print("IMPOSSIBLE")
return
dx = [1, 0, 0, -1]
dy = [0, -1, ... | {
"input": [
"3 3 4\n***\n*X*\n***\n",
"5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.\n",
"2 3 2\n.**\nX..\n",
"1 10 1\n........X.\n",
"2 1 2\nX\n.\n",
"20 10 116\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:
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the ... |
793_C. Mice problem_17856 | Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.
The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i... | import math
n = int(input())
x1, y1, x2, y2 = map(int, input().split())
t1 = 0
t2 = math.inf
yes = True
for i in range(n):
x, y, vx, vy = map(int, input().split())
if vx == 0:
if x <= x1 or x >= x2:
yes = False
break
else:
tt1 = (x1-x)/vx
tt2 = (x2-x)/vx
tt1, tt2 = min(tt1, tt2), max... | {
"input": [
"4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10\n",
"4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2\n",
"1\n0 0 10 10\n5 5 5 5\n",
"1\n0 0 5 5\n2 5 0 0\n",
"4\n0 49998 2 50002\n1 50000 0 0\n1 50000 0 0\n1 0 0 1\n1 100000 0 -1\n",
"1\n0 0 100000 100000\n0 0 -1 -1\n",
"4\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.
The desk can be consid... |
85_A. Domino_17864 | We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.
You are given a 4 × n rectangular fie... | def computeTiling(n):
if n == 1:
print("a\na\nf\nf")
return
for tiling in generateRowTilings(n):
print("".join(tiling))
def generateRowTilings(n):
for (rowNum, firstTile, pattern) in generateRowTilingPatterns(n):
yield makeRowTiling(rowNum, firstTile, pattern, n)
def g... | {
"input": [
"4\n",
"25\n",
"27\n",
"1\n",
"97\n",
"98\n",
"94\n",
"21\n",
"97\n",
"19\n",
"3\n",
"28\n",
"2\n",
"8\n",
"12\n",
"15\n",
"91\n",
"4\n",
"9\n",
"23\n",
"29\n",
"22\n",
"96\n",
"30\n",
"7\n",
"100\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some ot... |
886_A. ACM ICPC_17868 | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of ai. Team s... | a = list(map(int, input().split()))
summ = sum(a)
res = 'NO'
if summ % 2 != 1 :
summ //= 2
for i in range(4) :
for j in range(i + 1, 5) :
for k in range(j + 1, 6) :
if a[i] + a[j] + a[k] == summ :
res = 'YES'
print(res)
| {
"input": [
"1 1 1 1 1 99\n",
"1 3 2 1 2 1\n",
"1000 1000 1000 1000 1000 1000\n",
"180 179 188 50 75 214\n",
"633 609 369 704 573 416\n",
"2 2 2 2 2 1\n",
"101 200 400 300 10 9\n",
"1 6 6 1 20 2\n",
"72 8 186 92 267 69\n",
"101 200 300 400 10 9\n",
"353 313 327 470 597 31\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished... |
909_A. Generate Login_17872 | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | s=input().split(" ")
m=s[0]
j=s[1]
list=[]
for x in range(len(m)):
p=m[0:x+1]
p=p+j[0]
list.append(p)
list.sort()
print(list[0]) | {
"input": [
"tom riddle\n",
"harry potter\n",
"jjxwj kxccwx\n",
"dtbqya fyyymv\n",
"apple pie\n",
"ca cf\n",
"amolfed pun\n",
"ab b\n",
"bgopsdfji uaps\n",
"aa ab\n",
"aaaaaaaaaa aaaaaaaaaa\n",
"obljndajv q\n",
"mybiqxmnqq l\n",
"a aaa\n",
"aaaaaaa a\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, ... |
930_C. Teodor is not a liar!_17876 | Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor ... | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mo... | {
"input": [
"2 4\n1 2\n3 4\n",
"4 6\n1 3\n2 3\n4 6\n5 6\n",
"11 3\n1 1\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n3 3\n3 3\n3 3\n3 3\n",
"43 1319\n750 1030\n857 946\n941 1203\n407 1034\n947 1290\n546 585\n630 1201\n72 342\n693 1315\n34 719\n176 1097\n36 931\n198 973\n5 1025\n892 1054\n461 1287\n195 1273\n832 103... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one inte... |
958_D1. Hyperspace Jump (easy)_17880 | The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independent... | m = int(input())
esc = [eval(input()) for i in range(m)]
d = {i: 0 for i in esc}
for i in esc:
d[i] += 1
for i in esc:
print(d[i], end = ' ')
| {
"input": [
"4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n",
"30\n(89+76)/87\n(81+78)/18\n(60+97)/32\n(41+14)/48\n(55+65)/27\n(29+15)/95\n(64+13)/96\n(78+30)/75\n(43+6)/60\n(69+34)/48\n(62+2)/97\n(85+42)/3\n(4+97)/42\n(1+18)/39\n(46+55)/76\n(22+59)/24\n(62+81)/98\n(64+8)/51\n(9+59)/48\n(47+2)/80\n(33+74)/7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same... |
984_C. Finite or not?_17884 | You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction ... | from sys import stdin, stdout
n=int(stdin.readline())
s=''
for i in range(n):
p,q,b=map(int,input().split())
for i in range(6):
b=(b*b)%q
if((p*b)%q):
s+='Infinite\n'
else:
s+='Finite\n'
print(s) | {
"input": [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n",
"10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4\n",
"1\n1 5244319080000 30030\n",
"10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2\n",
"1\n1 864691128455135232 2\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction... |
p02571 AtCoder Beginner Contest 177 - Substring_17898 | Given are two strings S and T.
Let us change some of the characters in S so that T will be a substring of S.
At least how many characters do we need to change?
Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`.
Constraints
* The lengths of ... | s,t=open(0)
print(min(sum(x!=y for x,y in zip(s[i:],t[:-1]))for i in range(len(s)-len(t)+1))) | {
"input": [
"codeforces\natcoder",
"cabacc\nabc",
"codefsrceo\natcoder",
"cabacc\nabb",
"codefsrceo\natdocer",
"codefsrceo\natdrceo",
"codefsqceo\natdrceo",
"ccbaac\naac",
"caacbc\nbba",
"oeectfpcat\nalbs`tb",
"ccabac\nabb",
"ccabac\nbba",
"ccabac\ncba",
"codef... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are two strings S and T.
Let us change some of the characters in S so that T will be a substring of S.
At least how many characters do we need to change?
Here, a substring is... |
p02702 AtCoder Beginner Contest 164 - Multiple of 2019_17902 | Given is a string S consisting of digits from `1` through `9`.
Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:
Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.
Constraints
* 1 ≤ |S| ≤ 200000
* S is a string c... | s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
u=(u+(i*d)%2019)%2019
l[u]+=1
d=d*10%2019
for i in l:
ans+=i*(i-1)//2
print(ans)
| {
"input": [
"1817181712114",
"2119",
"14282668646",
"3054417607960",
"218",
"8160152899489",
"7932848001410",
"6806479110",
"9600282290",
"649171600089",
"3000732030",
"4123972862",
"5345763557347",
"261",
"6388732131",
"233",
"4177333742",
"283... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is a string S consisting of digits from `1` through `9`.
Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:
Condition: In base ... |
p02831 AtCoder Beginner Contest 148 - Snack_17906 | Takahashi is organizing a party.
At the party, each guest will receive one or more snack pieces.
Takahashi predicts that the number of guests at this party will be A or B.
Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.
We assume that a piece cannot be ... | import math
A,B=map(int,input().split())
print(int((A*B)/math.gcd(A,B)))
| {
"input": [
"100000 99999",
"123 456",
"2 3",
"110000 99999",
"123 179",
"2 1",
"110001 99999",
"108 179",
"3 1",
"110001 118998",
"50 179",
"1 1",
"110001 52132",
"50 306",
"2 0",
"110000 52132",
"50 267",
"100000 52132",
"50 243",
"100... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is organizing a party.
At the party, each guest will receive one or more snack pieces.
Takahashi predicts that the number of guests at this party will be A or B.
Find the... |
p03103 AtCoder Beginner Contest 121 - Energy Drink Collector_17911 | Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.
There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.
What is the minimum amount of money with which he can bu... | n,m = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
A.sort()
ans = 0
cnt = 0
for a in A:
tmp = min(m-cnt,a[1])
ans += tmp*a[0]
cnt+=tmp
if cnt >= m:
break
print(ans) | {
"input": [
"4 30\n6 18\n2 5\n3 10\n7 9",
"1 100000\n1000000000 100000",
"2 5\n4 9\n2 4",
"4 30\n6 18\n2 6\n3 10\n7 9",
"2 3\n4 9\n2 4",
"4 30\n6 18\n2 1\n3 10\n7 9",
"2 3\n4 9\n4 4",
"2 6\n4 9\n4 4",
"2 6\n3 9\n4 4",
"2 6\n3 9\n2 4",
"2 6\n3 9\n1 4",
"2 3\n3 4\n1 6",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.
There are N stores that sell energy drinks. In the i-th store, he can ... |
p03251 AtCoder Beginner Contest 110 - 1 Dimensional World's Tale_17915 | Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.
The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.
One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes incli... | N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
if max(max(x),X)<min(min(y),Y):
print('No War')
else:
print("War") | {
"input": [
"3 2 10 20\n8 15 13\n16 22",
"4 2 -48 -1\n-20 -35 -91 -23\n-22 66",
"5 3 6 8\n-10 3 1 5 -100\n100 6 14",
"3 2 10 20\n8 15 15\n16 22",
"4 2 -48 -1\n-20 -35 -91 -23\n-22 75",
"5 3 6 8\n-10 3 1 5 -100\n101 6 14",
"3 2 10 40\n8 15 15\n16 22",
"4 2 -48 -1\n-20 -35 -35 -23\n-22 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.
The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate... |
p03404 AtCoder Regular Contest 093 - Grid Components_17919 | You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is ... |
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
def read_a_int():
return int(read())
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(tupl... | {
"input": [
"3 14",
"1 1",
"2 3",
"7 8",
"0 14",
"1 2",
"0 3",
"12 8",
"1 4",
"0 1",
"19 8",
"1 7",
"19 12",
"1 13",
"2 1",
"19 23",
"2 13",
"19 14",
"2 25",
"9 23",
"0 25",
"17 23",
"17 39",
"0 8",
"17 64",
"17 4... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:
* Le... |
p03567 CODE FESTIVAL 2017 qual C - Can you get AC?_17923 | Snuke built an online judge to hold a programming contest.
When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.)
Determine whether the judge can return the ... | S = input()
for s, ns in zip(S, S[1:]):
if s + ns == "AC":
print("Yes")
exit()
print("No") | {
"input": [
"CABD",
"BACD",
"ACACA",
"ABCD",
"XX",
"CBBD",
"ACABA",
"B@CD",
"BBCD",
"XW",
"DBBD",
"B@BD",
"ACBAA",
"DCBB",
"XV",
"DBCD",
"DC@B",
"ACAAA",
"ECBB",
"VX",
"DCBD",
"DB@C",
"@CABA",
"BBCE",
"YW",
"DDBD"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke built an online judge to hold a programming contest.
When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the ... |
p03722 AtCoder Beginner Contest 061 - Score Attack_17927 | There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece.
Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move t... | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
dist = [float("inf")] * n
dist[s] = 0
negative = [False] * n
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if ... | {
"input": [
"2 2\n1 2 1\n2 1 1",
"3 3\n1 2 4\n2 3 3\n1 3 5",
"6 5\n1 2 -1000000000\n2 3 -1000000000\n3 4 -1000000000\n4 5 -1000000000\n5 6 -1000000000",
"3 3\n1 2 4\n2 2 3\n1 3 5",
"6 5\n1 2 -1000000000\n2 3 -1000000000\n3 5 -1000000000\n4 5 -1000000000\n5 6 -1000000000",
"6 5\n1 2 -100000000... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game ... |
p04043 AtCoder Beginner Contest 042 - Iroha and Haiku (ABC Edition)_17933 | Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of... | print("YES" if [5,5,7] == sorted(list(map(int,input().split()))) else "NO") | {
"input": [
"5 5 7",
"7 7 5",
"5 5 14",
"2 7 5",
"5 1 14",
"2 7 3",
"2 4 3",
"2 4 1",
"2 4 0",
"3 4 0",
"4 4 0",
"4 4 -1",
"4 4 -2",
"4 3 -2",
"4 2 -2",
"7 2 -2",
"7 4 -2",
"13 4 -2",
"13 4 -1",
"20 4 -1",
"20 4 0",
"20 0 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with thr... |
p00124 League Match Score Sheet_17937 | There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed based on the points. The points are win (3 points), negative (0 points), and draw (1 point), respectively.
Enter the number of teams and the... | b=False
while True:
n = int(input())
if n==0:break
d=dict()
if b:print()
b=True
for _ in range(n):
line = input().split()
tmp = int(line[1])*3+int(line[3]*1)
if tmp in d:
d[tmp].append(line[0])
else:
d[tmp] = []
d[tmp].append(li... | {
"input": [
"4\nJapan 1 0 2\nEgypt 1 2 0\nCanada 0 2 1\nSpain 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 0 1\n0",
"4\nJapan 1 0 2\nEgypt 1 2 0\nCanada 0 2 1\nSpain 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 -1 1\n0",
"4\nJapan 1 0 2\nEgypt 1 2 0\nCanada 0 2 1\nSpain 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed base... |
p00257 Making Sugoroku_17940 | Taro made a sugoroku so that everyone can play at the children's association event. In order to make the game interesting, I wrote instructions such as "advance 6" and "back 5" in some of the sugoroku squares other than "Furidashi" and "Agari". Turn the roulette wheel to advance as many times as you can, and if an inst... | while True:
m = int(input())
if not m:
break
n = int(input())
ds = [0] + [int(input()) for _ in range(n)] + [0]
g = [[] for _ in range(n+2)]
rg = [[] for _ in range(n+2)]
for i in range(n+2):
for j in range(min(n+1,i+1),min(n+1,i+m)+1):
j = max(0,min(n+1,j+ds[j])... | {
"input": [
"3\n3\n-2\n1\n0\n2\n4\n2\n0\n-1\n-2\n2\n2\n-2\n-2\n0",
"3\n3\n-2\n1\n0\n2\n4\n2\n1\n-1\n-2\n2\n2\n-2\n-2\n0",
"3\n3\n-2\n1\n0\n2\n4\n2\n1\n-1\n-3\n2\n2\n-2\n-2\n0",
"3\n3\n-2\n1\n0\n2\n4\n2\n1\n-1\n-3\n4\n2\n-2\n-2\n0",
"3\n3\n0\n1\n0\n2\n4\n2\n1\n-1\n-2\n4\n2\n-2\n-4\n0",
"3\n3\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro made a sugoroku so that everyone can play at the children's association event. In order to make the game interesting, I wrote instructions such as "advance 6" and "back 5" in som... |
p00444 Change_17944 | problem
Taro often shop at JOI general stores. At JOI general stores, there are enough coins of 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen, and we always pay the change so that the number of coins is the smallest. Create a program to find the number of coins included in the change you receive when Taro goes sh... | while True:
x = int(input())
if x == 0:
break
else:
x=1000-x
a=x//500
b=(x-500*a)//100
c=(x-(500*a+100*b))//50
d=(x-(500*a+100*b+50*c))//10
e=(x-(500*a+100*b+50*c+10*d))//5
f=(x-(500*a+100*b+50*c+10*d+5*e))//1
print(a+b+c+d+e+f)
| {
"input": [
"380\n1\n0",
"380\n0\n0",
"380\n2\n0",
"380\n-1\n0",
"380\n-2\n0",
"380\n3\n0",
"380\n4\n0",
"380\n-4\n0",
"380\n5\n0",
"380\n-7\n0",
"380\n10\n0",
"380\n-9\n0",
"380\n43\n0",
"380\n48\n0",
"380\n0\n-1",
"380\n0\n1",
"380\n0\n-2",
"3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
Taro often shop at JOI general stores. At JOI general stores, there are enough coins of 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen, and we always pay the change so th... |
p00909 Never Wait for Weights_17950 | In a laboratory, an assistant, Nathan Wada, is measuring weight differences between sample pieces pair by pair. He is using a balance because it can more precisely measure the weight difference between two samples than a spring scale when the samples have nearly the same weight.
He is occasionally asked the weight dif... | class Value_UnionFind():
def __init__(self,n):
self.par = [i for i in range(n)]
self.differ_weight = [0] * n
self.rank = [0] * n
def root(self,x):
if x == self.par[x]:
return x
r = self.root(self.par[x])
self.differ_weight[x] += self.differ_weight[se... | {
"input": [
"2 2\n! 1 2 1\n? 1 2\n2 2\n! 1 2 1\n? 2 1\n4 7\n! 1 2 100\n? 2 3\n! 2 3 100\n? 2 3\n? 1 3\n! 4 3 150\n? 4 1\n0 0",
"2 2\n! 1 2 1\n? 1 2\n2 2\n! 2 2 1\n? 2 1\n4 7\n! 1 2 100\n? 2 3\n! 2 3 100\n? 2 3\n? 1 3\n! 4 3 150\n? 4 1\n0 0",
"2 2\n! 2 2 1\n? 1 2\n2 2\n! 2 2 1\n? 2 1\n4 7\n! 1 2 100\n? 2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In a laboratory, an assistant, Nathan Wada, is measuring weight differences between sample pieces pair by pair. He is using a balance because it can more precisely measure the weight ... |
p01928 Matryoshka Doll_17961 | Matryoshka
Matryoshka is a famous Russian folk craft doll. Matryoshka can be divided into upper and lower parts, and when opened, there is another smaller doll inside. The nesting structure is such that when the small doll that appears is opened, a smaller doll is contained.
<image>
You found an unusually shaped ma... | import heapq
class MinCostFlow:
class Edge:
def __init__(self,to,cap,rev,cost):
self.to = to
self.cap = cap
self.rev = rev
self.cost = cost
def __init__(self,n,inf=1000000007):
self.n = n
self.inf = inf
self.e = [[] for _ in range... | {
"input": [
"2\n1 2 3\n4 2 3\n3\n2 5 2\n3 3 4\n5 5 5\n5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n5\n1 1 1\n2 1 1\n3 1 1\n4 1 1\n5 1 1\n10\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 7 9\n3 2 3\n8 4 6\n2 6 4\n3 3 8\n3 2 7\n0",
"2\n1 4 3\n4 2 3\n3\n2 5 2\n3 3 4\n5 5 5\n5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n5\n1 1 1\n2 1 1\n3 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Matryoshka
Matryoshka is a famous Russian folk craft doll. Matryoshka can be divided into upper and lower parts, and when opened, there is another smaller doll inside. The nesting st... |
p02208 Cutlet Sandwich_17964 | Cutlet Sandwich
In some worlds, there are $ X $ types of "sandwiches", $ Y $ types of "cutlets", and $ Z $ types of "curry" foods.
There is a $ N $ type of "cutlet sandwich" in this world, and the $ i $ type of cutlet sandwich is made from the $ A_i $ type of sand and the $ B_i $ type of cutlet.
There is also a $ M ... | from collections import deque
x,y,z,n,m,s,t=map(int,input().split())
g=[[]for _ in range(x+y+z)]
for i in range(n):
a,b=map(int,input().split())
g[a-1].append(b+x-1)
g[b+x-1].append(a-1)
if i==s-1:
p,q=a-1,b+x-1
for j in range(m):
a,b=map(int, input().split())
g[a+x-1].append(b+x+y-1)
g[b+x+y-1].appen... | {
"input": [
"1 1 1 1 1 1 1\n1 1\n1 1",
"2 1 1 1 1 1 1\n1 1\n1 1",
"2 1 1 1 1 1 1\n1 0\n1 1",
"1 1 1 1 2 1 1\n1 1\n1 1",
"2 0 1 1 1 1 1\n1 1\n1 1",
"0 1 1 1 1 1 1\n1 1\n1 1",
"1 1 1 1 1 1 1\n1 1\n2 1",
"1 1 1 1 1 1 1\n2 1\n2 1",
"2 1 1 1 1 1 1\n2 0\n1 1",
"1 2 1 1 1 1 1\n1 1\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Cutlet Sandwich
In some worlds, there are $ X $ types of "sandwiches", $ Y $ types of "cutlets", and $ Z $ types of "curry" foods.
There is a $ N $ type of "cutlet sandwich" in this... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.