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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
641/B | 641 | B | PyPy 3-64 | TESTS | 5 | 233 | 4,608,000 | 162558608 | from collections import defaultdict
n, m, q = map(int, input().split())
l = [[0 for i in range(m)] for i in range(n)]
nn = defaultdict(int)
mm = defaultdict(int)
lll = []
flag = 1
for i in range(q):
k = list(map(int, input().split()))
if flag and k[0] == 3:
lll.reverse()
flag = 0
lll.append(... | 26 | 93 | 6,348,800 | 167459412 | import sys
input = sys.stdin.readline
n, m, q = map(int, input().split())
d = [[0]*m for i in range(n)]
s = [list(map(int, input().split())) for _ in range(q)]
for w in reversed(s):
if w[0] == 1:
a = w[1] - 1
d[a] = [d[a][-1]] + d[a][:-1]
elif w[0] == 2:
a = w[1] - 1
x = d[n-1]... | VK Cup 2016 - Round 2 | CF | 2,016 | 2 | 256 | Little Artem and Matrix | Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There a... | The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the... | Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them. | null | null | [{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}] | 1,400 | ["implementation"] | 26 | [{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu... | false | stdio | null | true |
641/B | 641 | B | PyPy 3-64 | TESTS | 5 | 264 | 5,222,400 | 162557865 | from collections import defaultdict
n, m, q = map(int, input().split())
l = [[0 for i in range(m)] for i in range(n)]
nn = defaultdict(int)
mm = defaultdict(int)
for i in range(q):
k = list(map(int, input().split()))
if len(k) == 2:
if k[0] == 1:
nn[k[1]] += 1
else:
mm[k[... | 26 | 186 | 512,000 | 158702123 | f=lambda: map(int,input().split())
n,m,q=f()
p=[[0]*m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
j=t[1]-1
if t[0]==1: p[j].insert(0,p[j].pop())
elif t[0]==2:
s=p[-1][j]
for i in range(n-1,0,-1): p[i][j]=p[i-1][j]
p[0][j]=s
else: p[j][t[2]-1]=t[3]
for d in p... | VK Cup 2016 - Round 2 | CF | 2,016 | 2 | 256 | Little Artem and Matrix | Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There a... | The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the... | Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them. | null | null | [{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}] | 1,400 | ["implementation"] | 26 | [{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu... | false | stdio | null | true |
372/A | 372 | A | Python 3 | TESTS | 11 | 997 | 12,595,200 | 78554842 | import bisect
m=int(input())
l=[]
while m>0:
t=int(input())
l.append(t)
m-=1
l.sort()
#print(l)
k=l[m-1]//2
c=bisect.bisect_right(l,k)
n=len(l)
if c>len(l)//2:
c=len(l)//2
print(len(l)-c) | 45 | 249 | 11,673,600 | 214252777 | from sys import stdin
def lmap(function, iterable): return list(map(function, iterable))
def line(): return stdin.readline().strip()
def rd(converter): return converter(line())
def rl(converter, delimeter = None): return lmap(converter, line().split(delimeter))
def rls(num_lines, converter): return [rd(converter) for ... | Codeforces Round 219 (Div. 1) | CF | 2,013 | 1 | 256 | Counting Kangaroos is Fun | There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is ... | The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105). | Output a single integer — the optimal number of visible kangaroos. | null | null | [{"input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5"}, {"input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5"}] | 1,600 | ["binary search", "greedy", "sortings", "two pointers"] | 45 | [{"input": "8\r\n2\r\n5\r\n7\r\n6\r\n9\r\n8\r\n4\r\n2\r\n", "output": "5\r\n"}, {"input": "8\r\n9\r\n1\r\n6\r\n2\r\n6\r\n5\r\n8\r\n3\r\n", "output": "5\r\n"}, {"input": "12\r\n3\r\n99\r\n24\r\n46\r\n75\r\n63\r\n57\r\n55\r\n10\r\n62\r\n34\r\n52\r\n", "output": "7\r\n"}, {"input": "12\r\n55\r\n75\r\n1\r\n98\r\n63\r\n64\r... | false | stdio | null | true |
374/B | 374 | B | PyPy 3 | TESTS | 5 | 140 | 3,788,800 | 68477174 | sas = list(map(int, input()))
ass = sas.copy()
g = 1
for i in range(1, len(sas)):
if sas[i] + sas[i - 1] == 9 and ass[i - 1] != 9:
ass[i] = 9
ass[i - 1] = 0
for i in range(1, len(sas)):
if ass[i] != 9 and ass[i - 1] == 9 and ass[i] and sas[i] + sas[i - 1] == 9:
g *= 2
print(g) | 25 | 77 | 102,400 | 231128198 | s,a,c=input(),1,1
for i in range(1,len(s)):
if int(s[i])+int(s[i-1])==9:c+=1
elif c%2:a*=c//2+1;c=1
else:c=1
if(c%2):a*=c//2+1
print(a) | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
281/A | 281 | A | Python 3 | TESTS | 6 | 62 | 0 | 228414318 | word=input()
first_letter=word[0].upper()
new_word=word.replace(word[0], first_letter)
print(new_word) | 25 | 62 | 0 | 224149541 | word=input()
wordlist=[]
for x in word:
wordlist.append(x)
wordlist[0]=wordlist[0].upper()
for x in wordlist:
print(x,end='') | Codeforces Round 172 (Div. 2) | CF | 2,013 | 2 | 256 | Word Capitalization | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | null | null | [{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}] | 800 | ["implementation", "strings"] | 25 | [{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD... | false | stdio | null | true |
281/A | 281 | A | Python 3 | TESTS | 6 | 62 | 0 | 228152376 | a=input()
b=a[0].upper()
c=a.replace(a[0],b)
print(c) | 25 | 62 | 0 | 224155430 | a=input()
d=a[0].upper()
print(d,a[1:],sep="") | Codeforces Round 172 (Div. 2) | CF | 2,013 | 2 | 256 | Word Capitalization | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | null | null | [{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}] | 800 | ["implementation", "strings"] | 25 | [{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD... | false | stdio | null | true |
281/A | 281 | A | Python 3 | TESTS | 6 | 62 | 0 | 226420910 | word=input()
if word[0].isupper():
print(word)
else:
print(word.capitalize()) | 25 | 62 | 0 | 224564251 | # -*- coding: utf-8 -*-
"""
Created on Fri Sep 22 13:12:11 2023
@author: 25419
"""
str0=input()
str1=('abcdefghijklmnopqrstuvwxyz')
str2=('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
if str0[0] in str1:
var0=str0[0].capitalize()
print(var0 + str0[1:])
else: print(str0) | Codeforces Round 172 (Div. 2) | CF | 2,013 | 2 | 256 | Word Capitalization | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | null | null | [{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}] | 800 | ["implementation", "strings"] | 25 | [{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD... | false | stdio | null | true |
281/A | 281 | A | Python 3 | TESTS | 6 | 62 | 0 | 225709835 | my_word = input()
if my_word[0].islower():
my_word = my_word.replace(my_word[0], my_word[0].upper())
print(my_word) | 25 | 62 | 0 | 224687985 | word=input()
print(word[0].upper()+word[1:]) | Codeforces Round 172 (Div. 2) | CF | 2,013 | 2 | 256 | Word Capitalization | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | null | null | [{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}] | 800 | ["implementation", "strings"] | 25 | [{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD... | false | stdio | null | true |
280/B | 280 | B | PyPy 3-64 | TESTS | 3 | 61 | 614,400 | 167064135 | import collections
import os
import sys
from collections import Counter
# print(sys.hexversion)
# if os.getenv('LOCALCFTEST'):
# sys.stdin = open('cfinput.txt')
# else:
# input = sys.stdin.readline
if sys.hexversion == 50924784:
sys.stdin = open('cfinput.txt')
else:
input = sys.stdin.readline
MOD = 10 ... | 56 | 93 | 14,848,000 | 167070041 | n, a = int(input()), list(map(int, input().split()))
def f(arr):
ret = 0
st = []
for v in arr:
while st and st[-1] < v:
ret = max(st.pop(-1) ^ v, ret)
if st:
ret=max(st[-1]^v,ret)
st.append(v)
return ret
print(f(a)) | Codeforces Round 172 (Div. 1) | CF | 2,013 | 1 | 256 | Maximum Xor Secondary | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$.
The lucky number of the sequence of distinct positive integers x1, ... | The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109). | Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r]. | null | For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2].
For the second sample you must choose s[2..5] = {8, 3, 5, 7}. | [{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}] | 1,800 | ["data structures", "implementation", "two pointers"] | 56 | [{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958... | false | stdio | null | true |
282/A | 282 | A | Python 3 | TESTS | 3 | 46 | 0 | 226979062 | n=int(input())
l=[]
for i in range(n):
s=input()
l.append(s)
i=l.count("X++")
j=l.count("++X")
k=l.count("X--")
m=l.count("--X")
u=i+j
v=k+m
if u>v:
print(u-v)
else:
print(v-u) | 36 | 31 | 0 | 227089213 | n = int(input())
x = 0
for _ in range(n):
statement = list(map(str, input().strip()))
if statement[1] == "+":
x += 1
elif statement[1] == "-":
x -= 1
print(x) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
282/A | 282 | A | PyPy 3-64 | TESTS | 3 | 62 | 0 | 228464421 | n = int(input())
positive = []
negative = []
for i in range(n):
check = []
s = input().split()
for i in s:
for j in i:
check.append(j)
if check[0] == '+' or check[-1] == '+':
positive.append(0)
else:
negative.append(0)
print(abs(len(positive)-len(negative))) | 36 | 31 | 0 | 227429063 | n=int(input())
x=0
for i in range(n):
a=input()
if a.__contains__('+'):
x+=1
else:
x-=1
print(x) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
641/B | 641 | B | Python 3 | PRETESTS | 5 | 420 | 5,632,000 | 17491841 | n, m, q = map(int, input().split())
a = [[0 for j in range(m)] for i in range(n)]
query = []
for i in range(q):
s = list(map(int, input().split()))
if len(s) == 2:
query.append((s[0], s[1] - 1))
else:
a[s[1] - 1][s[2] - 1] = s[3]
for k in reversed(range(len(query))):
if query[k][0] == 1:... | 26 | 186 | 5,529,600 | 17491397 | def rotate_r(ar, row, n):
ar[row] = ar[row][-n:] + ar[row][:-n]
return ar
def rotate_c(ar, m, col):
#c = ar[col][0]
c = ar[m - 1][col]
for i in range(m - 1, 0, -1):
#for i in range(m - 1):
ar[i][col] = ar[i - 1][col]
#ar[col][m - 1] = c
ar[0][col] = c
return ar
def print_matr(ar, n):
for i in range(n):
... | VK Cup 2016 - Round 2 | CF | 2,016 | 2 | 256 | Little Artem and Matrix | Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There a... | The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the... | Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them. | null | null | [{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}] | 1,400 | ["implementation"] | 26 | [{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu... | false | stdio | null | true |
847/A | 847 | A | Python 3 | TESTS | 4 | 62 | 0 | 30468530 | n=int(input())
l1=[]
l2=[]
l3=[]
l4=[]
for i in range(0,n):
a,b=input().split(' ')
a,b=int(a),int(b)
l1.append(a)
l2.append(b)
if a==0:
l3.append(i)
if b==0:
l4.append(i)
x=len(l3)
for j in range(0,x-1):
l2[l4[j]]=l3[x-j-1]+1
l1[l3[x-j-1]]=l4[j]+1
for i in range(0,n):
... | 23 | 46 | 0 | 232715808 | n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int,input().split())))
k = 0
for x in enumerate(arr,1):
i = x[0]
l = x[1][0]
r = x[1][1]
if l == 0:
if k != 0:
arr[k-1][1] = i
arr[i-1][0] = k
k = i
while r:
k = r
... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 2 | 256 | Union of Doubly Linked Lists | Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located.
Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev... | Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them. | null | null | [{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}] | 1,500 | ["implementation"] | 23 | [{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r... | false | stdio | null | true |
374/B | 374 | B | PyPy 3-64 | TESTS | 5 | 61 | 1,433,600 | 175304293 | import sys
input = sys.stdin.readline
s = input()[:-1]
n = len(s)
d = dict()
f = 0
for i in range(1, 10):
d[str(i)] = str(9-i)
i = 0
while i < n-1:
c = 0
while i < n-1 and d[s[i]] == s[i+1]:
i += 1
c += 1
if c == 0 or c % 2:
i += 1
else:
f += 1
i += 1
prin... | 25 | 93 | 2,252,800 | 179034177 | n=input()
l=len(n)
ans=1
i=0
while(i<l):
x=1
while(i<l-1 and int(n[i])+int(n[i+1])==9):
x+=1
i+=1
if x%2==1 and x>1:
ans*=x//2+1
x=1
i+=1
print(ans) | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
774/D | 774 | D | Python 3 | TESTS | 14 | 140 | 14,848,000 | 26151223 | n=int,input().split()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=set()
b=set()
for i in range (int(n[1][1])-1,int(n[1][2])):
a.add(A[i])
b.add(B[i])
flag=True
for i in range (int(n[1][1])-1):
if A[i]!=B[i]:
flag=False
for i in range (int(n[1][2]),int(n[1][1])):
if ... | 52 | 93 | 15,155,200 | 26150252 | top = input().split()
n = top[0]
l = top[1]
r = top[2]
a = input().split()
b = input().split()
truth = True
for i in range(0 , int(l)-1):
if a[i] != b[i]:
truth = False
for i in range(int(r) , int(n)):
if a[i] != b[i]:
truth = False
if(truth == True):
print("TRUTH\n")
else:
print(... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Lie or Truth | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan... | The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence b1, b2, ... | Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). | null | In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and... | [{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}] | 1,500 | ["*special", "constructive algorithms", "implementation", "sortings"] | 52 | [{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ... | false | stdio | null | true |
494/B | 494 | B | Python 3 | TESTS | 6 | 264 | 4,915,200 | 31723820 | s, t = input(), input()
n, m = len(t), len(s)
p = [0] * (n + 1)
i, j = 0, 1
while j < n:
if t[i] == t[j]:
j += 1
i += 1
p[j] = i
elif i: i = p[i]
else: j += 1
i = j = 0
f = [0] * (m + 1)
while j < m:
if t[i] == s[j]:
i += 1
j += 1
if i == n:
... | 51 | 264 | 4,198,400 | 231039994 | s, t = input(), input()
n, m = len(t), len(s) + 1
d = 1000000007
g = [1] * m
f = k = 0
for i in range(1, m) :
if s[i - n:i] == t : k = i
if k : f = (f + g[k - n]) % d
g[i] += (g[i - 1] + f) % d
print(f) | Codeforces Round 282 (Div. 1) | CF | 2,014 | 2 | 256 | Obsessive String | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters. | Print the answer in a single line. | null | null | [{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}] | 2,000 | ["dp", "strings"] | 51 | [{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawaw... | false | stdio | null | true |
374/B | 374 | B | PyPy 3 | TESTS | 5 | 139 | 4,915,200 | 57446038 | class CodeforcesTask374BSolution:
def __init__(self):
self.result = ''
self.number = []
def read_input(self):
self.number = [int(c) for c in input()]
def process_task(self):
nums = 1
x = 0
while x + 1 < len(self.number):
s = 1
while s... | 25 | 93 | 5,939,200 | 161522543 | a=[int(i) for i in list(input())]
i=0
cl=[]
while True:
if i>=len(a)-1:
break
if a[i]+a[i+1]==9:
c=1
while True:
if i>=len(a)-1:
break
if a[i]+a[i+1]==9:
c+=1
else:
i+=1
break
... | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
374/B | 374 | B | PyPy 3 | TESTS | 5 | 155 | 1,843,200 | 79081761 | import sys
import math
data = sys.stdin.read().split()
data_ptr = 0
def data_next():
global data_ptr, data
data_ptr += 1
return data[data_ptr - 1]
S = data[0]
N = len(S)
ans = 1
block = 0
for i in range(N):
if i == N - 1 or int(S[i]) + int(S[i + 1]) != 9:
if block > 0 and block % 2 == 0:
... | 25 | 124 | 1,945,600 | 120766172 | s=input()
ans=1
c=1
for i in range(1,len(s)):
if int(s[i])+int(s[i-1])==9:
c+=1
elif c%2==1:
ans*=c//2+1;c=1
else:
c=1
if c%2==1:
ans*=c//2+1
print(ans) | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
963/B | 963 | B | Python 3 | TESTS | 6 | 265 | 7,065,600 | 37689210 | def tree(aim,x):
for i in aim:
if (line_num[i] % 2 == 0) and (not(i in ans)):
wk1 = line_num[i]
line_num[i] = 0
aim1 = []
for j in range(len(line[i])):
if not(line[i][j] in ans):
line_num[line[i][j]] -= 1
aim1.append(line[i][j])
ans[x] = i
tree(aim1, x + 1)
for j in range(x + 1, l... | 95 | 701 | 45,670,400 | 126191783 | import sys
input = sys.stdin.readline
n = int(input())
if n%2 == 0:
print("NO")
exit()
parent = list(map(int,input().split()))
print("YES")
s = [0]*n
G = [[] for _ in range(n)]
root = -1
for i in range(n):
parent[i] -= 1
if parent[i] != -1:
G[parent[i]].append(i)
else:
root = i
st... | Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1) | CF | 2,018 | 1 | 256 | Destruction of a Tree | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or... | The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree.
The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree. | If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes).
If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any. | null | In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order. | [{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}] | 2,000 | ["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"] | 95 | [{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33... | 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) as f:
n = int(f.readline())
p = list(map(int, f.readline().split()))
# Read reference output
with open(output_path) as f_ref:
... | true |
372/A | 372 | A | Python 3 | TESTS | 11 | 763 | 19,353,600 | 88756366 | from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input=sys.stdin.readline
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())
def inp():
return int(input())
def fk(a,s,k):
b=[]
for i i... | 45 | 249 | 15,872,000 | 180536162 | import sys
input = sys.stdin.readline
n = int(input())
q = sorted([int(input()) for _ in range(n)])
c = 0
i = (n-1)//2
j = n-1
while i >= 0:
if q[i]*2 <= q[j]:
i -= 1
j -= 1
c += 1
else:
i -= 1
print(n-min(c, n//2)) | Codeforces Round 219 (Div. 1) | CF | 2,013 | 1 | 256 | Counting Kangaroos is Fun | There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is ... | The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105). | Output a single integer — the optimal number of visible kangaroos. | null | null | [{"input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5"}, {"input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5"}] | 1,600 | ["binary search", "greedy", "sortings", "two pointers"] | 45 | [{"input": "8\r\n2\r\n5\r\n7\r\n6\r\n9\r\n8\r\n4\r\n2\r\n", "output": "5\r\n"}, {"input": "8\r\n9\r\n1\r\n6\r\n2\r\n6\r\n5\r\n8\r\n3\r\n", "output": "5\r\n"}, {"input": "12\r\n3\r\n99\r\n24\r\n46\r\n75\r\n63\r\n57\r\n55\r\n10\r\n62\r\n34\r\n52\r\n", "output": "7\r\n"}, {"input": "12\r\n55\r\n75\r\n1\r\n98\r\n63\r\n64\r... | false | stdio | null | true |
374/B | 374 | B | Python 3 | TESTS | 5 | 124 | 4,812,800 | 23931065 | a = input()
ans = 1
lst = 0
for i in range(1, len(a)):
sm = int(a[i]) + int(a[i - 1])
if sm != 9:
if lst > 0 and lst % 2 == 0:
ans *= 2
lst = 0
else:
lst += 1
if lst > 0 and lst % 2 == 0:
ans *= 2
print(ans) | 25 | 124 | 6,963,200 | 127492936 | s,a,c=input(),1,1
for i in range(1,len(s)):
if int(s[i])+int(s[i-1])==9:
c+=1
elif c%2:
a*=c//2+1
c=1
else:
c=1
if(c%2):
a*=c//2+1
print(a) | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
374/B | 374 | B | Python 3 | TESTS | 5 | 77 | 204,800 | 195377951 | n = str(input())
contador = 0
res = 1
anterior = int(n[0])
for num in n:
inum = int(num)
if inum + anterior == 9:
contador += 1
elif contador != 0:
if contador % 2 == 0:
res *= 2
contador = 0
anterior = inum
if contador != 0:
if contador % 2 == 0:
res *= 2
print(res) | 24 | 140 | 0 | 5463471 | s=input()
ans=0
i=1
past=int(s[0])
c=1
ans=1
while(i<len(s)):
if(int(s[i])+past==9):
c+=1
past=int(s[i])
else:
if(c%2==1 and c!=1):
ans*=(c//2+1)
c=1
past=int(s[i])
i+=1
if(c!=1 and c%2==1):
ans*=(c//2+1)
print(ans) | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
374/B | 374 | B | Python 3 | TESTS | 5 | 93 | 0 | 5660029 | t = input()
s = d = 0
p = {str(i): str(9 - i) for i in range(10)}
for i in range(len(t) - 1):
if p[t[i]] == t[i + 1]: s += 1
else:
if s % 2 == 0: d += s
s = 0
if s % 2 == 0: d += s
print(1 << (d // 2)) | 25 | 155 | 1,433,600 | 47807615 | s = input()
nine = []
num = 0
ans = 1
for i in range(1, len(s)):
if int(s[i - 1]) + int(s[i]) == 9:
num += 1
else:
if num > 0:
nine.append(num + 1)
num = 0
if num != 0:
nine.append(num + 1)
for i in range(len(nine)):
x= nine[i]
if x % 2 != 0:
ans = ans... | Codeforces Round 220 (Div. 2) | CF | 2,013 | 1 | 256 | Inna and Nine | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use 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 | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | [{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}] | 1,500 | ["combinatorics", "greedy"] | 25 | [{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "1212129121212... | false | stdio | null | true |
629/B | 629 | B | Python 3 | TESTS | 8 | 155 | 307,200 | 16260223 | n = (int)(input())
F1=[0]*n
F2=[0]*n
M1=[0]*n
M2=[0]*n
m=0
f=0
for i in range(n):
c = (input().split())
if(c[0]=='M'):
M1[m]=(int)(c[1])
M2[m]=(int)(c[2])
m=m+1
if(c[0]=='F'):
F1[f]=(int)(c[1])
F2[f]=(int)(c[2])
f=f+1
F=[0]*3232
M=[0]*3266
for i in range(f):
... | 76 | 62 | 0 | 16238652 | n = int(input())
females = [0] * 366
males = [0] * 366
for _ in range(n):
p, start, end = input().split()
start = int(start) - 1
end = int(end) # end == 366
if p == "F":
females[start] += 1
if end < 366:
females[end] -= 1
elif p == "M":
males[start] += 1
... | Codeforces Round 343 (Div. 2) | CF | 2,016 | 2 | 256 | Far Relative’s Problem | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far A... | The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.
Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 3... | Print the maximum number of people that may come to Famil Door's party. | null | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | [{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}] | 1,100 | ["brute force"] | 76 | [{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 ... | false | stdio | null | true |
847/A | 847 | A | Python 3 | TESTS | 7 | 109 | 0 | 43998625 | n = int(input())
unit = []
for i in range(1,n+1):
[l, r] = map(int, input().split())
find = -1
arrow = -1
for j in range(len(unit)):
if r != 0 and ((unit[j][0] == r) or (i == unit[j][0] and r == unit[j][1])):
find = j
if unit[j][0] == r:
arrow = 0
... | 23 | 62 | 0 | 191773329 | n = int(input().strip())
l = [0] * (n + 1)
r = [0] * (n + 1)
q = []
for i in range(1, n + 1):
l[i], r[i] = map(int, input().split())
if not l[i]:
q.append(i)
mark = True
ne = None
while q:
now = q.pop(0)
if not mark:
l[now] = ne
r[ne] = now
mark = False
ne = now
while... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 2 | 256 | Union of Doubly Linked Lists | Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located.
Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev... | Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them. | null | null | [{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}] | 1,500 | ["implementation"] | 23 | [{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r... | false | stdio | null | true |
847/A | 847 | A | PyPy 3-64 | TESTS | 9 | 77 | 0 | 190514304 | n=int(input())
L,L2,lst=[],[],[]
c=0
for _ in range(n):
l,r=map(int,input().split())
L.append([l,r])
if r==0:
c+=1
else:
L2.append(r)
for i in range(n):
if n-i not in L2:
lst.append(n-i)
p=0
for i in range(n):
if L[i][1]==0 and lst[p]!=L[i][0] and i+1!=lst[p] and i+1!= L[... | 23 | 62 | 0 | 219095258 | n = int(input())
pr = [0] * n
ne = [0] * n
for i in range(n):
pr[i], ne[i] = map(int, input().split())
pr[i] -= 1
ne[i] -= 1
lists = []
for i in range(n):
if pr[i] == -1:
p = i
while ne[p] != -1:
p = ne[p]
lists.append((i, p))
for i in range(1, len(lists)):
ne[lis... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 2 | 256 | Union of Doubly Linked Lists | Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located.
Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev... | Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them. | null | null | [{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}] | 1,500 | ["implementation"] | 23 | [{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r... | false | stdio | null | true |
847/A | 847 | A | PyPy 3-64 | TESTS | 7 | 46 | 0 | 191313017 | n = int(input())
M = []
N = []
B = []
for i in range(n):
a, b = map(int, input().split())
L = []
if a != 0:
L.append(a)
L.append(i + 1)
if b != 0:
L.append(b)
M.append(L)
M.sort(key = len)
for K in M:
N += K
for ele in N:
if ele not in B:
B.append(ele)
for k in ra... | 23 | 62 | 307,200 | 106171058 | if __name__=='__main__':
n=int(input())
dl=[[0,0]]
end=0
for i in range(n):
dl.append(list(map(int,input().split())))
for i in range(1,n+1):
if not dl[i][0]:
dl[end][1]=i
dl[i][0]=end
j=i
while(dl[j][1]):
#print(dl[j])
#j+=1
j=dl[j][1]
end=j
for node in dl[1:]:
print(*node) | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 2 | 256 | Union of Doubly Linked Lists | Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located.
Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev... | Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them. | null | null | [{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}] | 1,500 | ["implementation"] | 23 | [{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r... | false | stdio | null | true |
631/A | 631 | A | Python 3 | TESTS | 18 | 31 | 0 | 221238787 | n=int(input())
array=list(map(int, input().split()))
brray=list(map(int, input().split()))
ora=array[0]
orb=brray[0]
for a in range(1,n-1):
ora=ora|array[a]
for b in range(1,n-1):
orb=orb|brray[b]
if n==2:
print(2*(ora+orb))
else:
print(ora+orb) | 27 | 46 | 0 | 146703856 | n = int(input())
a = map(int, input().split())
ta = 0
for i in a:
ta |= i
b = map(int, input().split())
tb = 0
for i in b:
tb |= i
print(ta + tb) | Codeforces Round 344 (Div. 2) | CF | 2,016 | 1 | 256 | Interview | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.
The second line contains n integers ai (0 ≤ ai ≤ 109).
The third line contains n integers bi (0 ≤ bi ≤ 109). | Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n. | null | Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ... | [{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}] | 900 | ["brute force", "implementation"] | 27 | [{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1... | false | stdio | null | true |
282/A | 282 | A | Python 3 | TESTS | 6 | 46 | 0 | 228672944 | n=int(input())
A = []
m = 0
for i in range(n):
a = input()
A.append(a)
for i in range(len(A)):
if A[i] == "--X":
m-=1
elif A[i] == "++X":
m+=1
elif A[i] == "X++" and i != len(A)-1:
m+=1
elif A[i] == "X--" and i != len(A)-1:
m-=1
print(m) | 36 | 31 | 0 | 227571097 | n=int(input())
x=0
while n>0 :
s=list(input())
if '+' in s :
x+=1
else :
x-=1
n-=1
print(x) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
776/A | 776 | A | Python 3 | TESTS | 6 | 155 | 1,126,400 | 60618311 | import re
sk=[input().split()]
n=int(input())
for x in range(n):
n1=input().split()
if re.match(sk[x][0],n1[0]):
sk.append([n1[1],sk[x][1]])
else:
sk.append([sk[x][0],n1[1]])
for x in range(n+1):
print(sk[x][0],sk[x][1]) | 57 | 46 | 0 | 145593385 | import sys
candidates = sys.stdin.readline().strip().split(' ', 2)
n = int(sys.stdin.readline().strip())
killed = []
candidates_list = [candidates]
for i in range(n):
names = sys.stdin.readline().strip().split(' ', 2)
new_candidates = list(candidates_list[-1])
new_candidates.remove(names[0])
new_cand... | ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | A Serial Killer | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days.
Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ... | Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | null | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears.
- After day 2, rachel is killed and phoebe appears.
- After day 3, phoebe is killed and monica appears.
- After day 4, monica is killed and chandler appears. | [{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}] | 900 | ["brute force", "implementation", "strings"] | 57 | [{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
with open(output_path, 'r') as f:
correct_lines = [line.strip() for line in f.readlines()]
with open(submission_path, 'r') as f:
submission_lines = [line.strip() for line in f.readlines()]
if ... | true |
282/A | 282 | A | Python 3 | TESTS | 6 | 31 | 0 | 228528908 | n = int(input())
x = 0
for i in range(n):
op = input()
if ((op == "X++") and (i != n-1)) or (op == "++X"):
x += 1
elif ((op == "X--") and (i != n-1)) or (op == "--X"):
x -= 1
print(x) | 36 | 31 | 0 | 227584059 | n = int(input(""))
count = 0
for i in range(n):
s = input("")
if s[1] == "+":
count = count + 1
if s[1] == "-":
count = count - 1
print(count) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
282/A | 282 | A | Python 3 | TESTS | 6 | 31 | 0 | 228474718 | n = input()
x = 0
for i in range(int(n)):
code = input()
if i == (int(n) -1):
if code == "++X":
x += 1
elif code == "--X":
x -= 1
else:
if code == "++X" or code == "X++":
x += 1
else:
x -= 1
print(x) | 36 | 31 | 0 | 227587238 | def resta(x):
x-=1
return x
def suma(x):
x+=1
return x
n = int(input())
x = 0
for _ in range(n):
a = input()
if("-" in a):
x = resta(x)
else:
x = suma(x)
print(x) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
227/B | 227 | B | Python 3 | TESTS | 6 | 716 | 2,457,600 | 165327697 | n=int(input())
arr=input()
m=int(input())
goal=input()
vasya=0
pyta=0
for i in goal:
if i.isdigit():
x=arr.index(i)//2
vasya+=x+1
pyta+=n-x
print(vasya,pyta) | 34 | 186 | 16,076,800 | 214583225 | k=int(input())
l=[0]*(k+1)
ans=input().split()
for i in range(k):
l[int(ans[i])]=i+1
q=int(input())
q1=map(int,input().split())
sum=0
sum2=0
for i in q1:
sum+=l[i]
sum2+=(k-l[i]+1)
print(sum,sum2) | Codeforces Round 140 (Div. 2) | CF | 2,012 | 2 | 256 | Effective Approach | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the elements of array.
The third line contains integer m (1 ≤ m ≤ 105) — the number of queries. The last line contains m space-separated int... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | null | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | [{"input": "2\n1 2\n1\n1", "output": "1 2"}, {"input": "2\n2 1\n1\n1", "output": "2 1"}, {"input": "3\n3 1 2\n3\n1 2 3", "output": "6 6"}] | 1,100 | ["implementation"] | 34 | [{"input": "2\r\n1 2\r\n1\r\n1\r\n", "output": "1 2\r\n"}, {"input": "2\r\n2 1\r\n1\r\n1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n3 1 2\r\n3\r\n1 2 3\r\n", "output": "6 6\r\n"}, {"input": "9\r\n2 9 3 1 6 4 7 8 5\r\n9\r\n5 1 5 2 8 4 4 4 5\r\n", "output": "58 32\r\n"}, {"input": "10\r\n3 10 9 2 7 6 5 8 4 1\r\n1\r\n4\r... | false | stdio | null | true |
316/B1 | 316 | B2 | PyPy 3 | TESTS2 | 8 | 109 | 512,000 | 113604155 | from collections import defaultdict
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
... | 29 | 78 | 102,400 | 3864056 | n, x = map(int, input().split())
link1 = list(map(int, input().split()))
link2 = [0] * (n + 1)
for i, v in enumerate(link1, 1):
if v != 0:
link2[v] = i
table = [False] * n
table[0] = True
for i, v in enumerate(link1, 1):
if v == 0:
len = 0
flag = False
now = i
while now... | ABBYY Cup 3.0 | ICPC | 2,013 | 0.5 | 256 | EKG | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver f... | Print all possible positions of the Smart Beaver in the line in the increasing order. | null | Picture for the fourth test. | [{"input": "6 1\n2 0 4 0 6 0", "output": "2\n4\n6"}, {"input": "6 2\n2 3 0 5 6 0", "output": "2\n5"}, {"input": "4 1\n0 0 0 0", "output": "1\n2\n3\n4"}, {"input": "6 2\n0 0 1 0 4 5", "output": "1\n3\n4\n6"}] | 1,500 | ["brute force", "dfs and similar"] | 29 | [{"input": "6 1\r\n2 0 4 0 6 0\r\n", "output": "2\r\n4\r\n6\r\n"}, {"input": "6 2\r\n2 3 0 5 6 0\r\n", "output": "2\r\n5\r\n"}, {"input": "4 1\r\n0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n"}, {"input": "6 2\r\n0 0 1 0 4 5\r\n", "output": "1\r\n3\r\n4\r\n6\r\n"}, {"input": "10 7\r\n10 8 6 5 0 0 0 4 3 9\r\n", "output"... | false | stdio | null | true |
316/B1 | 316 | B2 | PyPy 3 | TESTS2 | 5 | 155 | 512,000 | 47025435 | import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations
from sys import stdout
R = lambda: map(int, input().split())
n, s = R()
seq = [0] + list(R())
incm = [0] * (n... | 29 | 93 | 3,788,800 | 183947154 | import sys
input = sys.stdin.readline
from collections import Counter
def f(t):
global xx
q = [t]
c = 0
while q:
a = q.pop()
xx[a] = 1
c += 1
for i in d[a]:
if xx[i] == 0:
q.append(i)
return c
n, x = map(int, input().split())
w = list(m... | ABBYY Cup 3.0 | ICPC | 2,013 | 0.5 | 256 | EKG | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver f... | Print all possible positions of the Smart Beaver in the line in the increasing order. | null | Picture for the fourth test. | [{"input": "6 1\n2 0 4 0 6 0", "output": "2\n4\n6"}, {"input": "6 2\n2 3 0 5 6 0", "output": "2\n5"}, {"input": "4 1\n0 0 0 0", "output": "1\n2\n3\n4"}, {"input": "6 2\n0 0 1 0 4 5", "output": "1\n3\n4\n6"}] | 1,500 | ["brute force", "dfs and similar"] | 29 | [{"input": "6 1\r\n2 0 4 0 6 0\r\n", "output": "2\r\n4\r\n6\r\n"}, {"input": "6 2\r\n2 3 0 5 6 0\r\n", "output": "2\r\n5\r\n"}, {"input": "4 1\r\n0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n"}, {"input": "6 2\r\n0 0 1 0 4 5\r\n", "output": "1\r\n3\r\n4\r\n6\r\n"}, {"input": "10 7\r\n10 8 6 5 0 0 0 4 3 9\r\n", "output"... | false | stdio | null | true |
629/B | 629 | B | Python 3 | TESTS | 2 | 46 | 5,120,000 | 18163604 | from sys import *
inp = lambda : stdin.readline()
N = 368
def main():
n = int(inp())
m = [0 for i in range(N)]
f = m[:]
for i in range(n):
s = inp().split()
if s[0] == 'M':
m[int(s[1])] = 1
m[int(s[2])+1] = -1
else:
f[int(s[1])] = 1
... | 76 | 62 | 0 | 16239840 | arrMa=[0]*367
arrFe=[0]*367
p=int(input())
for i in range(p):
inf=list(map(str,input().split()))
if inf[0]=='M':
arrMa[int(inf[1])-1]+=1
arrMa[int(inf[2])]-=1
else:
arrFe[int(inf[1])-1]+=1
arrFe[int(inf[2])]-=1
maxi=-1
curM=0
curF=0
for i in range(366):
curM+=ar... | Codeforces Round 343 (Div. 2) | CF | 2,016 | 2 | 256 | Far Relative’s Problem | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far A... | The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.
Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 3... | Print the maximum number of people that may come to Famil Door's party. | null | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | [{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}] | 1,100 | ["brute force"] | 76 | [{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 ... | false | stdio | null | true |
282/A | 282 | A | PyPy 3 | TESTS | 6 | 78 | 0 | 231316618 | def calc(n, x, arr, i):
if arr[i][0] == '+':
x += 1
n -= 1
if n == 0:
return x
elif arr[i][-1] == '+':
n -= 1
if n == 0:
return x
x += 1
elif arr[i][0] == '-':
x -= 1
n -= 1
if n == 0:
return x
... | 36 | 31 | 0 | 227592533 | x = int(input())
cnt = 0
for i in range(x):
s = input()
if s.find('+') == -1:
cnt = cnt-1
else:
cnt = cnt + 1
print(cnt) | Codeforces Round 173 (Div. 2) | CF | 2,013 | 1 | 256 | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A s... | The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c... | Print a single integer — the final value of x. | null | null | [{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}] | 800 | ["implementation"] | 36 | [{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n... | false | stdio | null | true |
22/D | 22 | D | Python 3 | TESTS | 39 | 46 | 0 | 149056782 | n = int(input())
cuie = []
siruri = []
nr = 0
actual = [-0.5, -0.5]
for k in range(n):
i, j = input().split()
if int(i)>int(j):
i, j = j, i
siruri.append([int(i), int(j)])
siruri.sort(key=lambda x: x[1])
for i in range(n):
if actual[1] < siruri[i][0]:
if actual[1] != -0.5:
... | 40 | 46 | 0 | 198822549 | n=int(input())
a=[]
for i in range(n):
s=input()
a.append([int(x) for x in s.split()])
if a[i][0]>a[i][1]:
x=a[i][0]
a[i][0]=a[i][1]
a[i][1]=x
a.sort(key=lambda x:x[1])
s=[a[0][1]]
i=0
for x in a[1:]:
if s[i]>x[1] or s[i]<x[0]:
s.append(x[1])
i+=1
print(len(s),... | Codeforces Beta Round 22 (Div. 2 Only) | ICPC | 2,010 | 1 | 256 | Segments | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need... | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | null | null | [{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}] | 1,900 | ["greedy", "sortings"] | 40 | [{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r... | false | stdio | null | true |
651/B | 651 | B | Python 3 | TESTS | 11 | 46 | 7,065,600 | 130838845 | from collections import defaultdict
n = int(input())
values = sorted(list(map(int, input().split())))
counts = defaultdict(int)
num_counts = defaultdict(int)
res = 0
max_val = 0
for value in values:
max_val = max(max_val, value)
counts[value] += 1
num_counts[counts[value]] += 1
for i in range(1, max_val)... | 31 | 46 | 0 | 132049611 | n = int(input().strip())
a = list(map(int, input().strip().split()))
d = {}
for i in a:
if i in d.keys():
d[i] += 1
else:
d[i] = 1
lst = []
for i in d.keys():
lst.append(d[i])
print(n - max(lst)) | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
65/D | 65 | D | PyPy 3-64 | TESTS | 0 | 31 | 0 | 219356581 | N = int(input())
buf = input()
TWO = (1 << 14) - 1
house = ["Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"]
a = [-1] * N
for i in range(N):
for j in range(4):
if buf[i] == house[j][0]:
a[i] = j
dp = [set() for _ in range(N + 1)]
ans = set()
def func(st, pos):
x = st
a1 = (x & TWO);... | 66 | 139 | 7,782,400 | 173624984 | n = input()
inputs = input()
first_letter_to_index = {
'G': 0, 'H': 1, 'R': 2, 'S': 3
}
pos = {(0, 0, 0, 0)} # call possibilities
for first_letter in inputs:
size = len(pos)
new_pos = []
if first_letter in first_letter_to_index:
idx = first_letter_to_index[first_letter]
for p in pos:
... | Codeforces Beta Round 60 | CF | 2,011 | 2 | 256 | Harry Potter and the Sorting Hat | As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the nam... | The first input line contains an integer n (1 ≤ n ≤ 10000). It is the number of students who are in the list before Hermione. The next line contains n symbols. If all the relatives of a student used to study in the same house, then the i-th character in the string coincides with the first letter of the name of this hou... | Print all the possible houses where Hermione can be sent. The names of the houses should be printed in the alphabetical order, one per line. | null | Consider the second example. There are only two students before Hermione. The first student is sent to Hufflepuff. The second disciple is given the choice between the houses where the least number of students has been sent, i.e. Gryffindor, Slytherin and Ravenclaw. If he chooses Gryffindor, Hermione is forced to choose... | [{"input": "11\nG????SS???H", "output": "Gryffindor\nRavenclaw"}, {"input": "2\nH?", "output": "Gryffindor\nRavenclaw\nSlytherin"}] | 2,200 | ["brute force", "dfs and similar", "hashing"] | 66 | [{"input": "11\r\nG????SS???H\r\n", "output": "Gryffindor\r\nRavenclaw\r\n"}, {"input": "2\r\nH?\r\n", "output": "Gryffindor\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "1\r\n?\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "1\r\nG\r\n", "output": "Hufflepuff\r\nRavenclaw\r\nSlyther... | false | stdio | null | true |
859/G | 859 | G | Python 3 | PRETESTS | 0 | 61 | 512,000 | 30402062 | import random
def f():
if (random.randint(1, 2) == 1):
print("YES");
else:
print("NO")
n = int(input())
a = list(map(int, input().split()))
f() | 70 | 93 | 6,144,000 | 227486527 | def factor(n):
ps = []
for i in range(2, n):
if i * i > n:
break
if n % i == 0:
e = 0
while n % i == 0:
e += 1
n //= i
ps += [(i, e)]
if n > 1:
ps += [(n, 1)]
return ps
n = int(input())
a = list(map... | MemSQL Start[c]UP 3.0 - Round 1 | CF | 2,017 | 1 | 256 | Circle of Numbers | n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points... | The first line of input contains an integer n (3 ≤ n ≤ 100000), the number of points along the circle.
The following line contains a string s with exactly n digits, indicating the numbers initially present at each of the points, in clockwise order. | Print "YES" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise "NO" (without quotes).
You can print each letter in any case (upper or lower). | null | If we label the points from 1 to n, then for the first test case we can set k = 1. Then we increase the numbers at points 7 and 22 by 1, then decrease the numbers at points 7, 17, and 27 by 1, then decrease the numbers at points 4, 10, 16, 22, and 28 by 1. | [{"input": "30\n000100000100000110000000001100", "output": "YES"}, {"input": "6\n314159", "output": "NO"}] | 3,000 | ["math"] | 70 | [{"input": "30\r\n000100000100000110000000001100\r\n", "output": "YES\r\n"}, {"input": "6\r\n314159\r\n", "output": "NO\r\n"}, {"input": "3\r\n000\r\n", "output": "YES\r\n"}, {"input": "15\r\n522085220852208\r\n", "output": "YES\r\n"}, {"input": "300\r\n518499551238825328417663140237955446550596254299485115465325550413... | false | stdio | null | true |
514/D | 514 | D | PyPy 3-64 | TESTS | 3 | 46 | 0 | 209047341 | def build_log(n):
dp = [0] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
dp[i] = dp[i // 2] + 1
return dp
class SparseTable:
def __init__(self, lg, fn):
self.lg = lg
self.fn = fn
def build(self, arr):
dp = [dict() for _ in range(len(arr))]
for i in ran... | 35 | 1,996 | 120,217,600 | 192669643 | def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
from math import log2,floor
def main():
n,l,k=rm()
rb=[]
for i in range(n):
rb.append(rl())
rb=[[rb[i][j] for i in range(len(rb))] for ... | Codeforces Round 291 (Div. 2) | CF | 2,015 | 2 | 256 | R2D2 and Droid Army | An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the... | The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively.
Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of det... | Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.
If there are multiple optimal solutions, print any of them.
It is not necessary to make exactly k shots, th... | null | In the first test the second, third and fourth droids will be destroyed.
In the second test the first and second droids will be destroyed. | [{"input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3", "output": "2 2"}, {"input": "3 2 4\n1 2\n1 3\n2 2", "output": "1 3"}] | 2,000 | ["binary search", "data structures", "two pointers"] | 35 | [{"input": "5 2 4\r\n4 0\r\n1 2\r\n2 1\r\n0 2\r\n1 3\r\n", "output": "2 2\r\n"}, {"input": "3 2 4\r\n1 2\r\n1 3\r\n2 2\r\n", "output": "1 3\r\n"}, {"input": "1 1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "4 5 33\r\n2 10 2 3... | false | stdio | null | true |
53/A | 53 | A | PyPy 3 | TESTS | 15 | 310 | 20,172,800 | 87268071 | s = str(input())
n = int(input())
T = [str(input()) for i in range(n)]
T = [(len(t), t) for t in T]
T.sort(key=lambda x: (x[0], x[1]))
for _, t in T:
if t.startswith(s):
print(t)
exit()
else:
print(s) | 25 | 92 | 0 | 136649994 | #!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-23 23:23:28
LastEditTime: 2021-11-23 23:27:49
Description: Autocomplete
FilePath: CF53A.py
'''
def func():
inputted = input().strip()
n = int(input())
lst = []
for _ in range(n):
visited = input().strip()
if visited.s... | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
977/E | 977 | E | PyPy 3-64 | TESTS | 17 | 701 | 74,444,800 | 225900118 | import sys
from collections import defaultdict
def set_bit(bitmap, index):
bitmap[index >> 6] |= 1 << (index & 63)
def clear_bit(bitmap, index):
bitmap[index >> 6] &= ~(1 << (index & 63))
def get_bit(bitmap, index):
return bitmap[index >> 6] & (1 << (index & 63))
def bit_scan_forward(bitmap):
return bin(bit... | 35 | 655 | 74,444,800 | 225901870 | import sys
from collections import defaultdict
# LOAD DATA IN LIST WITH 2 POINTS
# IF THERE IS 3rd POINT IN EDGE TURN BOTH POINTS INVALID
# node[a] = [c, b] + d
# turn a and d invalid
# keep check of invalid points in bitmap
# 0 - 63 => 0
# 64 - 127 => 1
def set_bit(bitmap, index):
bitmap[index >> 6] |= 1 << (... | Codeforces Round 479 (Div. 3) | ICPC | 2,018 | 2 | 256 | Cyclic Components | You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles.
Here are some definitions of graph theory.
An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair ... | The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges.
The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). ... | Print one integer — the number of connected components which are also cycles. | null | In the first example only component $$$[3, 4, 5]$$$ is also a cycle.
The illustration above corresponds to the second example. | [{"input": "5 4\n1 2\n3 4\n5 4\n3 5", "output": "1"}, {"input": "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6", "output": "2"}] | 1,500 | ["dfs and similar", "dsu", "graphs"] | 35 | [{"input": "5 4\r\n1 2\r\n3 4\r\n5 4\r\n3 5\r\n", "output": "1\r\n"}, {"input": "17 15\r\n1 8\r\n1 12\r\n5 11\r\n11 9\r\n9 15\r\n15 5\r\n4 13\r\n3 13\r\n4 3\r\n10 16\r\n7 10\r\n16 7\r\n14 3\r\n14 4\r\n17 6\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2\r\n2 3\r\n1 3\r\n1 4\r\n", "output": "0\r\n"}, {"input": "5 5\r\n1... | false | stdio | null | true |
21/C | 21 | C | Python 3 | TESTS | 15 | 140 | 10,649,600 | 124425973 | n = int(input())
s = input().split()
a = []
total = 0
for i in range(0, n) :
a.append(int(s[i]))
total += a[i]
if (total % 3 != 0) : print(0)
x = y = ans = 0
total //= 3
for i in range(0, n - 1) :
x += a[i]
if (x == total * 2) : ans += y
if (x == total) : y += 1
print(ans) | 35 | 77 | 12,288,000 | 215989463 | def solve(n, num):
a = [int(k) for k in num.split()]
a.insert(0, 0)
s = [0] * (n + 1)
for i in range(1, n + 1):
s[i] = s[i - 1] + a[i]
total = s[n]
ans, cnt = 0, 0
q = total * 2 / 3
if total % 3 != 0:
return 0
for i in range(1, n):
if s[i] == q and s[n]... | Codeforces Alpha Round 21 (Codeforces format) | CF | 2,010 | 1 | 64 | Stripe 2 | Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,... | The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | null | null | [{"input": "4\n1 2 3 3", "output": "1"}, {"input": "5\n1 2 3 4 5", "output": "0"}] | 2,000 | ["binary search", "dp", "sortings"] | 35 | [{"input": "1\r\n-3\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "4\r\n-2 3 3 2\r\n", "output": "0\r\n"}, {"input": "5\r\n-6 3 -1 2 -7\r\n", "output": "0\r\n"}, {"input": "6\r\n2 3 -3 0 -3 1\r\n", "output": "0\r\n"}, {"input": "7\r\n-1... | false | stdio | null | true |
620/C | 620 | C | Python 3 | TESTS | 13 | 46 | 102,400 | 227208945 | def check(pearls):
dic = {
}
c = 0
indexes = [0]
for ind, char in enumerate(pearls):
if char not in dic:
dic[char] = ind+1
elif char in dic:
c += 1
x = check_last(pearls[ind::])
if x:
indexes.append(indexes[-1]+1)
... | 51 | 249 | 47,513,600 | 195910030 | # 7
# 1 2 1 3 1 2 1
n=int(input())
l=[*map(int,input().split())]
ans=[]
ss = set()
p=0
for i,v in enumerate(l):
if v in ss:
ss.clear()
ans.append((p+1,i+1))
p = i+1
else:
ss.add(v)
if ans:
print(len(ans))
for t in ans[:-1]:
print(*t)
print(ans[-1][0], n)
else:... | Educational Codeforces Round 6 | ICPC | 2,016 | 2 | 256 | Pearls in a Row | There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of ... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.
The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. | On the first line print integer k — the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, s... | null | null | [{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}] | 1,500 | ["greedy"] | 51 | [{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
return lines
def main():
input_path = sys.argv[1]
ref_path = sys.argv[2]
sub_path = sys.argv[3]
input_lines = read_file(input_path)
ref_lines = read_file(ref... | true |
216/E | 216 | E | Python 3 | TESTS | 6 | 404 | 1,433,600 | 11926306 | k, b, n = map(int, input().split())
digits = list(map(int, input().split()))
def conv(t):
if t == 0:
return k - 1
return t
if b == 0:
j = -1
answer = 0
for i in range(n):
if digits[i] != 0 or i < j:
continue
j = i
while j < n and digits[j] == 0:
... | 41 | 404 | 33,587,200 | 124785044 | Line1 = list(map(int,input().split())) #Lee de consola la primera linea que contiene tres enteros(separados por espacios) que
#en orden representan la base en la que se representan los numeros, el "digito de la suerte" y
#la cantidad de dig... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Martian Luck | You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of... | The first line contains three integers k, b and n (2 ≤ k ≤ 109, 0 ≤ b < k, 1 ≤ n ≤ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≤ ai < k) — the i-th digit of string s. The numbers in the lines are space-separated. | Print a single integer — the number of substrings that are lucky numbers.
Please, do not use 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 | In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1". | [{"input": "10 5 6\n3 2 0 5 6 1", "output": "5"}, {"input": "7 6 4\n3 5 0 4", "output": "1"}, {"input": "257 0 3\n0 0 256", "output": "3"}] | 2,000 | ["math", "number theory"] | 41 | [{"input": "10 5 6\r\n3 2 0 5 6 1\r\n", "output": "5"}, {"input": "7 6 4\r\n3 5 0 4\r\n", "output": "1"}, {"input": "257 0 3\r\n0 0 256\r\n", "output": "3"}, {"input": "2 1 1\r\n0\r\n", "output": "0"}, {"input": "2 0 20\r\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1\r\n", "output": "22"}, {"input": "100 29 33\r\n28 89 23 1... | false | stdio | null | true |
22/B | 22 | B | PyPy 3 | TESTS | 6 | 124 | 1,331,200 | 152861284 | n,m=map(int,input().split())
MAP=[input().strip() for i in range(n)]
S=[[0]*m for i in range(n)]
for i in range(n):
for j in range(m):
if MAP[i][j]=="1":
S[i][j]=1
for i in range(1,n):
for j in range(m):
S[i][j]+=S[i-1][j]
for i in range(n):
for j in range(1,m):
S[i]... | 23 | 184 | 5,017,600 | 180511159 | def goDown(start, i, j, l):
rowsFound = 0
while i<n and sum(l[i][start:j+1])==0:
# print(l[i][start:j+1], end = " ")
rowsFound+=1
i+=1
# print("Rows Found:", rowsFound, end = " ")
return rowsFound
def start(i, j, n, m, l):
j1 = j
# print((i, j))
perimeter = 0
while j < m:
# print(j1, j, perimeter, "widt... | Codeforces Beta Round 22 (Div. 2 Only) | ICPC | 2,010 | 2 | 256 | Bargaining Table | Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it... | The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free. | Output one number — the maximum possible perimeter of a bargaining table for Bob's office room. | null | null | [{"input": "3 3\n000\n010\n000", "output": "8"}, {"input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16"}] | 1,500 | ["brute force", "dp"] | 23 | [{"input": "3 3\r\n000\r\n010\r\n000\r\n", "output": "8\r\n"}, {"input": "5 4\r\n1100\r\n0000\r\n0000\r\n0000\r\n0000\r\n", "output": "16\r\n"}, {"input": "3 3\r\n000\r\n110\r\n000\r\n", "output": "8\r\n"}, {"input": "4 2\r\n00\r\n10\r\n11\r\n00\r\n", "output": "6\r\n"}, {"input": "3 5\r\n00001\r\n00000\r\n10100\r\n", ... | false | stdio | null | true |
205/B | 205 | B | Python 3 | TESTS | 6 | 46 | 0 | 143496719 | n = int(input())
s = input().split()
s = [int(i) for i in s]
c = 0
i = 0
while(i< n-1):
if(s[i] > s[i+1]):
j = i+1
while(j<len(s) and s[j] < s[i]):
j += 1
c += s[i]-min(s[i:j])
i = j
else:
i += 1
print(c) | 45 | 77 | 13,516,800 | 215373812 | n = int(input())
a = list(map(int, input().split()))
moves = 0
for i in range(n - 1, 0, -1):
if a[i] < a[i - 1]:
moves += a[i - 1] - a[i]
print(moves) | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
21/C | 21 | C | PyPy 3-64 | TESTS | 12 | 62 | 2,662,400 | 193181445 | import sys; R = sys.stdin.readline
def S(): return map(int,R().split())
n = int(R())
a = [0]+[*S()]
for i in range(1,n+1): a[i] += a[i-1]
if not a[n]:
k = a.count(0)
print((k-2)*(k-3)//2); exit()
if a[n]<0:
for i in range(1,n+1): a[i] *= -1
if not a[n]%3:
r = 0
q = a[n]//3
dp = [1]+[0]*2
... | 35 | 77 | 14,950,400 | 227345166 | n = int(input())
a = list(map(int, input().split()))
s = sum(a)
counter = 0
dots = []
dots2 = []
prsum = []
a1 = dict()
k6 = 0
k3 = 0
c=0
if s % 3 == 0:
target = s // 3
for i in range(n):
if i == 0:
prsum.append(a[0])
else:
prsum.append(prsum[-1] + a[i])
#print(prsum... | Codeforces Alpha Round 21 (Codeforces format) | CF | 2,010 | 1 | 64 | Stripe 2 | Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,... | The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | null | null | [{"input": "4\n1 2 3 3", "output": "1"}, {"input": "5\n1 2 3 4 5", "output": "0"}] | 2,000 | ["binary search", "dp", "sortings"] | 35 | [{"input": "1\r\n-3\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "4\r\n-2 3 3 2\r\n", "output": "0\r\n"}, {"input": "5\r\n-6 3 -1 2 -7\r\n", "output": "0\r\n"}, {"input": "6\r\n2 3 -3 0 -3 1\r\n", "output": "0\r\n"}, {"input": "7\r\n-1... | false | stdio | null | true |
659/D | 659 | D | Python 3 | TESTS | 6 | 46 | 0 | 27274368 | def Izquierda(pos,D,R):
c = 0
for k in range (1,pos):
ax= D[k-1]
ay= R[k-1]
bx= D[k]
by= R[k]
cx= D[k+1]
cy= R[k+1]
if ((ax==bx and ay<by) and (by==cy and cx<bx)) or ((ay==by and ax<bx) and (bx==cx and by<cy)) or ((ax==bx and ay>by) and (by ==cy an... | 22 | 31 | 0 | 150142923 | n = int(input())
xi, yi = [], []
for _ in range(n + 1):
x, y = map(int,input().split())
xi.append(x)
yi.append(y)
ans = 0
for i in range(2, n):
if ((xi[i-1]-xi[i-2])*(yi[i]-yi[i-2])-(xi[i]-xi[i-2])*(yi[i-1]-yi[i-2]))>0:
ans += 1
print(ans) | Codeforces Round 346 (Div. 2) | CF | 2,016 | 1 | 256 | Bicycle Race | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the Ox axis from west to east, and th... | The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.
The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin... | Print a single integer — the number of dangerous turns on the track. | null | The first sample corresponds to the picture:
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1. | [{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}] | 1,500 | ["geometry", "implementation", "math"] | 22 | [{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1... | false | stdio | null | true |
205/B | 205 | B | Python 3 | TESTS | 6 | 46 | 4,505,600 | 134964340 | import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
... | 45 | 93 | 8,806,400 | 149895214 | def solve() :
c=0
for i in range(n-1):
if arr[i]>arr[i+1] :
c+=arr[i]-arr[i+1]
return c
from sys import stdin
input = stdin.readline
n=int(input())
arr=[int(x) for x in input().split()]
print(solve())
'''
t=int(input())
for i in range(t) :
print(solve(... | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
205/B | 205 | B | PyPy 3 | TESTS | 6 | 77 | 0 | 138583267 | n=int(input())
l=list(map(int,input().split()))
curr=l[0]
m=0
c=0
for i in range(1,n):
# print(curr)
if(l[i]<curr):
m=max(m,curr-l[i])
# print(m)
else:
curr=l[i]
c+=m
m=0
c+=m
print(c) | 45 | 93 | 13,926,400 | 212136866 | x = int(input())
l = list(map(int,input().split()))
answer = 0
for i in range(x-1):
answer += max(l[i] - l[i+1] , 0)
print(answer) | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
205/B | 205 | B | Python 3 | TESTS | 6 | 31 | 0 | 212136331 | x = int(input())
l = list(map(int,input().split()))
l.append(int(1e10))
answer = 0
anslist = []
if l == sorted(l):
print(0)
else:
for i in range(1,x+1):
initial = max(l[0:i])
if l[i] < initial:
anslist.append(l[i])
else:
if len(anslist) > 0:
answer... | 45 | 108 | 8,704,000 | 183824838 | def little_ele(length,array):
a=0
for z in range(1,length):
if array[z-1]>array[z]:a+=array[z-1]-array[z]
return a
a=int(input())
nums=[int(i) for i in input().split()]
print(little_ele(a,nums)) | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
205/B | 205 | B | Python 3 | TESTS | 6 | 31 | 0 | 141366358 | n=int(input())
a=list(map(int,list(input().split())))
x,y,total,steps,ans=0,0,0,0,0
for i in range(n-1):
if a[i]>a[i+1]:
x=a[i]
y=i
break
flag=True
for i in range(y,n):
if a[i]<x:
steps=x-a[i]
if steps>total:
total=steps
flag=True
else:
ans... | 45 | 109 | 8,806,400 | 147382913 | #بسم الله الرحمن الرحيم
n = int(input())
sequence =[int(i) for i in input().split()]
maxx = 0
s=0
for i in range(n-1):
s=sequence[i]-sequence[i+1]
if sequence[i+1]<sequence[i]:
maxx+=s
print(maxx) | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
205/B | 205 | B | Python 3 | TESTS | 6 | 62 | 0 | 104837557 | def solve(arr):
prev = arr[0]
m = prev
res = 0
for curr in arr[1:]:
if curr < prev:
if curr < m:
m = curr
else:
res += prev - m
prev = curr
m = prev
return res + prev - m
n = int(input())
arr = [int(i) for i in... | 45 | 124 | 8,089,600 | 141367431 | n=int(input())
a=list(map(int,list(input().split())))
total=0
for i in range(n-1):
x=max(0,a[i]-a[i+1])
total=total+x
print(total) | Codeforces Round 129 (Div. 2) | CF | 2,012 | 0.5 | 256 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
Please, do not use 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 | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | [{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}] | 1,400 | ["brute force", "greedy"] | 45 | [{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4... | false | stdio | null | true |
868/D | 868 | D | Python 3 | TESTS | 5 | 62 | 0 | 32082628 | from math import log
n = int(input())
p = [bin(p)[2:] for p in range(0,256)]
def q(s):
for k in range(0,10):
for pi in range(0,2**k):
cs = p[pi]
cs = (k-len(cs))*"0"+cs
if not cs in s:
return k - 1
s = [(v, q(v)) for v in [input() for i in range(n)]]
for q... | 49 | 109 | 9,728,000 | 31023840 | from sys import stdin, stdout
K = 20
def findAllStrings(s):
n = len(s)
sDict = {}
for i in range(1,K+1):
sDict[i]=set()
for x in range(n-i+1):
sDict[i].add(s[x:x+i])
return sDict
n = int(stdin.readline().rstrip())
stringDicts = []
stringEnd = []
stringBegin = []
for i in ... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Huge Strings | You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation ... | The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≤ |si| ≤ 100), one per line. The total length of strings is not greater than 100.
The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of... | Print m lines, each should contain one integer — the answer to the question after the corresponding operation. | null | On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.
On the secon... | [{"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "output": "1\n2\n0"}] | 2,200 | ["bitmasks", "brute force", "dp", "implementation", "strings"] | 49 | [{"input": "5\r\n01\r\n10\r\n101\r\n11111\r\n0\r\n3\r\n1 2\r\n6 5\r\n4 4\r\n", "output": "1\r\n2\r\n0\r\n"}, {"input": "5\r\n01\r\n1\r\n0011\r\n0\r\n01\r\n6\r\n5 5\r\n3 2\r\n4 2\r\n6 7\r\n5 1\r\n9 7\r\n", "output": "1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n"}, {"input": "5\r\n111101000111100011100110000100\r\n000111001\r\n0110100... | false | stdio | null | true |
358/C | 358 | C | Python 3 | TESTS | 5 | 31 | 0 | 208024221 | n = int(input())
sections = [[]]
for _ in range(n):
inna_command = int(input())
sections[-1].append(inna_command)
if inna_command == 0:
sections.append([])
if len(sections[-1]) == 0:
sections.pop()
for section in sections:
if section[-1] != 0:
for number in section:
... | 26 | 187 | 4,300,800 | 231249531 | i, n = 0, int(input())
s = ['pushQueue'] * n
a, b, c = ' popQueue', ' popStack', ' popBack'
p = ['0', '1' + a, '2' + a + b, '3' + a + b + c]
t = []
for j in range(n):
x = int(input())
if x:
t.append((x, j))
continue
t = sorted(k for x, k in sorted(t)[-3:])
k = len(t)
if k > 0: s[i: t... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Containers | Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to g... | The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer:
1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers.
2. Integer 0 shows that Inna asks Dima to make at most... | Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack;
- pushQueue — add to the end of the queue;
- pushFront — add to the beginning of the deck;
- push... | null | null | [{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}] | 2,000 | ["constructive algorithms", "greedy", "implementation"] | 26 | [{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
n = int(input_lines[0])
input_commands = input_lines[1:n+1]
with open(submission_path) as f:
submission_lines = [line.strip()... | true |
71/A | 71 | A | PyPy 3-64 | TESTS | 11 | 61 | 0 | 225205288 | # -*- coding: utf-8 -*-
"""waytoolongwords
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1BseqGBxW--4aunfaCeeXWMIl4SrMIEh3
"""
number = int(input(""))
words = []
while 100 > number > 0:
wordinput = str(input(""))
words.append(wordinput)
number... | 20 | 31 | 0 | 181425366 | x=int(input(""))
y=[]
for i in range (x):
s=str(input(""))
if len(s)<=10:
y.append(s)
else:
first_letter=s[0]
last_letter=s[-1]
z=(first_letter+str(len(s)-2)+last_letter)
y.append(z)
for h in range (x):
print(y[h]) | Codeforces Beta Round 65 (Div. 2) | CF | 2,011 | 1 | 256 | Way Too Long Words | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data. | null | null | [{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}] | 800 | ["strings"] | 20 | [{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"... | false | stdio | null | true |
71/A | 71 | A | PyPy 3-64 | TESTS | 11 | 62 | 0 | 206650350 | n = int(input())
wordlist = []
if (n > 0 and n < 100):
while (n > 0):
w = str(input())
wordlist.append(w)
n = n-1
for k in wordlist:
if (len(k) <= 10 ):
print(k)
else:
print(k[0],len(k)-2,k[-1],sep="") | 20 | 31 | 0 | 181554121 | n=int(input())
for i in range(n):
word=input()
word.strip()
if len(word)>10:
mid=len(word)-2
end=word[len(word)-1]
start=word[0]
print(start+str(mid)+end)
else:
print(word) | Codeforces Beta Round 65 (Div. 2) | CF | 2,011 | 1 | 256 | Way Too Long Words | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data. | null | null | [{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}] | 800 | ["strings"] | 20 | [{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"... | false | stdio | null | true |
620/C | 620 | C | PyPy 3 | TESTS | 34 | 670 | 28,876,800 | 70578834 | import sys
import math
input=sys.stdin.readline
n=int(input())
arr=list(map(int,input().split()))
ans=list()
left=-1
dc=dict()
for i in range(n):
if(arr[i] in dc.keys() and dc[arr[i]]>left):
ans.append([left+1,i])
dc.pop(arr[i],None)
left=i
else:
dc[arr[i]]=i
if(len(ans)==0):
print(-1)
else:
print(len(ans)... | 51 | 264 | 45,772,800 | 176962365 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
i = 0
s = set()
q = []
a = 0
while i < n:
if w[i] not in s:
s.add(w[i])
else:
s = set()
q.append((a+1, i+1))
a = i+1
i += 1
if len(q) == 0:
print(-1)
else:
q[-1] = (q[-1][0], n... | Educational Codeforces Round 6 | ICPC | 2,016 | 2 | 256 | Pearls in a Row | There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of ... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.
The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. | On the first line print integer k — the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, s... | null | null | [{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}] | 1,500 | ["greedy"] | 51 | [{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
return lines
def main():
input_path = sys.argv[1]
ref_path = sys.argv[2]
sub_path = sys.argv[3]
input_lines = read_file(input_path)
ref_lines = read_file(ref... | true |
620/C | 620 | C | Python 3 | TESTS | 34 | 888 | 40,960,000 | 74370671 | size = int(input())
myDic,capture,limit = {},[],-1
for x,y in enumerate(map(int,input().split())):
if y in myDic:
check = x - myDic[y][-1]
if myDic[y][-1] > limit:
capture.append((myDic[y][-1]+1,x+1))
limit = x; del myDic[y]
else: myDic[y][-1] = x
else:
my... | 51 | 280 | 44,646,400 | 175019623 | n = int(input())
a = list(map(int, input().split()))
d = dict()
res = []
for i in range(len(a)):
d[a[i]] = d.get(a[i], 0) + 1
if d[a[i]] % 2 == 0:
res.append(i)
d.clear()
if len(res):
res[-1] = n-1
print(len(res))
x = 0
for i in res:
print(x+1, i+1)
x = i+1
else... | Educational Codeforces Round 6 | ICPC | 2,016 | 2 | 256 | Pearls in a Row | There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of ... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.
The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. | On the first line print integer k — the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, s... | null | null | [{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}] | 1,500 | ["greedy"] | 51 | [{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
return lines
def main():
input_path = sys.argv[1]
ref_path = sys.argv[2]
sub_path = sys.argv[3]
input_lines = read_file(input_path)
ref_lines = read_file(ref... | true |
358/C | 358 | C | PyPy 3-64 | TESTS | 5 | 61 | 28,979,200 | 161892405 | from collections import deque
def main():
stack, queue, deck = [], deque(), deque()
number_of_commands = int(input())
for _ in range(number_of_commands):
appended_value = int(input())
if appended_value == 0:
number_of_extractions = 0
extractions = ""
... | 26 | 311 | 28,569,600 | 135330920 | # Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().s... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Containers | Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to g... | The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer:
1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers.
2. Integer 0 shows that Inna asks Dima to make at most... | Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack;
- pushQueue — add to the end of the queue;
- pushFront — add to the beginning of the deck;
- push... | null | null | [{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}] | 2,000 | ["constructive algorithms", "greedy", "implementation"] | 26 | [{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
n = int(input_lines[0])
input_commands = input_lines[1:n+1]
with open(submission_path) as f:
submission_lines = [line.strip()... | true |
494/B | 494 | B | Python 3 | TESTS | 6 | 296 | 6,860,800 | 9120107 | s = input()
t = input()
n = len(s)
m = len(t)
t = t + '$' + s
p = [0] * (n + m + 1)
k = 0
for i in range(1, n + m + 1):
while k > 0 and t[k] != t[i]:
k = p[k - 1]
if t[k] == t[i]:
k += 1
p[i] = k
ans = [0] * n
sums = [0] * (n + 1)
curs = 0
was = False
j = 0
MOD = 10 ** 9 + 7
for i in ran... | 51 | 264 | 4,198,400 | 231039994 | s, t = input(), input()
n, m = len(t), len(s) + 1
d = 1000000007
g = [1] * m
f = k = 0
for i in range(1, m) :
if s[i - n:i] == t : k = i
if k : f = (f + g[k - n]) % d
g[i] += (g[i - 1] + f) % d
print(f) | Codeforces Round 282 (Div. 1) | CF | 2,014 | 2 | 256 | Obsessive String | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters. | Print the answer in a single line. | null | null | [{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}] | 2,000 | ["dp", "strings"] | 51 | [{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawaw... | false | stdio | null | true |
494/B | 494 | B | Python 3 | TESTS | 6 | 499 | 9,523,200 | 53181649 | s, t = input(), input()
p = t + '#' + s
z = [0] * len(p)
l = r = 0
for i in range(1, len(p)):
if i <= r:
z[i] = min(r - i + 1, z[i - l])
while i + z[i] < len(p) and p[z[i]] == p[i + z[i]]:
z[i] += 1
if i + z[i] - 1 > r:
l, r = i, i + z[i] - 1
f = [0] * (len(p) + 1)
fsum = [0] * (le... | 51 | 264 | 4,198,400 | 231039994 | s, t = input(), input()
n, m = len(t), len(s) + 1
d = 1000000007
g = [1] * m
f = k = 0
for i in range(1, m) :
if s[i - n:i] == t : k = i
if k : f = (f + g[k - n]) % d
g[i] += (g[i - 1] + f) % d
print(f) | Codeforces Round 282 (Div. 1) | CF | 2,014 | 2 | 256 | Obsessive String | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters. | Print the answer in a single line. | null | null | [{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}] | 2,000 | ["dp", "strings"] | 51 | [{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawaw... | false | stdio | null | true |
71/A | 71 | A | PyPy 3-64 | TESTS | 11 | 61 | 0 | 227592389 | no_line = int (input ())
if no_line > 0 and no_line < 100:
for i in range (no_line):
word = input ()
length = len (word)
if length > 10 and length < 101:
abrivation = word [0]+ str (length - 2) + word [-1]
print (abrivation)
else:
print (word) | 20 | 31 | 0 | 182110578 | for _ in range(int(input())):
word = input()
l = len(word)
if l > 10:
print(word[0], l-2, word[-1], sep='')
else:
print(word) | Codeforces Beta Round 65 (Div. 2) | CF | 2,011 | 1 | 256 | Way Too Long Words | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data. | null | null | [{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}] | 800 | ["strings"] | 20 | [{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"... | false | stdio | null | true |
71/A | 71 | A | PyPy 3-64 | TESTS | 11 | 61 | 0 | 225207058 | # -*- coding: utf-8 -*-
"""WayTooLongWords.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1jR-K7NZyALsIcfCmgQTjg97eGOjfLWg-
"""
reps = int(input())
if reps<100:
outputList = []
while reps>0:
reps-= 1
word = str(input())
firstL = ... | 20 | 31 | 0 | 182335247 | n = int(input())
def long(x):
if len(x) <= 10:
return x
else:
length = str(len(x) - 2)
p = x[0] + length + x[len(x) - 1]
return p
for i in range(n):
word = input()
print(long(word)) | Codeforces Beta Round 65 (Div. 2) | CF | 2,011 | 1 | 256 | Way Too Long Words | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data. | null | null | [{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}] | 800 | ["strings"] | 20 | [{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"... | false | stdio | null | true |
2/B | 2 | B | PyPy 3 | TESTS | 30 | 1,497 | 23,347,200 | 71433062 | import sys,math
input=sys.stdin.readline
print=sys.stdout.write
n=int(input())
def primefact(n,b):
lo=0
hi=int(math.log(n,b))
if(hi==0):
return 0
while(lo<hi):
mid=(lo+hi)//2
if(n%pow(b,mid)==0):
lo=mid+1
else:
hi=mid-1
if(n%pow(b,lo)==0): ... | 37 | 405 | 52,121,600 | 187664948 | n=int(input());
ma=[[] for x in range(n)];
zflag=0;
zindex=[0,0];
#reading the input
for i in range(n):
j=0;
inp=input().split();
for x in inp:
if x=='0':
ma[i].append(10);
zflag=1;
zindex=[i,j];
else:
ma[i].append(int(x));
j+=1;
... | Codeforces Beta Round 2 | ICPC | 2,010 | 2 | 64 | The least round way | There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix;
- each following cell is to the right or down from the current cell;
- the way ends in the bottom right cell.
Moreover, if we multiply together all the numbe... | The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | null | null | [{"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR"}] | 2,000 | ["dp", "math"] | 37 | [{"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "0\r\nDDRR\r\n"}, {"input": "2\r\n7 6\r\n3 8\r\n", "output": "0\r\nDR\r\n"}, {"input": "3\r\n4 10 5\r\n10 9 4\r\n6 5 3\r\n", "output": "1\r\nDRRD\r\n"}, {"input": "4\r\n1 1 9 9\r\n3 4 7 3\r\n7 9 1 7\r\n1 7 1 5\r\n", "output": "0\r\nDDDRRR\r\n"}, {"input": "5\r\n8... | false | stdio | import sys
def count_factors(x, factor):
count = 0
while x > 0 and x % factor == 0:
count += 1
x //= factor
return count
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input matrix
with open(input_path) as f:
... | true |
53/A | 53 | A | Python 3 | TESTS | 11 | 92 | 0 | 169668652 | s = input()
x = len(s)
z = int(input())
l = []
for i in range(0,z):
t = input()
if t.startswith(s):
if x== len(t):
break
else:
l.append(t)
l.sort()
if len(l) ==0:
print(s)
else:
print(l[0]) | 25 | 92 | 0 | 141852553 | pattern, n = input(), int(input())
_len, arr = len(pattern), []
for i in range(n):
helper = input()
if pattern == helper[:_len]:
arr.append(helper)
arr.sort()
print(arr[0] if len(arr) > 0 else pattern) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 10 | 62 | 0 | 178808266 | a=input()
l=[]
for i in range(int(input())):
str=input()
if str[0:len(a)]==a:
l.append(str)
if len(l)==0:
print(a)
else:
k=l[0]
for i in l:
if len(i)<len(k):
k=i
print(k) | 25 | 92 | 0 | 142539513 | a=input()
b=int(input())
c=[]
for i in range(b):
d=input()
if d[:len(a)]==a:
c.append(d)
if len(c)>0:
print(min(c))
else:
print(a) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
53/A | 53 | A | PyPy 3 | TESTS | 15 | 280 | 0 | 97199769 | s = input()
res = float('inf')
flag = 0
for j in range(int(input())):
k = input()
if((k.find(s)!=-1) and (k.find(s)==0)):
l = len(k)
if(l<=res):
res = l
s1 = k
flag = 1
if((k==s) or (k.find(s)==-1 and flag == 0) ):
s1=s
print(s1) | 25 | 92 | 0 | 146307674 | s = input()
n = int(input())
length_orig = len(s)
ans = "z"*100
for _ in range(n):
astring = input()
if astring[:length_orig] == s and astring < ans:
ans = astring
print(s if ans == "z"*100 else ans) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 10 | 62 | 0 | 209653034 | s=list(input())
n=int(input())
out_put=""
size_out_put=1000
for i in range(n):
tem=list(input())
if (s==tem[:len(s)] and len(tem)<size_out_put):
size_out_put=len(tem)
out_put=tem
if(tem==s):
break
if(out_put==""):
print("".join(s))
else:
print("".join(out_put)... | 25 | 92 | 0 | 147235582 | s=input()
k=[]
l=0
for i in range(int(input())):
a=input()
if a.startswith(s):
k.append(a)
l=1
if l==0:
print(s)
exit()
min=k[0]
for i in range(1,len(k)):
if k[i]<min:
min=k[i]
print(min) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
87/D | 87 | D | PyPy 3 | TESTS | 3 | 77 | 307,200 | 149847642 | from collections import defaultdict
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)
... | 80 | 982 | 48,025,600 | 191793487 | from collections import defaultdict
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)
... | Codeforces Beta Round 73 (Div. 1 Only) | CF | 2,011 | 1 | 256 | Beautiful Road | A long time ago in some country in Asia were civil wars.
Each of n cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.
Road making was difficult, so the country had few roads, exactly n - 1. Also you could reach any city from any other city going ... | The first line contains an integer n (2 ≤ n ≤ 105), which represents the number of cities. Next n - 1 lines contain three integers each: the numbers of cities ai, bi (1 ≤ ai, bi ≤ n), connected by the i-th road and the number of days di the army spends to go on it (1 ≤ di ≤ 109). The lengths of several roads may coinci... | Print on the first line two integers — the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to n - 1 in the order in which they are ... | null | null | [{"input": "2\n2 1 5", "output": "2 1\n1"}, {"input": "6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4", "output": "16 1\n2"}] | 2,300 | ["dfs and similar", "dp", "dsu", "graphs", "implementation", "sortings", "trees"] | 80 | [{"input": "2\r\n2 1 5\r\n", "output": "2 1\r\n1 \r\n"}, {"input": "6\r\n1 2 1\r\n1 3 5\r\n3 4 2\r\n3 5 3\r\n3 6 4\r\n", "output": "16 1\r\n2 \r\n"}, {"input": "10\r\n3 9 131\r\n1 6 77017\r\n4 10 93113\r\n4 8 30971\r\n2 7 93113\r\n10 6 30971\r\n3 7 35091\r\n5 9 14051\r\n5 1 35091\r\n", "output": "32 1\r\n3 \r\n"}, {"in... | false | stdio | null | true |
875/D | 875 | D | Python 3 | TESTS | 6 | 62 | 5,529,600 | 31432874 | n = int(input())
a = list(map(int, input().split()))
c = 0
m = 0
for k in range(n):
m = max(m, a[k])
for i in range(n):
for j in range(n):
if (a[i] <= a[j]):
if (a[i] | a[j] < m):
c += 1
print(c) | 78 | 514 | 127,283,200 | 226308676 | from collections import defaultdict
def read_ints():
return map(int, input().split())
def read_int():
return int(input())
def yes_no(yes):
print('Yes' if yes else 'No')
return yes
def solve_test():
n = read_int()
a = list(read_ints())
def get_ans():
bit_size = 32
lef... | Codeforces Round 441 (Div. 1, by Moscow Team Olympiad) | CF | 2,017 | 1 | 512 | High Cry | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | The first line contains integer n (1 ≤ n ≤ 200 000), the number of mountains in the ridge.
Second line contains n integers ai (0 ≤ ai ≤ 109), the heights of mountains in order they are located in the ridge. | Print the only integer, the number of ways to choose two different mountains. | null | In the first test case all the ways are pairs of mountains with the numbers (numbering from one):
(1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of... | [{"input": "5\n3 2 1 6 5", "output": "8"}, {"input": "4\n3 3 3 3", "output": "0"}] | 2,200 | ["binary search", "bitmasks", "combinatorics", "data structures", "divide and conquer"] | 78 | [{"input": "5\r\n3 2 1 6 5\r\n", "output": "8\r\n"}, {"input": "4\r\n3 3 3 3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "1\r\n6\r\n", "output": "0\r\n"}, {"input": "228\r\n1 3 1 7 1 3 1 ... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 15 | 218 | 307,200 | 69823598 | a='z'*101
z=input()
for i in range(int(input())):
x=input()
if z==x[0:len(z)]:
if len(x)<=len(a) and sum(map(ord,x))<sum(map(ord,a)):
a=x
print([z,a][z==a[0:len(z)]]) | 25 | 92 | 0 | 148263339 | s=input()
n=int(input())
lst=[]
for i in range(n):
s1=input()
if len(s1)<len(s):
continue
if s1[:len(s)]==s:
lst.append(s1)
lst.sort()
if len(lst)==0:
print(s)
else:
print(lst[0]) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 10 | 92 | 0 | 216985063 | a=input()
c="a"*100
n=""
for i in range(int(input())):
b=input()
if a == b[:len(a)] :
if len(b) <len(c):
n=b
c=b
if len(n) > 0:
print(n)
else:
print(a) | 25 | 92 | 0 | 153434389 | def startWith(s1, s):
if len(s1) < len(s):
return False
if s1[:len(s)] == s:
return True
return False
s = input()
n = int(input())
myList = []
for i in range(n):
s1 = input()
if startWith(s1, s):
myList.append(s1)
myList.sort()
if len(myList) == 0:
print(s)
else:
pr... | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
39/F | 39 | F | PyPy 3 | TESTS | 10 | 280 | 0 | 68866503 | rdl = lambda: map(int, input().split())
def conv(x): x = str(x); x = x.replace('{','');x = x.replace('}',''); x = x.replace(',',''); return [int(s) for s in x.split()]
a,b,c = rdl();ll = list(rdl());hh = conv(set(ll));x = sorted(list(rdl()));lx =[];xr=[];sna = [];flag = False;Opss = False;xsa=[]
for i in range(len(x)... | 35 | 92 | 0 | 193071126 | n, m, k = map(int, input().split())
jumps = list(map(int, input().split()))
mos = list(map(int, input().split()))
hash = {}
for x, frog in enumerate(jumps, start=1):
count = 0
for kill in mos:
count += int(kill % frog == 0)
hash[count] = hash.get(count, [])
hash[count].append(x)
ans = min(h... | School Team Contest 1 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 64 | Pacifist frogs | Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.
One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n... | The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep... | In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data. | null | null | [{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}] | 1,300 | ["implementation"] | 35 | [{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r... | false | stdio | null | true |
313/C | 313 | C | PyPy 3-64 | TESTS | 2 | 46 | 0 | 219947693 | import sys
input=sys.stdin.readline
n=int(input())
l=[int(i) for i in input().split(" ")]
l.sort()
def f(n,l):
if n==1:
return l[0]
else:
l1=l[-1:-4-1*n:-4]
l2=l[-2:-4-1*n:-4]
l3=l[-3:-4-1*n:-4]
l4=l[-4:-4-1*n:-4]
k=n//4
return l[-1]+f(k,l1)+f(k,l2)+f(k,l... | 61 | 576 | 141,107,200 | 215367603 | n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
if n == 1:
print(A[0])
else:
res = 0
i = 1
while(i <= n):
res += sum(A[0: i])
i *= 4
print(res) | Codeforces Round 186 (Div. 2) | CF | 2,013 | 1 | 256 | Ilya and Matrix | Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individua... | The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix. | On a single line print the maximum value of the beauty of the described matrix.
Please, do not use 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 | Consider the second sample. You need to arrange the numbers in the matrix as follows:
Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14. | [{"input": "1\n13", "output": "13"}, {"input": "4\n1 2 3 4", "output": "14"}] | 1,400 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 61 | [{"input": "1\r\n13\r\n", "output": "13\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "14\r\n"}, {"input": "16\r\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\r\n", "output": "14440495117\r\n"}, {"input":... | false | stdio | null | true |
313/C | 313 | C | Python 3 | TESTS | 2 | 61 | 1,228,800 | 213012249 | from math import log2, sqrt
from typing import List
def calculate_beauty(nums: List[int], n: int) -> int:
if n == 0:
return nums[0]
# Divide the list into four roughly equal parts
quarter = len(nums) // 4
parts = [nums[i * quarter:(i + 1) * quarter] for i in range(4)]
# For each part, rec... | 61 | 576 | 141,107,200 | 215367603 | n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
if n == 1:
print(A[0])
else:
res = 0
i = 1
while(i <= n):
res += sum(A[0: i])
i *= 4
print(res) | Codeforces Round 186 (Div. 2) | CF | 2,013 | 1 | 256 | Ilya and Matrix | Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individua... | The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix. | On a single line print the maximum value of the beauty of the described matrix.
Please, do not use 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 | Consider the second sample. You need to arrange the numbers in the matrix as follows:
Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14. | [{"input": "1\n13", "output": "13"}, {"input": "4\n1 2 3 4", "output": "14"}] | 1,400 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 61 | [{"input": "1\r\n13\r\n", "output": "13\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "14\r\n"}, {"input": "16\r\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\r\n", "output": "14440495117\r\n"}, {"input":... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 15 | 216 | 0 | 52326209 | s = input()
n = int(input())
t = s
lt = 10**10
for a in range(n):
x = input()
if x.startswith(s):
lx = len(x)
if lx < lt:
lt = lx
t = x
elif lx == lt:
tx = x[len(s):]
tt = t[len(s):]
for i in range(len(tx)):
if o... | 25 | 92 | 0 | 153995316 | arr,keyWord,n = [],input(),int(input())
for i in range (n):
line = input()
if line.startswith(keyWord):
arr.append(line)
arr.sort()
print(arr[0] if len(arr) > 0 else keyWord) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
53/A | 53 | A | Python 3 | TESTS | 10 | 92 | 0 | 172996736 | s=input()
t=int(input())
z=10100000021490214901902490214091491041290109411204929041209421490129040921490124901490214901490
s2=s
for i in range(t):
k=input()
if k.startswith(s):
if len(k)<z:
z=len(k)
s2=k
print(s2)
'''
next
2
nextpermutation
nextelement
''' | 25 | 92 | 0 | 158134329 | import sys
input = sys.stdin.readline
s = input()[:-1]
a = len(s)
c = s + '~'
for _ in range(int(input())):
x = input()[:-1]
if x[:a] == s and x < c:
c = x
print(c if c != s+'~' else s) | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Autocomplete | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin lette... | If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in ... | null | null | [{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}] | 1,100 | ["implementation"] | 25 | [{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r... | false | stdio | null | true |
659/D | 659 | D | PyPy 3 | TESTS | 5 | 108 | 20,172,800 | 123129141 | n = int(input())
vertical = []
horizontal = []
l = []
ans = 0
for i in range(n+1):
l.append([int(j) for j in input().split()])
unique = {}
unique_id = 1
for i in range(1,n+1):
if l[i][0] == l[i-1][0]:
vertical.append([min(l[i][1],l[i-1][1]),max(l[i][1],l[i-1][1]),l[i][0]])
unique[unique_id] = [... | 22 | 46 | 0 | 145393059 | n = int(input())
trajeto = []
curvas = 0
for i in range(n):
x, y = input().split()
trajeto.append((int(x), int(y)))
for i in range(len(trajeto)-2):
if trajeto[i][1]<trajeto[i+1][1] and trajeto[i+1][0]>trajeto[i+2][0]:
curvas += 1
elif trajeto[i][0]<trajeto[i+1][0] and trajeto[i+1][1]<trajet... | Codeforces Round 346 (Div. 2) | CF | 2,016 | 1 | 256 | Bicycle Race | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the Ox axis from west to east, and th... | The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.
The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin... | Print a single integer — the number of dangerous turns on the track. | null | The first sample corresponds to the picture:
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1. | [{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}] | 1,500 | ["geometry", "implementation", "math"] | 22 | [{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1... | false | stdio | null | true |
239/B | 239 | B | Python 3 | TESTS | 3 | 186 | 307,200 | 54567099 | n,Q = map(int,input().strip().split())
s = input()
d = 1
for q in range(Q):
arr = [0]*(10)
l,r = map(int,input().strip().split())
su = ""
for i in range(l-1,r):
su+=s[i]
su = list(su)
i = 0
d = 1
#print(su)
while i<len(su) and i>=0:
if su[i].isdigit():
... | 33 | 92 | 0 | 154842265 | n, q = map(int, input().split())
S = list('x'+input()+'x')
for _ in range(q):
l, r = map(int, input().split())
s = S[l-1:r+2]
s[0] = s[-1] = 'x'
c = [0]*10
dp, p = 1, 1
while s[p]!='x':
if s[p]=='>':
dp = 1
if s[p+1] in "><":
s.pop(p)
else:
p += 1
elif s[p]=='<':
dp = -1
p -= 1
if s[... | Codeforces Round 148 (Div. 2) | CF | 2,012 | 2 | 256 | Easy Tape Programming | There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.
- Current character pointer (CP);
- Dire... | The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries.
The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces.
The next q lines ea... | For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. | null | null | [{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}] | 1,500 | ["brute force", "implementation"] | 33 | [{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\... | false | stdio | null | true |
878/E | 878 | E | Python 3 | TESTS | 8 | 61 | 0 | 32121679 | def find_max_ind(arr):
max_el, max_ind = arr[0], 0
for i in range(1, len(arr)):
el = arr[i]
if el >= max_el:
max_el = el
max_ind = i
return max_ind
def calc_max_prod(arr, l):
if l == 1:
return arr[0]
if l == 2:
a = arr[0] + arr[1] * 2
... | 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 |
384/B | 384 | B | Python 3 | TESTS | 0 | 15 | 0 | 196246988 | n,m,k = list(map(int,input().split()))
ans = []
vis = set()
for _ in range(n):
lst = list(map(int,input().split()))
for i in range(m):
for j in range(i+1,m):
if k==0 and lst[i] > lst[j] and (i,j) not in vis:
ans.append((i,j))
vis.add((i,j))
lst... | 31 | 46 | 0 | 181167279 | n,m,k = map(int, input().split())
print(m*(m-1)//2)
for i in range(m):
for j in range(i+1, m):
if k:
print (j+1, i+1)
else:
print (i+1, j+1) | 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 |
383/D | 383 | D | Python 3 | TESTS | 2 | 46 | 307,200 | 5764170 | __author__ = 'Pavel Mavrin'
n = int(input())
a = [int(x) for x in input().split()]
d = [1]
res = 0
for i in range(n):
dd = [0] * (len(d) + a[i])
dd[0] += 1
for j in range(len(d)):
kk = j + a[i]
dd[kk] += d[j]
kk = abs(j - a[i])
dd[kk] += d[j]
d = dd
res += d[0]
prin... | 48 | 249 | 4,915,200 | 178764601 | n = int(input())
a = list(map(int, input().split()))
maxn, mod, ans = 12000, 10 ** 9 + 7, 0
dp = [[0] * 2 for _ in range(2 * maxn + 10)]
curr, pre = 1, 0
for x in a:
for i in range(2000, 2 * maxn - 2000 + 1):
dp[i][curr] = (dp[i - x][pre] + dp[i + x][pre]) % mod
dp[maxn - x][curr] = (dp[maxn - x][curr] ... | Codeforces Round 225 (Div. 1) | CF | 2,014 | 1 | 256 | Antimatter | Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode fo... | The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000. | Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7). | null | The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter. | [{"input": "4\n1 1 1 1", "output": "12"}] | 2,300 | ["dp"] | 48 | [{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6 10 8\r\n", "output": "86\r\n"}, {"input": "50\r\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\r\n", "output": "115119382\r\n"}, {"input": "100\r\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 ... | false | stdio | null | true |
383/D | 383 | D | Python 3 | TESTS | 2 | 46 | 102,400 | 153285959 | from collections import defaultdict
import sys
readline=sys.stdin.readline
mod=10**9+7
N=int(readline())
A=list(map(int,readline().split()))
def main(l,r):
if l+1==r:
return 0
mid=(l+r)//2
ans=main(l,mid)+main(mid,r)
S=max(sum(A[l:mid]),sum(A[mid:r]))
AA=A[l:mid][::-1]
dp=[0]*(2*S+1)
... | 48 | 249 | 10,444,800 | 217982702 | n = int(input())
nums = list(map(int, input().split()))
mod = 10 ** 9 + 7
dp = [0] * 20001
ans = 0
for num in nums:
new_dp = [0] * 20001
for i in range(20001):
if dp[i]:
new_dp[i+num] += dp[i]
new_dp[i+num] %= mod
new_dp[i-num] += dp[i]
new_dp[i-num] %= ... | Codeforces Round 225 (Div. 1) | CF | 2,014 | 1 | 256 | Antimatter | Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode fo... | The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000. | Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7). | null | The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter. | [{"input": "4\n1 1 1 1", "output": "12"}] | 2,300 | ["dp"] | 48 | [{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6 10 8\r\n", "output": "86\r\n"}, {"input": "50\r\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\r\n", "output": "115119382\r\n"}, {"input": "100\r\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 ... | false | stdio | null | true |
384/B | 384 | B | Python 3 | TESTS | 3 | 62 | 0 | 6912443 | n, m, k = map(int, input().split())
arrays = []
for i in range(n):
arrays.append(list(map(int, input().split())))
print(m * (m - 1) // 2)
if k == 0:
for i in range(1, m):
for j in range(1, m - i + 1):
print(j, j + 1)
else:
for i in range(1, m):
for j in range(m - i + 1, 1, -1):
... | 31 | 46 | 0 | 187148211 | n, m, k = map(int, input().split())
if m == 1:
print(0)
else:
q = (m - 1) * m // 2
print(q)
if k == 0:
for i in range(1, m+1):
for j in range(i+1, m+1):
print(i, j)
else:
for i in range(1, m+1):
for j in range(i+1, m+1):
print(j... | 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 |
490/B | 490 | B | Python 3 | TESTS | 2 | 46 | 102,400 | 165853769 | from collections import *
n=int(input())
w=[0]*n
q=Counter([])
x=Counter([])
for i in range(n):
a,b=map(int,input().split())
q[a]=b
x[b]=a
k=q[0]
for i in range(1,n,2):
w[i]=k
k=q[k]
k=x[0]
for i in range(n-2,-1,-2):
w[i]=k
k=x[k]
print(*w) | 61 | 343 | 42,188,800 | 229878738 | from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
def solution():
... | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
19/B | 19 | B | PyPy 3-64 | TESTS | 13 | 62 | 2,048,000 | 229769422 | # First,for every i increase ti by 1..then you will see that statement require sum of t of the items
# bigger or equal to n..and their sum of c should be minimal..so it's just a 0-1 knapsack problem.
n = int(input())
nums = []
for _ in range(n):
time, cost = map(int, input().split())
nums.append([time+1, cos... | 34 | 140 | 5,734,400 | 164988162 | n=int(input())
ar=[float('inf')]*(n+1)
ar[0]=0
for i in range(n):
t,c=map(int,input().split())
for j in range(n-1,-1,-1):
w=min(j+t+1,n)
ar[w]=min(ar[w],ar[j]+c)
print(ar[n]) | Codeforces Beta Round 19 | ICPC | 2,010 | 1 | 256 | Checkout Assistant | Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. ... | The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i. | Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay. | null | null | [{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}] | 1,900 | ["dp"] | 34 | [{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 ... | false | stdio | null | true |
19/C | 19 | C | Python 3 | TESTS | 1 | 186 | 0 | 68205670 | n = int(input())
number = [int(x) for x in input().split()]
x = list(set(number))
print(len(x))
for i in x:
print(i,end=" ") | 70 | 1,216 | 14,131,200 | 174568804 | import sys
n=int(input())
a=list(map(int,input().split()))
M=10**9+1
g={}
for i in range(n):
g[a[i]]=g.get(a[i],[])+[i]
p=[1]
for i in range(n):
p+=[hash(M*p[-1])]
h=[0]*(n+1)
for i in range(n):
h[i+1]=hash(h[i]*M+a[i])
gh=lambda k,l:hash(h[k+l]-h[k]*p[l])%sys.hash_info.modulus
i,t=0,0
while i < n:
for ... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 256 | Deletion of Repeats | Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coin... | The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times. | In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way. | null | null | [{"input": "6\n1 2 3 1 2 3", "output": "3\n1 2 3"}, {"input": "7\n4 5 6 5 6 7 7", "output": "1\n7"}] | 2,200 | ["greedy", "hashing", "string suffix structures"] | 70 | [{"input": "6\r\n1 2 3 1 2 3\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "7\r\n4 5 6 5 6 7 7\r\n", "output": "1\r\n7 \r\n"}, {"input": "10\r\n5 7 2 1 8 8 5 10 2 5\r\n", "output": "5\r\n8 5 10 2 5 \r\n"}, {"input": "10\r\n0 1 1 1 0 3 0 1 4 0\r\n", "output": "7\r\n1 0 3 0 1 4 0 \r\n"}, {"input": "10\r\n0 1 0 2 0 0 1 1 ... | false | stdio | null | true |
19/B | 19 | B | Python 3 | TESTS | 13 | 77 | 0 | 155582766 | n = int(input())
gifts, prices = [], []
for i in range(n):
line = list(map(int, input().split()))
gifts.append(line[0] + 1)
prices.append(line[1])
dp = [10 ** 10] * (n + 1)
dp[0] = 0
for i in range(n):
for j in range(n, -1, -1):
dp[j] = min(dp[j], dp[max(0, j - gifts[i])] + prices[i])
print(dp... | 34 | 202 | 6,656,000 | 227722808 | n = int(input())
dp = [float('inf')] * (n+1)
dp[0] = 0
for i in range(n):
t, c = tuple(int(x) for x in input().split())
for j in range(n)[::-1]:
dp[min(n,j+t+1)] = min(dp[min(n,j+t+1)],dp[j]+c)
print(dp[n]) | Codeforces Beta Round 19 | ICPC | 2,010 | 1 | 256 | Checkout Assistant | Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. ... | The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i. | Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay. | null | null | [{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}] | 1,900 | ["dp"] | 34 | [{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 ... | false | stdio | null | true |
19/B | 19 | B | Python 3 | TESTS | 13 | 108 | 0 | 196441661 | n=int(input());
dp=[10**10]*(n+1);
dp[0]=0;
for _ in range(n):
ti,ci=map(int,input().split());
for j in range(n-1,-1,-1):
k=min(j+ti+1,n);
dp[k]=min(dp[k],dp[j]+ci);
print(dp[n]); | 34 | 296 | 9,318,400 | 154633479 | from math import inf
n = int(input())
F = [inf]*(n+1)
F[0] = 0
for i in range(n):
t, c = map(int, input().split())
for j in range(n-1, -1, -1):
w = min(j+t+1, n)
F[w] = min(F[w], F[j]+c)
print(F[n])
# F[i][j] = min(F[i][j], F[i][j-t-1]) | Codeforces Beta Round 19 | ICPC | 2,010 | 1 | 256 | Checkout Assistant | Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. ... | The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i. | Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay. | null | null | [{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}] | 1,900 | ["dp"] | 34 | [{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 ... | false | stdio | null | true |
992/D | 992 | D | PyPy 3 | TESTS | 0 | 77 | 0 | 135798591 | def process(A, k):
n = len(A)
S = [0]
P = [1]
answer = 0
p_index = 0
for i in range(n):
S.append(S[-1]+A[i])
P.append(P[-1]*A[i])
while P[-1] > P[p_index]*k*S[-1]:
p_index+=1
if p_index > 0:
for j in range(p_index, i+1):
P[j... | 134 | 1,325 | 26,624,000 | 80847835 | n,k = map(int,input().split())
A = list(map(int,input().split()))
A = [0]+A;
x = 0
prev = [0 for i in range(n+1)]
sm = [0 for i in range(n+1)]
for i in range(1,n+1):
prev[i] = x
if A[i]>1:
x = i
sm[i] = A[i]+sm[i-1]
lim = int(2*(10**18))
ans = 0
for i in range(1,n+1):
p = 1
j = i
while j:
if lim//A[j]>p:
s... | Codeforces Round 489 (Div. 2) | CF | 2,018 | 2 | 256 | Nastya and a Game | Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $$\frac{p}{s} = k$$, where p is the product of all integers on the given array, s is their sum, and k is a given... | The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array. | In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k. | null | In the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because $${ \frac { 1 } { 1 } } = 1$$.
There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because $$\frac{18}{9}=2$$. Subsegme... | [{"input": "1 1\n1", "output": "1"}, {"input": "4 2\n6 3 8 1", "output": "2"}] | 2,100 | ["brute force", "implementation", "math"] | 134 | [{"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n6 3 8 1\r\n", "output": "2\r\n"}, {"input": "94 58\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\r\... | false | stdio | null | true |
766/D | 766 | D | PyPy 3 | TESTS | 1 | 77 | 0 | 179671116 | # LUOGU_RID: 93124141
n, m, q = map(int, input().split())
words = input().split()
idx = {word: i for i, word in enumerate(words)}
fa = list(range(n * 2))
def find(x):
if fa[x] != x:
fa[x] = find(fa[x])
return fa[x]
def union(x, y):
rx, ry = find(x), find(y)
if rx <= ry:
fa[ry] = ... | 32 | 1,154 | 45,568,000 | 189635045 | 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 not rs ^ rt:
return
... | Codeforces Round 396 (Div. 2) | CF | 2,017 | 4 | 256 | Mahmoud and a Dictionary | Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.
He know that if two words have ... | The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations.
The second line contains n distinct words a1, a2, ..., ... | First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes).
After that print q lines, one per each question. If the two words have the same mean... | null | null | [{"input": "3 3 4\nhate love like\n1 love like\n2 love hate\n1 hate like\nlove like\nlove hate\nlike hate\nhate like", "output": "YES\nYES\nNO\n1\n2\n2\n2"}, {"input": "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\nd... | 2,000 | ["data structures", "dfs and similar", "dp", "dsu", "graphs"] | 32 | [{"input": "3 3 4\r\nhate love like\r\n1 love like\r\n2 love hate\r\n1 hate like\r\nlove like\r\nlove hate\r\nlike hate\r\nhate like\r\n", "output": "YES\r\nYES\r\nNO\r\n1\r\n2\r\n2\r\n2\r\n"}, {"input": "8 6 5\r\nhi welcome hello ihateyou goaway dog cat rat\r\n1 hi welcome\r\n1 ihateyou goaway\r\n2 hello ihateyou\r\n2... | false | stdio | null | true |
615/B | 615 | B | Python 3 | TESTS | 5 | 483 | 19,660,800 | 87278461 | from collections import defaultdict
graph = defaultdict(list)
n, m = list(map(int, input().split()))
for i in range(m):
v, u = list(map(int, input().split()))
graph[v].append(u)
graph[u].append(v)
dp = [0] * (n + 1)
dp[1] = 1
ans = len(graph[1])
for i in range(2, n + 1):
for v in graph[i]:
if v... | 60 | 280 | 20,480,000 | 194207905 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
d = [[] for i in range(n+1)]
for i in range(m):
a, b = map(int, input().split())
d[a].append(b)
d[b].append(a)
x = [1]*(n+1)
t = 0
for i in range(1, n+1):
t = max(t, x[i]*len(d[i]))
for j in d[i]:
if j > i:
... | 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 |
66/C | 66 | C | Python 3 | TESTS | 10 | 216 | 307,200 | 66518468 | import sys, operator
filePaths = sys.stdin.readlines()
foldercount = 0
fileoccurences = {'C:':[0,0,{}],'D:':[0,0,{}],'E:':[0,0,{}],'F:':[0,0,{}],'G:':[0,0,{}]}
for line in filePaths:
path = list(map(str,line.split('\\')))
fileoccurences[path[0]][0] += 1
newFolder = False
for i in range(1,len(path)-1):
... | 100 | 92 | 716,800 | 205045482 | import sys
def main():
path_set = set()
is_created = {}
storage = {}
freq_folders = {}
folder_recorded = {}
for path in sys.stdin:
path = path.strip()
if path in path_set:
continue
path_set.add(path)
if path not in is_created:
is_create... | Codeforces Beta Round 61 (Div. 2) | CF | 2,011 | 3 | 256 | Petya and File System | Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file... | Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol... | null | In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1.
In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ... | [{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi... | 1,800 | ["data structures", "implementation"] | 100 | [{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4... | false | stdio | null | true |
884/A | 884 | A | Python 3 | TESTS | 14 | 62 | 0 | 31875754 | line = input().split()
n = int(line[0])
t = int(line[1])
line = input().split()
for i in range(t):
t = t - (86400 - int(line[i]))
if t < 1:
break
print(i + 1) | 16 | 31 | 0 | 184609915 | g = list(map(int ,input().strip().split()))
n=int(g[0])
m=int(g[-1])
l = list(map(int ,input().strip().split()))
c = 0
day = 0
for i in range(n):
c += 86400 - l[i]
day += 1
if c >= m:
print(day)
break | Educational Codeforces Round 31 | ICPC | 2,017 | 2 | 256 | Book Reading | Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend... | The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book.
The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed n. | null | null | [{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}] | 800 | ["implementation"] | 16 | [{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | false | stdio | null | true |
884/A | 884 | A | Python 3 | TESTS | 4 | 30 | 0 | 135766151 | n,t=map(int,input().split())
a=[int(a) for a in input().split()]
count=0
for i in range(n):
if 86400>=t+a[i]:
count+=1
break
count+=1
print(count) | 16 | 31 | 0 | 187660697 | [a,b] = map(int,input().split())
l = list(map(int,input().split()))
s = 0
d = 0
for i in range(a):
d += 1
s += 86400-l[i]
if s >= b:
break
print(d) | Educational Codeforces Round 31 | ICPC | 2,017 | 2 | 256 | Book Reading | Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend... | The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book.
The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed n. | null | null | [{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}] | 800 | ["implementation"] | 16 | [{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | false | stdio | null | true |
289/A | 289 | A | Python 3 | TESTS | 13 | 92 | 0 | 215088212 | n,k =map(int,input().split())
num1,num2=0,0
sum=0
for i in range(n):
num1,num2 =map(int,input().split())
sum+=abs(abs(num1)-abs(num2))+1
i=0
while True :
if ((sum+i) % k) ==0:
print(i)
break
i+=1 | 28 | 342 | 0 | 211253332 | n, k = map(int, input().split())
value = 0
positions = {}
for i in range(n):
l, r = map(int, input().split())
value += r-l+1
print((((value+k)-(value+k)%k)-value)%k) | Codeforces Round 177 (Div. 2) | CF | 2,013 | 2 | 256 | Polo the Penguin and Segments | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r).
He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the r... | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequal... | In a single line print a single integer — the answer to the problem. | null | null | [{"input": "2 3\n1 2\n3 4", "output": "2"}, {"input": "3 7\n1 2\n3 3\n4 7", "output": "0"}] | 1,100 | ["brute force", "implementation"] | 28 | [{"input": "2 3\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3 7\r\n1 2\r\n3 3\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3 7\r\n1 10\r\n11 47\r\n74 128\r\n", "output": "3\r\n"}, {"input": "5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "7 4\r\n2 2\r\n-1 -1\r\n0 1\r\n7 8\r\n-3 -2\r\n9... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.