problem_id stringlengths 3 7 | contestId stringclasses 660
values | problem_index stringclasses 27
values | programmingLanguage stringclasses 3
values | testset stringclasses 5
values | incorrect_passedTestCount float64 0 146 | incorrect_timeConsumedMillis float64 15 4.26k | incorrect_memoryConsumedBytes float64 0 271M | incorrect_submission_id stringlengths 7 9 | incorrect_source stringlengths 10 27.7k | correct_passedTestCount float64 2 360 | correct_timeConsumedMillis int64 30 8.06k | correct_memoryConsumedBytes int64 0 475M | correct_submission_id stringlengths 7 9 | correct_source stringlengths 28 21.2k | contest_name stringclasses 664
values | contest_type stringclasses 3
values | contest_start_year int64 2.01k 2.02k | time_limit float64 0.5 15 | memory_limit float64 64 1.02k | title stringlengths 2 54 | description stringlengths 35 3.16k | input_format stringlengths 67 1.76k | output_format stringlengths 18 1.06k ⌀ | interaction_format null | note stringclasses 840
values | examples stringlengths 34 1.16k | rating int64 800 3.4k ⌀ | tags stringclasses 533
values | testset_size int64 2 360 | official_tests stringlengths 44 19.7M | official_tests_complete bool 1
class | input_mode stringclasses 1
value | generated_checker stringclasses 231
values | executable bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
258/D | 258 | D | PyPy 3 | TESTS | 2 | 122 | 0 | 145416966 | n, m = map(int, input().split())
p = [0]+list(map(int, input().split()))
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if p[i] > p[j]:
dp[i][j] = 1
ans = 0
for _ in range(m):
x, y = map(int, input().split())
if x > y:
x, y = y, x
for... | 55 | 996 | 43,212,800 | 130036596 | import bisect
import copy
import decimal
import fractions
import functools
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _hea... | Codeforces Round 157 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Broken Sorting | The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n.
This time the Little Elephant has permutation p1, p2, ..., pn. Its sort... | The first line contains two integers n and m (1 ≤ n, m ≤ 1000, n > 1) — the permutation size and the number of moves. The second line contains n distinct integers, not exceeding n — the initial permutation. Next m lines each contain two integers: the i-th line contains integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the... | In the only line print a single real number — the answer to the problem. The answer will be considered correct if its relative or absolute error does not exceed 10 - 6. | null | null | [{"input": "2 1\n1 2\n1 2", "output": "0.500000000"}, {"input": "4 3\n1 3 2 4\n1 2\n2 3\n1 4", "output": "3.000000000"}] | 2,600 | ["dp", "math", "probabilities"] | 55 | [{"input": "2 1\r\n1 2\r\n1 2\r\n", "output": "0.500000000\r\n"}, {"input": "4 3\r\n1 3 2 4\r\n1 2\r\n2 3\r\n1 4\r\n", "output": "3.000000000\r\n"}, {"input": "7 4\r\n7 6 4 2 1 5 3\r\n1 3\r\n2 1\r\n7 2\r\n3 5\r\n", "output": "11.250000000\r\n"}, {"input": "10 1\r\n1 2 3 4 5 6 7 8 9 10\r\n1 10\r\n", "output": "8.5000000... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct_line = f.readline().strip()
correct = float(correct_line)
with open(submission_path) as f:
submitted_line = f.readline().strip()... | true |
774/B | 774 | B | PyPy 3 | TESTS | 0 | 93 | 23,142,400 | 26152857 | class Mcl:
def __init__(self, a, b):
self.c = a
self.w = b
def __lt__(a, b):
return a.c < b.c or a.c == b.c and a.w > b.w
def __gt__(a, b):
return a.c > b.c or a.c == b.c and a.w < b.w
def __repr__(self):
return "(" + str(self.c) + ", " + str(self.w) + ")"
de... | 44 | 2,371 | 56,934,400 | 215299376 | from functools import cmp_to_key
def comparator(a, b) :
if a[0] > b[0] :
return -1
if a[0] < b[0] :
return 1
if a[1] < b[1] :
return -1
if a[1] > b[1] :
return 1
return 0
n, m, d = list(map(int, input().split()))
a = []
b = []
for i in range(n):
a.append(list(ma... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 3 | 256 | Significant Cups | Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance ci and width wi.
Stepan decided to expose some of his cups on a shelf with width d in such a way, that:
- there is at least one Ph... | The first line contains three integers n, m and d (1 ≤ n, m ≤ 100 000, 1 ≤ d ≤ 109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf.
Each of the following n lines contains two integers ci and wi (1 ≤ ci, wi ≤ 109) — significance and width of the i-th ... | Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement.
If there is no way to expose cups on the shelf, then print 0. | null | In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most sign... | [{"input": "3 1 8\n4 2\n5 5\n4 2\n3 2", "output": "8"}, {"input": "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "output": "11"}, {"input": "2 2 2\n5 3\n6 3\n4 2\n8 1", "output": "0"}] | 2,100 | ["*special", "binary search", "data structures", "two pointers"] | 44 | [{"input": "3 1 8\r\n4 2\r\n5 5\r\n4 2\r\n3 2\r\n", "output": "8\r\n"}, {"input": "4 3 12\r\n3 4\r\n2 4\r\n3 5\r\n3 4\r\n3 5\r\n5 2\r\n3 4\r\n", "output": "11\r\n"}, {"input": "2 2 2\r\n5 3\r\n6 3\r\n4 2\r\n8 1\r\n", "output": "0\r\n"}, {"input": "10 10 229\r\n15 17\r\n5 4\r\n4 15\r\n4 17\r\n15 11\r\n7 6\r\n5 19\r\n14 ... | false | stdio | null | true |
194/B | 194 | B | PyPy 3 | TESTS | 3 | 93 | 3,788,800 | 177777222 | t=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0:
print(i*4+1)
else:
print(i*2+1) | 8 | 46 | 614,400 | 152634001 | t=int(input())
a=list(map(int,input().strip().split()))
ans=[-1]*t
for i in range(t):
if a[i]%4==0:ans[i]=a[i]*4+1
elif a[i]%4==1:ans[i]=a[i]*2+1
elif a[i]%4==2:ans[i]=a[i]*4+1
else:ans[i]=a[i]+1
for x in ans:
print(x) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
400/A | 400 | A | Python 3 | TESTS | 1 | 93 | 307,200 | 91984387 | # Author: SaykaT
# Problem: 400A
# Time Created: September 06(Sunday) 2020 || 10:49:06
#>-------------------------<#
#>-------------------------<#
# Helper Functions. -> Don't cluster your code.
def col_check(b, row):
ans = True
for idx, val in enumerate(row):
if (idx + 1) % b == 0 and val != 'X':
... | 44 | 46 | 0 | 209912113 | t = int(input())
for _ in range(t):
s = input()
res, n = [], len(s)
for a in [1, 2, 3, 4, 6, 12]:
b = 12 // a
for i in range(b):
if all(s[j] == "X" for j in range(i, n, b)):
res.append(f"{a}x{b}")
break
if res:
print(len(res), *res)
... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac... | null | null | [{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}] | 1,000 | ["implementation"] | 44 | [{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX... | false | stdio | null | true |
729/D | 729 | D | Python 3 | TESTS | 1 | 46 | 0 | 22398511 | n,a,b,k=[int(i) for i in input().split()]
s=input()
l=[]
i=0
j=0
while i<len(s):
if s[i]=="1":
j=0
else :
j+=1
if(j%b)==0:
l+=[i+1]
j=0
i+=1
print(len(l))
print(*l[a-1:]) | 21 | 93 | 17,817,600 | 220882553 | n,a,b,k=list(map(int,input().split()))
s=input()
ans,p,l=[],[],0
for i in range(n):
if int(s[i]): l=0
else: l+=1
if l==b:
ans.append(i)
l=0
end=len(ans)-a+1
for i in range(end):
p.append(ans[i]+1)
print(end)
print(*p) | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
522/C | 522 | C | Python 3 | TESTS | 3 | 31 | 0 | 163171165 | def solve():
n = int(input().split()[0])
while n>0:
input()
m,k = map(int,input().split())
porciones=list(map(int,input().split()))
informacionDpasajeros=list()
while m>1:
informacionDpasajeros.append(list(map(int,input().split())))
m-=1
for info in informacionDpasajeros... | 48 | 654 | 10,342,400 | 10207272 | import sys
test_count = int(sys.stdin.readline())
for test in range(test_count):
sys.stdin.readline()
m, k = map(int, sys.stdin.readline().split())
counts = list(map(int, sys.stdin.readline().split()))
took = []
unhappy = []
for i in range(m - 1):
t, r = map(int, sys.stdin.readline().sp... | VK Cup 2015 - Qualification Round 1 | CF | 2,015 | 1 | 256 | Chicken or Fish? | Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in t... | Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,... | For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp. | null | In the first input set depending on the choice of the second passenger the situation could develop in different ways:
- If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
- If he chose the fourth dish, then by the moment the stewardess reaches Poly... | [{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}] | 2,100 | ["greedy"] | 48 | [{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1... | false | stdio | null | true |
965/E | 965 | E | Python 3 | TESTS | 3 | 31 | 0 | 158697451 | t = int(input())
for _ in range(t):
a = input()
if a == 'code':
print(6)
elif a == 'aacada':
print(11)
else:
print(3) | 24 | 156 | 22,937,600 | 177672519 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def trie():
G, cnt = [[-1] * 26], [0]
return G, cnt
def insert(s):
j = 0
for i in s:
if not G[j][i - 97] ^ -1:
G[j][i - 97] = len(cnt)
G.append([-1] * 26)
cnt.append(0)
... | Codeforces Round 476 (Div. 2) [Thanks, Telegram!] | CF | 2,018 | 1 | 256 | Short Code | Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincid... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables.
The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are ... | Print a single integer — the minimum possible total length of new variable names. | null | In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".
In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names. | [{"input": "3\ncodeforces\ncodehorses\ncode", "output": "6"}, {"input": "5\nabba\nabb\nab\naa\naacada", "output": "11"}, {"input": "3\ntelegram\ndigital\nresistance", "output": "3"}] | 2,200 | ["data structures", "dp", "greedy", "strings", "trees"] | 24 | [{"input": "3\r\ncodeforces\r\ncodehorses\r\ncode\r\n", "output": "6\r\n"}, {"input": "5\r\nabba\r\nabb\r\nab\r\naa\r\naacada\r\n", "output": "11\r\n"}, {"input": "3\r\ntelegram\r\ndigital\r\nresistance\r\n", "output": "3\r\n"}, {"input": "1\r\na\r\n", "output": "1\r\n"}, {"input": "10\r\naaaba\r\nbabba\r\nbbba\r\naaab... | false | stdio | null | true |
400/A | 400 | A | Python 3 | TESTS | 1 | 93 | 0 | 61176367 | le=int(input())
for _ in range(le):
str1=input()
count=0
arr=[1,2,3,4,6,12]
arr1=[]
for num in arr:
flag=False
i=12//num
for j in range(i):
if(str1[j]=="X"):
flag=True
if(j+i>=12):
flag=True
b... | 44 | 61 | 0 | 11000914 | '''
Created on May 4, 2015
@author: mohamed265
'''
def fun():
num = input()
slon = []
if num.count('X') > 0:
slon.append("1x12")
if num[0] == 'X' and num[6] == 'X' or num[1] == 'X' and num[7] == 'X' or num[2] == 'X' and num[8] == 'X' or num[3] == 'X' and num[9] == 'X' or num[4] == 'X' and nu... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac... | null | null | [{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}] | 1,000 | ["implementation"] | 44 | [{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX... | false | stdio | null | true |
963/C | 963 | C | Python 3 | TESTS | 3 | 1,747 | 7,065,600 | 37554747 | import math
q = int(input())
l, A, B = 0, 0, 0
for i in range(q):
v = input().split()
l += int(v[2])
A += int(v[0]) * int(v[2])
B += int(v[1]) * int(v[2])
d = []
for i in range(1 , int(math.sqrt(l)) + 1):
if l % i == 0:
a = (i, int(l / i))
if a not in d:
d.append(a)
... | 80 | 1,294 | 132,300,800 | 220705287 | from math import gcd
num_elements = int(input())
a_vals = [0] * (3000001)
b_vals = [0] * (3000001)
c_vals = [0] * (3000001)
f1_map = {}
f2_map = {}
sum_c = 0
gcd_c = 0
for i in range(1, num_elements+1):
a_vals[i], b_vals[i], c_vals[i] = map(int, input().split())
if a_vals[i] not in f1_map:
f1_m... | Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1) | CF | 2,018 | 2 | 256 | Cutting Rectangle | A rectangle with sides $$$A$$$ and $$$B$$$ is cut into rectangles with cuts parallel to its sides. For example, if $$$p$$$ horizontal and $$$q$$$ vertical cuts were made, $$$(p + 1) \cdot (q + 1)$$$ rectangles were left after the cutting. After the cutting, rectangles were of $$$n$$$ different types. Two rectangles are... | The first line consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^{5}$$$) — amount of different types of rectangles left after cutting the initial rectangle.
The next $$$n$$$ lines each consist of three integers $$$w_{i}, h_{i}, c_{i}$$$ $$$(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$$$ — the lengths of t... | Output one integer — the answer to the problem. | null | In the first sample there are three suitable pairs: $$$(1; 9)$$$, $$$(3; 3)$$$ and $$$(9; 1)$$$.
In the second sample case there are 6 suitable pairs: $$$(2; 220)$$$, $$$(4; 110)$$$, $$$(8; 55)$$$, $$$(10; 44)$$$, $$$(20; 22)$$$ and $$$(40; 11)$$$.
Here the sample of cut for $$$(20; 22)$$$.
The third sample has no s... | [{"input": "1\n1 1 9", "output": "3"}, {"input": "2\n2 3 20\n2 4 40", "output": "6"}, {"input": "2\n1 2 5\n2 3 5", "output": "0"}] | 2,600 | ["brute force", "math", "number theory"] | 80 | [{"input": "1\r\n1 1 9\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3 20\r\n2 4 40\r\n", "output": "6\r\n"}, {"input": "2\r\n1 2 5\r\n2 3 5\r\n", "output": "0\r\n"}] | false | stdio | null | true |
774/L | 774 | L | Python 3 | TESTS | 0 | 93 | 307,200 | 83712785 | a,b = map(int,input().split())
c = list(map(int,input()))
d = []
e = []
f = 1
if c.count(0) > b:f += c.count(0) - b
for x in range(len(c)):
if c[x] == 0:d.append(x)
for x in d[1: -1]:
if d.index(x) - f < 0:k = (x - d[0]) - 1
else:k = (x - d[d.index(x) - f]) - 1
if d.index(x) + f > len(d) - 1:l = (d[-1] - x) - 1
el... | 81 | 546 | 12,288,000 | 85819039 | import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
s = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done
n,k=readints(... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Bars | Polycarp's workday lasts exactly $$$n$$$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $$$k$$$ bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200\,000$$$, $$$2 \le k \le n$$$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length $$$n$$$ consisting of zeros and ones. I... | Print the minimum possible break in minutes between eating chocolate bars. | null | In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes $$$1$$$ and $$$8$$$ anyway, also he needs to eat the chocolate bar in the minute $$$5$$$, so that the time of the maximum break wi... | [{"input": "3 3\n010", "output": "1"}, {"input": "8 3\n01010110", "output": "3"}] | 2,000 | ["*special", "binary search"] | 81 | [{"input": "3 3\r\n010\r\n", "output": "1\r\n"}, {"input": "8 3\r\n01010110\r\n", "output": "3\r\n"}, {"input": "9 5\r\n001100110\r\n", "output": "2\r\n"}, {"input": "2 2\r\n00\r\n", "output": "0\r\n"}, {"input": "3 2\r\n010\r\n", "output": "1\r\n"}, {"input": "3 2\r\n000\r\n", "output": "1\r\n"}, {"input": "3 3\r\n000... | false | stdio | null | true |
194/B | 194 | B | PyPy 3 | TESTS | 3 | 155 | 3,788,800 | 83140351 | input()
li = list(map(int, input().split()))
for x in li:
if x % 2:
print(2 * x + 1)
else:
print(4 * x + 1) | 8 | 46 | 1,126,400 | 217932765 | from math import gcd
t = int(input())
sides = list(map(int, input().split()))
for n in sides:
lcm = (4 * n * (n + 1)) // gcd(4 * n, n + 1)
print(lcm // (n + 1) + 1) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
965/E | 965 | E | Python 3 | TESTS | 3 | 46 | 0 | 158740656 | n=int(input())
b=[]
for i in range(n):
a=input()
b+=[a]
if b[0]=='codeforces':
print(6)
elif b[0]=='abba':
print(11)
elif b[0]=='telegram':
print(3) | 24 | 156 | 22,937,600 | 177672519 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def trie():
G, cnt = [[-1] * 26], [0]
return G, cnt
def insert(s):
j = 0
for i in s:
if not G[j][i - 97] ^ -1:
G[j][i - 97] = len(cnt)
G.append([-1] * 26)
cnt.append(0)
... | Codeforces Round 476 (Div. 2) [Thanks, Telegram!] | CF | 2,018 | 1 | 256 | Short Code | Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincid... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables.
The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are ... | Print a single integer — the minimum possible total length of new variable names. | null | In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".
In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names. | [{"input": "3\ncodeforces\ncodehorses\ncode", "output": "6"}, {"input": "5\nabba\nabb\nab\naa\naacada", "output": "11"}, {"input": "3\ntelegram\ndigital\nresistance", "output": "3"}] | 2,200 | ["data structures", "dp", "greedy", "strings", "trees"] | 24 | [{"input": "3\r\ncodeforces\r\ncodehorses\r\ncode\r\n", "output": "6\r\n"}, {"input": "5\r\nabba\r\nabb\r\nab\r\naa\r\naacada\r\n", "output": "11\r\n"}, {"input": "3\r\ntelegram\r\ndigital\r\nresistance\r\n", "output": "3\r\n"}, {"input": "1\r\na\r\n", "output": "1\r\n"}, {"input": "10\r\naaaba\r\nbabba\r\nbbba\r\naaab... | false | stdio | null | true |
729/D | 729 | D | PyPy 3 | TESTS | 6 | 109 | 4,915,200 | 112067302 | n, a, b, k = map(int, input().split())
s = input()
start = False
cnt = 0
arr = []
idx = -1
for i in range(n):
if(s[i] == "0"):
if(start):
cnt += 1
else:
start = True
idx = i
cnt = 1
else:
if(start):
start = False
arr... | 21 | 108 | 15,667,200 | 171032675 | import sys
input = sys.stdin.readline
n, a, b, k = map(int, input().split())
s = input()[:-1]
res = []
l, r = 0, 0
while r < n:
if s[r] == '1':
r += 1
l = r
elif a > 1:
while a > 1 and r < n and s[r] == '0':
r += 1
if r - l == b:
l = r
... | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
894/E | 894 | E | PyPy 3-64 | TESTS | 2 | 62 | 4,608,000 | 183371151 | from collections import defaultdict
import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def scc():
for i in range(1, n + 1):
if not visit[i]:
dfs1(i)
for i in range(len(t) - 1, -1, -1):
if not ok[t[i]]:
bfs1(t[i])
t.reverse()... | 40 | 1,434 | 43,724,800 | 214560577 | import sys
import math
from collections import defaultdict
class TarjanSolver:
def __init__(self):
self.graph = defaultdict(list)
self.dfn = None
self.low = None
self.stack = None
self.visited = None
self.component = None
self.new_graph = defaultdict(list)
... | Codeforces Round 447 (Div. 2) | CF | 2,017 | 2.5 | 512 | Ralph and Mushrooms | Ralph is going to collect mushrooms in the Mushroom Forest.
There are m directed paths connecting n trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantastic s... | The first line contains two integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), representing the number of trees and the number of directed paths in the Mushroom Forest, respectively.
Each of the following m lines contains three integers x, y and w (1 ≤ x, y ≤ n, 0 ≤ w ≤ 108), denoting a path that leads from tree x to tree y... | Print an integer denoting the maximum number of the mushrooms Ralph can collect during his route. | null | In the first sample Ralph can pass three times on the circle and collect 4 + 4 + 3 + 3 + 1 + 1 = 16 mushrooms. After that there will be no mushrooms for Ralph to collect.
In the second sample, Ralph can go to tree 3 and collect 8 mushrooms on the path from tree 1 to tree 3. | [{"input": "2 2\n1 2 4\n2 1 4\n1", "output": "16"}, {"input": "3 3\n1 2 4\n2 3 3\n1 3 8\n1", "output": "8"}] | 2,100 | ["dp", "graphs"] | 40 | [{"input": "2 2\r\n1 2 4\r\n2 1 4\r\n1\r\n", "output": "16"}, {"input": "3 3\r\n1 2 4\r\n2 3 3\r\n1 3 8\r\n1\r\n", "output": "8"}, {"input": "1 0\r\n1\r\n", "output": "0"}] | false | stdio | null | true |
961/E | 961 | E | PyPy 3-64 | TESTS | 2 | 46 | 0 | 183342706 | n = int(input())
a = [int(i) for i in input().split()]
pref = []
now = 0
for i in range(n):
if i + 1 < a[i]:
now += 1
pref.append(now)
print(sum(pref) // 2) | 30 | 655 | 22,528,000 | 100875670 | from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
ans = 0
#ans = slow_test()
class fenwick():
"""
This Tree Data Structure speeds up caliculating summations of partial sum
and also updating subsets of sequences. Both queries finish in logarithmic times.
... | Educational Codeforces Round 41 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Tufurama | One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ... | The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons.
The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season. | Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x. | null | Possible pairs in the second example:
1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1);
2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2);
3. x = 1, y... | [{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}] | 1,900 | ["data structures"] | 30 | [{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000... | false | stdio | null | true |
729/D | 729 | D | Python 3 | PRETESTS | 4 | 61 | 0 | 22357550 | L, ships_left, len_of_ship, n = map(int, input().split())
S = '1' + input()
lst = [[0, 0]]
counter = 0
for i in range(1,L+1):
if S[i] == '0':
counter += 1
else:
lst[-1][1] = counter//len_of_ship
counter = 0
lst.append([i, 0])
lst[-1][1] = counter//len_of_ship
L=len(lst)
shots = ... | 21 | 109 | 17,817,600 | 220882641 | import sys
def st(): return str(input())
def inp(): return int(sys.stdin.readline())
def strip(): return list(sys.stdin.readline().strip())
def li(): return list(map(int, sys.stdin.readline().split()))
n,a,b,k=li()
s=st()
ans,p,l=[],[],0
for i in range(n):
if int(s[i]): l=0
else: l+=1
if l==b:
ans.... | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
754/C | 754 | C | Python 3 | TESTS | 1 | 124 | 0 | 45444602 | t = int(input())
SANITIZE_REMOVE = ",.!? "
def sanitize(s):
for ch in SANITIZE_REMOVE:
while s.startswith(ch):
s = s[1:]
while s.endswith(ch):
s = s[:-1]
return s
def solve():
n = int(input())
users = set(input().split())
puser = None
chat = dict()
m = int(input())
msgs = [input() for i in range(... | 104 | 1,154 | 5,017,600 | 23606122 | def dfs(ind):
if ind > 0:
if possible[ind][0] in possible[ind - 1]:
possible[ind - 1].remove(possible[ind][0])
if len(possible[ind - 1]) == 1:
dfs(ind - 1)
if ind < m - 1:
if possible[ind][0] in possible[ind + 1]:
possible[ind + 1].remove(possi... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 2 | 256 | Vladik and chat | Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.
At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ... | The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format.
The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat.
The next line contains n space-separated distinct usernames. E... | Print the information about the t chats in the following format:
If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format:
<username>:<text>
If there are multiple answers, print any of them. | null | null | [{"input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "output": "netman: Hello, Vladik!\nVladik: Hi"}, {"input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "output": "Impossible"}, {"input": "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: some... | 2,200 | ["brute force", "constructive algorithms", "dp", "implementation", "strings"] | 104 | [{"input": "1\r\n2\r\nVladik netman\r\n2\r\n?: Hello, Vladik!\r\n?: Hi\r\n", "output": "netman: Hello, Vladik!\r\nVladik: Hi\r\n"}, {"input": "1\r\n2\r\nnetman vladik\r\n3\r\nnetman:how are you?\r\n?:wrong message\r\nvladik:im fine\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n3\r\nnetman vladik Fedosik\r\n2\r\n?:... | false | stdio | null | true |
729/D | 729 | D | Python 3 | TESTS | 1 | 30 | 0 | 171026277 | import sys
input=sys.stdin.readline
if __name__=='__main__':
n,a,b,k=map(int,input().split())
s=input()
p=0
res=[]
for i in range(n):
if s[i]=='1':
p=0
else:
p+=1
if p==b:
res.append(i+1)
p=0
print(len(res)... | 21 | 124 | 19,148,800 | 197320020 | # ﷽
from collections import deque
import sys
input = lambda: sys.stdin.readline().strip()
mod=7+10**9
def solve():
n,a,b,k=[int(i) for i in input().split()]
s=input()
i=0
d=deque()
tot=0
while i<n:
while i<n and s[i]!='0':i+=1
if "".join(s[i:i+b])!='0'*b:
j=i
... | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
1007/B | 1007 | B | Python 3 | TESTS | 3 | 155 | 409,600 | 44399559 | import sys
import math
from functools import reduce
def factors(n):
seta=set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
return sorted(list(seta))
n=int(input())
for _ in range(n):
lisa = []
a,b,c=map(int,input().strip().split())
fa,fb,fc=fac... | 28 | 998 | 8,396,800 | 40311323 | from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3, 1, 2, 2, 2, 1] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
... | Codeforces Round 497 (Div. 1) | CF | 2,018 | 2 | 256 | Pave the Parallelepiped | You are given a rectangular parallelepiped with sides of positive integer lengths $$$A$$$, $$$B$$$ and $$$C$$$.
Find the number of different groups of three integers ($$$a$$$, $$$b$$$, $$$c$$$) such that $$$1\leq a\leq b\leq c$$$ and parallelepiped $$$A\times B\times C$$$ can be paved with parallelepipeds $$$a\times b... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains three integers $$$A$$$, $$$B$$$ and $$$C$$$ ($$$1 \leq A, B, C \leq 10^5$$$) — the sizes of the parallelepiped. | For each test case, print the number of different groups of three points that satisfy all given conditions. | null | In the first test case, rectangular parallelepiped $$$(1, 1, 1)$$$ can be only divided into rectangular parallelepiped with sizes $$$(1, 1, 1)$$$.
In the second test case, rectangular parallelepiped $$$(1, 6, 1)$$$ can be divided into rectangular parallelepipeds with sizes $$$(1, 1, 1)$$$, $$$(1, 1, 2)$$$, $$$(1, 1, 3... | [{"input": "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100", "output": "1\n4\n4\n165"}] | 2,400 | ["bitmasks", "brute force", "combinatorics", "math", "number theory"] | 28 | [{"input": "4\r\n1 1 1\r\n1 6 1\r\n2 2 2\r\n100 100 100\r\n", "output": "1\r\n4\r\n4\r\n165\r\n"}, {"input": "10\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "10\r\n9 6 8\r\n5 5 2\r\n8 9 2\r\n2 ... | false | stdio | null | true |
962/E | 962 | E | Python 3 | TESTS | 10 | 421 | 0 | 179002342 | N = int(input())
lastR = None
lastB = None
hasP = False
sum = 0
for i in range(N):
x, c = input().split()
x = int(x)
if c == 'R':
if lastR is not None:
sum += x - lastR
lastR = x
elif c == 'B':
if lastB is not None:
sum += x - lastB
lastB = x
... | 45 | 405 | 13,516,800 | 94132083 | import sys
n = int(sys.stdin.buffer.readline().decode('utf-8'))
pos, type_ = [0]*n, ['']*n
for i, (x, c) in enumerate(line.decode('utf-8').split() for line in sys.stdin.buffer):
pos[i] = int(x)
type_[i] = c
r_cnt = type_.count('R')
b_cnt = type_.count('B')
p_cnt = n - r_cnt - b_cnt
inf = 2100000000
if p_cn... | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Byteland, Berland and Disputed Cities | The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities:
- the cities of Byteland,
- the cities of Berland,
- disputed cities.
Recen... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities.
The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals ... | Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from an... | null | In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$.
In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the n... | [{"input": "4\n-5 R\n0 P\n3 P\n7 B", "output": "12"}, {"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R", "output": "24"}] | 2,200 | ["constructive algorithms", "greedy"] | 45 | [{"input": "4\r\n-5 R\r\n0 P\r\n3 P\r\n7 B\r\n", "output": "12\r\n"}, {"input": "5\r\n10 R\r\n14 B\r\n16 B\r\n21 R\r\n32 R\r\n", "output": "24\r\n"}, {"input": "10\r\n66 R\r\n67 R\r\n72 R\r\n73 R\r\n76 R\r\n78 B\r\n79 B\r\n83 B\r\n84 B\r\n85 P\r\n", "output": "26\r\n"}, {"input": "10\r\n61 R\r\n64 R\r\n68 R\r\n71 R\r\n... | false | stdio | null | true |
995/D | 995 | D | Python 3 | TESTS | 3 | 1,029 | 31,539,200 | 39730519 | from sys import stdin
def main():
n, m = map(int, input().split())
ff = list(map(float, input().split()))
scale, r = .5 ** n, sum(ff)
res = [r * scale]
for s in stdin.read().splitlines():
i, f = map(int, s.split())
r += f - ff[i]
res.append(r * scale)
print('\n'.join(ma... | 53 | 1,746 | 31,641,600 | 39623059 | n, r = [int(x) for x in input().split()]
n = 2 ** n
xs = [int(x) for x in input().split()]
s = sum(xs)
res = [0 for _ in range(r+1)]
for i in range(r):
res[i] = s / n
i, val = [int(x) for x in input().split()]
s += val - xs[i]
xs[i] = val
res[r] = s / n
print("\n".join(map(str, res))) | Codeforces Round 492 (Div. 1) [Thanks, uDebug!] | CF | 2,018 | 3 | 256 | Game | Allen and Bessie are playing a simple number game. They both know a function $$$f: \{0, 1\}^n \to \mathbb{R}$$$, i. e. the function takes $$$n$$$ binary arguments and returns a real value. At the start of the game, the variables $$$x_1, x_2, \dots, x_n$$$ are all set to $$$-1$$$. Each round, with equal probability, one... | The first line contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n \le 18$$$, $$$0 \le r \le 2^{18}$$$).
The next line contains $$$2^n$$$ integers $$$c_0, c_1, \dots, c_{2^n-1}$$$ ($$$0 \le c_i \le 10^9$$$), denoting the initial values of $$$f$$$. More specifically, $$$f(x_0, x_1, \dots, x_{n-1}) = c_x$$$, if $$$x =... | Print $$$r+1$$$ lines, the $$$i$$$-th of which denotes the value of the game $$$f$$$ during the $$$i$$$-th round. Your answer must have absolute or relative error within $$$10^{-6}$$$.
Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max{(1... | null | Consider the second test case. If Allen goes first, he will set $$$x_1 \to 1$$$, so the final value will be $$$3$$$. If Bessie goes first, then she will set $$$x_1 \to 0$$$ so the final value will be $$$2$$$. Thus the answer is $$$2.5$$$.
In the third test case, the game value will always be $$$1$$$ regardless of Alle... | [{"input": "2 2\n0 1 2 3\n2 5\n0 4", "output": "1.500000\n2.250000\n3.250000"}, {"input": "1 0\n2 3", "output": "2.500000"}, {"input": "2 0\n1 1 1 1", "output": "1.000000"}] | 2,500 | ["math"] | 53 | [{"input": "2 2\r\n0 1 2 3\r\n2 5\r\n0 4\r\n", "output": "1.500000\r\n2.250000\r\n3.250000\r\n"}, {"input": "1 0\r\n2 3\r\n", "output": "2.500000\r\n"}, {"input": "2 0\r\n1 1 1 1\r\n", "output": "1.000000\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n, r = map(int, f.readline().split())
expected_lines = r + 1
with open(output_path) as f:
correct = [float(line.strip()) for line in f]
if le... | true |
729/D | 729 | D | Python 3 | PRETESTS | 1 | 46 | 0 | 22360158 | n,a,b,k = map(int,input().split())
s= input()
i=0
kol=0
qor=0
for i in range(n):
if s[i]=='0':
kol+=1
if s[i]=='1':
qor+= kol//b
kol=0
qor+=kol//b
print(qor-a+1)
kn=0
e=0
i=0
q1=1
while i<(qor-a+1):
if s[e]=='0':
kn+=1
e+=1
if kn>=b:
print((kn+2*q... | 21 | 155 | 17,510,400 | 199341648 | import math
from sys import stdin
input = lambda: stdin.readline()[:-1]
def solve():
n, a, b, k = map(int, input().split())
st = input()
seg = []
dx = [i for i in range(n) if st[i] == '1']
dx = [-1] + dx
dx.append(n)
dif = []
for i in range(len(dx) - 1):
if dx[i + 1] - dx[i] >... | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
400/A | 400 | A | Python 3 | TESTS | 6 | 109 | 307,200 | 99605756 | t = int(input())
for i in range(t):
s = input()
lst = []
if 'X' in s:
lst.append('1x12')
for i in range(6):
if s[i]==s[i+6]=='X':
lst.append('2x6')
break
for i in range(4):
if s[i]==s[i+4]==s[i+8]=='X':
lst.append('3x4')
break
... | 44 | 62 | 0 | 5934069 | #!/usr/bin/env python3
def read_ints():
return map(int, input().strip().split())
t, = read_ints()
for _ in range(t):
x = input()
correct = []
for a in [1, 2, 3, 4, 6, 12]:
cor = False
for c in range(0, 12//a):
s = set(x[c::12//a])
if len(s)==1 and 'X' in s:
cor = True
break
if cor == True... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac... | null | null | [{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}] | 1,000 | ["implementation"] | 44 | [{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX... | false | stdio | null | true |
1007/B | 1007 | B | Python 3 | PRETESTS | 2 | 108 | 1,126,400 | 40282760 | cache = [0 for i in range(10**5 + 10)]
def gcd(a, b):
if a > b:
return gcd(b, a)
elif a == 0:
return b
elif a == 1:
return a
else:
return gcd(b % a, a)
def cd(x):
if cache[x] > 0:
return cache[x]
d = 2
res = 1
while d**2 <= x:
cur = 0
while x % d == 0:
cur += 1
x //= d
res *= (cur + 1)
... | 28 | 998 | 8,396,800 | 40311323 | from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3, 1, 2, 2, 2, 1] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
... | Codeforces Round 497 (Div. 1) | CF | 2,018 | 2 | 256 | Pave the Parallelepiped | You are given a rectangular parallelepiped with sides of positive integer lengths $$$A$$$, $$$B$$$ and $$$C$$$.
Find the number of different groups of three integers ($$$a$$$, $$$b$$$, $$$c$$$) such that $$$1\leq a\leq b\leq c$$$ and parallelepiped $$$A\times B\times C$$$ can be paved with parallelepipeds $$$a\times b... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains three integers $$$A$$$, $$$B$$$ and $$$C$$$ ($$$1 \leq A, B, C \leq 10^5$$$) — the sizes of the parallelepiped. | For each test case, print the number of different groups of three points that satisfy all given conditions. | null | In the first test case, rectangular parallelepiped $$$(1, 1, 1)$$$ can be only divided into rectangular parallelepiped with sizes $$$(1, 1, 1)$$$.
In the second test case, rectangular parallelepiped $$$(1, 6, 1)$$$ can be divided into rectangular parallelepipeds with sizes $$$(1, 1, 1)$$$, $$$(1, 1, 2)$$$, $$$(1, 1, 3... | [{"input": "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100", "output": "1\n4\n4\n165"}] | 2,400 | ["bitmasks", "brute force", "combinatorics", "math", "number theory"] | 28 | [{"input": "4\r\n1 1 1\r\n1 6 1\r\n2 2 2\r\n100 100 100\r\n", "output": "1\r\n4\r\n4\r\n165\r\n"}, {"input": "10\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "10\r\n9 6 8\r\n5 5 2\r\n8 9 2\r\n2 ... | false | stdio | null | true |
1007/B | 1007 | B | Python 3 | TESTS | 2 | 873 | 47,513,600 | 40507451 | #
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
try :
import numpy
dprint = print
dprint('debug mode')
except ModuleNotFoundError:
def... | 28 | 998 | 8,396,800 | 40311323 | from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3, 1, 2, 2, 2, 1] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
... | Codeforces Round 497 (Div. 1) | CF | 2,018 | 2 | 256 | Pave the Parallelepiped | You are given a rectangular parallelepiped with sides of positive integer lengths $$$A$$$, $$$B$$$ and $$$C$$$.
Find the number of different groups of three integers ($$$a$$$, $$$b$$$, $$$c$$$) such that $$$1\leq a\leq b\leq c$$$ and parallelepiped $$$A\times B\times C$$$ can be paved with parallelepipeds $$$a\times b... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains three integers $$$A$$$, $$$B$$$ and $$$C$$$ ($$$1 \leq A, B, C \leq 10^5$$$) — the sizes of the parallelepiped. | For each test case, print the number of different groups of three points that satisfy all given conditions. | null | In the first test case, rectangular parallelepiped $$$(1, 1, 1)$$$ can be only divided into rectangular parallelepiped with sizes $$$(1, 1, 1)$$$.
In the second test case, rectangular parallelepiped $$$(1, 6, 1)$$$ can be divided into rectangular parallelepipeds with sizes $$$(1, 1, 1)$$$, $$$(1, 1, 2)$$$, $$$(1, 1, 3... | [{"input": "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100", "output": "1\n4\n4\n165"}] | 2,400 | ["bitmasks", "brute force", "combinatorics", "math", "number theory"] | 28 | [{"input": "4\r\n1 1 1\r\n1 6 1\r\n2 2 2\r\n100 100 100\r\n", "output": "1\r\n4\r\n4\r\n165\r\n"}, {"input": "10\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "10\r\n9 6 8\r\n5 5 2\r\n8 9 2\r\n2 ... | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 139 | 614,400 | 103138362 | def isPrime(n):
i = 2
if n == 21:
return True
elif n == 1:
return False
while i*i <= n:
if n % i == 0:
return False
else:
i+=1
return True
a = int(input())
w = map(int,input().split())
b = map(lambda x:x*4+1,w)
for w in b:
w-=1
w/=4
... | 8 | 62 | 921,600 | 221460183 | input()
def sqaure(array):
for number in array:
if int(number) % 2 == 0:
print(int(number) * 4 + 1)
elif -(-int(number) // 2) % 2 == 0:
print(int(number) +1)
else: print(2 * int(number) + 1)
sqaure(input().split()) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 124 | 409,600 | 45181564 | x=int(input())
a=list(map(int,input().split()))
for i in range(x):
if a[i]%2==0:
print(a[i]*4+1)
else:
print(a[i]*2+1) | 8 | 77 | 614,400 | 142595505 | import sys
import math
def get_int():
return int(sys.stdin.readline())
def get_string():
return sys.stdin.readline().strip()
FILE=False
if FILE:
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
t=get_int()
sides=list(map(int,get_string().split()))
for side in sides:
z=math.gc... | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 109 | 819,200 | 57581192 | N = int(input())
num = input().split()
for x in num:
y = int(x)
if( y % 2 == 0):
y = 4*y + 1;
else:
y = 2*y + 1;
print(y) | 8 | 77 | 5,427,200 | 180481809 | from math import gcd
n = int(input())
arr = input().split()
res = [4*int(i)//gcd(4*int(i), int(i) + 1) + 1 for i in arr]
for i in res:
print(i) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
1000/C | 1000 | C | Python 3 | TESTS | 3 | 514 | 22,937,600 | 216918080 | import sys
# sys.stdin = open("2.in", "r")
N = int(input())
beg = [0]*N
end = [0]*N
for i in range(N):
beg[i], end[i] = list(map(int, input().split()))
end[i] += 1
beg.sort()
end.sort()
p1 = 0
p2 = 0
count = 0
prev = 0
res = [0]*(N+1)
while p1 < len(beg):
if beg[p1] <= end[p2]:
res[count] += beg[... | 18 | 576 | 43,622,400 | 212247138 | import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
d = defaultdict(int)
ans = [0] * (n + 1)
for i in range(n):
l ,r = map(int, input().split())
d[l] += 1
d[r + 1] -= 1
s = p = 0
for k in sorted(d):
ans[s] += k - p
s += d[k]
p = k
print(*ans[1:]... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Covered Points Count | You are given $$$n$$$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $$$k \in [1..n]$$$, calculate the number of points... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments.
The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains a pair of integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 10^{18}$$$) — the endpoints of the $$$i$$$-th segment. | Print $$$n$$$ space separated integers $$$cnt_1, cnt_2, \dots, cnt_n$$$, where $$$cnt_i$$$ is equal to the number of points such that the number of segments that cover these points equals to $$$i$$$. | null | The picture describing the first example:
Points with coordinates $$$[0, 4, 5, 6, 7, 8]$$$ are covered by one segment, points $$$[1, 2]$$$ are covered by two segments and point $$$[3]$$$ is covered by three segments.
The picture describing the second example:
Points $$$[1, 4, 5, 6, 7]$$$ are covered by one segment, ... | [{"input": "3\n0 3\n1 3\n3 8", "output": "6 2 1"}, {"input": "3\n1 3\n2 4\n5 7", "output": "5 2 0"}] | 1,700 | ["data structures", "implementation", "sortings"] | 18 | [{"input": "3\r\n0 3\r\n1 3\r\n3 8\r\n", "output": "6 2 1 \r\n"}, {"input": "3\r\n1 3\r\n2 4\r\n5 7\r\n", "output": "5 2 0 \r\n"}, {"input": "1\r\n0 1000000000000000000\r\n", "output": "1000000000000000001 \r\n"}] | false | stdio | null | true |
843/A | 843 | A | Python 3 | TESTS | 1 | 15 | 0 | 195042946 | n = int(input())
a = list(map(int, input().split()))
sorted_a = sorted(a)
ind = 0
num = a[0]
ans = []
for i in range(1, n):
num = max(a[ind:i + 1])
if sorted_a[i] == num and ind != i:
ans.append((2, ind + 1, i + 1))
for j in range(ind + 1, i):
ans.append((1, j + 1))
ind = i ... | 71 | 421 | 24,371,200 | 233547685 | # LUOGU_RID: 136079801
def read_input():
"""
Read the input from the user.
Returns:
- n: The length of the sequence.
- a: The sequence of integers.
"""
n = int(input())
a = list(map(int, input().split()))
return n, a
def discretization(n, a):
"""
Sort the sequence and gene... | AIM Tech Round 4 (Div. 1) | CF | 2,017 | 1 | 256 | Sorting by Subsequences | You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequence is... | The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence.
The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. | In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.
In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤... | null | In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | [{"input": "6\n3 2 1 6 5 4", "output": "4\n2 1 3\n1 2\n2 4 6\n1 5"}, {"input": "6\n83 -75 -49 11 37 62", "output": "1\n6 1 2 3 4 5 6"}] | 1,400 | ["dfs and similar", "dsu", "implementation", "math", "sortings"] | 71 | [{"input": "6\r\n3 2 1 6 5 4\r\n", "output": "4\r\n2 1 3\r\n1 2\r\n2 4 6\r\n1 5\r\n"}, {"input": "6\r\n83 -75 -49 11 37 62\r\n", "output": "1\r\n6 1 2 3 4 5 6\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 1\r\n1 2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n2... | false | stdio | import sys
from collections import defaultdict
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
sorted_a = sorted(a)
pos_in_sorted = {v: i+1 f... | true |
419/B | 420 | B | Python 3 | TESTS | 0 | 15 | 0 | 169612615 | import sys
n, m = map(int, input().split())
def best_input():return list(map(str.strip, sys.stdin))
who_is_now = set()
who_was = set()
ret = set(range(1, n + 1))
k = 1
posl = None
pod = None
for t in best_input():
init = int(t.split()[1])
ret -= set([init])
if '-' in t:
if (not who_is_now) and (... | 61 | 343 | 9,523,200 | 108631899 | n, m = map(int, input().split())
covers_all = set(range(1, n+1))
in_there = set([])
occurred = set([])
minus_delete_candidates = set([])
plus_delete_candidates = set([])
for i in range(m):
a, b = input().split()
b = int(b)
if a == '+':
in_there.add(b)
covers_all -= (plus_delete_candidates - in_there)
p... | Coder-Strike 2014 - Finals | CF | 2,014 | 1 | 256 | Online Meeting | Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat.
One day the director of the F ... | The first line contains integers n and m (1 ≤ n, m ≤ 105) — the number of team participants and the number of messages. Each of the next m lines contains a message in the format:
- '+ id': the record means that the person with number id (1 ≤ id ≤ n) has logged on to the meeting.
- '- id': the record means that the per... | In the first line print integer k (0 ≤ k ≤ n) — how many people can be leaders. In the next line, print k integers in the increasing order — the numbers of the people who can be leaders.
If the data is such that no member of the team can be a leader, print a single number 0. | null | null | [{"input": "5 4\n+ 1\n+ 2\n- 2\n- 1", "output": "4\n1 3 4 5"}, {"input": "3 2\n+ 1\n- 2", "output": "1\n3"}, {"input": "2 4\n+ 1\n- 1\n+ 2\n- 2", "output": "0"}, {"input": "5 6\n+ 1\n- 1\n- 3\n+ 3\n+ 4\n- 4", "output": "3\n2 3 5"}, {"input": "2 4\n+ 1\n- 2\n+ 2\n- 1", "output": "0"}] | 1,800 | [] | 61 | [{"input": "5 4\r\n+ 1\r\n+ 2\r\n- 2\r\n- 1\r\n", "output": "4\r\n1 3 4 5 "}, {"input": "3 2\r\n+ 1\r\n- 2\r\n", "output": "1\r\n3 "}, {"input": "2 4\r\n+ 1\r\n- 1\r\n+ 2\r\n- 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n+ 1\r\n- 1\r\n- 3\r\n+ 3\r\n+ 4\r\n- 4\r\n", "output": "3\r\n2 3 5 "}, {"input": "2 4\r\n+ 1\r\n- ... | false | stdio | null | true |
627/B | 627 | B | PyPy 3 | TESTS | 3 | 2,995 | 8,806,400 | 53175579 | n, k, a, b, q = map(int, input().split())
cnt = [0] * (n + 1)
days = [0] * (n+1)
for i in range(q):
c = list(map(int, input().split()))
if len(c) == 3:
cnt[c[1] - 1] += cnt[c[1] - 2] + min(b, c[2])
days[c[1] - 1] += c[2]
else:
cop = cnt[::]
c[1] += k
cop[c[1] - 1] = c... | 42 | 1,981 | 45,670,400 | 16414444 | from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y, initilizer = None):
self.function = function
self.initilizer = initilizer
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in r... | 8VC Venture Cup 2016 - Final Round | CF | 2,016 | 4 | 256 | Factory Repairs | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is o... | For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days. | null | Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for t... | [{"input": "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "output": "3\n6\n4"}, {"input": "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2", "output": "7\n1"}] | 1,700 | ["data structures"] | 42 | [{"input": "5 2 2 1 8\r\n1 1 2\r\n1 5 3\r\n1 2 1\r\n2 2\r\n1 4 2\r\n1 3 2\r\n2 1\r\n2 3\r\n", "output": "3\r\n6\r\n4\r\n"}, {"input": "5 4 10 1 6\r\n1 1 5\r\n1 5 5\r\n1 3 2\r\n1 5 2\r\n2 1\r\n2 2\r\n", "output": "7\r\n1\r\n"}, {"input": "1 1 2 1 1\r\n2 1\r\n", "output": "0\r\n"}] | false | stdio | null | true |
1000/C | 1000 | C | Python 3 | TESTS | 10 | 1,403 | 46,284,800 | 186684648 | n = int(input())
lines = []
for i in range(n):
line = list(map(int,input().split()))
lines.append([line[0],1])
lines.append([line[1]+1,-1]) # attention
lines.sort(key=lambda x:x[0])
res = [0 for _ in range(n)]
ans = 0
for i in range(1,2*n):
res[ans] += lines[i][0] - lines[i-1][0]
ans += lines[i][... | 18 | 936 | 44,032,000 | 197134996 | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
debug = lambda *x: print(*x, file=sys.stderr)
ceil_ = lambda a, b: (a + b - 1) // b
sum_n = lambda n: (n * (n + 1)) // 2
get_bit = lambda x, i: (x >> i) & 1
Mint, Mlon... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Covered Points Count | You are given $$$n$$$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $$$k \in [1..n]$$$, calculate the number of points... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments.
The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains a pair of integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 10^{18}$$$) — the endpoints of the $$$i$$$-th segment. | Print $$$n$$$ space separated integers $$$cnt_1, cnt_2, \dots, cnt_n$$$, where $$$cnt_i$$$ is equal to the number of points such that the number of segments that cover these points equals to $$$i$$$. | null | The picture describing the first example:
Points with coordinates $$$[0, 4, 5, 6, 7, 8]$$$ are covered by one segment, points $$$[1, 2]$$$ are covered by two segments and point $$$[3]$$$ is covered by three segments.
The picture describing the second example:
Points $$$[1, 4, 5, 6, 7]$$$ are covered by one segment, ... | [{"input": "3\n0 3\n1 3\n3 8", "output": "6 2 1"}, {"input": "3\n1 3\n2 4\n5 7", "output": "5 2 0"}] | 1,700 | ["data structures", "implementation", "sortings"] | 18 | [{"input": "3\r\n0 3\r\n1 3\r\n3 8\r\n", "output": "6 2 1 \r\n"}, {"input": "3\r\n1 3\r\n2 4\r\n5 7\r\n", "output": "5 2 0 \r\n"}, {"input": "1\r\n0 1000000000000000000\r\n", "output": "1000000000000000001 \r\n"}] | false | stdio | null | true |
1000/C | 1000 | C | Python 3 | TESTS | 10 | 1,699 | 40,243,200 | 178631506 | # Write your code here :-)
# Covered Points Count
from collections import Counter
n = int(input())
endpoints = set()
change = Counter()
for _ in range(n):
l, r = map(int, input().split())
endpoints.update((l, r + 1))
change[l] += 1
change[r + 1] -= 1
endpoints = sorted(endpoints)
cur_count = 0
ans = [0... | 18 | 1,559 | 31,027,200 | 39714395 | n=int(input())
l=[0 for i in range(n+1)]
lo=[]
lc=[]
for i in range(n):
x,y=map(int,input().strip().split())
lo.append(x)
lc.append(y)
lo.sort()
lc.sort()
i=1
j=0
count=1
st=lo[0]
ref=0
while(i<n and j<n):
if (lo[i]<=lc[j]):
if ref==0:
l[count]=l[count]+lo[i]-st
else:
l[count]=l[count]+lo[i]-st-1
ref=0
... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Covered Points Count | You are given $$$n$$$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $$$k \in [1..n]$$$, calculate the number of points... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments.
The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains a pair of integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 10^{18}$$$) — the endpoints of the $$$i$$$-th segment. | Print $$$n$$$ space separated integers $$$cnt_1, cnt_2, \dots, cnt_n$$$, where $$$cnt_i$$$ is equal to the number of points such that the number of segments that cover these points equals to $$$i$$$. | null | The picture describing the first example:
Points with coordinates $$$[0, 4, 5, 6, 7, 8]$$$ are covered by one segment, points $$$[1, 2]$$$ are covered by two segments and point $$$[3]$$$ is covered by three segments.
The picture describing the second example:
Points $$$[1, 4, 5, 6, 7]$$$ are covered by one segment, ... | [{"input": "3\n0 3\n1 3\n3 8", "output": "6 2 1"}, {"input": "3\n1 3\n2 4\n5 7", "output": "5 2 0"}] | 1,700 | ["data structures", "implementation", "sortings"] | 18 | [{"input": "3\r\n0 3\r\n1 3\r\n3 8\r\n", "output": "6 2 1 \r\n"}, {"input": "3\r\n1 3\r\n2 4\r\n5 7\r\n", "output": "5 2 0 \r\n"}, {"input": "1\r\n0 1000000000000000000\r\n", "output": "1000000000000000001 \r\n"}] | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 218 | 512,000 | 7060737 | t = int(input())
n = list(map(int,input().split()))
for i in range(t):
if n[i] % 2 == 0:
print((n[i]*4) + 1)
else:
print((n[i]*2) + 1) | 8 | 77 | 5,427,200 | 180516435 | from math import gcd
input()
for i in list(map(int, input().split())):
print(4 * i // gcd(4 * i, i + 1) + 1) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
545/B | 545 | B | Python 3 | TESTS | 0 | 30 | 0 | 194911722 | def distance(a,b):
rast = 0
for i in range(len(a)):
if a[i] != b[i]:
rast += 1
return rast
def ravn(a,b):
while len(a) < len(b):
a = '0'+a
return a
a = '000'
b = '111'
i = 0
a1 = ''
try:
while len(a1)<=len(a):
i+=1
a1 = bin(i)
a1 = a1.replace... | 54 | 109 | 409,600 | 11148464 | s = input()
t = input()
sa = s.count('0')
sb = s.count('1')
ta = t.count('0')
tb = t.count('1')
n = len(s)
L = abs(sa - ta) + abs(sb - tb)
L /= 2
if L % 2 == 1:
print("impossible")
else:
ans = ''
c = 0
for i in range(n):
if s[i] == t[i]:
ans += s[i]
else:
if c == ... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Equidistant String | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num... | The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one. | Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).
If there are multiple possible answers, print any of them. | null | In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101. | [{"input": "0001\n1011", "output": "0011"}, {"input": "000\n111", "output": "impossible"}] | 1,100 | ["greedy"] | 54 | [{"input": "0001\r\n1011\r\n", "output": "0011\r\n"}, {"input": "000\r\n111\r\n", "output": "impossible\r\n"}, {"input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\r\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
s = f.readline().strip()
t = f.readline().strip()
n = len(s)
assert len(t) == n
with open(submission_path, 'r') as f:
submission... | true |
1000/C | 1000 | C | PyPy 3-64 | TESTS | 10 | 1,824 | 69,222,400 | 217776662 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
N = int(input())
A = []
for _... | 18 | 1,731 | 85,401,600 | 187055982 | import collections
if __name__ == '__main__':
n = int(input())
a = collections.defaultdict(int)
# O(n) loop
for _ in range(n):
start, end = [int(x) for x in input().split()]
a[start] += 1
a[end + 1] -= 1
# print(a)
# takes n*long(n) for sorting
key_points = sorted(... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Covered Points Count | You are given $$$n$$$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $$$k \in [1..n]$$$, calculate the number of points... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments.
The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains a pair of integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 10^{18}$$$) — the endpoints of the $$$i$$$-th segment. | Print $$$n$$$ space separated integers $$$cnt_1, cnt_2, \dots, cnt_n$$$, where $$$cnt_i$$$ is equal to the number of points such that the number of segments that cover these points equals to $$$i$$$. | null | The picture describing the first example:
Points with coordinates $$$[0, 4, 5, 6, 7, 8]$$$ are covered by one segment, points $$$[1, 2]$$$ are covered by two segments and point $$$[3]$$$ is covered by three segments.
The picture describing the second example:
Points $$$[1, 4, 5, 6, 7]$$$ are covered by one segment, ... | [{"input": "3\n0 3\n1 3\n3 8", "output": "6 2 1"}, {"input": "3\n1 3\n2 4\n5 7", "output": "5 2 0"}] | 1,700 | ["data structures", "implementation", "sortings"] | 18 | [{"input": "3\r\n0 3\r\n1 3\r\n3 8\r\n", "output": "6 2 1 \r\n"}, {"input": "3\r\n1 3\r\n2 4\r\n5 7\r\n", "output": "5 2 0 \r\n"}, {"input": "1\r\n0 1000000000000000000\r\n", "output": "1000000000000000001 \r\n"}] | false | stdio | null | true |
1000/C | 1000 | C | PyPy 3-64 | TESTS | 3 | 280 | 41,164,800 | 212243374 | import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a.sort()
ans = [0] * (n)
ans[0] = a[0][1] - a[0][0] + 1
for i in range(1, n):
ans[i] += min(a[i][1], a[i - 1][1]) - a[i][0] + 1
ans[i - 1] -= ans[i]
ans[0] += max(0, a[... | 18 | 1,793 | 80,793,600 | 217500762 | import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
N = int(input())
A = []
for _ in range(N):
l,r = map(int, input().split())
A.append((l,1))
A.append((r+1,-1))
lib = defaultdict(int)
A.sort()
cur = 0... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Covered Points Count | You are given $$$n$$$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $$$k \in [1..n]$$$, calculate the number of points... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments.
The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains a pair of integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 10^{18}$$$) — the endpoints of the $$$i$$$-th segment. | Print $$$n$$$ space separated integers $$$cnt_1, cnt_2, \dots, cnt_n$$$, where $$$cnt_i$$$ is equal to the number of points such that the number of segments that cover these points equals to $$$i$$$. | null | The picture describing the first example:
Points with coordinates $$$[0, 4, 5, 6, 7, 8]$$$ are covered by one segment, points $$$[1, 2]$$$ are covered by two segments and point $$$[3]$$$ is covered by three segments.
The picture describing the second example:
Points $$$[1, 4, 5, 6, 7]$$$ are covered by one segment, ... | [{"input": "3\n0 3\n1 3\n3 8", "output": "6 2 1"}, {"input": "3\n1 3\n2 4\n5 7", "output": "5 2 0"}] | 1,700 | ["data structures", "implementation", "sortings"] | 18 | [{"input": "3\r\n0 3\r\n1 3\r\n3 8\r\n", "output": "6 2 1 \r\n"}, {"input": "3\r\n1 3\r\n2 4\r\n5 7\r\n", "output": "5 2 0 \r\n"}, {"input": "1\r\n0 1000000000000000000\r\n", "output": "1000000000000000001 \r\n"}] | false | stdio | null | true |
400/A | 400 | A | PyPy 3 | TESTS | 1 | 108 | 2,355,200 | 222671942 | t = int(input())
for l in range(t):
s = input()
l = []
for i in range(1, 13):
if 12 % i == 0:
for j in range(12 // i):
c = ""
for k in range(i):
c = c + s[(k * (12 // i)) + j]
if c == "X" * i:
l.append(f"{i}x{12 // i}")
print(len(l), " ".join(list(map(str, l)))) | 44 | 62 | 0 | 5934536 | # http://codeforces.com/contest/400/problem/0
# Codeforces : A. Inna and choose options
liste_a = (1, 2, 3, 4, 6, 12)
liste_results = []
def process(essai):
global liste_results
liste_av = [0]
for a in liste_a:
b = 12 // a
for r in range(b):
if essai[r::b] == 'X'*a:
... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac... | null | null | [{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}] | 1,000 | ["implementation"] | 44 | [{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX... | false | stdio | null | true |
400/A | 400 | A | PyPy 3 | TESTS | 1 | 93 | 20,172,800 | 115899395 | for _ in range(int(input())):
s=list(input())
n=len(s)
ans=[]
d=[1,2,3,4,6,12]
for item in d:
z=item-1
for i in range(z,n,item):
if s[i]!='X':
break
else:
ans.append((12//item,item))
print(len(ans),end=' ')
ans.sort()
for item in ans:
print(f'{item[0]}x{item[1]}',end=' ')
print() | 44 | 62 | 0 | 5935369 | for _ in range(int(input())):
cards = input()
count = 0
output = ''
if 'X' in cards:
count += 1
output += ' 1x12'
for q, p in zip(cards[:6], cards[6:]):
if q == p == 'X':
count += 1
output += ' 2x6'
break
for q, p, r in zip(cards[:4], c... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac... | null | null | [{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}] | 1,000 | ["implementation"] | 44 | [{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX... | false | stdio | null | true |
627/B | 627 | B | Python 3 | TESTS | 3 | 1,388 | 409,600 | 51967316 | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def add(a,x,v):
while x<len(a):
a[x] += v
x |= x+1
def get(a,x):
r = 0
while x>=0:
r += a[x]
x = (x&(x+1))-1
return r
n, k, a, b, q = mints()
h1 ... | 42 | 2,433 | 18,739,200 | 209762436 | N = 4 * 10**5 + 10
s = [[0] * N for i in range(2)]
x, y = [0] * N, [0] * N
def modify(q : int, x: int, v: int, n: int) -> None:
while x <= n:
s[q][x] += v
x = (x | (x - 1)) + 1
def find_sum(q: int, x: int) -> int:
ret = 0
while x > 0:
ret += s[q][x]
x &= x - 1
return ret
n, k... | 8VC Venture Cup 2016 - Final Round | CF | 2,016 | 4 | 256 | Factory Repairs | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is o... | For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days. | null | Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for t... | [{"input": "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "output": "3\n6\n4"}, {"input": "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2", "output": "7\n1"}] | 1,700 | ["data structures"] | 42 | [{"input": "5 2 2 1 8\r\n1 1 2\r\n1 5 3\r\n1 2 1\r\n2 2\r\n1 4 2\r\n1 3 2\r\n2 1\r\n2 3\r\n", "output": "3\r\n6\r\n4\r\n"}, {"input": "5 4 10 1 6\r\n1 1 5\r\n1 5 5\r\n1 3 2\r\n1 5 2\r\n2 1\r\n2 2\r\n", "output": "7\r\n1\r\n"}, {"input": "1 1 2 1 1\r\n2 1\r\n", "output": "0\r\n"}] | false | stdio | null | true |
237/D | 237 | D | PyPy 3 | TESTS | 3 | 184 | 0 | 110451051 | n=int(input())
adj = [[] for _ in range(n+5)]
for _ in range(n-1):
u, v = map(int,(input().split()))
adj[u].append(v)
adj[v].append(u)
nodes = []
edges = []
def solve(cur, idx):
fi, se = cur
for u in adj[se]:
if(u is fi):
continue
nodes.append((u, se))
edges.a... | 40 | 1,090 | 112,537,600 | 142574146 | from bisect import bisect_right
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
sel... | Codeforces Round 147 (Div. 2) | CF | 2,012 | 2 | 256 | T-decomposition | You've got a undirected tree s, consisting of n nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.
Let's denote the set of all nodes s as v. Let's consider an undirected tree t, whose nodes are some non-empty subsets of v, we'll call them xi $$( x _ { i } \subset... | The first line contains a single integer n (2 ≤ n ≤ 105), that denotes the number of nodes in tree s.
Each of the following n - 1 lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting that the nodes of tree s with indices ai and bi are connected by an edge.
Consider the nodes of tree ... | In the first line print a single integer m that denotes the number of nodes in the required T-decomposition.
Then print m lines, containing descriptions of the T-decomposition nodes. In the i-th (1 ≤ i ≤ m) of them print the description of node xi of the T-decomposition. The description of each node xi should start fr... | null | null | [{"input": "2\n1 2", "output": "1\n2 1 2"}, {"input": "3\n1 2\n2 3", "output": "2\n2 1 2\n2 2 3\n1 2"}, {"input": "4\n2 1\n3 1\n4 1", "output": "3\n2 2 1\n2 3 1\n2 4 1\n1 2\n2 3"}] | 2,000 | ["dfs and similar", "graphs", "greedy", "trees"] | 40 | [{"input": "2\r\n1 2\r\n", "output": "1\r\n2 1 2\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n", "output": "2\r\n2 1 2\r\n2 2 3\r\n1 2\r\n"}, {"input": "4\r\n2 1\r\n3 1\r\n4 1\r\n", "output": "3\r\n2 2 1\r\n2 3 1\r\n2 4 1\r\n1 2\r\n2 3\r\n"}, {"input": "6\r\n2 5\r\n4 3\r\n4 2\r\n4 6\r\n3 1\r\n", "output": "5\r\n2 2 5\r\n2 4 3\... | false | stdio | import sys
from collections import deque
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input tree
with open(input_path, 'r') as f:
n = int(f.readline().strip())
original_edges = set()
for _ in range(n-1):
a, ... | true |
855/C | 855 | C | PyPy 3-64 | TESTS | 3 | 77 | 0 | 140099447 | import sys
import os
from io import BytesIO, IOBase
from _collections import deque
# 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
... | 71 | 857 | 73,113,600 | 140174254 | import sys
import os
from io import BytesIO, IOBase
from _collections import deque
# 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
... | Manthan, Codefest 17 | CF | 2,017 | 2 | 256 | Helga Hufflepuff's Cup | Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.
The Wizarding bank is in the form of a tree with total n vaults where each vault has... | The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109).
Each of the next n - 1 lines contain two space separated integers ui and vi (1 ≤ ui, vi ≤ n) representing the i-th edge, which shows there is a pat... | Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7. | null | In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2. | [{"input": "4 2\n1 2\n2 3\n1 4\n1 2", "output": "1"}, {"input": "3 3\n1 2\n1 3\n2 1", "output": "13"}, {"input": "3 1\n1 2\n1 3\n1 1", "output": "0"}] | 2,000 | ["dp", "trees"] | 71 | [{"input": "4 2\r\n1 2\r\n2 3\r\n1 4\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 1\r\n", "output": "13\r\n"}, {"input": "3 1\r\n1 2\r\n1 3\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3 1000000000\r\n2 3\r\n3 1\r\n585430050 9\r\n", "output": "91592837\r\n"}, {"input": "4 50000\r\n2 1\r\n4 2\r\n2 3... | false | stdio | null | true |
958/C1 | 958 | C1 | Python 3 | TESTS | 9 | 124 | 9,523,200 | 90647038 | m,n=list(map(int,input().split()))
l=list(map(int,input().split()))
a=[0]*m
a[0],ma=l[0],0
for i in range(1,m):
a[i]=a[i-1]+l[i]
for i in range(m):
if(a[i]%n+(a[m-1]-a[i])%n)>ma:
ma=(a[i]%n+(a[m-1]-a[i])%n)
else:
break
print(ma) | 27 | 62 | 7,372,800 | 143250560 | n, p = map(int, input().split())
a = list(map(int, input().split()))
a = [c % p for c in a]
s = sum(a)
sp = s % p
if sp == s or sp + 1 == p:
print(sp)
else:
print(sp + p) | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Encryption (easy) | Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo... | The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.
The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000]. | Output the number S as described in the problem statement. | null | In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of $$(3+4\mod10)+(7+2\mod10)=16$$.
In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then,... | [{"input": "4 10\n3 4 7 2", "output": "16"}, {"input": "10 12\n16 3 24 13 9 8 7 5 12 12", "output": "13"}] | 1,200 | ["brute force"] | 27 | [{"input": "4 10\r\n3 4 7 2\r\n", "output": "16\r\n"}, {"input": "10 12\r\n16 3 24 13 9 8 7 5 12 12\r\n", "output": "13\r\n"}, {"input": "2 2\r\n9 9\r\n", "output": "2\r\n"}, {"input": "2 2\r\n8 8\r\n", "output": "0\r\n"}, {"input": "5 50\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "5 50\r\n100 150 200 100 50\r\n"... | false | stdio | null | true |
301/C | 301 | C | Python 3 | TESTS | 0 | 62 | 0 | 27705900 | print('9??>>??0')
for i in range(9):
print(str(i)+'??<>'+str(i+1)+'??')
print('??<>1')
for i in range(10):
print('?'+str(i)+'>>'+str(i)+'?')
print('?>>??')
for i in range(10):
print(str(i)+'>>'+str(i)+'?') | 23 | 124 | 0 | 19357253 | print ( """0??<>1
1??<>2
2??<>3
3??<>4
4??<>5
5??<>6
6??<>7
7??<>8
8??<>9
9??>>??0
??<>1
?0>>0?
?1>>1?
?2>>2?
?3>>3?
?4>>4?
?5>>5?
?6>>6?
?7>>7?
?8>>8?
?9>>9?
?>>??
>>?""" ) | Codeforces Round 182 (Div. 1) | CF | 2,013 | 2 | 256 | Yaroslav and Algorithm | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of... | The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025. | Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces.
Your algorithm will be launched for each of these numbers. The answer will be considered correct if:
- Each line will a correct algorithm command (see the description in the problem ... | null | null | [{"input": "2\n10\n79", "output": "10<>11\n79<>80"}] | 2,500 | ["constructive algorithms"] | 23 | [{"input": "2\r\n10\r\n79\r\n", "output": "10<>11\r\n79<>80\r\n"}, {"input": "5\r\n9\r\n99\r\n999\r\n9999\r\n99999\r\n", "output": "0??<>1\r\n1??<>2\r\n2??<>3\r\n3??<>4\r\n4??<>5\r\n5??<>6\r\n6??<>7\r\n7??<>8\r\n8??<>9\r\n9??>>??0\r\n??<>1\r\n?0>>0?\r\n?1>>1?\r\n?2>>2?\r\n?3>>3?\r\n?4>>4?\r\n?5>>5?\r\n?6>>6?\r\n?7>>7?\... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
numbers = [int(line.strip()) for line in f]
commands = []
with open(submission_output_path) as f:
for line in f:
line = line.strip()
if '>... | true |
617/C | 617 | C | PyPy 3-64 | TESTS | 0 | 46 | 0 | 224718617 | def distance(x1, y1, x2, y2):
return (x1 - x2) ** 2 + (y1 - y2) ** 2
n, x1, y1, x2, y2 = map(int, input().split())
flowers = []
for _ in range(n):
xi, yi = map(int, input().split())
flowers.append((xi, yi))
total_water_fountain1 = 0
total_water_fountain2 = 0
for flower in flowers:
dist1 = distance(x... | 31 | 296 | 5,836,800 | 15533625 | n, x1, y1, x2, y2 = map(int, input().split())
l = [(0,0)]
for i in range(n):
X, Y = map(int, input().split())
l += [((X-x1)**2+(Y-y1)**2, (X-x2)**2+(Y-y2)**2)]
l = sorted(l)
a = 10000000000000000
Y = a
for i in range(n+1):
x, y = l[i][0], 0
for j in range(i+1,n+1):
if l[j][0] > x:
y ... | Codeforces Round 340 (Div. 2) | CF | 2,016 | 2 | 256 | Watering Flowers | A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t... | The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flo... | Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer. | null | The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32): | [{"input": "2 -1 0 5 3\n0 2\n5 2", "output": "6"}, {"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33"}] | 1,600 | ["implementation"] | 31 | [{"input": "2 -1 0 5 3\r\n0 2\r\n5 2\r\n", "output": "6\r\n"}, {"input": "4 0 0 5 0\r\n9 4\r\n8 3\r\n-1 0\r\n1 4\r\n", "output": "33\r\n"}, {"input": "5 -6 -4 0 10\r\n-7 6\r\n-9 7\r\n-5 -1\r\n-2 1\r\n-8 10\r\n", "output": "100\r\n"}, {"input": "10 -68 10 87 22\r\n30 89\r\n82 -97\r\n-52 25\r\n76 -22\r\n-20 95\r\n21 25\r... | false | stdio | null | true |
127/A | 127 | A | PyPy 3-64 | TESTS | 1 | 124 | 0 | 216210447 | from math import sqrt
n, k = [int(i) for i in input().split()]
length = 0
x, y = [int(i) for i in input().split()]
x1, y1 = 0, 0
for i in range(n - 1):
x1, y1 = [int(i) for i in input().split()]
length += (sqrt((x1 - x) ** 2 + (y1 - y1) ** 2)) / 50
x, y = x1, y1
print(length * k) | 42 | 62 | 0 | 204687634 | import math
n , k = map(int , input().split())
speed = 50
lst_check = []
total_time = []
def distance(x, y):
return math.sqrt((x[0] - y[0])**2 + (x[1] - y[1])**2)
for _ in range(n):
lst_cont = list(map(int, input().split()))
lst_check.append(lst_cont)
total_time = [distance(lst_check[i], lst_check[i - 1])/speed for ... | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 2 | 256 | Wasted Time | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline ... | The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space.
All points Ai are different. The absolute value of all coordinates ... | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6. | null | null | [{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}] | 900 | ["geometry"] | 42 | [{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\... | false | stdio | import sys
import math
def read_points(n, input_file):
points = []
for _ in range(n):
x, y = map(int, input_file.readline().split())
points.append((x, y))
return points
def compute_total_time(n, k, points):
total_length = 0.0
for i in range(1, n):
x0, y0 = points[i-1]
... | true |
990/F | 990 | F | Python 3 | TESTS | 0 | 61 | 0 | 39120133 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(2*10**5 + 10)
n = int(input().strip())
sis = list(map(int, input().strip().split()))
m = int(input().strip())
tos = [[] for _ in range(n)]
for i in range(1, m + 1):
u, v = map(int, input().strip().split())
tos[u - 1].append((v - 1, i))
tos[v - 1].append((u -... | 37 | 1,216 | 96,768,000 | 155788846 | from collections import deque
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(s), get_root(t)
if n... | Educational Codeforces Round 45 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Flow Control | You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$.
The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use ... | The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions.
The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions.
The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the ... | If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere... | null | null | [{"input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n4\n-6\n8\n-7\n7"}, {"input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible"}] | 2,400 | ["dfs and similar", "dp", "greedy", "trees"] | 37 | [{"input": "4\r\n3 -10 6 1\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Possible\r\n-3\r\n-6\r\n1\r\n0\r\n0\r\n"}, {"input": "4\r\n3 -10 6 4\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n0\r\n0\r\n", "output": "Possible\r\n"}, {"input": "1\r\n123\r\n0\r\n", "outp... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
s = list(map(int, f.readline().split()))
m = int(f.readline())
pipes = [tuple(map(int, f.readline().split())) for _ in range(m)]
sum_s = ... | true |
959/D | 959 | D | PyPy 3 | TESTS | 2 | 108 | 2,764,800 | 107520225 | import math
N = 10**5+50
spf = [-1]*(N+1)
for i in range(N+1):
spf[i] = i
for i in range(2, int(math.sqrt(N))+1):
if spf[i] == i:
for j in range(i*2, N+1, i):
if spf[j] == j:
spf[j] = i
def factorize(n):
d = {}
while n != 1:
p = spf[n]
if p in d:
... | 55 | 1,793 | 23,961,600 | 36926599 | import atexit
import io
import sys
# Buffering IO
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
ppp = ('2 3 5 7 1... | Codeforces Round 473 (Div. 2) | CF | 2,018 | 3 | 256 | Mahmoud and Ehab and another array construction task | Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:
- b is lexicographically greater than or equal to a.
- bi ≥ 2.
- b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divi... | The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b.
The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a. | Output n space-separated integers, the i-th of them representing bi. | null | Note that in the second sample, the array is already pairwise coprime so we printed it. | [{"input": "5\n2 3 5 4 13", "output": "2 3 5 7 11"}, {"input": "3\n10 3 7", "output": "10 3 7"}] | 1,900 | ["constructive algorithms", "greedy", "math", "number theory"] | 55 | [{"input": "5\r\n2 3 5 4 13\r\n", "output": "2 3 5 7 11 "}, {"input": "3\r\n10 3 7\r\n", "output": "10 3 7 "}, {"input": "5\r\n7 10 2 5 5\r\n", "output": "7 10 3 11 13 "}, {"input": "7\r\n20 9 7 6 7 9 15\r\n", "output": "20 9 7 11 13 17 19 "}, {"input": "10\r\n5 3 2 2 3 3 3 4 2 5\r\n", "output": "5 3 2 7 11 13 17 19 23... | false | stdio | null | true |
958/B1 | 958 | B1 | Python 3 | TESTS | 3 | 31 | 0 | 208283582 | t = int(input())
res = [0 for i in range(t)]
for _ in range(t-1):
a,b = list(map(int,input().split()))
res[a-1]+=1
res[b-1]+=1
print(res.count(a)) | 9 | 31 | 0 | 165771154 | num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n = int(input())
E = [0] * n
for i in range(n - 1):
u, v = map(int, input().split())
E[u-1] += 1
E[v-1] += 1
print(E.count(1)) | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 2 | 256 | Maximum Control (easy) | The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s... | The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy.
The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn... | A single integer denoting the number of remote planets. | null | In the first example, only planets 2, 3 and 5 are connected by a single tunnel.
In the second example, the remote planets are 2 and 3.
Note that this problem has only two versions – easy and medium. | [{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}] | 1,000 | ["implementation"] | 9 | [{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}] | false | stdio | null | true |
894/E | 894 | E | PyPy 3-64 | TESTS | 2 | 62 | 4,608,000 | 183369397 | from collections import defaultdict
import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def scc():
R = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in G[i]:
R[j].append(i)
for i in range(1, n + 1):
if not visit[i]:
... | 40 | 1,434 | 44,236,800 | 214559285 | import sys
import math
from collections import defaultdict
class TarjanSolver:
def __init__(self):
self.b = None
self.dfn = None
self.low = None
self.s = None
self.v = None
self.r = None
self.a = None
self.out = None
self.in_ = None
se... | Codeforces Round 447 (Div. 2) | CF | 2,017 | 2.5 | 512 | Ralph and Mushrooms | Ralph is going to collect mushrooms in the Mushroom Forest.
There are m directed paths connecting n trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantastic s... | The first line contains two integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), representing the number of trees and the number of directed paths in the Mushroom Forest, respectively.
Each of the following m lines contains three integers x, y and w (1 ≤ x, y ≤ n, 0 ≤ w ≤ 108), denoting a path that leads from tree x to tree y... | Print an integer denoting the maximum number of the mushrooms Ralph can collect during his route. | null | In the first sample Ralph can pass three times on the circle and collect 4 + 4 + 3 + 3 + 1 + 1 = 16 mushrooms. After that there will be no mushrooms for Ralph to collect.
In the second sample, Ralph can go to tree 3 and collect 8 mushrooms on the path from tree 1 to tree 3. | [{"input": "2 2\n1 2 4\n2 1 4\n1", "output": "16"}, {"input": "3 3\n1 2 4\n2 3 3\n1 3 8\n1", "output": "8"}] | 2,100 | ["dp", "graphs"] | 40 | [{"input": "2 2\r\n1 2 4\r\n2 1 4\r\n1\r\n", "output": "16"}, {"input": "3 3\r\n1 2 4\r\n2 3 3\r\n1 3 8\r\n1\r\n", "output": "8"}, {"input": "1 0\r\n1\r\n", "output": "0"}] | false | stdio | null | true |
615/B | 615 | B | Python 3 | TESTS | 2 | 31 | 102,400 | 146237876 | import sys
from math import comb
from collections import deque
input=sys.stdin.readline
n,m=map(int,input().split())
h=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
h[a].append(b)
h[b].append(a)
maxvalue=-sys.maxsize
l=[1 for i in range(n+1)]
for i in range(1,n+1):
for j in h[... | 60 | 779 | 159,334,400 | 186005678 | from collections import defaultdict, Counter
from math import inf
from functools import lru_cache
import sys
#input=sys.stdin.readline
def solution():
n,m = map(int, input().split())
graph = defaultdict(list)
dp = defaultdict(lambda : 1)
for _ in range(m):
a,b = map(int, input().split())
... | Codeforces Round 338 (Div. 2) | CF | 2,016 | 3 | 256 | Longtail Hedgehog | This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed... | First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar... | Print the maximum possible value of the hedgehog's beauty. | null | The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9. | [{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}] | 1,600 | ["dp", "graphs"] | 60 | [{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 ... | false | stdio | null | true |
615/B | 615 | B | PyPy 3-64 | TESTS | 1 | 46 | 8,396,800 | 190142097 | from collections import defaultdict
def main():
n, m = map(int, input().split())
adj = defaultdict(list)
for i in range(m):
u, v = map(int, input().split())
adj[u].append(v)
adj[v].append(u)
dp = [0] * 10 ** 6
ans = -111
for v in range(n):
dp[v] = 1
for u in adj[v]:
if u < v:
dp[v] = max(dp[v]... | 60 | 795 | 15,257,600 | 188367801 | n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for i in range(m):
x, y = map(lambda i: int(i) - 1, input().split())
edge[x].append(y)
edge[y].append(x)
inc = [1 for _ in range(n)]
for x in range(n):
for y in edge[x]:
if x > y:
inc[x] = max(inc[x], inc[y] + 1)
for x... | Codeforces Round 338 (Div. 2) | CF | 2,016 | 3 | 256 | Longtail Hedgehog | This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed... | First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar... | Print the maximum possible value of the hedgehog's beauty. | null | The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9. | [{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}] | 1,600 | ["dp", "graphs"] | 60 | [{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 ... | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 93 | 614,400 | 95989990 | q = int(input())
for x in list(map(int, input().split())):
if (x + 1) % 2 == 0:
k = (x + 1) * 2
else:
k = (x + 1) * 4
print((k * int(x)) // (int(x) + 1) + 1) | 8 | 78 | 3,584,000 | 196890569 | def sol(n):
if n % 2 == 0: return 1 + 4*n
if n % 4 == 3: return 1 + n
return 1 + 2*n
n = int(input())
lst = list(map(int, input().split()))
res = [str(sol(x)) for x in lst]
print(' '.join(res)) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
194/B | 194 | B | Python 3 | TESTS | 3 | 62 | 819,200 | 4927004 | def readln(): return tuple(map(int, input().split()))
t, = readln()
for n in readln():
if n % 4 in (0, 2):
print(4 * n + 1)
elif n % 4 in (1, 4):
print(2 * n + 1) | 8 | 78 | 7,372,800 | 127499312 | import math
input()
for x in map(int,input().split()):
z=math.gcd(x+1,x*4)
print(4*x//z+1) | Codeforces Round 122 (Div. 2) | CF | 2,012 | 2 | 256 | Square | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.
The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | null | null | [{"input": "3\n4 8 100", "output": "17\n33\n401"}] | 1,200 | ["math"] | 8 | [{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou... | false | stdio | null | true |
384/B | 384 | B | PyPy 3 | TESTS | 0 | 93 | 3,584,000 | 147528907 | import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from sys import stdin, stdout
import io
import math
import heapq
import bisect
import collections
import copy
import collections, sys, threading
def ceil(a, b):
return (a + b - 1) // b
inf = float('inf')
def get():
... | 31 | 78 | 2,048,000 | 144258801 | def Sol(n, m, k):
pairs = list()
if k == 0:
for i in range(m - 1):
for k in range(m - 1, i, -1):
pairs.append((k - 1, k))
else:
for i in range(m - 2, -1, -1):
for k in range(i + 1):
pairs.append((k + 1, k))
return pairs
n, m, k =... | Codeforces Round 225 (Div. 2) | CF | 2,014 | 1 | 256 | Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ... | The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each elemen... | On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.
If there are multiple correct answers, you can print any. | null | Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5]. | [{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}] | 1,500 | ["greedy", "implementation", "sortings", "two pointers"] | 31 | [{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.read().splitlines()
n, m, k = map(int, lines[0].split())
arrays = [list(map(int, line.split())) for line in lines[1:n+1]]
try:
with... | true |
732/D | 732 | D | Python 3 | TESTS | 0 | 31 | 0 | 208576783 | n, m = map(int, input().split())
d = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 0
r = n
while r - l > 1:
x = (l + r)//2
b = 0
c = []
f = 0
for i in range(x - 1, -1, -1):
if b != m and d[i] != 0:
b += 1
c.insert(0, d[i])
else:
... | 49 | 234 | 13,004,800 | 21543624 | n, m = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
ms = [int(i) for i in input().split()]
#n, m = 7, 2
#data = [0, 1, 0, 2, 1, 0, 2]
#ms = [2, 1]
cnt = [0 for i in range(n)]
used = [0 for i in range(m)]
passed = m
d = 0
for i in range(n):
if data[i] == 0:
d += 1
cnt[i]... | Codeforces Round 377 (Div. 2) | CF | 2,016 | 1 | 256 | Exams | Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m.
About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day.
On e... | The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects.
The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed t... | Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. | null | In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day.
In the second example Vasiliy should prepare for the exam number 3 during the first four d... | [{"input": "7 2\n0 1 0 2 1 0 2\n2 1", "output": "5"}, {"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "output": "9"}, {"input": "5 1\n1 1 1 1 1\n5", "output": "-1"}] | 1,700 | ["binary search", "greedy", "sortings"] | 53 | [{"input": "7 2\r\n0 1 0 2 1 0 2\r\n2 1\r\n", "output": "5\r\n"}, {"input": "10 3\r\n0 0 1 2 3 0 2 0 1 2\r\n1 1 4\r\n", "output": "9\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "-1\r\n"}, {"input": "100 10\r\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8... | false | stdio | null | true |
384/B | 384 | B | Python 3 | TESTS | 0 | 46 | 307,200 | 5763041 | # -*- encoding: utf-8 -*-
n, m, k = map(int, input().split())
print(m*(m-1)//2)
for i in range(m-1):
for j in range(m-1-i):
print('{} {}'.format(*((j, j+1)) if k == 0 else (j+1, j))) | 31 | 78 | 2,048,000 | 162727156 | n, m, k = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
print(m * (m - 1) // 2)
for i in range(1, m):
for j in range(i + 1, m + 1):
if k == 0:
print(i, j)
else:
print(j, i)
# Mon Jul 04 2022 09:33:42 GMT+0000 (Coordinated Un... | Codeforces Round 225 (Div. 2) | CF | 2,014 | 1 | 256 | Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ... | The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each elemen... | On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.
If there are multiple correct answers, you can print any. | null | Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5]. | [{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}] | 1,500 | ["greedy", "implementation", "sortings", "two pointers"] | 31 | [{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.read().splitlines()
n, m, k = map(int, lines[0].split())
arrays = [list(map(int, line.split())) for line in lines[1:n+1]]
try:
with... | true |
241/A | 241 | A | Python 3 | TESTS | 3 | 186 | 0 | 54078833 | estradas,k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
gas = max(s)
indG = s.index(gas)
fuel = 0
time = 0
for i in range(estradas):
fuel+=s[i]
while(fuel<d[i]):
time+=k
if(i>=indG):
fuel+=gas
else:
... | 52 | 92 | 0 | 208267425 | # LUOGU_RID: 111916882
from sys import stdin
input = stdin.readline
def get() :
return map(int,input().split())
N = 1010
D = [0] * N
S = [0] * N
mx = [0] * N
m,k = get()
D[1:m + 1] = list(get())
S[1:m + 1] = list(get())
for i in range(1, m + 1) :
mx[i] = max(mx[i - 1], S[i])
now = 0
ans = 0
fo... | Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements) | ICPC | 2,012 | 2 | 256 | Old Peykan | There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil... | The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.
The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,... | In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1. | null | In the second sample above, the Old Peykan stays in c1 for 3 hours. | [{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}] | 1,300 | ["greedy"] | 52 | [{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2... | false | stdio | null | true |
709/B | 709 | B | Python 3 | TESTS | 1 | 30 | 0 | 189014611 | a, b = map(int, input().split())
checks = input().split()
n = 0
while n != a-1:
smaller = abs(int(checks[0]) - b)
for i in checks:
if abs(int(i) - b) <= smaller:
newCords = int(i)
smaller = abs(int(i) - b)
checks.remove(str(newCords))
b = newCords
n = n + 1
print(b) | 81 | 93 | 13,721,600 | 218400431 | import sys
inp = lambda: sys.stdin.readline()[:-1]
mass = lambda: list(map(int, input().split()))
def solve():
a = mass()[1]
x = mass()
if len(x) == 1:
print(0)
return
x.sort()
l = x[:-1]
r = x[1:]
print(min(abs(a - l[0]) + l[-1] - l[0], abs(a - l[-1]) + l[-1] - l[0], abs(a... | AIM Tech Round 3 (Div. 2) | CF | 2,016 | 1 | 256 | Checkpoints | Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order... | The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000, - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.
The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints. | Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint. | null | In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.
In the second sample it's enough to visit only one check... | [{"input": "3 10\n1 7 12", "output": "7"}, {"input": "2 0\n11 -10", "output": "10"}, {"input": "5 0\n0 0 1000 0 0", "output": "0"}] | 1,500 | ["greedy", "implementation", "sortings"] | 81 | [{"input": "3 10\r\n1 7 12\r\n", "output": "7\r\n"}, {"input": "2 0\r\n11 -10\r\n", "output": "10\r\n"}, {"input": "5 0\r\n0 0 1000 0 0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n4 -8\r\n", "output": "3\r\n"}, {"input": "3 4\r\n4 2 4\r\n", "output": "0\r\n"}, {"input": "4 ... | false | stdio | null | true |
735/B | 735 | B | Python 3 | TESTS | 3 | 108 | 0 | 54065774 | inp=[int(s) for s in input().split()]
people=[int(s) for s in input().split()]
for i in range(inp[0]-inp[1]-inp[2]):
people.remove(min(people))
sum=0
if inp[1]<inp[2]:
for i in range(inp[1]):
per=max(people)
sum+=per/inp[1]
people.remove(per)
for a in people:
sum+=a/inp[2]
else:
for i in range(inp[2]):
... | 37 | 93 | 7,372,800 | 156026671 | n, n1, n2 = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort(reverse = True)
if n1 > n2:
n1, n2 = n2, n1
mean1 = sum(nums[:n1]) / n1
mean2 = sum(nums[n1: n1+n2]) / n2
print(mean1 + mean2) | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
241/A | 241 | A | PyPy 3-64 | TESTS | 3 | 122 | 0 | 164831945 | import sys
input = sys.stdin.readline
from math import ceil
n, k = map(int, input().split())
w = list(map(int, input().split()))
s = list(map(int, input().split()))
d = []
c = 0
for i in range(n):
if s[i] > c:
c = s[i]
d.append(i)
d.append(n)
m = len(d)
x = 0
y = 0
t = 0
j = 1
while 1:
x = su... | 52 | 124 | 0 | 223956643 | import math
if __name__ == '__main__':
m_k = input().split()
m = int(m_k[0])
k = int(m_k[1])
d_arr = input().split()
s_arr = input().split()
oil = 0
max_n = 0
count = 0
for distance in d_arr:
count += int(distance)
for i in range(0, m):
curr_s = int(s_arr[i... | Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements) | ICPC | 2,012 | 2 | 256 | Old Peykan | There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil... | The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.
The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,... | In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1. | null | In the second sample above, the Old Peykan stays in c1 for 3 hours. | [{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}] | 1,300 | ["greedy"] | 52 | [{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2... | false | stdio | null | true |
735/B | 735 | B | PyPy 3 | TESTS | 3 | 93 | 0 | 114085322 | import sys
from os import path
if (path.exists('input.txt') and path.exists('output.txt')):
sys.stdout = open('output.txt', 'w')
sys.stdin = open('input.txt', 'r')
def main():
n, n1, n2 = (int(i) for i in input().split())
l = sorted([int(i) for i in input().split()], reverse=True)
if n1 > n2: n1, ... | 37 | 93 | 7,372,800 | 156028545 | n, n1, n2 = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse = True)
if n1 > n2:
n1, n2 = n2, n1
sumOfN1 = sum(arr[:n1])
sumOfN2 = sum(arr[n1:n1 + n2])
print(sumOfN1/n1 + sumOfN2/n2) | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
735/B | 735 | B | PyPy 3 | TESTS | 3 | 78 | 20,172,800 | 124453446 | n, n1, n2 = map(int, input().split())
wealths = sorted(map(int, input().split()))[::-1]
res = 0
res += sum(wealths[:min(n1, n2)])/min(n1, n2) + sum(wealths[min(n1, n2):max(n1, n2)+1])/max(n1, n2)
print(res) | 37 | 93 | 7,372,800 | 182431643 | n, n1, n2 = map(int,input().split())
a = list(sorted(list(map(int,input().split()))))[::-1]
n1, n2 = min(n1,n2), max(n1,n2)
print(sum(a[:n1])/n1+sum(a[n1:n1+n2])/n2) | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
735/B | 735 | B | Python 3 | TESTS | 3 | 77 | 6,963,200 | 129620082 | # بسم الله الرحمن الرحيم
def main():
n, n1, n2 = [int(i) for i in input().split()]
wealthes = [int(i) for i in input().split()]
sorted_wealthes = sorted(wealthes)
# print(sorted_wealthes)
max_mean1 = 0
max_mean2 = 0
if n1 <= n2:
# start fill n1 with people hav maxis wealthes
... | 37 | 93 | 7,372,800 | 200317194 | from heapq import nlargest,heapify
def solve():
n,n1,n2=map(int,input().split());a=sorted(list(map(int,input().split())))
ans=0
t1=sum(a[n-(min(n1,n2))::])/min(n1,n2)
for i in range(min(n1,n2)):a.pop()
t2=sum(a[(n-min(n1,n2))-max(n1,n2)::])/max(n1,n2)
print(t1+t2)
solve()
# 3 2
# 2 3 4 5 6 | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
735/B | 735 | B | PyPy 3 | TESTS | 3 | 77 | 0 | 103902618 | n, n1, n2 = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
if n1>n2:
ans1 = 0
for i in range(n2):
ans1+=l[i]
ans2 = 0
for j in range(n2, n1+1):
ans2+=l[j]
ans = (ans1/n2)+(ans2/n1)
else:
ans1 = 0
for i in range(n1):
ans1+=l[i... | 37 | 93 | 10,649,600 | 183806458 | from sys import stdin ,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
n,n1,n2=map(int,input().split()) ; arr=[int(i) for i in input().split()] ; arr.sort() ; na1=n1 ; na2=n2 ; summ1=0 ; summ2=0
if n2>n1:
for i in range(n-1,-1,-1):
... | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
735/B | 735 | B | Python 3 | TESTS | 3 | 46 | 4,608,000 | 25331930 | n,a,b=map(int,input().split())
a,b=map(int,sorted([a,b]))
x=sorted(list(map(int,input().split())))[::-1]
print(sum(x[:a])/a+sum(x[a:b+1])/b) | 37 | 93 | 13,721,600 | 164991866 | n,n1,n2=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
n1,n2=min(n1,n2),max(n1,n2)
ans=0
res=0
for i in range(n1):
ans+=arr.pop()
ans=ans/n1
for j in range(n2):
res+=arr.pop()
res=res/n2
print(ans+res) | Codeforces Round 382 (Div. 2) | CF | 2,016 | 2 | 256 | Urbanization | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo... | The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., a... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ... | null | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5 | [{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}] | 1,100 | ["greedy", "number theory", "sortings"] | 37 | [{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10... | false | stdio | import sys
def main():
input_path, correct_output_path, submission_output_path = sys.argv[1:4]
with open(correct_output_path, 'r') as f:
correct_output = f.read().strip()
with open(submission_output_path, 'r') as f:
submission_output = f.read().strip()
try:
correct = float(cor... | true |
741/C | 741 | C | Python 3 | TESTS | 1 | 30 | 0 | 132194250 | t=int(input())
la={}
for times in range(t):
a,b=map(int,input().split())
la[a]=b
la[b]=a
lb = [1] * (t*2)
for i in range(1,t+1):
lb[la[i]-1] = 2
num_1 = 0
num_2 = 0
last = -1
for i in range(t*2-2):
if lb[i] == lb[i+1] and lb[i+1] == lb[i+2]:
lb[i+1],lb[la[lb[i+1]]]=lb[la[lb[i+1]]],l... | 94 | 452 | 33,280,000 | 22770741 | import sys
def solve():
n = int(input())
partner = [0]*(2*n)
pacani = []
for line in sys.stdin:
pacan, telka = [int(x) - 1 for x in line.split()]
partner[pacan] = telka
partner[telka] = pacan
pacani.append(pacan)
khavka = [None]*(2*n)
for i in range(2*n):
... | Codeforces Round 383 (Div. 1) | CF | 2,016 | 1 | 256 | Arpa’s overnight party and Mehrdad’s silent entering | Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs wer... | The first line contains an integer n (1 ≤ n ≤ 105) — the number of pairs of guests.
The i-th of the next n lines contains a pair of integers ai and bi (1 ≤ ai, bi ≤ 2n) — the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed... | If there is no solution, print -1.
Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise p... | null | null | [{"input": "3\n1 4\n2 5\n3 6", "output": "1 2\n2 1\n1 2"}] | 2,600 | ["constructive algorithms", "dfs and similar", "graphs"] | 94 | [{"input": "3\r\n1 4\r\n2 5\r\n3 6\r\n", "output": "1 2\r\n2 1\r\n1 2\r\n"}, {"input": "6\r\n3 2\r\n5 11\r\n7 12\r\n6 9\r\n8 4\r\n1 10\r\n", "output": "1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n"}, {"input": "19\r\n30 27\r\n6 38\r\n10 28\r\n20 5\r\n14 18\r\n32 2\r\n36 29\r\n12 1\r\n31 24\r\n15 4\r\n35 11\r\n3 7\r\n21 1... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
pairs = [tuple(map(int, f.readline().split())) for _ in range(n)]
# Read reference output
with open(output_path) as f:
ref_lines = [line.strip() for... | true |
463/D | 463 | D | PyPy 3 | TESTS | 1 | 155 | 1,740,800 | 118349369 | from collections import deque
tt=0
def dfs(i,cnt):
global tt
vis=[0]*n
q=deque()
q.append((i,cnt))
while q:
xx=q.popleft()
vis[xx[0]]=1
tt=max(tt,xx[1])
for i in adj[xx[0]]:
if not vis[i]:
q.append((i,xx[1]+1))
n,k=map(int,input().split(... | 40 | 171 | 3,379,200 | 116205354 | from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from c... | Codeforces Round 264 (Div. 2) | CF | 2,014 | 2 | 256 | Gargari and Permutations | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can... | The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. | Print the length of the longest common subsequence. | null | The answer for the first test sample is subsequence [1, 2, 3]. | [{"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3"}] | 1,900 | ["dfs and similar", "dp", "graphs", "implementation"] | 40 | [{"input": "4 3\r\n1 4 2 3\r\n4 1 2 3\r\n1 2 4 3\r\n", "output": "3\r\n"}, {"input": "6 3\r\n2 5 1 4 6 3\r\n5 1 4 3 2 6\r\n5 4 2 6 3 1\r\n", "output": "3\r\n"}, {"input": "41 4\r\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\r\n22 13 25 24 38 35 29 12... | false | stdio | null | true |
274/B | 274 | B | Python 3 | TESTS | 1 | 62 | 102,400 | 163713558 | from sys import setrecursionlimit
from sys import stdin
input=stdin.readline
#setrecursionlimit(10**6)
from collections import defaultdict
n=int(input())
g=defaultdict(list)
for _ in range(n-1):
u,v=map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
q=[(0,-1)]
for x in range(n):
cn,p=... | 27 | 934 | 66,150,400 | 174618887 | import sys
from types import GeneratorType
input = sys.stdin.readline
n = int(input())
g = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
v = [-1] + list(map(int, input().split()))
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kw... | Codeforces Round 168 (Div. 1) | CF | 2,013 | 2 | 256 | Zero Tree | A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.
You're given a tr... | The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree.
The last line of the input contains a list of n space-separated integers v1... | Print the minimum number of operations needed to solve the task.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | null | [{"input": "3\n1 2\n1 3\n1 -1 1", "output": "3"}] | 1,800 | ["dfs and similar", "dp", "greedy", "trees"] | 27 | [{"input": "3\r\n1 2\r\n1 3\r\n1 -1 1\r\n", "output": "3\r\n"}, {"input": "5\r\n2 3\r\n4 5\r\n2 5\r\n1 3\r\n0 2 1 4 3\r\n", "output": "8\r\n"}, {"input": "10\r\n5 6\r\n8 2\r\n9 3\r\n4 1\r\n6 10\r\n9 8\r\n7 10\r\n7 4\r\n5 2\r\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3\r\n", "output": "18\r\n"}, {"input": "5\r\n3 1\r\n2 4\r\n3 4\r\n2... | false | stdio | null | true |
831/B | 831 | B | PyPy 3-64 | TESTS | 1 | 62 | 0 | 225828230 | a = str(input())
b = str(input())
c = str(input())
massiv = []
massiv2 = []
massiv3 = []
massiv4 = []
massiv2+=c
counter=0
for i in range(len(massiv2)):
if massiv2[i].istitle():
massiv4.append(massiv2.index(massiv2[i]))
c = c.lower()
massiv2 = []
massiv2+=c
for i in range(len(a)):
massiv.append([a[i], i... | 19 | 31 | 0 | 145715138 | #!/usr/bin/env/python
# -*- coding: utf-8 -*-
s1 = input()
s2 = input()
dc = {s1[i]: s2[i] for i in range(26)}
res = ''
for c in input():
if '0' <= c <= '9':
res += c
elif 'a' <= c <= 'z':
res += dc[c]
else:
res += dc[c.lower()].upper()
print(res) | Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string s consisting of lowercase and... | Print the text if the same keys were pressed in the second layout. | null | null | [{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}] | 800 | ["implementation", "strings"] | 19 | [{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf... | false | stdio | null | true |
832/D | 832 | D | PyPy 3-64 | TESTS | 3 | 124 | 15,769,600 | 139310892 | from sys import stdin, stdout
from itertools import permutations
def dfs(v, p):
global timer
timer += 1
IN[v] = timer
up[0][v] = p
for i in range(1, LG):
up[i][v] = up[i - 1][up[i - 1][v]]
for q in G[v]:
if q[0] != p:
dep[q[0]] = dep[v] + q[1]
dfs(q[0], v... | 94 | 1,325 | 40,550,400 | 110042385 | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def pre(n,path,lim):
# lim = n.bit_length()
up = [[-1]*(lim+1) for _ in range(n)]
st,visi,height = [0],[1]+[0]*(n-1),[0]*n
start,finish,time = [0]*n,[0]*n,0
while len(st):
x = st[-1]
... | Codeforces Round 425 (Div. 2) | CF | 2,017 | 2 | 256 | Misha, Grisha and Underground | Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decided to have fun and came up with a plan. Namely, in some day in the morning M... | The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days.
The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station... | Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day. | null | In the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1 $$\rightarrow$$ 2, and Grisha would go on the route 3 $$\rightarrow$$ 1 $$\rightarrow$$ 2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3 $$\rightarrow... | [{"input": "3 2\n1 1\n1 2 3\n2 3 3", "output": "2\n3"}, {"input": "4 1\n1 2 3\n1 2 3", "output": "2"}] | 1,900 | ["dfs and similar", "graphs", "trees"] | 94 | [{"input": "3 2\r\n1 1\r\n1 2 3\r\n2 3 3\r\n", "output": "2\r\n3\r\n"}, {"input": "4 1\r\n1 2 3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "2 4\r\n1\r\n1 1 1\r\n1 1 2\r\n1 2 2\r\n2 2 2\r\n", "output": "1\r\n2\r\n2\r\n1\r\n"}, {"input": "5 20\r\n4 1 1 4\r\n2 2 5\r\n3 2 5\r\n2 3 4\r\n4 2 5\r\n4 1 2\r\n5 3 1\r\n2 1 2\r\... | false | stdio | null | true |
613/B | 613 | B | Python 3 | TESTS | 1 | 46 | 5,529,600 | 33278578 | f = lambda: map(int, input().split())
g = lambda: m - l * p[l - 1] + s[l]
n, b, x, y, m = f()
t = list(f())
p = sorted(t)
s = [0] * (n + 1)
for j in range(n): s[j + 1] = p[j] + s[j]
l = r = n
a = v = 0
d = [-1]
while r >= 0 and m >= 0 and a < b:
if r:
while g() < 0: l -= 1
u = p[l - 1]
a ... | 35 | 920 | 20,684,800 | 197615001 | f = lambda: map(int, input().split())
g = lambda: m - l * p[l - 1] + s[l]
n, A, x, y, m = f()
t = sorted((q, i) for i, q in enumerate(f()))
p = [q for q, i in t]
s = [0] * (n + 1)
for j in range(n): s[j + 1] = p[j] + s[j]
l = r = n
F = L = R = B = -1
while 1:
if p:
while l > r or g() < 0: l -= 1
b... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Skills | Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.
Along with... | The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015).
The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills. | On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.
On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers s... | null | In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.
In the second test one should increase all skills to maximum. | [{"input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2"}, {"input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5"}] | 1,900 | ["binary search", "brute force", "dp", "greedy", "sortings", "two pointers"] | 35 | [{"input": "3 5 10 1 5\r\n1 3 1\r\n", "output": "12\r\n2 5 2 \r\n"}, {"input": "3 5 10 1 339\r\n1 3 1\r\n", "output": "35\r\n5 5 5 \r\n"}, {"input": "2 6 0 1 4\r\n5 1\r\n", "output": "5\r\n5 5 \r\n"}, {"input": "1 1000000000 1000 1000 1000000000000000\r\n0\r\n", "output": "1000000001000\r\n1000000000 \r\n"}, {"input": ... | false | stdio | null | true |
786/A | 786 | A | Python 3 | TESTS | 1 | 109 | 0 | 41253346 | RESULT = ['Lose', 'Loop', 'Win']
class Player(object):
"""docstring for Player"""
def __init__(self):
super(Player, self).__init__()
self.a = list(map(int, input().split()))
self.f = [len(self.a)] * n
self.f[0] = 0
def prev(self, i):
for x in self.a:
yie... | 49 | 733 | 4,300,800 | 53973991 | import sys
#range = xrange
#input = raw_input
n = int(input())
k1,*A = [int(x) for x in input().split()]
k2,*B = [int(x) for x in input().split()]
DPA = [None]*n
DPA[0] = False
counterA = [k1]*n
counterA[0] = -1
DPB = [None]*n
DPB[0] = False
counterB = [k2]*n
counterB[0] = -1
QA = [0]
QB = [0]
while QA or QB:
... | Codeforces Round 406 (Div. 1) | CF | 2,017 | 4 | 256 | Berzerk | Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the oth... | The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game.
The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set.
The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set
1 ≤ ... | In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.
Similarly, in the second line print n - 1 words separated by ... | null | null | [{"input": "5\n2 3 2\n3 1 2 3", "output": "Lose Win Win Loop\nLoop Win Win Win"}, {"input": "8\n4 6 2 3 4\n2 3 6", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose"}] | 2,000 | ["dfs and similar", "dp", "games"] | 49 | [{"input": "5\r\n2 3 2\r\n3 1 2 3\r\n", "output": "Lose Win Win Loop\r\nLoop Win Win Win\r\n"}, {"input": "8\r\n4 6 2 3 4\r\n2 3 6\r\n", "output": "Win Win Win Win Win Win Win\r\nLose Win Lose Lose Win Lose Lose\r\n"}, {"input": "10\r\n3 4 7 5\r\n2 8 5\r\n", "output": "Win Win Win Win Win Win Win Loop Win\r\nLose Win L... | false | stdio | null | true |
46/D | 46 | D | Python 3 | TESTS | 0 | 60 | 0 | 215862732 | L, b, f = map(int, input().split())
n = int(input())
requests = []
cars = []
empty_slots = []
for i in range(n):
type, value = map(int, input().split())
if type == 1:
cars.append([0, value, 0])
requests.append([type, value])
path = -b
current_car = 0
for request in requests:
if request[0... | 30 | 124 | 0 | 13790581 | class Car:
def __init__(self, id, size, location):
self.id = id
self.size = size
self.location = location
print(location)
cars = []
lot_size, back_gap, front_gap = map(int, input().split())
q = int(input())
for id in range(1, q + 1):
request, value = map(int, input().split())
if request == 1:
... | School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Parking Lot | Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of... | The first line contains three integers L, b и f (10 ≤ L ≤ 100000, 1 ≤ b, f ≤ 100). The second line contains an integer n (1 ≤ n ≤ 100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number represents the request type. If the ... | For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone. | null | null | [{"input": "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n23"}, {"input": "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n6"}, {"input": "10 1 1\n1\n1 12", "output": "-1"}] | 1,800 | ["data structures", "implementation"] | 30 | [{"input": "30 1 2\r\n6\r\n1 5\r\n1 4\r\n1 5\r\n2 2\r\n1 5\r\n1 4\r\n", "output": "0\r\n6\r\n11\r\n17\r\n23\r\n"}, {"input": "30 1 1\r\n6\r\n1 5\r\n1 4\r\n1 5\r\n2 2\r\n1 5\r\n1 4\r\n", "output": "0\r\n6\r\n11\r\n17\r\n6\r\n"}, {"input": "10 1 1\r\n1\r\n1 12\r\n", "output": "-1\r\n"}, {"input": "10 1 1\r\n1\r\n1 9\r\n"... | false | stdio | null | true |
691/E | 691 | E | PyPy 3-64 | TESTS | 3 | 46 | 1,433,600 | 176840275 | mod=10**9+7
def matmul(A,B,mod):
res = [[0]*len(B[0]) for _ in [None]*len(A)]
for i, resi in enumerate(res):
for k, aik in enumerate(A[i]):
for j,bkj in enumerate(B[k]):
resi[j] += aik*bkj
resi[j] %= mod
return res
def matpow(A,p,mod):
if p%2:
... | 12 | 482 | 9,420,800 | 176840656 | mod=10**9+7
def popcount(n):
c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555)
c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333)
c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f)
c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff)
c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ffff0000ffff)
c=(c&0x00000... | Educational Codeforces Round 14 | ICPC | 2,016 | 3 | 256 | Xor-sequences | You are given n integers a1, a2, ..., an.
A sequence of integers x1, x2, ..., xk is called a "xor-sequence" if for every 1 ≤ i ≤ k - 1 the number of ones in the binary representation of the number xi $$\times$$ xi + 1's is a multiple of 3 and $$x_i \in \{a_1, a_2, \ldots, a_n\}$$ for all 1 ≤ i ≤ k. The sym... | The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of given integers and the length of the "xor-sequences".
The second line contains n integers ai (0 ≤ ai ≤ 1018). | Print the only integer c — the number of "xor-sequences" of length k modulo 109 + 7. | null | null | [{"input": "5 2\n15 1 2 4 8", "output": "13"}, {"input": "5 1\n15 1 2 4 8", "output": "5"}] | 1,900 | ["matrices"] | 12 | [{"input": "5 2\r\n15 1 2 4 8\r\n", "output": "13\r\n"}, {"input": "5 1\r\n15 1 2 4 8\r\n", "output": "5\r\n"}, {"input": "10 1\r\n44 65 23 44 100 19 19 23 19 40\r\n", "output": "10\r\n"}, {"input": "10 2\r\n93 93 85 48 44 98 93 100 98 98\r\n", "output": "52\r\n"}, {"input": "10 100\r\n22 0 41 63 22 41 17 22 15 42\r\n"... | false | stdio | null | true |
615/B | 615 | B | Python 3 | TESTS | 0 | 46 | 0 | 209766175 | def calculate_beauty(n, m, segments):
# Tạo một danh sách liên kết chứa các đỉnh kề của mỗi đỉnh
adjacent = [[] for _ in range(n + 1)]
for u, v in segments:
adjacent[u].append(v)
# Tạo một mảng lưu trữ độ dài đuôi dài nhất kết thúc tại mỗi đỉnh
tail_lengths = [0] * (n + 1)
# Du... | 60 | 1,075 | 13,209,600 | 15243597 | n, m = [int(x) for x in input().split()]
values = [1] * n
nodes = [list() for _ in range(n)]
spikes = [0] * n
for _ in range(m):
n1, n2 = [int(x) for x in input().split()]
if n1 > n2:
n1, n2 = n2, n1
nodes[n1-1].append(n2-1)
spikes[n1-1] += 1
spikes[n2-1] += 1
for i in range(0, n):
fo... | Codeforces Round 338 (Div. 2) | CF | 2,016 | 3 | 256 | Longtail Hedgehog | This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed... | First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar... | Print the maximum possible value of the hedgehog's beauty. | null | The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9. | [{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}] | 1,600 | ["dp", "graphs"] | 60 | [{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 ... | false | stdio | null | true |
463/D | 463 | D | Python 3 | TESTS | 1 | 78 | 0 | 148165325 | def lcs(s1,s2):
n1=len(s1)
n2=len(s2)
dp=[[None]*(n2+1) for i in range(n1+1)]
for i in range(n1+1):
for j in range(n2+1):
if i==0 or j==0:
dp[i][j]=0
elif s1[i-1]==s2[j-1]:
dp[i][j]=dp[i-1][j-1]+1
else:
... | 40 | 233 | 3,584,000 | 162224619 | n, k = map(int, input().split())
v = [list(map(int, input().split())) for _ in range(k)]
pos = [[0] * (n + 1) for _ in range(k)]
e = [[] for _ in range(n + 1)]
for j in range(k):
for p, x in enumerate(v[j]):
pos[j][x] = p
e[x].append(p)
e = sorted((e[j], j) for j in range(1, n + 1))
#print(e)
dp = [... | Codeforces Round 264 (Div. 2) | CF | 2,014 | 2 | 256 | Gargari and Permutations | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can... | The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. | Print the length of the longest common subsequence. | null | The answer for the first test sample is subsequence [1, 2, 3]. | [{"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3"}] | 1,900 | ["dfs and similar", "dp", "graphs", "implementation"] | 40 | [{"input": "4 3\r\n1 4 2 3\r\n4 1 2 3\r\n1 2 4 3\r\n", "output": "3\r\n"}, {"input": "6 3\r\n2 5 1 4 6 3\r\n5 1 4 3 2 6\r\n5 4 2 6 3 1\r\n", "output": "3\r\n"}, {"input": "41 4\r\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\r\n22 13 25 24 38 35 29 12... | false | stdio | null | true |
463/D | 463 | D | PyPy 3 | TESTS | 1 | 77 | 1,536,000 | 147021243 | length,no_of_permutations = map(int,input().split(" "))
P = [-1]*(no_of_permutations+1)
position = [[0]*(length+1)]*(no_of_permutations+1)
for k in range(1,no_of_permutations+1):
P[k] = list(map(int,input().split(" ")))
P[k].insert(0,0)
for i in range(1,length+1):
element = P[k][i]
position[... | 40 | 389 | 7,372,800 | 118350342 | n, k = map(int, input().split())
ra = [[0] * k for _ in range(n)]
for p in range(k):
for i, v in enumerate(map(int, input().split())):
v -= 1
ra[v][p] = i
g = [[] for _ in range(n)]
for u in range(n):
for v in range(n):
if all(x < y for x, y in zip(ra[u], ra[v])):
g[u].append... | Codeforces Round 264 (Div. 2) | CF | 2,014 | 2 | 256 | Gargari and Permutations | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can... | The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. | Print the length of the longest common subsequence. | null | The answer for the first test sample is subsequence [1, 2, 3]. | [{"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3"}] | 1,900 | ["dfs and similar", "dp", "graphs", "implementation"] | 40 | [{"input": "4 3\r\n1 4 2 3\r\n4 1 2 3\r\n1 2 4 3\r\n", "output": "3\r\n"}, {"input": "6 3\r\n2 5 1 4 6 3\r\n5 1 4 3 2 6\r\n5 4 2 6 3 1\r\n", "output": "3\r\n"}, {"input": "41 4\r\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\r\n22 13 25 24 38 35 29 12... | false | stdio | null | true |
1000/E | 1000 | E | PyPy 3-64 | TESTS | 2 | 342 | 16,179,200 | 203203035 | def dfs(node,p):
global time,ans
visited[node] = True
time += 1
tin[node] = time
low[node] = time
for child in adj[node]:
if child == p:
continue
if visited[child]:
low[node] = min(low[node],low[child])
else:
dfs(child,node)
low[node] = min(low[node],low[child])
... | 55 | 1,200 | 146,432,000 | 186307945 | from sys import stdin
input=lambda :stdin.readline()[:-1]
def lowlink(links):
n = len(links)
order = [-1] * n
low = [n] * n
parent = [-1] * n
child = [[] for _ in range(n)]
roots = set()
x = 0
for root in range(n):
if order[root] != -1:
continue
roots.add(ro... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | We Need More Bosses | Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $$$n$$$ locations connected by $$$m$$$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location.
Of course, some passag... | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$n - 1 \le m \le 3 \cdot 10^5$$$) — the number of locations and passages, respectively.
Then $$$m$$$ lines follow, each containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$, $$$x \ne y$$$) describing the endpoint... | Print one integer — the maximum number of bosses your friend can place, considering all possible choices for $$$s$$$ and $$$t$$$. | null | null | [{"input": "5 5\n1 2\n2 3\n3 1\n4 1\n5 2", "output": "2"}, {"input": "4 3\n1 2\n4 3\n3 2", "output": "3"}] | 2,100 | ["dfs and similar", "graphs", "trees"] | 55 | [{"input": "5 5\r\n1 2\r\n2 3\r\n3 1\r\n4 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "4 3\r\n1 2\r\n4 3\r\n3 2\r\n", "output": "3\r\n"}, {"input": "50 72\r\n35 38\r\n19 46\r\n35 12\r\n27 30\r\n23 41\r\n50 16\r\n31 6\r\n20 33\r\n38 1\r\n10 35\r\n13 43\r\n29 25\r\n25 4\r\n1 13\r\n4 20\r\n36 29\r\n13 47\r\n48 5\r\n30 21... | false | stdio | null | true |
1000/E | 1000 | E | PyPy 3-64 | TESTS | 2 | 342 | 19,763,200 | 203203102 | def dfs(node,p):
global time,ans
visited[node] = True
time += 1
tin[node] = time
low[node] = time
for child in adj[node]:
if child == p:
continue
if visited[child]:
low[node] = min(low[node],low[child])
else:
dfs(child,node)
low[node] = min(low[node],low[child])
... | 55 | 1,200 | 146,432,000 | 186307945 | from sys import stdin
input=lambda :stdin.readline()[:-1]
def lowlink(links):
n = len(links)
order = [-1] * n
low = [n] * n
parent = [-1] * n
child = [[] for _ in range(n)]
roots = set()
x = 0
for root in range(n):
if order[root] != -1:
continue
roots.add(ro... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | We Need More Bosses | Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $$$n$$$ locations connected by $$$m$$$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location.
Of course, some passag... | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$n - 1 \le m \le 3 \cdot 10^5$$$) — the number of locations and passages, respectively.
Then $$$m$$$ lines follow, each containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$, $$$x \ne y$$$) describing the endpoint... | Print one integer — the maximum number of bosses your friend can place, considering all possible choices for $$$s$$$ and $$$t$$$. | null | null | [{"input": "5 5\n1 2\n2 3\n3 1\n4 1\n5 2", "output": "2"}, {"input": "4 3\n1 2\n4 3\n3 2", "output": "3"}] | 2,100 | ["dfs and similar", "graphs", "trees"] | 55 | [{"input": "5 5\r\n1 2\r\n2 3\r\n3 1\r\n4 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "4 3\r\n1 2\r\n4 3\r\n3 2\r\n", "output": "3\r\n"}, {"input": "50 72\r\n35 38\r\n19 46\r\n35 12\r\n27 30\r\n23 41\r\n50 16\r\n31 6\r\n20 33\r\n38 1\r\n10 35\r\n13 43\r\n29 25\r\n25 4\r\n1 13\r\n4 20\r\n36 29\r\n13 47\r\n48 5\r\n30 21... | false | stdio | null | true |
384/B | 384 | B | Python 3 | TESTS | 0 | 15 | 0 | 162726502 | n, m, k = map(int, input().split())
trash = [list(map(int, input().split())) for i in range(n)]
ans = []
if k == 0:
for i in range(m):
for j in range(i+1, m):
ans.append([i, j])
if k == 1:
for i in range(m):
for j in range(i+1, m):
ans.append([j, i])
print(len(ans))
for p... | 31 | 78 | 5,632,000 | 229925052 | n, m, k = [int(i) for i in input().split()]
p = (m - 1) * m // 2
print(p)
if k == 0:
for i in range(m - 1):
for j in range(i + 1, m):
print(i + 1, j + 1)
else:
for i in range(m - 1, 0, -1):
for j in range(i - 1, -1, -1):
print(i + 1, j + 1)# 1698348805.8155658 | Codeforces Round 225 (Div. 2) | CF | 2,014 | 1 | 256 | Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ... | The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each elemen... | On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.
If there are multiple correct answers, you can print any. | null | Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5]. | [{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}] | 1,500 | ["greedy", "implementation", "sortings", "two pointers"] | 31 | [{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.read().splitlines()
n, m, k = map(int, lines[0].split())
arrays = [list(map(int, line.split())) for line in lines[1:n+1]]
try:
with... | true |
180/A | 180 | A | PyPy 3-64 | TESTS | 2 | 124 | 0 | 209285527 | import sys
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
tot = 0
vac = []
use = set()
for i in ... | 24 | 278 | 102,400 | 46822069 | n, m = map(int, input().split())
mem = [-1] * 205
d = []
for i in range(m):
f = list(map(int, input().split()))[1:]
for j in f:
mem[j] = i
d.append(f)
free = -1
for i in range(1, n+1):
if mem[i] == -1:
free = i
break
res, cnt = [], 0
for x in range(m):
for i in range(len(d[x]... | Codeforces Round 116 (Div. 2, ACM-ICPC Rules) | ICPC | 2,012 | 1 | 256 | Defragmentation | In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m recorded files, the i-th file occupies clusters with numbers ai, 1, ai, 2, ..., ai, ni. These clusters are not necessarily located consecuti... | The first line contains two integers n and m (1 ≤ n, m ≤ 200) — the number of clusters and the number of files, correspondingly. Next m lines contain descriptions of the files. The first number in the line is ni (ni ≥ 1), the number of clusters occupied by the i-th file. Then follow ni numbers ai, 1, ai, 2, ..., ai, ni... | In the first line print a single integer k (0 ≤ k ≤ 2n) — the number of operations needed to defragment the disk. Next k lines should contain the operations' descriptions as "i j" (copy the contents of the cluster number i to the cluster number j). | null | Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.
$$$$
Example 2: each file must occupy a contiguous area of memory.
Example 3... | [{"input": "7 2\n2 1 2\n3 3 4 5", "output": "0"}, {"input": "7 2\n2 1 3\n3 2 4 5", "output": "3\n2 6\n3 2\n6 3"}] | 1,800 | ["implementation"] | 24 | [{"input": "7 2\r\n2 1 2\r\n3 3 4 5\r\n", "output": "0\r\n"}, {"input": "7 2\r\n2 1 3\r\n3 2 4 5\r\n", "output": "3\r\n2 6\r\n3 2\r\n6 3\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "1\r\n2 1\r\n"}, {"input": "3 1\r\n2 3 1\r\n", "output": "2\r\n1 2\r\n3 1\r\n"}, {"input": "3 2\r\n1 3\r\n1 2\r\n", "output": "1\r\n3 1\r\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
lines = f.readlines()
n, m = map(int, lines[0].split())
files = []
S = set()
for line in lines[1:m+1]:
parts = list(... | true |
628/E | 628 | E | PyPy 3-64 | TESTS | 6 | 202 | 9,318,400 | 175847605 | from sys import stdin
input=lambda :stdin.readline()[:-1]
class segtree():
def __init__(self,init,func,ide):
self.n=len(init)
self.func=func
self.ide=ide
self.size=1<<(self.n-1).bit_length()
self.tree=[self.ide for i in range(2*self.size)]
for i in range(self.n):
self.tree[self.size+i]=... | 18 | 4,991 | 312,627,200 | 192747542 | import sys
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
# Binary ... | Educational Codeforces Round 8 | ICPC | 2,016 | 5 | 512 | Zbazi in Zeydabad | A tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).
The country Zeydabad is a rectangular table consisting of n rows and m columns. Each cell on the country is either 'z' or '.'.
The tourist knows this country is named Zeydabad because there are lots of ''Z-pattern"s in the country. A ''Z-... | The first line contains two integers n, m (1 ≤ n, m ≤ 3000) — the number of rows and columns respectively.
Each of the next n lines contains m characters 'z' or '.' — the description of Zeydabad. | Print the only integer a — the number of ''Z-pattern"s in Zeydabad. | null | null | [{"input": "4 4\nzzzz\nzzz.\n.z..\nzzzz", "output": "16"}, {"input": "1 4\nz.z.", "output": "2"}, {"input": "2 2\nzz\nzz", "output": "5"}] | 2,300 | ["data structures", "implementation"] | 18 | [{"input": "4 4\r\nzzzz\r\nzzz.\r\n.z..\r\nzzzz\r\n", "output": "16\r\n"}, {"input": "1 4\r\nz.z.\r\n", "output": "2\r\n"}, {"input": "2 2\r\nzz\r\nzz\r\n", "output": "5\r\n"}] | false | stdio | null | true |
878/E | 878 | E | Python 3 | TESTS | 3 | 61 | 5,529,600 | 32998344 | #x+2y on string find max value
n, q = map(int, input().split(" "))
boardm = [int(i) for i in input().split(" ")]
memo = [[0 for _ in range(n)] for i in range(n)]
# x,y,answer
sub = 10**9 + 7
for cases in range(q):
li, lj = map(int, input().split(" "))
li -= 1
lj -= 1
board = boardm[li:lj+1]
dp = [0,0,0]
dp[0] =... | 55 | 999 | 80,281,600 | 303302080 | import sys
MOD = 10**9 + 7
INF = 2 * 10**9 + 5
def upd(a):
a += (a >> 31) & MOD
return a
def init(n):
_2 = [1] * (n + 1)
for i in range(1, n + 1):
_2[i] = (_2[i-1] << 1) % MOD
return _2
def find(x, fa):
if fa[x] != x:
fa[x] = find(fa[x], fa)
return fa[x]
def merge(x, y, ... | Codeforces Round 443 (Div. 1) | CF | 2,017 | 2 | 512 | Numbers on the blackboard | A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perform these operations until one number is left. Sasha likes big numbers and ... | The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of integers on the blackboard and the number of Nikita's options.
The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence on the blackboard.
Each of the next q lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n... | For each option output Sasha's result modulo 109 + 7. | null | In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 1 and 2 and writes 5. Then he erases 5 and -3 and gets -1. -1 modulo 109 + 7 is 109 + 6. | [{"input": "3 3\n1 2 3\n1 3\n1 2\n2 3", "output": "17\n5\n8"}, {"input": "3 1\n1 2 -3\n1 3", "output": "1000000006"}, {"input": "4 2\n1 1 1 -1\n1 4\n3 4", "output": "5\n1000000006"}] | 3,300 | ["combinatorics", "dp"] | 55 | [{"input": "3 3\r\n1 2 3\r\n1 3\r\n1 2\r\n2 3\r\n", "output": "17\r\n5\r\n8\r\n"}, {"input": "3 1\r\n1 2 -3\r\n1 3\r\n", "output": "1000000006\r\n"}, {"input": "4 2\r\n1 1 1 -1\r\n1 4\r\n3 4\r\n", "output": "5\r\n1000000006\r\n"}, {"input": "4 1\r\n1 1 -3 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\... | false | stdio | null | true |
615/B | 615 | B | PyPy 3-64 | TESTS | 2 | 62 | 0 | 190140323 | from collections import defaultdict
n, m = map(int, input().split())
adj = defaultdict(list)
for i in range(m):
u, v = map(int, input().split())
adj[u].append(v)
adj[v].append(u)
tested = set()
best = 0
for v in adj:
if v in tested: continue
seen = set()
s = [v]
while s:
node = s.pop()
seen.add(node)
te... | 60 | 1,075 | 15,257,600 | 101015468 | n, m = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
max_dist = 0
dist = [0]*n
for v in range(n):
dist[v] = 1
for u in G[v]:
if (u < v):
dist[v] = max(dist[v], dist[u] + 1);
... | Codeforces Round 338 (Div. 2) | CF | 2,016 | 3 | 256 | Longtail Hedgehog | This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed... | First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar... | Print the maximum possible value of the hedgehog's beauty. | null | The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9. | [{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}] | 1,600 | ["dp", "graphs"] | 60 | [{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 ... | false | stdio | null | true |
30/C | 30 | C | PyPy 3 | TESTS | 3 | 310 | 0 | 61403735 | if __name__ == '__main__':
n = int(input())
targets = [input() for _ in range(n)]
targets = [line.split() for line in targets]
targets = [(int(x), int(y), int(t), float(p)) for x, y, t, p in targets]
if n == 1:
print(targets[0][3])
else:
targets = sorted(targets, key=lambda targ... | 50 | 840 | 2,560,000 | 101254345 | ##########################################################
from collections import Counter
def nCk(n, k):
res = 1
for i in range(1, k + 1):
res = res * (n - i + 1) // i
return res
import math
inf=10**20
n=int(input())
c=[]
dp=[0]*(n+1)
for i in range(n):
x,y, t,p = map(float, input().split())
... | Codeforces Beta Round 30 (Codeforces format) | CF | 2,010 | 2 | 256 | Shooting Gallery | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.
The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ... | The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers, - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ... | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6. | null | null | [{"input": "1\n0 0 0 0.5", "output": "0.5000000000"}, {"input": "2\n0 0 0 0.6\n5 0 5 0.7", "output": "1.3000000000"}] | 1,800 | ["dp", "probabilities"] | 50 | [{"input": "1\r\n0 0 0 0.5\r\n", "output": "0.5000000000\r\n"}, {"input": "2\r\n0 0 0 0.6\r\n5 0 5 0.7\r\n", "output": "1.3000000000\r\n"}, {"input": "1\r\n-5 2 3 0.886986\r\n", "output": "0.8869860000\r\n"}, {"input": "4\r\n10 -7 14 0.926305\r\n-7 -8 12 0.121809\r\n-7 7 14 0.413446\r\n3 -8 6 0.859061\r\n", "output": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
try:
correct = float(correct_line)
except:
print(0)
return
with... | true |
30/C | 30 | C | Python 3 | TESTS | 3 | 124 | 7,065,600 | 123911717 | import math
from copy import deepcopy
n = int(input())
lst = []
for i in range(n):
lst.append(list(map(eval, input().split())))
res = [[0]]
for i in range(1, n):
for j in range(len(res)):
r = deepcopy(res[j])
d = math.sqrt((lst[i][0]-lst[res[j][-1]][0])**2 +
(lst[i][1]-ls... | 50 | 1,746 | 0 | 7284138 | def is_reachable(from_state, target):
return (from_state[0]-target[0])**2 + (from_state[1]-target[1])**2 <= (target[2] - from_state[2])**2
num_iter = int(input())
targets = sorted([list(map(float, input().strip().split(' '))) for dummy in range(0, num_iter)], key=lambda single_target: single_target[2])
state... | Codeforces Beta Round 30 (Codeforces format) | CF | 2,010 | 2 | 256 | Shooting Gallery | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.
The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ... | The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers, - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ... | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6. | null | null | [{"input": "1\n0 0 0 0.5", "output": "0.5000000000"}, {"input": "2\n0 0 0 0.6\n5 0 5 0.7", "output": "1.3000000000"}] | 1,800 | ["dp", "probabilities"] | 50 | [{"input": "1\r\n0 0 0 0.5\r\n", "output": "0.5000000000\r\n"}, {"input": "2\r\n0 0 0 0.6\r\n5 0 5 0.7\r\n", "output": "1.3000000000\r\n"}, {"input": "1\r\n-5 2 3 0.886986\r\n", "output": "0.8869860000\r\n"}, {"input": "4\r\n10 -7 14 0.926305\r\n-7 -8 12 0.121809\r\n-7 7 14 0.413446\r\n3 -8 6 0.859061\r\n", "output": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
try:
correct = float(correct_line)
except:
print(0)
return
with... | true |
877/F | 877 | F | PyPy 3 | TESTS | 2 | 77 | 0 | 198658362 | import sys
readline=sys.stdin.readline
from collections import defaultdict
def Mo(N,Q,query):
D=max(1,int(N/Q**.5)//4)
mo=[[] for d in range((N+D-1)//D+1)]
for q,(l,r) in enumerate(query):
mo[r//D].append((l,r,q))
retu=[]
for d in range((N+D-1)//D+1):
retu+=sorted(mo[d],reverse=d%2)... | 78 | 358 | 28,160,000 | 221593503 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v, w):
return (u * m + v) * m + w
n, k = map(int, input().split())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
u = [0] * (n + 1)
for i in range(n):
x = a[i] if t[i] & 1 else -a[i]
u[i + 1] ... | Codeforces Round 442 (Div. 2) | CF | 2,017 | 2 | 256 | Ann and Books | In Ann's favorite book shop are as many as n books on math and economics. Books are numbered from 1 to n. Each of them contains non-negative number of problems.
Today there is a sale: any subsegment of a segment from l to r can be bought at a fixed price.
Ann decided that she wants to buy such non-empty subsegment th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, - 109 ≤ k ≤ 109) — the number of books and the needed difference between the number of math problems and the number of economics problems.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 2), where ti is 1 if the i-th book is on math or 2 if ... | Print q lines, in the i-th of them print the number of subsegments for the i-th Ann's assumption. | null | In the first sample Ann can buy subsegments [1;1], [2;2], [3;3], [2;4] if they fall into the sales segment, because the number of math problems is greater by 1 on them that the number of economics problems. So we should count for each assumption the number of these subsegments that are subsegments of the given segment.... | [{"input": "4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4", "output": "2\n3\n4\n1"}, {"input": "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4", "output": "10"}] | 2,300 | ["data structures", "flows", "hashing"] | 78 | [{"input": "4 1\r\n1 1 1 2\r\n1 1 1 1\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "2\r\n3\r\n4\r\n1\r\n"}, {"input": "4 0\r\n1 2 1 2\r\n0 0 0 0\r\n1\r\n1 4\r\n", "output": "10\r\n"}, {"input": "10 10\r\n2 1 1 1 1 1 1 1 1 2\r\n0 10 10 0 0 10 10 10 10 0\r\n10\r\n4 10\r\n3 7\r\n9 9\r\n2 9\r\n10 10\r\n5 5\r\n2 2\r\n6 ... | false | stdio | null | true |
856/A | 856 | A | PyPy 3 | TESTS | 3 | 124 | 2,355,200 | 108443168 | for _ in range(int(input())):
n = int(input())
b = list(map(int, input(). split()))
print('YES')
m = max(b) - min(b)
k = [i for i in range(max(b), n * (m + 1) + max(b), m + 1)]
print(*k) | 11 | 312 | 4,300,800 | 30833172 | d = [-1] * 1000001
for t in range(int(input())):
n, a = int(input()), list(map(int, input().split()))
a.sort()
for i in range(n):
for j in range(i + 1, n): d[a[j] - a[i]] = t
i = 1
while any(d[i * j] == t for j in range(1, n)): i += 1
print("YES\n" + ' '.join(str(j * i + 1) for j in ran... | Russian Code Cup 2017 - Finals [Unofficial Mirror, Div. 1 Only Recommended, Teams Allowed] | ICPC | 2,017 | 1 | 256 | Set Theory | Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ... | Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100).
Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A (1 ≤ n ≤ 100).
The second line contains n integers ai — the e... | For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set B.
- YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possib... | null | null | [{"input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3\nYES\n1\nYES\n1 2"}] | 1,600 | ["brute force", "constructive algorithms"] | 11 | [{"input": "3\r\n3\r\n1 10 100\r\n1\r\n1\r\n2\r\n2 4\r\n", "output": "YES\r\n1 2 3 \r\nYES\r\n1 \r\nYES\r\n1 2 \r\n"}, {"input": "1\r\n100\r\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f_in, open(submission_path) as f_sub:
input_lines = list(f_in.readlines())
sub_lines = list(f_sub.readlines())
t = int(input_lines[0].strip())
ptr =... | true |
856/A | 856 | A | PyPy 3 | TESTS | 3 | 389 | 2,048,000 | 52780981 | t = int(input())
bound = 10 ** 6
for u in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [1]
difs = set()
for i in range(n):
for j in range(i + 1, n):
difs.add(a[j] - a[i])
last = 2
for i in range(n - 1):
ok = False
whil... | 11 | 405 | 2,048,000 | 30365314 | from random import randint
def solve():
n, aa = int(input()), list(map(int, input().split()))
bb, ab = set(), set()
while True:
b = randint(1, 1000000)
for a in aa:
if a + b in ab:
break
else:
bb.add(b)
if len(bb) == n:
... | Russian Code Cup 2017 - Finals [Unofficial Mirror, Div. 1 Only Recommended, Teams Allowed] | ICPC | 2,017 | 1 | 256 | Set Theory | Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ... | Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100).
Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A (1 ≤ n ≤ 100).
The second line contains n integers ai — the e... | For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set B.
- YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possib... | null | null | [{"input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3\nYES\n1\nYES\n1 2"}] | 1,600 | ["brute force", "constructive algorithms"] | 11 | [{"input": "3\r\n3\r\n1 10 100\r\n1\r\n1\r\n2\r\n2 4\r\n", "output": "YES\r\n1 2 3 \r\nYES\r\n1 \r\nYES\r\n1 2 \r\n"}, {"input": "1\r\n100\r\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f_in, open(submission_path) as f_sub:
input_lines = list(f_in.readlines())
sub_lines = list(f_sub.readlines())
t = int(input_lines[0].strip())
ptr =... | true |
831/B | 831 | B | Python 3 | TESTS | 0 | 15 | 4,505,600 | 134417529 | s1=input()
s2=input()
s=input()
res=''
for i in s:
if i.isdigit() and i.isupper():
t=s2[s1.index(i)]
res+=t.upper()
elif i.isdigit() and i.islower():
t=s2[s1.index(i)]
res+=t
else:
res+=i
print(res) | 19 | 31 | 0 | 147109770 | x = input()
y = input()
z = input()
output = ''
for i in z:
if(i.isupper()):
letter = y[x.index(i.lower())].upper()
elif(i.islower()): letter = y[x.index(i)]
else: letter = i
output += letter
print(output) | Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string s consisting of lowercase and... | Print the text if the same keys were pressed in the second layout. | null | null | [{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}] | 800 | ["implementation", "strings"] | 19 | [{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf... | false | stdio | null | true |
191/C | 191 | C | PyPy 3 | TESTS | 3 | 764 | 257,228,800 | 97199529 | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" ... | 136 | 717 | 58,368,000 | 218130480 | from io import BytesIO, IOBase
import sys
import os
# import time
import bisect
# import functools
import math
import random
# import re
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
from heapq import heapify, heappop, heappush, heappu... | Codeforces Round 121 (Div. 1) | CF | 2,012 | 2 | 256 | Fools and Roads | They say that Berland has exactly two problems, fools and roads. Besides, Berland has n cities, populated by the fools and connected by the roads. All Berland roads are bidirectional. As there are many fools in Berland, between each pair of cities there is a path (or else the fools would get upset). Also, between each ... | The first line contains a single integer n (2 ≤ n ≤ 105) — the number of cities.
Each of the next n - 1 lines contains two space-separated integers ui, vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that means that there is a road connecting cities ui and vi.
The next line contains integer k (0 ≤ k ≤ 105) — the number of pairs of foo... | Print n - 1 integer. The integers should be separated by spaces. The i-th number should equal the number of fools who can go on the i-th road. The roads are numbered starting from one in the order, in which they occur in the input. | null | In the first sample the fool number one goes on the first and third road and the fool number 3 goes on the second, first and fourth ones.
In the second sample, the fools number 1, 3 and 5 go on the first road, the fool number 5 will go on the second road, on the third road goes the fool number 3, and on the fourth one... | [{"input": "5\n1 2\n1 3\n2 4\n2 5\n2\n1 4\n3 5", "output": "2 1 1 1"}, {"input": "5\n3 4\n4 5\n1 4\n2 4\n3\n2 3\n1 3\n3 5", "output": "3 1 1 1"}] | 1,900 | ["data structures", "dfs and similar", "trees"] | 136 | [{"input": "5\r\n1 2\r\n1 3\r\n2 4\r\n2 5\r\n2\r\n1 4\r\n3 5\r\n", "output": "2 1 1 1 \r\n"}, {"input": "5\r\n3 4\r\n4 5\r\n1 4\r\n2 4\r\n3\r\n2 3\r\n1 3\r\n3 5\r\n", "output": "3 1 1 1 \r\n"}] | false | stdio | null | true |
832/D | 832 | D | PyPy 3-64 | TESTS | 2 | 108 | 15,769,600 | 139293891 | from sys import stdin, stdout
def dfs(v, p):
global timer
timer += 1
IN[v] = timer
up[0][v] = p
for i in range(1, LG):
up[i][v] = up[i - 1][up[i - 1][v]]
for q in G[v]:
if q[0] != p:
dep[q[0]] = dep[v] + q[1]
dfs(q[0], v)
out[v] = timer
def upper(u... | 94 | 1,325 | 40,550,400 | 110042385 | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def pre(n,path,lim):
# lim = n.bit_length()
up = [[-1]*(lim+1) for _ in range(n)]
st,visi,height = [0],[1]+[0]*(n-1),[0]*n
start,finish,time = [0]*n,[0]*n,0
while len(st):
x = st[-1]
... | Codeforces Round 425 (Div. 2) | CF | 2,017 | 2 | 256 | Misha, Grisha and Underground | Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decided to have fun and came up with a plan. Namely, in some day in the morning M... | The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days.
The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station... | Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day. | null | In the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1 $$\rightarrow$$ 2, and Grisha would go on the route 3 $$\rightarrow$$ 1 $$\rightarrow$$ 2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3 $$\rightarrow... | [{"input": "3 2\n1 1\n1 2 3\n2 3 3", "output": "2\n3"}, {"input": "4 1\n1 2 3\n1 2 3", "output": "2"}] | 1,900 | ["dfs and similar", "graphs", "trees"] | 94 | [{"input": "3 2\r\n1 1\r\n1 2 3\r\n2 3 3\r\n", "output": "2\r\n3\r\n"}, {"input": "4 1\r\n1 2 3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "2 4\r\n1\r\n1 1 1\r\n1 1 2\r\n1 2 2\r\n2 2 2\r\n", "output": "1\r\n2\r\n2\r\n1\r\n"}, {"input": "5 20\r\n4 1 1 4\r\n2 2 5\r\n3 2 5\r\n2 3 4\r\n4 2 5\r\n4 1 2\r\n5 3 1\r\n2 1 2\r\... | false | stdio | null | true |
270/A | 270 | A | Python 3 | TESTS | 2 | 62 | 0 | 227651361 | tests = int(input())
while tests > 0:
angle = int(input())
tests -= 1
if angle < 60:
print("NO")
else:
print("YES") | 3 | 30 | 0 | 130331529 | t=int(input())
li=[]
for i in range(t):
a=int(input())
n=360/(180-a)
li.append(n)
for i in range(t):
b=li[i]
if b==int(b) and int(b)>2:
print('YES')
else: print('NO') | Codeforces Round 165 (Div. 2) | CF | 2,013 | 2 | 256 | Fancy Fence | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.
Will the robot be able to build the fence Emuskald... | The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | null | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | [{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}] | 1,100 | ["geometry", "implementation", "math"] | 3 | [{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}] | false | stdio | null | true |
111/B | 111 | B | Python 3 | TESTS | 2 | 778 | 9,932,800 | 121490375 | maxn=100000
div=[0]*(maxn+1)
last=[-maxn]*(maxn+1)
for i in range(maxn+1):
div[i]=list()
for i in range(2,int(maxn/2)):
for j in range(i,maxn+1,i):
div[j].append(i)
t=int(input())
for k in range(0,t):
x_i,y_i = input().split(" ")
x_i=int(x_i)
y_i=int(y_i)
if y_i==0:
print(len... | 44 | 2,214 | 9,932,800 | 209312632 | def calculate_smallest_factor(n):
from math import sqrt
for prime in range(2,int(sqrt(n+1))+1):
if smallest_factor[prime]==prime:
for factor in range(prime*prime,n+1,prime):
if smallest_factor[factor] == factor:
smallest_factor[factor] = prime
return s... | Codeforces Beta Round 85 (Div. 1 Only) | CF | 2,011 | 5 | 256 | Petya and Divisors | Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. | The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of t... | For each query print the answer on a single line: the number of positive integers k such that $${ x _ { i } \bmod k = 0 \& ( \forall j : i - y _ { i } \leq j < i ) x _ { j } \bmod k \neq 0 }$$ | null | Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | [{"input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3", "output": "3\n1\n1\n2\n2\n22"}] | 1,900 | ["binary search", "data structures", "number theory"] | 44 | [{"input": "6\r\n4 0\r\n3 1\r\n5 2\r\n6 2\r\n18 4\r\n10000 3\r\n", "output": "3\r\n1\r\n1\r\n2\r\n2\r\n22\r\n"}, {"input": "5\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n", "output": "4\r\n4\r\n4\r\n4\r\n4\r\n"}, {"input": "12\r\n41684 0\r\n95210 1\r\n60053 1\r\n32438 3\r\n97956 1\r\n21785 2\r\n14594 6\r\n17170 4\r\n939... | false | stdio | null | true |
379/C | 379 | C | Python 3 | TESTS | 0 | 15 | 0 | 150994681 | n=(int(input()))
arr=list(map(int,input().rstrip().split()))
s=""
t=1
for e in range(n):
o= max(t,arr[e])
s=s+""+str(o)+" "
t+=1
print(s) | 41 | 748 | 24,576,000 | 200592146 | n = int(input())
arr = list(map(int,input().split()))
sort = sorted(range(n), key=lambda i: arr[i])
curr = 0
for i in sort:
if arr[i]<=curr:
curr+=1
arr[i]=curr
else:
curr=arr[i]
# sort[i]=curr
# print(curr)
print(*arr) | Good Bye 2013 | CF | 2,013 | 1 | 256 | New Year Ratings Change | One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109). | Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them. | null | null | [{"input": "3\n5 1 1", "output": "5 1 2"}, {"input": "1\n1000000000", "output": "1000000000"}] | 1,400 | ["greedy", "sortings"] | 41 | [{"input": "3\r\n5 1 1\r\n", "output": "5 1 2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"}, {"input": "10\r\n1 10 1 10 1 1 7 8 6 7\r\n", "output": "1 10 2 11 3 4 7 9 6 8\r\n"}, {"input": "10\r\n20 19 12 1 12 15 2 12... | false | stdio | null | true |
379/C | 379 | C | Python 3 | TESTS | 0 | 30 | 0 | 200590713 | n = int(input())
arr = list(map(int,input().split()))
if n==1:
print(*arr)
else:
ans = []
for i in range(n):
ans.append(arr[i]+i)
print(*ans) | 41 | 998 | 47,001,600 | 197560118 | n=int(input())
lst=[*map(int,input().split())]
ind=sorted(range(n),key=lst.__getitem__)
elem=0
for i,x in enumerate(ind):
elem=max(elem+1,lst[x])
lst[x]=elem
print(''.join(map(lambda x:str(x)+' ',lst))) | Good Bye 2013 | CF | 2,013 | 1 | 256 | New Year Ratings Change | One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109). | Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them. | null | null | [{"input": "3\n5 1 1", "output": "5 1 2"}, {"input": "1\n1000000000", "output": "1000000000"}] | 1,400 | ["greedy", "sortings"] | 41 | [{"input": "3\r\n5 1 1\r\n", "output": "5 1 2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"}, {"input": "10\r\n1 10 1 10 1 1 7 8 6 7\r\n", "output": "1 10 2 11 3 4 7 9 6 8\r\n"}, {"input": "10\r\n20 19 12 1 12 15 2 12... | false | stdio | null | true |
856/A | 856 | A | Python 3 | TESTS | 3 | 61 | 0 | 30961666 | t = int(input())
for i in range(t):
n = int(input())
list = [int(x) for x in input().split()]
s = set(list)
if (len(s) != n):
print("NO")
else:
gap = max(set(list)) + 1
ans = [i*gap for i in range(1, n+1)]
print ("YES")
print (*ans, sep = ' ') | 11 | 452 | 819,200 | 198737758 | from random import randint
def solve():
n, aa = int(input()), list(map(int, input().split()))
bb, ab = set(), set()
while True:
b = randint(1, 1000000)
for a in aa:
if a + b in ab:
break
else:
bb.add(b)
if len(bb) == n:
... | Russian Code Cup 2017 - Finals [Unofficial Mirror, Div. 1 Only Recommended, Teams Allowed] | ICPC | 2,017 | 1 | 256 | Set Theory | Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ... | Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100).
Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A (1 ≤ n ≤ 100).
The second line contains n integers ai — the e... | For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set B.
- YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possib... | null | null | [{"input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3\nYES\n1\nYES\n1 2"}] | 1,600 | ["brute force", "constructive algorithms"] | 11 | [{"input": "3\r\n3\r\n1 10 100\r\n1\r\n1\r\n2\r\n2 4\r\n", "output": "YES\r\n1 2 3 \r\nYES\r\n1 \r\nYES\r\n1 2 \r\n"}, {"input": "1\r\n100\r\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f_in, open(submission_path) as f_sub:
input_lines = list(f_in.readlines())
sub_lines = list(f_sub.readlines())
t = int(input_lines[0].strip())
ptr =... | true |
856/A | 856 | A | Python 3 | TESTS | 3 | 77 | 102,400 | 30763377 | test_number = int(input())
for _ in range(test_number):
a_size = int(input())
a = [int(i) for i in input().split()]
if sorted(set(a)) != sorted(a):
print("NO")
else:
b = []
for i in range(a_size):
b.append(max(a)*i + 1)
if max(b) < 10**6:
pri... | 11 | 499 | 10,240,000 | 77382547 | visited = [-1] * (2 * 10 ** 6 + 1)
t = int(input())
for i in range(t):
n, A = int(input()), list(map(int, input().split()))
A.sort()
res = []
v = 1
while len(res) < n:
flag = True
for a in A:
if visited[a + v] == i:
flag = False
break
... | Russian Code Cup 2017 - Finals [Unofficial Mirror, Div. 1 Only Recommended, Teams Allowed] | ICPC | 2,017 | 1 | 256 | Set Theory | Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ... | Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100).
Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A (1 ≤ n ≤ 100).
The second line contains n integers ai — the e... | For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set B.
- YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possib... | null | null | [{"input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3\nYES\n1\nYES\n1 2"}] | 1,600 | ["brute force", "constructive algorithms"] | 11 | [{"input": "3\r\n3\r\n1 10 100\r\n1\r\n1\r\n2\r\n2 4\r\n", "output": "YES\r\n1 2 3 \r\nYES\r\n1 \r\nYES\r\n1 2 \r\n"}, {"input": "1\r\n100\r\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f_in, open(submission_path) as f_sub:
input_lines = list(f_in.readlines())
sub_lines = list(f_sub.readlines())
t = int(input_lines[0].strip())
ptr =... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.