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 |
|---|---|---|---|---|---|
682_C. Alyona and the Tree_25040 | Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call ver... | n=int(input())
a=[0]+list(map(int,input().split()))
E=[[] for _ in range(n+1)]
for i in range(n-1):
p,c=map(int,input().split())
E[i+2]+=[(p,c)]
E[p]+=[(i+2,c)]
ans=0
ch=[(1,0,0)]
while ch:
nom,pre,l=ch.pop()
if l>a[nom]: continue
ans+=1
for x,c in E[nom]:
if x!=pre: ch+=[(x,nom,max... | {
"input": [
"9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n",
"6\n60 89 33 64 92 75\n4 50\n1 32\n5 21\n3 77\n1 86\n",
"9\n59 48 48 14 51 51 86 53 58\n1 -47\n5 10\n8 -6\n9 46\n2 -69\n8 -79\n9 92\n6 12\n",
"8\n2 19 83 95 9 87 15 6\n6 16\n7 98\n5 32\n7 90\n8 37\n2 -34\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of wh... |
705_B. Spider Man_25044 | Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.
Initially t... | n = int(input())
sum = 0
for i in input().split():
sum += int(i) - 1
if sum % 2 == 0:
print(2)
else:
print(1) | {
"input": [
"5\n1 1 5 1 1\n",
"3\n1 2 3\n",
"2\n3 1\n",
"5\n1 1 4 1 1\n",
"4\n1 2 1 1\n",
"2\n1 1\n",
"10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n",
"2\n3 3\n",
"2\n2 4\n",
"3\n1 3 1\n",
"2\n1 2\n",
"5\n5 4 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected wi... |
817_A. Treasure Hunt_25057 | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values x and y written on it. These values define four moves which can be performed... | a, b, c, d = map(int, input().split())
x, y = map(int, input().split())
if abs(c - a) % abs(x) == 0 and abs(c - a) / abs(x) % 2 == abs(d - b) / abs(y) % 2 and abs(d - b) % abs(y) == 0:
print("YES")
else:
print("NO")
| {
"input": [
"1 1 3 6\n1 5\n",
"0 0 0 6\n2 3\n",
"7 -7 1 -7\n2 2\n",
"-61972 -39646 -42371 -24854\n573 238\n",
"1 1 4 4\n2 2\n",
"9 -3 -9 -3\n2 2\n",
"70 -81 -17 80\n87 23\n",
"0 8 6 2\n1 1\n",
"-6 -6 -10 -5\n6 7\n",
"1 1 1 6\n1 5\n",
"3 7 -8 8\n2 2\n",
"0 0 -100 -100\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help the... |
842_A. Kirill And The Game_25061 | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | IL = lambda: list(map(int, input().split()))
IS = lambda: input().split()
I = lambda: int(input())
S = lambda: input()
l, r, x, y, k = IL()
for i in range(max(l, x*k), min(r, y*k) + 1):
if i%k == 0:
print("YES")
quit()
print("NO") | {
"input": [
"1 10 1 10 1\n",
"1 5 6 10 1\n",
"71841 96625 73295 77648 8\n",
"17 19 2 3 8\n",
"1 100000 1 100000 100001\n",
"11 17 2 5 2\n",
"46646 79126 78816 91164 5\n",
"91939 94921 10197 89487 1\n",
"4 5 1 2 3\n",
"10 10 3 4 3\n",
"70 70 1 2 50\n",
"1 100000 1 10000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency... |
863_A. Quasi-palindrome_25065 | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String t is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strin... | s=input()
if s==s[::-1]:
print("YES")
else:
news=""
c=0
start=0
end=len(s)
for i in range(len(s)):
if s[i]!="0":
start=i
break
for i in range(len(s)-1,-1,-1):
if s[i]!="0":
end=i+1
break
news=s[start:end]
if news==news[:... | {
"input": [
"2010200\n",
"320\n",
"131\n",
"11001\n",
"100101\n",
"99\n",
"33003\n",
"999999999\n",
"21002\n",
"1201\n",
"20010002\n",
"999999998\n",
"1101\n",
"2011\n",
"98809\n",
"1021\n",
"1000000000\n",
"11010\n",
"10110\n",
"1010110... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String t is called a palindrome, if it reads the same... |
888_E. Maximum Subsequence_25069 | You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first l... | import bisect
import array
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a1,a2=array.array('L'),array.array('L')
n1=n//2
def sums1(i,sum=0):
if i==n1:
a1.append(sum)
else:
sums1(i+1,(sum+a[i])%m)
sums1(i+1,sum)
def sums2(i,sum=0):
if i==n:
a2.a... | {
"input": [
"3 20\n199 41 299\n",
"4 4\n5 2 4 1\n",
"4 1\n435 124 324 2\n",
"5 1000\n38361 75847 14913 11499 8297\n",
"5 10\n47 100 49 2 56\n",
"10 1000\n16140 63909 7177 99953 35627 40994 29288 7324 44476 36738\n",
"35 1000000000\n513 9778 5859 8149 297 7965 7152 917 243 4353 7248 4913 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a wa... |
911_C. Three Garlands_25073 | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th secon... | k1, k2, k3 = map(int, input().split())
ans = 'NO'
if [k1, k2, k3].count(2) >= 2:
ans = 'YES'
if 1 in [k1, k2, k3]:
ans = 'YES'
if [k1, k2, k3].count(3) >= 3:
ans = 'YES'
if 2 in [k1, k2, k3] and [k1, k2, k3].count(4) == 2:
ans = 'YES'
print(ans)
| {
"input": [
"2 2 3\n",
"4 2 3\n",
"6 4 7\n",
"3 2 3\n",
"1 1 3\n",
"1 1 1\n",
"2 2 7\n",
"2 4 8\n",
"2 5 2\n",
"2 3 5\n",
"3 3 4\n",
"3 4 5\n",
"4 2 4\n",
"1500 1500 1500\n",
"2 100 100\n",
"4 4 2\n",
"228 2 2\n",
"2 3 14\n",
"5 2 2\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switch... |
933_A. A Twisty Movement_25077 | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | # -*- coding: utf-8 -*-
# Watashi wa ARUGONEKO wo tsukatteru. [algoneko.github.io]
# I hate python --RedCat
from math import *
import re
n = int(input())
a = list(map(int, input().split()))
d1, d2, d3, d4 = [0]*n, [0]*n, [0]*n, [0]*n
d1[0] = d3[0] = (1 if a[0] == 1 else 0)
d2[0] = d4[0] = (1 if a[0] == 2 else 0)
for i... | {
"input": [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n",
"1\n2\n",
"3\n1 2 1\n",
"2\n1 2\n",
"200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to re... |
95_C. Volleyball_25081 | Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can... | import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wr... | {
"input": [
"4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7\n",
"15 29\n6 6\n7 12 7\n11 3 7\n4 5 18\n13 9 18\n3 8 12\n6 1 7\n4 1 4\n12 5 18\n10 8 15\n2 10 1\n9 7 11\n2 4 10\n2 14 3\n15 12 14\n1 13 8\n11 4 1\n15 11 2\n1 5 9\n5 2 5\n9 10 5\n15 2 17\n11 5 1\n14 15 14\n10 1 16\n15 9 2\n13 15 6\n13 5 1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, ... |
987_A. Infinity Gauntlet_25085 | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
* the Space Gem of blue color,
* the Soul Gem of orange color,
* the Reality Gem of red color,
* the Mind Gem of yellow color.
... | stone = {'purple': 'Power', 'green': 'Time', 'blue': 'Space','orange': 'Soul','red': 'Reality','yellow': 'Mind'}
color = {}
n = int(input())
for _ in range(0, n):
c = input()
if c in stone:
del stone[c]
print(6-n)
print('\n'.join(stone.values()))
| {
"input": [
"0\n",
"4\nred\npurple\nyellow\norange\n",
"4\nblue\norange\nyellow\ngreen\n",
"1\norange\n",
"2\norange\ngreen\n",
"4\ngreen\nyellow\norange\npurple\n",
"3\norange\nyellow\ngreen\n",
"3\npurple\ngreen\nblue\n",
"1\nred\n",
"0\n",
"1\nblue\n",
"3\nblue\ngre... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
* the Power Gem of purple color,
* the Time Gem of green color,
*... |
p02587 AtCoder Beginner Contest 175 - Making Palindrome_25098 | We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N.
Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice.
The cost of using the string S_i once is C_i, and t... | from collections import defaultdict
from heapq import heappush, heappop, heapify
def main():
N = int(input())
SC = []
SCrev = []
for _ in range(N):
s, c = input().split()
c = int(c)
SC.append((s, c))
SCrev.append((s[::-1], c))
dist = defaultdict(lambda: 10**18)
q ... | {
"input": [
"2\nabc 1\nab 2",
"4\nab 5\ncba 3\na 12\nab 10",
"2\nabcab 5\ncba 3",
"3\nba 3\nabc 4\ncbaa 5",
"2\nabc 1\nab 0",
"4\nba 5\ncba 3\na 12\nab 10",
"2\nabcbb 5\ncba 3",
"3\nbb 3\nabc 4\ncbaa 5",
"2\nabc 1\nba 0",
"2\nabcbb 5\ncba 4",
"2\nabcbb 5\ncba 1",
"2\na... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N.
Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same strin... |
p02718 AtCoder Beginner Contest 161 - Popular Vote_25102 | We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \... | n,m=map(int,input().split())
a=list(map(int,input().split()))
c=len([i for i in a if i>=sum(a)/(4*m)])
print("Yes" if c>=m else "No") | {
"input": [
"4 1\n5 4 2 1",
"12 3\n4 56 78 901 2 345 67 890 123 45 6 789",
"3 2\n380 19 1",
"4 1\n5 4 0 1",
"3 2\n519 19 1",
"12 3\n4 56 78 901 2 345 67 890 123 45 3 789",
"3 1\n5 4 0 1",
"3 2\n39 19 1",
"3 2\n39 14 1",
"3 2\n39 18 1",
"3 1\n39 18 1",
"3 1\n39 16 1",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than... |
p02847 AtCoder Beginner Contest 146 - Can't Wait for Holiday_25106 | Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`,... | s=input()
A=["","SAT","FRI","THU","WED","TUE","MON","SUN"]
print(A.index(s)) | {
"input": [
"SUN",
"SAT"
],
"output": [
"7",
"1"
]
} | 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 representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Sat... |
p02984 AtCoder Beginner Contest 133 - Rain Flows into Dams_25110 | There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.
Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).
When Mountain i (1 \leq i \l... | n = int(input())
a = list(map(int,input().split()))
ans = [0] * n
ans[0] = sum(a) - sum(a[1::2])*2
for i in range(1,n):
ans[i] = a[i-1]*2 - ans[i-1]
print(' '.join(map(str,ans))) | {
"input": [
"3\n1000000000 1000000000 0",
"5\n3 8 7 5 5",
"3\n2 2 4",
"3\n1000000000 1000100000 0",
"3\n2 0 4",
"3\n1000000000 1001100000 0",
"3\n1000000000 1011100000 0",
"3\n1000000000 1011101000 0",
"3\n1010000000 1011101000 0",
"3\n1010100000 1011101000 0",
"3\n1000000... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.
Between these mountains, there are N dams, called Dam 1, Dam... |
p03126 AtCoder Beginner Contest 118 - Foods Loved by Everyone_25114 | Katsusando loves omelette rice.
Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.
The i-th person answered that he/she only l... | N,M=map(int,input().split())
a=[0]*(M+1)
for i in range(N):
l=list(map(int,input().split()))
for j in range(l[0]):
a[l[j+1]]+=1
print(a.count(N))
| {
"input": [
"3 4\n2 1 3\n3 1 2 3\n2 3 2",
"1 30\n3 5 10 30",
"5 5\n4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4",
"1 30\n3 2 10 30",
"3 7\n2 1 3\n3 1 2 3\n2 3 2",
"3 7\n2 1 3\n3 1 2 3\n2 3 1",
"3 7\n2 1 3\n3 0 2 3\n2 5 1",
"1 30\n3 4 10 30",
"1 30\n5 4 10 30",
"1 30\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Katsusando loves omelette rice.
Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
To prove that hypothesis, he con... |
p03268 AtCoder Regular Contest 102 - Triangular Relationship_25118 | You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same.
Constraints
* 1 \leq N,K \leq 2\times 10^5
* N and K are integers.
Input
Input is given from ... | n,k = map(int, input().split())
ans=(n//k)**3
if k%2==0:
ans+=((n+k//2)//k)**3
print(ans) | {
"input": [
"31415 9265",
"3 2",
"35897 932",
"5 3",
"31415 12506",
"35897 446",
"4 3",
"2970 12506",
"35897 490",
"35897 92",
"62976 92",
"101525 92",
"101525 162",
"50082 162",
"53556 162",
"462 366",
"37826 162",
"462 198",
"37826 236",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does ma... |
p03426 AtCoder Beginner Contest 089 - Practical Skill Test_25122 | We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.
You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by... | h,w,d = map(int,input().split())
a = [0]*h
for i in range(h):
a[i] = list(map(int,input().split()))
num = [[] for i in range(w*h+1)]
for i in range(h):
for j in range(w):
num[a[i][j]].append([i,j])
s = [0]*(h*w+1)
for i in range(1,h*w-d+1):
s[d+i] = s[i] + abs(num[d+i][0][0]-num[i][0][0]) + abs(num[... | {
"input": [
"3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8",
"4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 2\n2 2",
"5 5 4\n13 25 7 15 17\n16 22 20 2 9\n14 11 12 1 19\n10 6 23 8 18\n3 21 5 24 4\n3\n13 13\n2 10\n13 13",
"4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 1\n2 2",
"5 5 4\n13 25 7 15 17\n16 22 20 2 9\n14 11 12 1 19\n10 6 23 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid,... |
p03583 Tenka1 Programmer Contest - 4/N_25126 | You are given an integer N.
Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.
If there are multiple solutions, any of them will be accepted.
Constraints
* It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.
Inputs
Input is given from Stan... | a = int(input())
for b in range(1,3501):
for c in range(1,3501):
if ((4*b*c)/a)-c-b == 0:
continue
k = b*c/(((4*b*c)/a)-c-b)
if k <= 0:
continue
if k == int(k):
print(b,c,int(k))
exit() | {
"input": [
"2",
"4664",
"3485",
"3",
"3492",
"6",
"3999",
"10",
"12",
"4",
"4141",
"8",
"7",
"22",
"5",
"9",
"35",
"16",
"11",
"31",
"17",
"23",
"33",
"46",
"59",
"92",
"123",
"39",
"30",
"14",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer N.
Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.
If there are multiple solutions, any of them will be accepted.
Constraint... |
p03740 AtCoder Beginner Contest 059 - Alice&Brown_25130 | Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the... | print('ABlriocwen'[-2<eval(input().replace(' ','-'))<2::2]) | {
"input": [
"0 0",
"5 0",
"2 1",
"4 8",
"1 0",
"6 0",
"2 0",
"1 8",
"6 -1",
"4 0",
"1 5",
"7 -1",
"3 0",
"1 10",
"7 -2",
"3 -1",
"0 10",
"13 -1",
"4 -1",
"-1 10",
"18 -1",
"-1 14",
"9 -1",
"-1 7",
"14 -1",
"0 7",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternate... |
p03902 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi the Magician_25133 | Takahashi is a magician. He can cast a spell on an integer sequence (a_1,a_2,...,a_M) with M terms, to turn it into another sequence (s_1,s_2,...,s_M), where s_i is the sum of the first i terms in the original sequence.
One day, he received N integer sequences, each with M terms, and named those sequences A_1,A_2,...,... | import sys
readline = sys.stdin.readline
from math import log2
from itertools import accumulate
N, M = map(int, readline().split())
A = [list(map(int, readline().split())) for i in range(N)]
B = max(max(Ai) for Ai in A)
if M == 1:
if N == 1 or all(A[i][0] < A[i+1][0] for i in range(N-1)):
print("0")
els... | {
"input": [
"5 5\n2 6 5 6 9\n2 6 4 9 10\n2 6 8 6 7\n2 1 7 3 8\n2 1 4 8 3",
"3 3\n3 2 10\n10 5 4\n9 1 9",
"3 3\n2 3 1\n2 1 2\n2 6 3",
"5 5\n2 6 5 6 9\n2 6 4 9 10\n2 6 8 6 7\n0 1 7 3 8\n2 1 4 8 3",
"3 3\n2 3 1\n2 1 2\n3 6 3",
"3 3\n2 3 1\n2 0 2\n3 6 3",
"5 5\n2 6 5 6 9\n2 6 4 9 10\n2 6 8 6 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is a magician. He can cast a spell on an integer sequence (a_1,a_2,...,a_M) with M terms, to turn it into another sequence (s_1,s_2,...,s_M), where s_i is the sum of the fir... |
p00008 Sum of 4 Integers_25137 | Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality:
a + b + c + d = n
For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
Input
... | import sys
answer = [0] * 51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
answer[a + b + c + d] += 1
for line in sys.stdin:
try:
print(answer[int(line)])
except:
break | {
"input": [
"35\n1",
"35\n2",
"35\n3",
"35\n4",
"35\n8",
"35\n15",
"35\n26",
"35\n0",
"35\n-1",
"35\n13",
"35\n6",
"35\n29",
"35\n22",
"35\n5",
"35\n9",
"35\n12",
"35\n11",
"35\n16",
"35\n19",
"35\n18",
"35\n35",
"35\n-2",
"3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality:
a + b + c + d = n
For exa... |
p00140 Bus Line_25141 | There is a bus route as shown in Figure 1. There are 10 stops, each numbered 0-9. The bus turns back at stop 0, but the other side is a circulation route, which circulates in the order of 5 → 6 → 7 → 8 → 9 → 5 as shown in the figure.
<image>
For this bus route, create a program that inputs the stop to get on and the... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0140
"""
import sys
from sys import stdin
input = stdin.readline
def solve(start, goal):
path = [] # ?????????n???????????????????????????????????????
# ????????????????????¨????????´?????¨???????????????... | {
"input": [
"2\n2 4\n4 2",
"2\n2 5\n4 2",
"2\n2 1\n4 2",
"2\n2 0\n4 2",
"2\n1 4\n4 2",
"2\n2 0\n4 0",
"2\n2 0\n4 1",
"2\n1 8\n4 2",
"2\n2 0\n3 0",
"2\n2 0\n1 1",
"2\n1 8\n4 0",
"2\n4 0\n1 1",
"2\n1 8\n8 0",
"2\n2 0\n2 1",
"2\n1 2\n8 0",
"2\n1 0\n2 1",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a bus route as shown in Figure 1. There are 10 stops, each numbered 0-9. The bus turns back at stop 0, but the other side is a circulation route, which circulates in the orde... |
p00273 Admission Fee_25145 | Aiz Onsen has a bathhouse and a pool. To use the bathhouse, you need to buy a bathing ticket, and to use the pool, you need to buy a pool ticket. Prices for these tickets may vary from day to day. In addition, Aiz Onsen has the following rules.
* Tickets are valid only once on the day of purchase.
* If you buy 5 or mo... | n=int(input())
for i in range(n):
a,b,c,d=map(int,input().split())
q,w,e,r,g=0,0,0,0,0
q,w=a*c,b*d
e=q+w
f=[]
f.append(e)
if c<5 and d<2:
g=(a*5+b*2)*0.8
f.append(g)
if c<5 and d>=2:
g=(a*5+b*d)*0.8
f.append(g)
if c>=5 and d<2:
g=(a*c+b*2)*0.8
... | {
"input": [
"2\n100 100 1 1\n1000 500 5 2",
"2\n100 000 1 1\n1000 500 5 2",
"2\n100 000 1 1\n1010 500 5 2",
"2\n110 000 1 1\n1010 500 5 2",
"2\n110 000 1 2\n1010 500 10 2",
"2\n110 000 1 2\n1010 500 17 2",
"2\n110 000 2 4\n1010 500 17 2",
"2\n110 000 2 4\n0010 500 17 2",
"2\n110 0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Aiz Onsen has a bathhouse and a pool. To use the bathhouse, you need to buy a bathing ticket, and to use the pool, you need to buy a pool ticket. Prices for these tickets may vary fro... |
p00461 IOIOI_25149 | problem
For the integer n (1 ≤ n), let Pn be a string of n + 1 I's and n O's starting with I and alternating, where I and O are the uppercase Ai and O, respectively. is there.
P1 | IOI
--- | ---
P2 | IOIOI
P3 | IOIOIOI
|. |
|. |
|. |
Pn | IOIOIO ... OI (n O)
Figure 1-1 Character string considered in this question... | # -*- coding: utf-8 -*-
"""
IOIOI
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0538
"""
import sys
import re
def solve(n, s):
ans = 0
p = '(I(?:OI){' + str(n) + ',})'
for f in re.findall(p, s):
repeat = len(f) // 2
if repeat >= n:
ans += (repeat - n + 1)
return ... | {
"input": [
"1\n13\nOOIOIOIOIIOII\n2\n13\nOOIOIOIOIIOII\n0",
"1\n13\nOIIOIOIOIIOIO\n2\n13\nOOIOIOIOIIOII\n0",
"1\n13\nOOIOIOIOIIOII\n3\n13\nOOIOIOIOIIOII\n0",
"1\n25\nOOIOIOIOIIOII\n3\n13\nOOJOIOIOIIOIJ\n0",
"1\n25\nOIIOIOIOIIOIO\n0\n13\nOOJOIOIOIIOIJ\n0",
"1\n25\nOOIOIOIOIIOII\n1\n13\nJIOIIO... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
For the integer n (1 ≤ n), let Pn be a string of n + 1 I's and n O's starting with I and alternating, where I and O are the uppercase Ai and O, respectively. is there.
P1 |... |
p00927 Space Golf_25155 | Example
Input
100 1 0
50 100
Output
14.57738 | import math
d, n, b = map(int, input().split())
O = [list(map(int, input().split())) for i in range(n)]
def solve(b):
l = d / (b+1)
idx = 0
vx2 = 10**9
for i in range(b+1):
while idx < n and O[idx][0]*(b+1) <= d*(i+1):
p, h = O[idx]
p -= l*i
vx2 = min(vx2, p*... | {
"input": [
"100 1 0\n50 100",
"100 1 0\n28 100",
"101 1 0\n28 100",
"100 1 0\n50 101",
"100 1 0\n4 100",
"100 1 0\n89 101",
"100 1 0\n50 001",
"111 1 0\n28 100",
"111 1 0\n28 000",
"100 1 0\n3 100",
"100 1 0\n3 101",
"101 1 0\n3 101",
"101 1 0\n3 111",
"101 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
100 1 0
50 100
Output
14.57738
### Input:
100 1 0
50 100
### Output:
14.57738
### Input:
100 1 0
28 100
### Output:
16.065362523637
### Code:
import math
d, n, ... |
p01060 Product Sale Lines_25157 | Problem
Uniqlo Uzuki and Rin Meguro are coming to SEARIGHT LIVE FES for sale. As shown in the figure below, the product sales line consists of two lines, with W people in the horizontal direction and H people in the vertical direction, forming a U-shape. The person at the top of the line is removed from the line after... | w,h = map(int, input().split())
n = int(input())
p = list(map(int, input().split()))
u = m = cnt = 0
for i in range(n):
if p[i] == 0:
u += 1
else:
m += 1
if u <= w-2:
if u == m:
cnt += 1
elif w <= u <= w+h-3:
if u == m+2:
cnt += 1
elif h+h-1 <=... | {
"input": [
"11 11\n5\n0 0 0 0 0",
"11 11\n5\n0 0 1 1 1",
"11 11\n5\n0 1 0 0 0",
"12 11\n5\n0 0 0 0 0",
"11 11\n5\n1 0 0 1 1",
"11 8\n5\n0 1 0 0 0",
"11 14\n5\n0 1 0 0 0",
"0 14\n5\n0 1 0 0 0",
"0 25\n5\n0 1 0 0 0",
"11 11\n5\n1 0 1 1 1",
"11 11\n8\n0 1 0 0 0",
"11 19\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Uniqlo Uzuki and Rin Meguro are coming to SEARIGHT LIVE FES for sale. As shown in the figure below, the product sales line consists of two lines, with W people in the horizon... |
p01497 Bubble Puzzle_25163 | A browser-based puzzle game called "Bubble Puzzle" is now popular on the Internet.
The puzzle is played on a 4 × 4 grid, and initially there are several bubbles in the grid squares. Each bubble has a state expressed by a positive integer, and the state changes when the bubble gets stimulated. You can stimulate a bubbl... | from functools import reduce
import operator
def solve():
L = 4; M = 5
MP = [list(map(int, input().split())) for i in range(L)]
memo = {(0,)*(L**2): 0}
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
INF = 10
def dfs(k, R):
key = reduce(operator.add, map(tuple, R))
if key in memo:
... | {
"input": [
"2 4 4 1\n2 4 4 1\n2 4 4 1\n2 4 4 1",
"4 4 4 4\n4 4 4 4\n4 4 4 4\n4 4 4 4",
"2 4 3 4\n2 2 4 4\n3 3 2 2\n2 3 3 3",
"2 4 4 1\n2 4 4 1\n2 4 4 1\n0 4 4 1",
"4 4 4 4\n4 4 4 4\n4 4 4 4\n3 4 4 4",
"2 4 3 4\n2 2 4 4\n3 3 2 2\n0 3 3 3",
"2 4 3 4\n2 2 4 4\n3 3 2 2\n2 0 3 3",
"2 4 3 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A browser-based puzzle game called "Bubble Puzzle" is now popular on the Internet.
The puzzle is played on a 4 × 4 grid, and initially there are several bubbles in the grid squares. ... |
p01810 Jail_25168 | prison
There are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, ....
Do the following N times:
* Release the 0th prisoner and execute the k, 2k, 3k, ... th prisoners.
* Then renumber the remaining prisoners. At this time, the prisoners with the smallest original numbers are numbered ... | #!/usr/bin/env python3
n, k = map(int, input().split())
a = 0
for i in range(n-1):
a = a * k // (k - 1) + 1
print(a) | {
"input": [
"4 2",
"5 2",
"7 2",
"10 2",
"2 2",
"1 2",
"4 3",
"8 2",
"6 2",
"7 4",
"3 3",
"14 4",
"4 15",
"18 4",
"8 15",
"17 4",
"17 3",
"17 2",
"9 53",
"7 27",
"10 4",
"7 3",
"5 4",
"14 2",
"19 2",
"17 7",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
prison
There are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, ....
Do the following N times:
* Release the 0th prisoner and execute the k, 2k, 3k... |
p01945 Star in Parentheses_25171 | You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted.
Any balanced parentheses can be constructed using the following rules:
* An empty string is balanced.
* Concatenation of two balanced parentheses is balanced.
* If $T$ is balanced parentheses, concatenation of '(', $T$, and ')'... | S = list(input())
S_l = len(S)
n=0
l = []
r = []
f_l, f_r = 0,0
for n in range(S.index('*')):
if S[n]== '(':
f_l += 1
elif S[n]== ')':
f_l -= 1
for n in range(S_l - S.index('*')):
if S[S_l-n-1] == ')':
f_r += 1
elif S[S_l-n-1]== '(':
f_r -= 1
print(min(f_r, f_l))
| {
"input": [
"*",
"((((((((((*))))))))))",
"((*)())",
"(*)",
"()*()",
"(()())*",
"((*)(()",
"(*)())(",
"((()(*(",
"((((((((((*))))))()))",
"*))()((",
"(((((((()(*))))))()))",
"(((((((()()*)))))()()",
"((((*()",
"((()(((()(*)))))())))",
"(((((*)",
"((... | 6AIZU | 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$, which is balanced parentheses with a star symbol '*' inserted.
Any balanced parentheses can be constructed using the following rules:
* An empty string i... |
p02378 Bipartite Matching_25176 | A bipartite graph G = (V, E) is a graph in which the vertex set V can be divided into two disjoint subsets X and Y such that every edge e ∈ E has one end point in X and the other end point in Y.
A matching M is a subset of edges such that each node in V appears in at most one edge in M.
Given a bipartite graph, find ... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
output:
3
"""
import sys
def generate_adj_table(_edges):
for edge in _edges:
vx, vy = map(int, edge)
init_adj_table[vx].add(vy)
return init_adj_table
def graph_dfs(current, matching, visited):
for ... | {
"input": [
"3 4 6\n0 0\n0 2\n0 3\n1 1\n2 1\n2 3",
"3 4 6\n0 0\n0 0\n0 3\n1 1\n2 1\n2 3",
"3 7 2\n1 0\n0 0\n0 3\n0 1\n1 1\n2 3",
"3 4 5\n0 0\n0 2\n0 3\n1 1\n2 1\n2 0",
"6 7 10\n2 2\n0 0\n0 1\n1 0\n1 0\n3 5",
"3 6 0\n2 0\n1 0\n0 3\n0 1\n0 1\n6 1",
"3 4 6\n0 0\n0 0\n0 3\n1 1\n0 1\n2 3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A bipartite graph G = (V, E) is a graph in which the vertex set V can be divided into two disjoint subsets X and Y such that every edge e ∈ E has one end point in X and the other end ... |
1015_D. Walking Between Houses_25186 | There are n houses in a row. They are numbered from 1 to n in order from left to right. Initially you are in the house 1.
You have to perform k moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current h... | import math
def main():
n, k, s = [int(x) for x in input().split()]
if (n - 1) * k < s:
print('NO')
return
if k > s:
print('NO')
return
curr = 1
print('YES')
while s > 0:
d = min(n - 1, s - k + 1)
s -= d
k -= 1
if curr + d <= n... | {
"input": [
"10 2 15\n",
"10 9 82\n",
"10 9 81\n",
"10 9 45\n",
"10 50 449\n",
"2 200000 199999\n",
"6 6 16\n",
"4 15 4071505\n",
"3 7 7\n",
"4 5 8\n",
"1000000000 1 199979000100000\n",
"1000000000 1 999999998\n",
"4 125 994071505\n",
"1000000000 10 8999999954\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n houses in a row. They are numbered from 1 to n in order from left to right. Initially you are in the house 1.
You have to perform k moves to other house. In one move you ... |
1039_B. Subway Pursuit_25190 | This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontr... | import sys,random
n,k=map(int,input().split())
l=1
r=n
count=0
while True:
if l+200<r:
try1=(l+r)//2
print(l,try1,flush=True)
s=input()
if s=='Yes':
r=min(try1+10,n)
l=max(1,l-10)
else:
l=max(1,try1-10)
r=min(n,r+10)
else:
guess=random.randint(l,r)
print(guess,gue... | {
"input": [
"10 2\n\nYes\n\nNo\n\nYes\n\nYes\n",
"1 2\n\nYes\n\nNo\n\nYes\n\nseY\n",
"1 4\n\nseY\n\npN\n\nYes\n\nsdY\n",
"1 4\n\nYes\n\nNo\n\nYes\n\nseY\n",
"1 4\n\nYes\n\nNo\n\nseY\n\nseY\n",
"1 4\n\nYes\n\noN\n\nseY\n\nseY\n",
"1 4\n\nYes\n\noN\n\nYes\n\nseY\n",
"1 4\n\nYes\n\npN\n\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Arti... |
1061_D. TV Shows_25194 | There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive.
You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you... | from bisect import bisect_right
n, x, y = map(int, input().split(' '))
s=[0]*n
e=[0]*n
v=[0]*n
c=0
for i in range(n):
s[i],e[i]=map(int, input().split(' '))
c+=x+(e[i]-s[i])*y
s.sort()
e.sort()
for i in range(n-2,-1,-1):
k=bisect_right(s,e[i])
while (k < n) and (v[k]==1) and (s[k]-e[i]) * y < x :
... | {
"input": [
"6 3 2\n8 20\n6 22\n4 15\n20 28\n17 25\n20 27\n",
"5 4 3\n1 2\n4 10\n2 4\n10 11\n5 9\n",
"2 1000000000 2\n1 2\n2 3\n",
"2 2 1\n24 25\n18 23\n",
"5 9 5\n25 27\n23 24\n9 29\n25 30\n20 20\n",
"11 4 3\n26 29\n5 28\n20 27\n12 16\n27 27\n25 28\n20 25\n9 15\n18 21\n9 20\n6 10\n",
"20... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclu... |
1102_E. Monotonic Renumeration_25200 | You are given an array a consisting of n integers. Let's denote monotonic renumeration of array a as an array b consisting of n integers such that all of the following conditions are met:
* b_1 = 0;
* for every pair of indices i and j such that 1 ≤ i, j ≤ n, if a_i = a_j, then b_i = b_j (note that if a_i ≠ a_j, i... | import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
# sys.setrecursionlimit(100000)
# ^^^TAKE CARE FOR MEMORY LIMIT^^^
import random
def main():
pass
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
de... | {
"input": [
"4\n1 3 3 7\n",
"5\n1 2 1 2 3\n",
"2\n100 1\n",
"100\n23 39 85 46 97 72 41 70 37 18 8 40 33 61 12 79 51 78 61 66 85 97 78 14 70 47 100 40 15 40 61 52 19 30 14 91 82 56 10 6 68 24 97 61 31 78 18 45 88 6 37 38 51 86 37 42 58 30 79 56 50 14 61 18 13 20 57 3 93 15 24 74 32 21 71 93 2 66 25 75... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integers. Let's denote monotonic renumeration of array a as an array b consisting of n integers such that all of the following conditions are ... |
1130_D2. Toy Train_25204 | Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte... | n, m = map(int, input().split())
def dist(a, b):
return (n + b - a) % n
def main():
inp1 = [0] * (n + 1)
inp2 = [n] * (n + 1)
for _ in range(m):
a, b = map(int, input().split())
inp1[a] += 1
inp2[a] = min(inp2[a], dist(a, b))
inp = tuple((((r1 - 1) * n + r2) for r1, r2 in... | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"10 8\n5 2\n6 5\n3 8\n9 10\n4 3\n9 5\n2 6\n9 10\n",
"10 20\n6 10\n2 3\n10 7\n8 10\n4 7\n6 2\n7 10\n7 4\n10 3\n9 3\n4 8\n1 7\n2 10\n6 9\n3 6\n6 3\n10 2\n10 7\n10 5\n4 5\n",
"5000 1\n4008 1126\n",
"10 4\n8 6\n1 7\n6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a t... |
1151_A. Maxim and Biology_25208 | Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".
Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string s consisting of uppercase letters and length of a... | Answer = 'ACTG'
MIN = 10 ** 6
input()
X = input()
for i in range(0, len(X) - 3):
Temp = X[i:i + 4]
Index, Count = 0, 0
for j in Temp:
tmp = 0
if ord(j) > ord(Answer[Index]):
tmp += 26 + ord(Answer[Index]) - ord(j)
else:
tmp += 26 + ord(j) - ord(Answer[Index])
... | {
"input": [
"4\nZCTH\n",
"5\nZDATG\n",
"6\nAFBAKC\n",
"50\nROWGGKNUITVHOBMKZXOZNBZMQGSFERNCZDFKLRBCFVVDXJEFLP\n",
"33\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\n",
"39\nIHESTJHHSZRSHNUSPGMHDTKOJFEFLAUDXUEQWLO\n",
"5\nACTGA\n",
"50\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".
Maxim was ver... |
1190_C. Tokitsukaze and Duel_25213 | "Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping card... | n, k = map(int,input().split())
s= input()
fir0 = -1
last0 = -1
fir1 = -1
last1 = -1
for i in range(n):
if(s[i] == '0'):
if(fir0 == -1):
fir0 = i
last0 = i
else:
if(fir1 == -1):
fir1 = i
last1 = i
d0 = last0 - fir0
d1 = last1 - fir1
if(min(d0, d1) < k... | {
"input": [
"6 1\n010101\n",
"4 1\n0011\n",
"4 2\n0101\n",
"6 5\n010101\n",
"4 1\n1100\n",
"6 2\n000111\n",
"17 12\n00001110011001111\n",
"20 15\n01000010100101100001\n",
"10 6\n0001110111\n",
"10 7\n0011111011\n",
"5 3\n01101\n",
"1 1\n1\n",
"20 15\n11011101001111... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At ... |
1228_F. One Node is Gone_25218 | You have an integer n. Let's define following tree generation as McDic's generation:
1. Make a complete and full binary tree of 2^{n} - 1 vertices. Complete and full binary tree means a tree that exactly one vertex is a root, all leaves have the same depth (distance from the root), and all non-leaf nodes have exactl... | #!/usr/bin/python3
import array
import math
import os
import sys
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
def solve(N, M, G):
if N == 2:
return [0, 1]
degv = [s... | {
"input": [
"4\n1 2\n1 3\n2 4\n2 5\n3 6\n3 13\n3 14\n4 7\n4 8\n5 9\n5 10\n6 11\n6 12\n",
"2\n1 2\n",
"3\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n53 61\n35 53\n35 39\n34 53\n34 54\n34 62\n43 54\n23 43\n12 43\n1 54\n1 7\n1 57\n40 62\n30 40\n28 40\n4 62\n4 60\n4 45\n19 61\n19 36\n36 42\n36 52\n10 19\n10 48\n10 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have an integer n. Let's define following tree generation as McDic's generation:
1. Make a complete and full binary tree of 2^{n} - 1 vertices. Complete and full binary tree me... |
1293_D. Aroma's Search_25225 | [THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu)
[KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane,... | x,y,a,b,c,d,xs,ys,t,maxx = [0]*10
arr = []
#must run now
def abs(x):
if x < 0:
return 0 - x
return x
def max(x,y):
if x > y:
return x
return y
def dfs(idx,left,currx,curry,dir,cnt):
global arr,maxx
if dir == 0:
if idx < 0:
maxx = max(maxx,cnt)
return
else:
if abs(currx - arr[idx][0]) +... | {
"input": [
"1 1 2 3 1 0\n2 4 20\n",
"1 1 2 3 1 0\n2 2 1\n",
"1 1 2 3 1 0\n15 27 26\n",
"10000000000000000 10000000000000000 100 100 10000000000000000 10000000000000000\n10000000000000000 10000000000000000 10000000000000000\n",
"104297919 1 8 7 4511 8536\n104297915 1 1749847629985887\n",
"1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu)
[KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma Whi... |
1313_C2. Skyscrapers (hard version)_25229 | This is a harder version of the problem. In this version n ≤ 500 000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the compan... | import sys
input=sys.stdin.readline
n=int(input())
m=[int(i) for i in input().split()]
copy=m[:]
def maxsumchecker(arr):
stack,lr=[],[0]*(n)
for i in range(n):
while stack and stack[-1][1]>m[i]:
stack.pop()
if stack:
j=stack[-1][0]
lr[i]=lr[j]+(i-j)*m[i]
... | {
"input": [
"5\n1 2 3 2 1\n",
"3\n10 6 8\n",
"6\n1 3 4 3 5 4\n",
"7\n2 1 2 1 2 2 1\n",
"7\n5 2 4 2 4 1 1\n",
"100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is a harder version of the problem. In this version n ≤ 500 000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the const... |
1336_A. Linova and Kingdom_25233 | Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self... | {
"input": [
"7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n",
"4 1\n1 2\n1 3\n2 4\n",
"8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n",
"3 1\n1 2\n2 3\n",
"2 1\n1 2\n",
"20 7\n9 7\n3 7\n15 9\n1 3\n11 9\n18 7\n17 18\n20 1\n4 11\n2 11\n12 18\n8 18\n13 2\n19 2\n10 9\n6 13\n5 8\n14 1\n16 13\n",
"3 2\n1 2\n1 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as sh... |
1358_D. The Best Vacation_25237 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of d... | def sm(a, b):
val = (a + b) * (b - a + 1) // 2
return (val)
n, x = [int(x) for x in input().split()]
d = [int(x) for x in input().split()] * 2
mx, i, j, day, hug = 0, 0, 0, 0, 0
while(i < n):
if day + d[j] <= x:
day += d[j]
hug += sm(1, d[j])
j += 1
else:
mx = max(mx, h... | {
"input": [
"5 6\n4 2 3 1 3\n",
"3 6\n3 3 3\n",
"3 2\n1 3 1\n",
"2 179\n444 57\n",
"3 10\n5 8 1\n",
"10 6\n6 4 8 9 9 10 5 2 8 1\n",
"48 14\n1 1 1 1 1 6 1 1 1 1 1 1 3 3 1 1 1 1 1 2 2 2 1 1 1 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 5\n",
"6 1\n1 1 1 300 1 1\n",
"3 3\n1 1 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
Y... |
1399_E1. Weights Division (easy version)_25242 | Easy and hard versions are actually different problems, so we advise you to read both statements carefully.
You are given a weighted rooted tree, vertex 1 is the root of this tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last differ... | import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush,heappop,heapify
def add... | {
"input": [
"3\n3 20\n2 1 8\n3 1 7\n5 50\n1 3 100\n1 5 10\n2 3 123\n5 4 55\n2 100\n1 2 409\n",
"4\n4 18\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 1 7 2\n5 50\n1 3 100 1\n1 5 10 2\n2 3 123 2\n5 4 55 1\n2 100\n1 2 409 2\n",
"4\n4 22\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 1 7 2\n5 50\n1 3 100 1\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Easy and hard versions are actually different problems, so we advise you to read both statements carefully.
You are given a weighted rooted tree, vertex 1 is the root of this tree.
... |
1423_B. Valuable Paper_25245 | The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help all other world nations with this valuable resource. To do that, the country will send airplanes to other countries carrying toilet paper.
... | def hopcroft_karp(graph, n, m):
"""
Maximum bipartite matching using Hopcroft-Karp algorithm, running in O(|E| sqrt(|V|))
"""
assert (n == len(graph))
match1 = [-1] * n
match2 = [-1] * m
# Find a greedy match for possible speed up
for node in range(n):
for nei in graph[node]:
... | {
"input": [
"3 5\n1 2 1\n2 3 2\n3 3 3\n2 1 4\n2 2 5\n",
"5 9\n3 3 8\n2 4 7\n2 3 6\n2 1 9\n5 1 3\n1 1 6\n4 3 6\n4 1 2\n4 2 3\n",
"7 29\n6 2 627\n7 6 580\n6 6 624\n2 7 381\n4 6 894\n7 7 776\n3 5 929\n1 4 313\n7 5 699\n4 4 977\n3 2 586\n5 5 456\n4 5 13\n4 3 935\n3 7 946\n1 5 950\n2 1 597\n1 3 338\n3 4 844\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help al... |
1442_A. Extreme Subtraction_25249 | You are given an array a of n positive integers.
You can use the following operation as many times as you like: select any integer 1 ≤ k ≤ n and do one of two things:
* decrement by one k of the first elements of the array.
* decrement by one k of the last elements of the array.
For example, if n=5 and a=[3... | t = int(input())
for case in range(t):
n = int(input())
a = list(map(int, input().split()))
x = 0
low = a[0]
works = True
for i in range(1, n):
if a[i] < x:
print("NO")
works = False
break
next_low = low
if a[i] - x < low:
... | {
"input": [
"4\n3\n1 2 1\n5\n11 7 9 6 8\n5\n1 3 1 3 1\n4\n5 2 1 10\n",
"4\n3\n1 2 1\n5\n11 7 9 6 9\n5\n1 3 1 3 1\n4\n5 2 1 10\n",
"4\n3\n1 2 1\n5\n11 7 15 6 9\n5\n1 3 1 3 1\n4\n5 2 1 10\n",
"4\n3\n1 2 2\n5\n20 9 15 6 9\n5\n1 1 0 1 1\n4\n5 2 1 10\n",
"4\n3\n1 2 0\n5\n20 9 15 6 9\n5\n1 1 0 1 1\n4\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a of n positive integers.
You can use the following operation as many times as you like: select any integer 1 ≤ k ≤ n and do one of two things:
* decrement... |
1468_C. Berpizza_25253 | Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. W... | from sys import stdin
from heapq import *
Q = int(stdin.readline())
customer_id = 1
pq = []
first = 1
ans = []
served = set()
for q in range(Q):
args = stdin.readline().split()
if args[0] == "1":
heappush(pq, [-1*int(args[1]), customer_id])
customer_id += 1
elif args[0] == "2":
ans.append(first)
... | {
"input": [
"8\n1 8\n1 10\n1 6\n3\n2\n1 9\n2\n3\n",
"8\n1 103913\n3\n1 103913\n1 103913\n3\n1 103913\n1 103913\n2\n",
"6\n1 8\n1 10\n1 8\n3\n3\n3\n",
"2\n1 500000\n3\n",
"2\n1 10\n2\n",
"2\n1 6\n2\n",
"6\n1 8\n1 10\n1 5\n3\n3\n3\n",
"6\n1 8\n1 7\n1 8\n3\n3\n3\n",
"6\n1 8\n1 7\n1 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose w... |
1492_B. Card Deck_25257 | You have a deck of n cards, and you'd like to reorder it to a new one.
Each card has a value between 1 and n equal to p_i. All p_i are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. p_1 stands for the bottom card, p_n is the top card.
In each step you pick some integer k > 0, take the top ... | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
look = [0] * n
look[0] = a[0]
for i in range(1, n):
look[i] = max(look[i - 1], a[i])
j = n
ans = []
for i in range(n - 1, -1, -1):
if look[i] == a[i]:
ans.extend(a[i:j])
j = i
print(*ans) | {
"input": [
"4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n",
"4\n4\n2 1 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n",
"4\n4\n2 1 3 4\n5\n1 5 2 4 3\n6\n2 4 5 3 6 1\n1\n1\n"
],
"output": [
"\n4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n",
"4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n",
"4 3 2 1\n5 2 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a deck of n cards, and you'd like to reorder it to a new one.
Each card has a value between 1 and n equal to p_i. All p_i are pairwise distinct. Cards in a deck are numbered... |
1515_C. Phoenix and Towers_25261 | Phoenix has n blocks of height h_1, h_2, ..., h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than x.
P... | import heapq
import sys
input = iter(sys.stdin.read().splitlines()).__next__
def solve():
n, m, x = map(int, input().split())
h = list(map(int, input().split()))
# greedy; put on shortest tower
towers = [(0, i+1) for i in range(m)]
y = []
for h_i in h:
height, tower = heapq.heappop(tow... | {
"input": [
"2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n",
"2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n",
"2\n5 2 3\n1 2 3 1 4\n4 3 3\n1 1 2 3\n",
"2\n5 2 3\n1 2 3 1 2\n4 3 3\n2 1 2 3\n",
"2\n5 2 3\n1 2 3 1 2\n4 1 3\n1 1 2 0\n",
"2\n5 2 2\n1 2 3 2 2\n4 3 4\n1 1 2 0\n",
"2\n5 2 3\n1 2 2 1 2\n4 1 3\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Phoenix has n blocks of height h_1, h_2, ..., h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the su... |
1542_B. Plus and Multiply_25265 | There is an infinite set generated as follows:
* 1 is in this set.
* If x is in this set, x ⋅ a and x+b both are in this set.
For example, when a=3 and b=6, the five smallest elements of the set are:
* 1,
* 3 (1 is in this set, so 1⋅ a=3 is in this set),
* 7 (1 is in this set, so 1+b=7 is in this set... | import sys
input=sys.stdin.readline
t=int(input())
for i in range(t):
n,a,b=map(int,input().split())
if(a==1):
if((n-1)%b==0):
print('YES')
else:
print('NO')
continue;
t=1
flag=0
while(t<=n):
if((n-t)%b==0):
flag=1
b... | {
"input": [
"5\n24 3 5\n10 3 6\n2345 1 4\n19260817 394 485\n19260817 233 264\n",
"5\n24 3 5\n10 5 6\n2345 1 4\n19260817 394 485\n19260817 233 264\n",
"5\n24 3 1\n1 5 6\n2345 1 4\n35879228 394 859\n19260817 233 264\n",
"5\n24 3 5\n10 3 6\n2345 1 4\n19260817 394 485\n19260817 233 65\n",
"5\n24 3 5\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is an infinite set generated as follows:
* 1 is in this set.
* If x is in this set, x ⋅ a and x+b both are in this set.
For example, when a=3 and b=6, the five smalles... |
16_B. Burglar and Matches_25269 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task i... | """
read: 1:01
think: 2:46
code: 10:48
debug: --:--
status: TL
"""
n, m = map(int, input().split())
c = [list(map(int, input().split())) for i in range(m)]
c.sort(key=lambda x: x[1], reverse=True)
mx = 0
i = 0
while n > 0 and i < m:
add = min(n, c[i][0])
mx += add * c[i][1]
n -= add
i += 1
print(mx) | {
"input": [
"3 3\n1 3\n2 2\n3 1\n",
"7 3\n5 10\n2 5\n3 6\n",
"200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6\n",
"5 5\n2 9\n3 1\n2 1\n1 8\n2 8\n",
"1 1\n1 2\n",
"10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4\n",
"1 10\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each... |
18_E. Flag 2_25273 | According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different colours can be used.
* No two adjacent squares can be painted the same c... | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)]
dp = [[[m] * 26 for _ in range(26)] for _ in range(n)]
for i in range(n):
for j in... | {
"input": [
"3 3\naba\naba\nzzz\n",
"3 4\naaaa\nbbbb\ncccc\n",
"1 1\nq\n",
"1 500\nwljexjwjwsxhascgpyezfotqyieywzyzpnjzxqebroginhlpsvtbgmbckgqixkdveraxlgleieeagubywaacncxoouibbhwyxhjiczlymscsqlttecvundzjqtuizqwsjalmizgeekugacatlwhiiyaamjuiafmyzxadbxsgwhfawotawfxkpyzyoceiqfppituvaqmgfjinulkbkgpnibaefq... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following ... |
237_E. Build String_25279 | You desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on these strings. Each operation looks like that:
1. choose any non-empty string from strings s1, s2, ..., sn;
2. ch... | class Edge:
def __init__(self, to, cost, capacity, next_edge):
self.to = to
self.cost = cost
self.origin_cost = cost
self.capacity = capacity
self.next_edge = next_edge
self.pair = None
class MinCostMaxFlow:
def __init__(self, max_node):
self.null = Edge... | {
"input": [
"abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5\n",
"xyz\n4\naxx 8\nza 1\nefg 4\nt 1\n",
"bbaze\n3\nbzb 2\naeb 3\nba 10\n",
"jdnpjbbeenepebwudwujwppdppbjepenwb\n50\ndu 2\nnjdp 4\np 3\nj 1\nebnb 5\ndu 1\nup 1\nb 2\nujn 1\nednun 2\nepd 2\nwuune 3\nwdjbb 2\njwpn 2\nw 5\nuw 1\njjund 1\nuwwen 2\nedwjn... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string... |
262_C. Maxim and Discounts_25283 | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | m=int(input())
q=list(map(int,input().split()))
n=int(input())
a=list(map(int,input().split()))
q.sort()
a.sort()
j=n-1
i=0
ans=0
while j>=0:
for i in range(q[0]):
ans=ans+a[j]
j=j-1
if j<0:
break
j=j-2
print(ans) | {
"input": [
"1\n1\n7\n1 1 1 1 1 1 1\n",
"2\n2 3\n5\n50 50 50 50 50\n",
"1\n2\n4\n50 50 100 100\n",
"1\n1\n3\n3 1 1\n",
"1\n1\n1\n1\n",
"57\n3 13 20 17 18 18 17 2 17 8 20 2 11 12 11 14 4 20 9 20 14 19 20 4 4 8 8 18 17 16 18 10 4 7 9 8 10 8 20 4 11 8 12 16 16 4 11 12 16 1 6 14 11 12 19 8 20\n7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are index... |
334_A. Candy Bags_25292 | Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so th... | n=int(input())**2
k=0
for i in range(n//2):
print(i+1,n-i,end=' ')
k+=1
if k%2==0:
print() | {
"input": [
"2\n",
"68\n",
"12\n",
"88\n",
"44\n",
"86\n",
"28\n",
"4\n",
"64\n",
"48\n",
"54\n",
"96\n",
"66\n",
"18\n",
"100\n",
"10\n",
"58\n",
"80\n",
"6\n",
"8\n",
"62\n",
"76\n",
"74\n",
"26\n",
"78\n",
"36\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on... |
357_A. Group of Students_25296 | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 po... | m=int(input())
l=list(map(int,input().split()))
x,y=map(int,input().split())
theI=0
for i in range(len(l)):
first_sum=sum(l[0:i])
second_sum=sum(l[i:])
if (first_sum>=x and first_sum<=y) and (second_sum>=x and second_sum<=y):
theI=i+1
print(theI) | {
"input": [
"5\n3 4 3 2 1\n6 8\n",
"2\n2 5\n3 6\n",
"5\n0 3 3 4 2\n3 10\n",
"8\n1 1 1 1 2 2 2 1\n3 7\n",
"5\n2 2 2 2 2\n5 5\n",
"100\n86 19 100 37 9 49 97 9 70 51 14 31 47 53 76 65 10 40 4 92 2 79 22 70 85 58 73 96 89 91 41 88 70 31 53 33 22 51 10 56 90 39 70 38 86 15 94 63 82 19 7 65 22 83 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to... |
400_D. Dima and Bacteria_25301 | Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are nu... | #!/usr/bin/env python3
from sys import stdin
from bisect import bisect_left, bisect_right
INF = int(1e9)
def find(par, a):
if par[a] == a:
return a
par[a] = find(par, par[a])
return par[a]
def union(par, rnk, a, b):
a = find(par,a)
b = find(par,b)
if a==b:
return
... | {
"input": [
"3 2 2\n2 1\n1 2 0\n2 3 1\n",
"4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2\n",
"3 1 2\n2 1\n1 2 0\n",
"3 0 2\n1 2\n",
"4 2 3\n1 1 2\n1 3 0\n2 4 0\n",
"3 1 1\n3\n1 2 0\n",
"4 3 2\n3 1\n1 3 0\n1 4 1\n3 4 1\n",
"3 2 2\n2 1\n1 3 0\n2 3 0\n",
"73 29 73\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:
Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bac... |
427_E. Police Patrol_25305 | Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the mayor wants to build one.
As you are going to be in charge of this new pol... | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... | {
"input": [
"3 6\n1 2 3\n",
"1 369\n0\n",
"11 2\n-375 -108 1336 1453 1598 1892 2804 3732 4291 4588 4822\n",
"5 5\n-7 -6 -3 -1 1\n",
"2 1\n-1000000000 1000000000\n",
"6 1\n1 2 3 4 5 6\n",
"45 45\n-95 -94 -92 -83 -83 -76 -75 -74 -71 -70 -68 -44 -36 -31 -20 -18 -14 -11 -8 -7 -2 -2 -1 0 1 20 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the ro... |
450_C. Jzzhu and Chocolate_25309 | Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit choc... | #!/usr/bin/env python3
from itertools import *
def read_ints():
return map(int, input().strip().split())
n, m, k = read_ints()
def val(x, k, n, m):
Y = x+1
Z = k-x+1
if Y>0 and Z>0:
return (n//(x+1)) * (m//(k-x+1))
def sym(n, m, k):
x = min(n-1, k)
return val(x, k, n, m)
def test(n, m... | {
"input": [
"6 4 2\n",
"2 3 4\n",
"3 4 1\n",
"1000000000 10000000 10000000\n",
"646139320 570870045 9580639\n",
"458000643 743974603 152040411\n",
"999999999 1000000000 1\n",
"167035009 877444310 205461190\n",
"999999123 999999789 123456789\n",
"192837483 829387483 828374\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut s... |
472_D. Design Tutorial: Inverse the Problem_25312 | There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now ... | # Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
def main():
n=int(input())
arr=[]
for _ in range(n):
arr.append(list(map(int,input().split())))
if n==1:
if arr[0][0]==0:
print(... | {
"input": [
"2\n0 0\n0 0\n",
"3\n0 2 7\n2 0 9\n7 9 0\n",
"3\n0 2 2\n7 0 9\n7 9 0\n",
"3\n0 1 1\n1 0 1\n1 1 0\n",
"3\n1 2 7\n2 0 9\n7 9 0\n",
"2\n0 1000000000\n1000000000 0\n",
"1\n0\n",
"4\n0 3 7 6\n3 0 4 9\n7 4 0 2\n6 9 2 0\n",
"5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the... |
520_B. Two Buttons_25318 | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | n, m = [int(x) for x in input().split()]
s = 0
while(n < m):
s += 1 + (m % 2)
m = (m + m % 2) // 2
print(s + n - m)
| {
"input": [
"4 6\n",
"10 1\n",
"5001 10000\n",
"9097 9998\n",
"2 100\n",
"886 9383\n",
"4000 7997\n",
"1 8193\n",
"9912 1023\n",
"9967 9973\n",
"3 6\n",
"9102 9103\n",
"1918 10000\n",
"1 9999\n",
"1 8192\n",
"10 8722\n",
"100 99\n",
"99 100\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, dev... |
547_D. Mike and Fish_25321 | As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish.
<image>
He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such tha... | n = int(input())
edges = []
from collections import defaultdict
edges_dico = {}
count = defaultdict(int)
graph = defaultdict(lambda: defaultdict(int))
edges = []
for _ in range(n):
u, v = map(int, input().split())
count[u] += 1
count[-v] += 1
graph[u][-v] = 1
graph[-v][u] = 1
edges.append((u, -... | {
"input": [
"4\n1 1\n1 2\n2 1\n2 2\n",
"3\n1 1\n1 2\n2 1\n",
"2\n1 2\n2 3\n",
"1\n1 1\n",
"1\n1000 3434\n",
"10\n4126 18194\n143965 18194\n32687 18194\n118527 18194\n186573 18194\n97223 18194\n179697 18194\n175536 18194\n107767 18194\n127019 18194\n",
"9\n95316 68815\n95316 23738\n60801 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish.
<image>
He h... |
574_A. Bear and Elections_25325 | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he... | n=int(input())
a=list(map(int,input().split(" ")))
lim=a[0]
a[1:]=sorted(a[1:])
# print(a,a[-1])
t=0
while(a[0] <= a[-1]):
a[0]=a[0]+1
a[-1]=a[-1]-1
t+=1
a[1:]=sorted(a[1:])
print(t)
| {
"input": [
"2\n7 6\n",
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"100\n1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are n candidates, including Limak. We know how many c... |
595_D. Max and Bike_25329 | For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight lin... | from math import *
def solve(dist,spd):
z=floor(dist/(2*pi))
ans=z*2*pi/spd
dist=(dist-z*2*pi)/2
st,cur=3/spd,0
while st>=2e-7:
if spd*(cur+st)+sin(spd*(cur+st))<=dist:
cur+=st
st/=2
return ans+cur*2
n,rd,v=map(int,input().split())
for i in range(n):
l,r=map(int,i... | {
"input": [
"2 1 2\n1 10\n5 9\n",
"3 1 1\n1 2\n1 1000000000\n999999999 1000000000\n",
"1 9 2\n8 11\n",
"5 9 2\n15 18\n13 15\n9 16\n5 21\n10 11\n",
"3 1000000000 1\n1 2\n1 1000000000\n999999999 1000000000\n",
"3 1000000000 1000000000\n1 2\n1 1000000000\n999999999 1000000000\n",
"3 1 100000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year n c... |
617_A. Elephant_25333 | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ... |
if __name__ == '__main__':
c = int(input())
x = [5,4,3,2,1]
count = 0
while x!=[]:
m = max(x)
while c>=max(x):
c=c-m
count+=1
x.pop(0)
print (count)
| {
"input": [
"12\n",
"5\n",
"574\n",
"999997\n",
"46573\n",
"89\n",
"999994\n",
"94190\n",
"716\n",
"3\n",
"53\n",
"999991\n",
"1\n",
"999999\n",
"1000000\n",
"999990\n",
"999992\n",
"534204\n",
"999996\n",
"41\n",
"729\n",
"50287... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In o... |
637_B. Chat Order_25337 | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | n = int(input())
chat_list = []
names = set()
for i in range(n):
name = input()
if name not in names:
names.add(name)
chat_list.append(name)
x = len(names)
for i in chat_list[::-1]:
if i in names:
print(i)
names.remove(i)
x -= 1
if x == 0:
break
| {
"input": [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n",
"3\na\naa\naaa\n",
"9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz\n",
"30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat ri... |
665_B. Shopping_25341 | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the... | user,item,total=map(int,input().split())
items=list(map(int,input().split()))
to=0
for i in range(user):
a=list(map(int,input().split()))
for j in a:
to+=items.index(j)+1
items.pop(items.index(j))
items=[j]+items
print(to)
| {
"input": [
"2 2 5\n3 4 1 2 5\n1 5\n3 1\n",
"1 1 1\n1\n1\n",
"100 1 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n custom... |
689_E. Mike and Geometry Problem_25345 | Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that <image>). You are given two integers n and k and n closed intervals [li, ri] on OX axis an... | MOD = 10**9 + 7
from sys import stderr
def readints():
return [int(fld) for fld in input().strip().split()]
def combk(n, k, MOD=MOD, tbl=[]):
if len(tbl) < k:
tbl += [0] * k + [1]
while n >= len(tbl):
tbl.append(tbl[-1] * len(tbl) * pow(len(tbl) - k, MOD-2, MOD) % MOD)
return tbl[n]
... | {
"input": [
"3 3\n1 3\n1 3\n1 3\n",
"3 1\n1 2\n2 3\n3 4\n",
"3 2\n1 2\n1 3\n2 3\n",
"9 6\n-44 -29\n-11 85\n11 84\n-63 1\n75 89\n-37 61\n14 73\n78 88\n-22 -18\n",
"1 1\n45 70\n",
"2 2\n-93 -22\n12 72\n",
"1 1\n-35 -8\n",
"2 2\n26 99\n-56 40\n",
"1 1\n-79 -51\n",
"9 6\n-44 -29\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer poi... |
711_C. Coloring Trees_25349 | ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m dif... | import math
dp=[[[math.inf for i in range(105)] for i in range(105)] for i in range(105)]
#dp[x][y][z] denote index x , beauty y , using paint z
#dp[x][y][z] denotes cost of it
n,m,k=map(int,input().split())
k+=1
z=list(map(int,input().split()))
matrix=[]
for i in range(n):
ans=list(map(int,input().split()))
... | {
"input": [
"3 2 2\n2 1 2\n1 3\n2 4\n3 5\n",
"3 2 2\n0 0 0\n1 2\n3 4\n5 6\n",
"3 2 2\n2 0 0\n1 3\n2 4\n3 5\n",
"3 2 3\n2 1 2\n1 3\n2 4\n3 5\n",
"1 1 1\n0\n5\n",
"4 2 1\n0 0 0 0\n10 30000\n20000 1000000000\n1000000000 50000\n55 55\n",
"1 10 1\n0\n1 2 20 1000000000 41 23 39 55 44 1234567\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are number... |
732_C. Sanatorium_25353 | Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes ho... | mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
a,b,c=sorted(il(),reverse=True)
sm=0
if a!=b:
sm+=max(0,(a-b-1))+max(0,(a-c-1))
else:
sm+=max(... | {
"input": [
"1 0 0\n",
"3 2 1\n",
"1000000000000000000 0 1000000000000000000\n",
"1 1 1\n",
"1000000000000000000 1 1\n",
"999999999999999999 999999999999999999 999999999999999999\n",
"1 3 1\n",
"0 1000 0\n",
"117864695669097197 53280311324979856 171825292362519668\n",
"9999999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining... |
777_E. Hanoi Factory_25360 | Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang... | aux = [(9e9, 0, 0)]
n = int(input())
for i in range(n):
a, b, h = map(int, input().split())
aux.append((b, a, h)) #sort padrao eh pelo item 0 da tupla
aux.sort(reverse=True)
s, p = [0], [0] *(n + 1)
for i in range(1, n + 1):
while aux[s[-1]][1] >= aux[i][0]:
s.pop()
p[i] = p[s[-... | {
"input": [
"4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n",
"3\n1 5 1\n2 6 2\n3 7 3\n",
"15\n7 8 940377876\n5 26 602265950\n18 19 193066910\n23 24 754826087\n2 3 555140266\n6 25 830980693\n27 28 636793242\n20 21 809913904\n1 30 868457738\n10 17 698644057\n9 22 443624155\n13 16 941205435\n14 15 42481040\n4 29 30529542... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler ... |
965_C. Greedy Arkady_25378 | k people want to split n candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from 1 to k, and Arkady is the first of them. To split the candies, Arkady will choose an integer x and then give the first x candies to himself, the next x candies to the second ... | n, k, m, d = map(int, input().split())
ans = 0
for i in range(d + 1):
w = 0
if i > 0:
w = n // (k * i)
if w > m:
w = m
res = w * i
if n - k * i * w >= w and i + 1 <= d:
res += w
ans = max(ans, res)
w = n // (k * i + 1)
if w > m:
w = m
res = w * i
... | {
"input": [
"20 4 5 2\n",
"30 9 4 1\n",
"1000000000000000000 100000000000000000 1 1000\n",
"294 4 13 8\n",
"100 33 100 100\n",
"72 66 28 9\n",
"1000000000000000000 1000000000000000000 1000 1000\n",
"42 20 5 29\n",
"576460752303423488 576460752303423488 351082447248993993 1000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
k people want to split n candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from 1 to k, and Arkady is the first of th... |
992_C. Nastya and a Wardrobe_25382 | Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).
Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with ... | #------------------------template--------------------------#
import os
import sys
# from math import *
from collections import *
# from fractions import *
from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')... | {
"input": [
"2 0\n",
"2 1\n",
"3 2\n",
"904089164817530426 53747406876903279\n",
"860936792402722414 59551033597232946\n",
"316313018463929883 78259904441946885\n",
"1 3\n",
"216006901533424028 8313457244750219\n",
"883717267463724670 29585639347346605\n",
"1000000007 2\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as la... |
p02624 AtCoder Beginner Contest 172 - Sum of Divisors_25396 | For a positive integer X, let f(X) be the number of positive divisors of X.
Given a positive integer N, find \sum_{K=1}^N K\times f(K).
Constraints
* 1 \leq N \leq 10^7
Input
Input is given from Standard Input in the following format:
N
Output
Print the value \sum_{K=1}^N K\times f(K).
Examples
Input
4
O... | N=int(input())
ans=0
for i in range(1,N+1):
n=N//i
ans+=n*(n+1)*i//2
print(ans) | {
"input": [
"4",
"100",
"10000000",
"7",
"110",
"10000010",
"0",
"010",
"10010010",
"011",
"10011010",
"001",
"10111010",
"101",
"10111000",
"10011000",
"111",
"10001000",
"11001000",
"11000000",
"01001000",
"11001001",
"1100... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a positive integer X, let f(X) be the number of positive divisors of X.
Given a positive integer N, find \sum_{K=1}^N K\times f(K).
Constraints
* 1 \leq N \leq 10^7
Input
Inp... |
p02755 AtCoder Beginner Contest 158 - Tax Increase_25400 | Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded d... | A,B=map(int,input().split());v=max(A*25+1>>1,B*10);print(v if v<min(A*25+26>>1,B*10+10)else-1) | {
"input": [
"19 99",
"2 2",
"8 10",
"19 54",
"1 2",
"1 1",
"0 1",
"9 12",
"10 12",
"2 3",
"10 13",
"3 4",
"7 8",
"3 3",
"12 15",
"5 6",
"12 16",
"9 11",
"4 5",
"5 7",
"0 2",
"9 10",
"35 54",
"9 7",
"35 102",
"2 0"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectivel... |
p02890 AtCoder Beginner Contest 143 - Distinct Numbers_25404 | Takahashi has N cards. The i-th of these cards has an integer A_i written on it.
Takahashi will choose an integer K, and then repeat the following operation some number of times:
* Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)
For... | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
from collections import Counter
n=int(input())
A=list(Counter(map(int,input().split())).values())
A.sort()
m=len(A)
S=[0]*(m+1) # cumulative distribution
for i... | {
"input": [
"5\n1 2 3 4 5",
"4\n1 3 3 3",
"3\n2 1 2",
"4\n1 3 1 3",
"4\n1 3 3 2",
"3\n2 2 2",
"4\n2 3 2 2",
"5\n1 2 3 3 5",
"5\n2 2 3 3 5",
"4\n2 3 4 1",
"4\n2 2 2 2",
"5\n4 2 2 4 4",
"3\n2 2 1",
"5\n4 4 5 4 4",
"5\n5 1 2 3 4",
"4\n2 3 1 3",
"4\n1 3... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi has N cards. The i-th of these cards has an integer A_i written on it.
Takahashi will choose an integer K, and then repeat the following operation some number of times:
* ... |
p03025 M-SOLUTIONS Programming Contest - Best-of-(2n-1)_25408 | Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.
When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that wi... | M=10**9+7
N,A,B,C=map(int,input().split())
f=[1]
for i in range(1,2*N):
f.append(f[-1]*i%M)
t=pow(A+B,M-2,M)
A*=t
B*=t
a=pow(A,N,M)
b=pow(B,N,M)
z=0
for i in range(N):
z+=(N+i)*100*pow(100-C,M-2,M)*f[N+i-1]*pow(f[N-1]*f[i],M-2,M)*(a+b)
z%=M
a=a*B%M
b=b*A%M
print(z)
| {
"input": [
"4 50 50 0",
"1 25 25 50",
"1 100 0 0",
"100000 31 41 28",
"8 50 50 0",
"1 000 0 0",
"2 100 0 0",
"6 50 50 0",
"1 101 0 -1",
"100001 31 41 28",
"1 100 -1 1",
"000001 31 41 28",
"000011 31 41 28",
"2 25 25 50",
"10 50 50 0",
"5 50 50 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.
When they play the game once, Takahashi wins with probability A %, Aoki wins... |
p03166 Educational DP Contest - Longest Path_25412 | There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles.
Find the length of the longest directed path in G. Here, the length of a directed path is the num... | import sys
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
x, y = map(int, input().split())
x, y = x -1, y-1
g[x].append(y)
# dp[v]: ノードvを起点にしたときの、Gの有効パスの長さの最大値
dp = [-1]*n
def rec(v):
if dp[v] != -1:
return dp[v]
else:
res = 0
f... | {
"input": [
"6 3\n2 3\n4 5\n5 6",
"5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3",
"4 5\n1 2\n1 3\n3 2\n2 4\n3 4",
"6 3\n2 6\n4 5\n5 6",
"6 3\n2 6\n4 6\n5 6",
"6 3\n4 3\n3 5\n5 6",
"4 0\n1 2\n1 3\n3 2\n2 4\n3 4",
"7 3\n2 3\n4 5\n5 6",
"7 3\n2 3\n1 5\n5 6",
"11 3\n2 3\n4 5\n5 6",... | 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 G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_... |
p03309 AtCoder Beginner Contest 102 - Linear Approximation_25416 | Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the... | n=int(input())
a=list(map(int,input().split()))
for i in range(n):
a[i]-=i+1
a.sort()
m=a[n//2]
sum=0
for x in a:
sum+=abs(x-m)
print(sum)
| {
"input": [
"5\n2 2 3 5 5",
"7\n1 1 1 1 2 3 4",
"9\n1 2 3 4 5 6 7 8 9",
"6\n6 5 4 3 2 1",
"5\n2 2 3 5 10",
"7\n1 2 1 1 2 3 4",
"9\n1 2 3 4 5 6 7 8 1",
"6\n6 0 4 3 2 1",
"7\n1 0 1 1 2 3 4",
"9\n1 2 3 4 5 4 7 8 1",
"6\n6 0 4 3 2 2",
"9\n1 2 3 4 5 2 7 8 1",
"6\n6 0 4 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke... |
p03630 AtCoder Regular Contest 081 - Flip and Rectangles_25421 | We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of time... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・2x2内の偶奇が不変量。これが偶数なら、そこは単色でとれる
・単色でとれる領域を調べる -> 色変更なしに大きい長方形をとる問題になる
・ベースラインを固定すると、ヒストグラムの長方形の問題(アリ本)
"""
H,W = map(int,readline().split())
grid = read().replace(b'\r',b'').replace(b'\n',b'')
H,W
... | {
"input": [
"3 3\n..#\n.\n.#.",
"10 8\n...#.#\n...#.#\n..###.#.\n.##.#.#\n.#..#.#.\n..##.#.#\n.#.#..\n...#.#..\n.#.##\n..###",
"3 3\n..#\n##.\n.#.",
"4 4\n....\n....\n....\n....",
"3 3\n..\"\n.\n.#.",
"10 8\n...#.#\n...#.#\n..###.#.\n.##.$.#\n.#..#.#.\n..##.#.#\n.#.#..\n...#.#..\n.#.##\n..###... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-... |
p03788 AtCoder Grand Contest 011 - Half Reflector_25425 | Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows:
* When a device in state A receives a ball from either side (left or right), the device throws out the ball from the... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import deque
# f(AX) = XB
# f(BX) = flip(X) + A = flip(XB)
N,K = map(int,readline().split())
S = read().rstrip()
S = deque(0 if x == b'A'[0] else 1 for x... | {
"input": [
"5 2\nABAAA",
"5 1\nABAAA",
"4 123456789\nAABB",
"5 1\nAAAAA",
"4 87042533\nAABB",
"5 2\nAAABA",
"5 1\nAAABA",
"5 3\nAAABA",
"5 1\nAAAAB",
"5 2\nAAAAA",
"5 1\nAAABB",
"5 3\nAAAAA",
"5 2\nAAAAB",
"5 1\nAABBB",
"5 2\nAABAA",
"5 1\nABAAB",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device o... |
p00046 Differential_25431 | There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains.
Input
The input is given in the following format:
Mountain height
...
...
The height of the mountain is given o... | minv = 10000000
maxv = 0
while 1:
try:
n = float(input())
if minv > n:
minv = n
if maxv < n:
maxv = n
except:
break
print(maxv-minv)
| {
"input": [
"3776.0\n1819.0\n645.2\n2004.1\n1208.6",
"3776.5765005393655\n1819.0\n645.2\n2004.1\n1208.6",
"3777.502968017379\n1819.0\n645.2\n2004.1\n1208.6",
"3778.4165917426626\n1819.0\n645.2\n2004.2183724359945\n1208.6",
"3779.3515835085277\n1819.169376096264\n645.2\n2004.5930566110492\n1208.6"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and ... |
p00178 TETORIS_25435 | Tetris is a game in which falling blocks are lined up on the board and erased. Here, let's consider a game that arranges it a little.
The size of the board of this game is 5 frames wide, and it is high enough to accommodate all the blocks that appear. The falling blocks are straight and come in two types, landscape an... | while 1:
N = int(input())
if N == 0:
break
L = 5000
MP = [[0]*L for i in range(5)]
cs = [L]*5
us = []
U = [0]*L
for i in range(N):
d, p, q = map(int, input().split()); q -= 1
if d == 1:
y = L
for j in range(p):
y = min(y, cs... | {
"input": [
"4\n1 4 1\n1 3 1\n2 2 4\n2 3 5\n1\n1 5 1\n7\n2 2 2\n1 4 1\n2 1 3\n1 4 1\n1 1 1\n2 5 5\n1 4 2\n0",
"4\n1 4 1\n1 3 2\n2 2 4\n2 3 5\n1\n1 5 1\n7\n2 2 2\n1 4 1\n2 1 3\n1 4 1\n1 1 1\n2 5 5\n1 4 2\n0",
"4\n1 4 1\n1 3 2\n1 2 4\n2 3 5\n1\n1 5 1\n7\n2 2 2\n1 4 1\n2 1 3\n1 4 1\n1 1 1\n2 5 5\n1 4 2\n0",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Tetris is a game in which falling blocks are lined up on the board and erased. Here, let's consider a game that arranges it a little.
The size of the board of this game is 5 frames w... |
p00334 Geometric Data_25439 | Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of t... | N = int(input())
l = []
count = 0
for _ in range(N):
p = set(map(int, input().split()))
if p in l: count+=1
else: l.append(p)
print(count)
| {
"input": [
"4\n1 3 2\n1 2 4\n1 4 3\n2 3 4",
"6\n1 3 2\n1 2 4\n1 4 3\n2 3 4\n3 2 1\n2 3 1",
"4\n1 3 2\n1 2 4\n1 4 3\n0 3 4",
"6\n1 3 2\n1 2 4\n1 4 3\n0 3 4\n3 2 1\n2 3 1",
"6\n1 3 1\n1 2 4\n1 4 3\n0 3 4\n3 2 1\n2 3 1",
"4\n1 3 2\n1 2 4\n1 4 0\n0 3 4",
"4\n1 3 2\n1 2 4\n1 0 0\n0 3 4",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how t... |
p00519 Taxis_25443 | problem
The IOI country consists of N towns from town 1 to town N, and the towns are connected by roads. The IOI country has K roads, all of which connect two different towns. Cars can move freely in both directions on the road, but they cannot go from one town to another through anything other than the road.
JOI, wh... | from heapq import heappop as pop
from heapq import heappush as push
def main():
n, k = map(int, input().split())
clst = []
rlst = []
for i in range(n):
c, r = map(int, input().split())
clst.append(c)
rlst.append(r)
edges = [[] * n for i in range(n)]
for i in range(k):
a, b = map... | {
"input": [
"6 6\n400 2\n200 1\n600 3\n1000 1\n300 5\n700 4\n1 2\n2 3\n3 6\n4 6\n1 5\n2 4",
"None",
"enoN",
"eooN",
"Nooe",
"Nood",
"Nopd",
"Ndpo",
"Mdpo",
"Mdpn",
"npdM",
"npdL",
"npcL",
"npbL",
"npbM",
"pnbM",
"bnpM",
"bMpn",
"pMbn",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
The IOI country consists of N towns from town 1 to town N, and the towns are connected by roads. The IOI country has K roads, all of which connect two different towns. Cars c... |
p00692 Patience_25446 | As the proverb says,
> "Patience is bitter, but its fruit is sweet."
Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, we hope.
The word "patience" has the meaning of perseverance, but it has another meaning in card games. Card games for one player are ca... | # AOJ 1110: Patience
# Python3 2018.7.8 bal4u
pair = [[1,4,5], [2,4,5,6], [3,5,6,7], [6,7], [5,8,9],
[6,8,9,10], [7,9,10,11], [10,11], [9,12,13], [10,12,13,14],
[11,13,14,15], [14,15], [13,16,17], [14,16,17,18], [15,17,18,19],
[18,19], [17], [18], [19]]
def combi(cd, n):
global ans
ans = min(ans, n)
if n == 0: ... | {
"input": [
"4\n1 4 5 2\n3 1 4 3\n5 4 2 2\n4 5 2 3\n1 1 3 5\n5 1 5 1\n4 5 3 2\n3 2 1 4\n1 4 5 3\n2 3 4 2\n1 2 1 2\n5 4 5 4\n2 1 2 1\n3 5 3 4\n3 3 5 4\n4 2 3 1\n2 5 3 1\n3 5 4 2\n1 5 4 1\n4 5 3 2",
"4\n1 4 5 2\n3 1 4 3\n5 4 2 2\n4 5 2 3\n1 1 3 5\n5 1 5 1\n4 5 3 2\n3 2 1 4\n1 4 5 3\n2 3 4 2\n1 2 1 2\n5 4 3 4\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As the proverb says,
> "Patience is bitter, but its fruit is sweet."
Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, ... |
p00833 Color the Map_25449 | You were lucky enough to get a map just before entering the legendary magical mystery world. The map shows the whole area of your planned exploration, including several countries with complicated borders. The map is clearly drawn, but in sepia ink only; it is hard to recognize at a glance which region belongs to which ... | def main():
while 1:
N = int(input())
if N == 0:
break
D = {}
G = [set() for i in range(N)]
cur = 0
K = []
PS = []
for i in range(N):
ps = []
s = input()
if s in D:
k = D[s]
el... | {
"input": [
"6\nBlizid\n0 0\n60 0\n60 60\n0 60\n0 50\n50 50\n50 10\n0 10\n-1\nBlizid\n0 10\n10 10\n10 50\n0 50\n-1\nWindom\n10 10\n50 10\n40 20\n20 20\n20 40\n10 50\n-1\nAccent\n50 10\n50 50\n35 50\n35 25\n-1\nPilot\n35 25\n35 50\n10 50\n-1\nBlizid\n20 20\n40 20\n20 40\n-1\n4\nA1234567890123456789\n0 0\n0 100\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You were lucky enough to get a map just before entering the legendary magical mystery world. The map shows the whole area of your planned exploration, including several countries with... |
p00965 Starting a Scenic Railroad Service_25452 | Problem I Starting a Scenic Railroad Service
Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be.
A market survey was ordered and Jim has just received an ... | n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
pol1 = 0
pol2 = 0
ft = [[0] * 2 for _ in range(100000)]
for i in ab:
ft[i[0] - 1][0] += 1
ft[i[1] - 1][1] += 1
ftsum = [[0] * 2 for _ in range(100000)]
ftsum[0][0] = ft[0][0]
for i in range(1, len(ft)):
ftsum[i][0] = ftsum[i-1][0... | {
"input": [
"4\n1 3\n1 3\n3 6\n3 6",
"4\n1 3\n1 3\n3 6\n3 9",
"4\n1 3\n1 6\n3 2\n3 9",
"4\n2 2\n1 11\n10 2\n3 9",
"4\n2 1\n1 11\n10 2\n3 9",
"4\n3 1\n1 7\n10 2\n9 3",
"4\n6 1\n1 10\n10 2\n9 3",
"4\n1 3\n1 11\n0 2\n3 9",
"4\n1 3\n1 6\n3 1\n5 9",
"4\n4 1\n1 11\n10 2\n6 1",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem I Starting a Scenic Railroad Service
Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a sce... |
p01097 3D Printing_25456 | 3D Printing
We are designing an installation art piece consisting of a number of cubes with 3D printing technology for submitting one to Installation art Contest with Printed Cubes (ICPC). At this time, we are trying to model a piece consisting of exactly k cubes of the same size facing the same direction.
First, usi... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
input = sys.stdin.readline
INF = 10**20
EPS = 1.0 / 10**10
MOD = 10**9 + 7
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def ... | {
"input": [
"1 1 100\n100 100 100\n6 4 10\n100 100 100\n106 102 102\n112 110 104\n104 116 102\n100 114 104\n92 107 100\n10 4 10\n-100 101 100\n-108 102 120\n-116 103 100\n-124 100 100\n-132 99 100\n-92 98 100\n-84 100 140\n-76 103 100\n-68 102 100\n-60 101 100\n10 4 10\n100 100 100\n108 101 100\n116 102 100\n124... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
3D Printing
We are designing an installation art piece consisting of a number of cubes with 3D printing technology for submitting one to Installation art Contest with Printed Cubes (... |
p01367 Operator_25460 | The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out how many operators needed to handle this situation.
For simplicity, let u... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def check(N, C, T, x):
used = [0]*N
S = [0]*(T+1)
cap = x
f = 0
for t in range(T):
cap += S[t]
if cap == 0:
continue
for i in range(f, N):
if used[i]:
continue
... | {
"input": [
"3 300\n100 50 150\n100 50 150\n100 50 150\n3 300\n100 50 150\n100 50 150\n200 50 150\n9 18\n3 1 1\n3 1 1\n3 1 1\n4 100 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9 10 11\n10 11 12\n0 0",
"3 300\n100 46 150\n100 50 150\n100 50 15... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the su... |
p01549 Zero Division Checker_25464 | Mr. Morishita was in trouble ... I had Mr. Anehara write a program, but the program crashed.
Mr. Anehara wrote a program that reads the formula in Reverse Polish Notation and outputs the calculation result. According to the crash log, it seems that the cause was that it was divided by 0. This may be because Mr. Morish... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"1\na 0 255\n7\n1 a 2 * 1 + /",
"1\na 1 10\n3\n10 a /",
"2\na 1 10\nb 1 10\n5\n1 a b - /",
"1\na 1 10\n3\n15 a /",
"2\na 1 10\nb 1 10\n5\n1 b b - /",
"2\nb 1 10\nb 1 10\n5\n1 b b - /",
"1\na 0 255\n7\n1 a 2 * 1 * /",
"1\na 1 11\n3\n10 a /",
"1\na 0 255\n7\n1 a 2 * 1 * ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. Morishita was in trouble ... I had Mr. Anehara write a program, but the program crashed.
Mr. Anehara wrote a program that reads the formula in Reverse Polish Notation and outputs... |
p01705 Square in Circles_25467 | Problem Statement
Circles Island is known for its mysterious shape: it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their inside regions.
The King of Circles Island plans to build a large square on Circles Island in order to celebrate the fiftieth anniversa... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
C = [list(map(int, readline().split())) for i in range(N)]
e = 2**.5/2
r_min = max(r*e for x, r in C)
r_max = max(r for x, r in C)
H = []
for i in range(N-1)... | {
"input": [
"2\n0 8\n10 8\n2\n0 7\n10 7\n0",
"2\n0 8\n10 8\n0\n0 7\n10 7\n0",
"2\n0 8\n1 8\n0\n0 7\n10 7\n0",
"2\n0 8\n20 8\n2\n0 7\n10 7\n0",
"2\n0 8\n1 3\n0\n0 8\n10 1\n1",
"2\n1 13\n1 8\n0\n0 0\n10 1\n1",
"2\n1 14\n1 8\n0\n0 0\n10 1\n1",
"2\n0 16\n0 8\n0\n0 7\n10 7\n0",
"2\n0 6... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem Statement
Circles Island is known for its mysterious shape: it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their... |
p01849 The Most Powerful Bed_25469 | My futon
You bought N futons in preparation for your new life. The i-th futon has the warmth supply capacity of si. From the temperature forecast for the next M days, the warmth demand of dj is expected on the jth day. If the warmth is not enough or too much, the comfort will be impaired, so the absolute value of the ... | from collections import deque
while 1:
n, m = map(int, input().split())
if n == m == 0:
break
*S, = map(int, input().split())
D = sorted(map(int, input().split()))
SA = sum(S)
rest = sum(d-SA for d in D if SA <= d)
memo = {2**n-1: rest}
def dfs(state, su, idx):
if state... | {
"input": [
"1 1\n5\n6\n1 1\n5\n2\n1 1\n20\n5\n4 1\n2 4 5 9\n8\n4 3\n3 5 2 1\n10 4 7\n5 5\n2 2 2 2 2\n1 3 5 7 9\n2 5\n2 5\n2 5 2 5 2\n0 0",
"1 1\n5\n6\n1 1\n5\n2\n1 1\n20\n5\n4 1\n2 4 5 9\n8\n4 3\n3 5 2 1\n10 4 7\n5 5\n2 2 2 2 2\n1 3 5 7 9\n2 5\n2 5\n2 5 2 6 2\n0 0",
"1 1\n5\n6\n1 1\n5\n2\n1 1\n20\n5\n4 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
My futon
You bought N futons in preparation for your new life. The i-th futon has the warmth supply capacity of si. From the temperature forecast for the next M days, the warmth dema... |
p01985 Divide and Conquer_25472 | Divide and rule
Taro, Hanako, and Jiro rule the JAG Kingdom together. There are N cities in the JAG Kingdom, some of which are connected by two-way roads. You can always reach all the other cities from any city via one or more roads.
One day, Taro and Hanako finally made a mistake and decided to share the city and go... | import sys
input = sys.stdin.readline
def main():
while True:
N, M = map(int, input().split())
if N == 0:
break
path = [[False] * N for i in range(N)]
for i in range(M):
u, v = map(int, input().split())
u -= 1; v -= 1;
path[u][v] = Tru... | {
"input": [
"6 7\n1 2\n1 4\n2 3\n2 5\n3 4\n4 5\n4 6\n2 1\n1 2\n3 3\n1 2\n1 3\n2 3\n4 3\n1 2\n2 3\n3 4\n5 4\n1 2\n2 3\n3 4\n4 5\n0 0",
"6 7\n1 2\n1 4\n2 3\n2 5\n3 4\n4 5\n4 6\n2 1\n1 2\n3 3\n1 2\n2 3\n2 3\n4 3\n1 2\n2 3\n3 4\n5 4\n1 2\n2 3\n3 4\n4 5\n0 0",
"6 7\n1 4\n1 4\n2 3\n2 5\n3 4\n4 5\n4 6\n2 1\n1 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Divide and rule
Taro, Hanako, and Jiro rule the JAG Kingdom together. There are N cities in the JAG Kingdom, some of which are connected by two-way roads. You can always reach all th... |
p02272 Merge Sort_25477 | Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function.
Merge(A, left, mid, right)
n1 = mid - left;
n2 = right - mid;
create array L[0...n1], R[0...n2]
for i = 0 to n1-1
do L[i] = A[left + i]
for i = 0 to n2-1
do R[i] =... | count = 0
def merge(a, left, mid, right):
global count
l = a[left:mid]
r = a[mid:right]
l.append(10**9+1)
r.append(10**9+1)
i = 0
j = 0
for k in range(left, right):
count += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = ... | {
"input": [
"10\n8 5 9 2 6 3 7 1 10 4",
"10\n8 5 9 2 6 3 7 0 10 4",
"10\n8 5 9 2 6 3 7 0 10 3",
"10\n8 5 9 2 6 4 11 0 10 3",
"10\n8 5 9 2 6 4 11 0 10 5",
"10\n8 5 9 2 6 4 11 1 10 5",
"10\n10 5 9 2 6 4 11 1 10 5",
"10\n10 5 9 2 6 4 19 1 10 5",
"10\n10 5 9 2 6 4 19 2 10 5",
"10\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function.
Merge(A, left, mid, right)... |
p02419 Finding a Word_25481 | Write a program which reads a word W and a text T, and prints the number of word W which appears in text T
T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
Constraints
* The length of W ≤ 10
* W consists of lower cas... | A=0
W=str(input())
while True:
t=str(input())
if t=='END_OF_TEXT':
break
t=(t.lower().split())
a=(t.count(W))
A=A+a
print(A)
| {
"input": [
"computer\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and exploit \"knowledge\" for the new era.\nProvides an outstanding computer environment.\nEND_OF_TEXT",
"computer\nNurtures computer scientists and highly-skilled computer engineers\nwho will create an... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T
T consists of string Ti separated by space characters and newlines. Count t... |
1041_E. Tree Reconstruction_25493 | Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 1 to n. For every edge e of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge e (and only this edge) is... | #
def solve():
n = int(input())
d = {}
for _ in range(n-1):
u, v = map(int, input().split())
min_ = min(u, v)
max_ = max(u, v)
if max_ != n:
return False, None
if min_ not in d:
d[min_] = 0
d[min_] += 1
... | {
"input": [
"3\n1 2\n2 3\n",
"4\n3 4\n1 4\n3 4\n",
"3\n1 3\n1 3\n",
"15\n10 15\n12 15\n6 15\n8 15\n2 15\n3 15\n10 15\n13 15\n5 15\n7 15\n11 15\n4 14\n1 15\n14 15\n",
"15\n9 15\n6 15\n12 15\n3 14\n14 15\n11 15\n6 15\n7 15\n10 15\n4 15\n1 15\n13 15\n2 15\n9 15\n",
"2\n1 2\n",
"15\n13 15\n9 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 1 to n. For every edge e of this tree,... |
1064_D. Labyrinth_25497 | You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not o... | #!/usr/bin/env python3
import sys
from collections import deque
from math import inf
def rint():
return map(int, sys.stdin.readline().split())
#lines = stdin.readlines()
def bfs(sr, sc):
global ans
q = deque()
q.append((x, y, sr, sc))
visit[sr][sc] = 1
ans += 1
while q:
ll, rr, r, ... | {
"input": [
"4 5\n3 2\n1 2\n.....\n.***.\n...**\n*....\n",
"4 4\n2 2\n0 1\n....\n..*.\n....\n....\n",
"7 16\n1 15\n1000 0\n...*...*........\n.*.*.*.*.******.\n.*.*.*.*.*....*.\n.*.*.*.*.*....*.\n.*...*...*....*.\n.**************.\n................\n",
"1 1\n1 1\n0 0\n.\n",
"10 15\n7 7\n7 7\n.****... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle.... |
1086_B. Minimum Diameter Tree_25501 | You are given a tree (an undirected connected graph without cycles) and an integer s.
Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is s. At the same time, he wants to make the diameter of the tree as small as possible.
Let's define the diameter of... | n, s = map(int, input().split())
a = [0] * n
if n == 2:
xc, xd = map(int, input().split())
print(s)
exit()
for i in range(n - 1):
xc, xd = map(int, input().split())
a[xd - 1] += 1
a[xc - 1] += 1
cnt = 0
for i in range(n):
if a[i] == 1:
cnt += 1
print(2 * round(s / cnt, 10)) | {
"input": [
"6 1\n2 1\n2 3\n2 5\n5 4\n5 6\n",
"4 3\n1 2\n1 3\n1 4\n",
"5 5\n1 2\n2 3\n3 4\n3 5\n",
"2 1000000000\n2 1\n",
"2 1\n2 1\n",
"4 1\n4 1\n2 4\n3 1\n",
"3 1000000000\n3 2\n2 1\n",
"4 1\n1 3\n1 4\n2 1\n",
"4 1\n2 3\n1 4\n2 1\n",
"6 1\n2 1\n4 3\n2 5\n5 4\n5 6\n",
"6 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree (an undirected connected graph without cycles) and an integer s.
Vanya wants to put weights on all edges of the tree so that all weights are non-negative real nu... |
1106_B. Lunar New Year and Food Ordering_25505 | Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers w... | n, m = map(int, input().split())
dish = list(map(int, input().split()))
cost = list(map(int, input().split()))
scost = []
for i in range(n):
scost.append([cost[i], dish[i], i])
scost = sorted(scost)
# print(scost)
cur = 0
for i in range(m):
x, y = map(int, input().split())
x -= 1
# print(x, y)
pri... | {
"input": [
"6 6\n6 6 6 6 6 6\n6 66 666 6666 66666 666666\n1 6\n2 13\n3 6\n4 11\n5 6\n6 6\n",
"8 5\n8 6 2 1 4 5 7 5\n6 3 3 2 6 2 3 2\n2 8\n1 4\n4 7\n3 4\n6 10\n",
"6 6\n6 6 6 6 6 6\n6 66 666 6666 66666 666666\n1 6\n2 6\n3 6\n4 6\n5 6\n6 66\n",
"1 1\n10000000\n284517\n1 10000000\n",
"1 1\n1\n64240... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_... |
1133_C. Balanced Team_25509 | You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maxi... | n=int(input().strip())
numbers=list(map(int,input().strip().split(" ")))
numbers.sort()
start=0
current=0
l=[]
tot=0
while (current<len(numbers) and start<len(numbers)):
if(numbers[current]-numbers[start]>5):
start=start+1
l.append(tot)
tot-=1
else:
tot+=1
current+=1
if(l... | {
"input": [
"6\n1 10 17 12 15 2\n",
"10\n1337 1337 1337 1337 1337 1337 1337 1337 1337 1337\n",
"6\n1 1000 10000 10 100 1000000000\n",
"1\n1337\n",
"100\n1342 1342 1342 1339 1338 1340 1339 1338 1341 1341 1339 1342 1337 1337 1337 1341 1340 1338 1338 1340 1337 1337 1337 1339 1337 1342 1337 1340 1342... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programmi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.