contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,525,503,278 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 124 | 7,782,400 | import math
import string
len = int(input())
s = str(input())
flag = False
if len == 1 and s == "0":
print("0")
else:
s = s.replace("1","")
s = "1"+s
print(s) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
import math
import string
len = int(input())
s = str(input())
flag = False
if len == 1 and s == "0":
print("0")
else:
s = s.replace("1","")
s = "1"+s
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,630,222,583 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 170 | 30,720,000 | n, b, d = map(int, input().split())
arr = list(map(int, input().split()))
sum1 = 0
ans = 0
for i in range(len(arr)):
if arr[i] <= b:
sum1 += arr[i]
if sum1 > d:
ans += 1
sum1 = 0
print(ans)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
arr = list(map(int, input().split()))
sum1 = 0
ans = 0
for i in range(len(arr)):
if arr[i] <= b:
sum1 += arr[i]
if sum1 > d:
ans += 1
sum1 = 0
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,696,326,513 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 1,000 | 512,000 | inlist=list(map(int,input().split()))
n=inlist[0]
m=inlist[1]
set1=[]
set2=[]
final=[]
for i in range(m):
s1,s2=input().split()
set1.append(s1)
if(len(s1)<len(s2)):
set1.append(s1)
elif(len(s2)<len(s1)):
set1.append(s2)
elif(len(s2)==len(s1)):
set1.append(s1)... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
inlist=list(map(int,input().split()))
n=inlist[0]
m=inlist[1]
set1=[]
set2=[]
final=[]
for i in range(m):
s1,s2=input().split()
set1.append(s1)
if(len(s1)<len(s2)):
set1.append(s1)
elif(len(s2)<len(s1)):
set1.append(s2)
elif(len(s2)==len(s1)):
set1.... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,612,033,271 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 140 | 307,200 | numPeople=int(input(""))*2
peopleWeights=input("").split(" ")
peopleWeights=[int(x) for x in peopleWeights]
peopleWeights.sort()
minUns=9999999999
for i in range(numPeople):
for j in range(numPeople):
if i<j:
curUns=0
temp=peopleWeights.copy()
temp.pop(j)
... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
numPeople=int(input(""))*2
peopleWeights=input("").split(" ")
peopleWeights=[int(x) for x in peopleWeights]
peopleWeights.sort()
minUns=9999999999
for i in range(numPeople):
for j in range(numPeople):
if i<j:
curUns=0
temp=peopleWeights.copy()
temp.pop... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
300 | D | Painting Square | PROGRAMMING | 2,300 | [
"dp",
"fft"
] | null | null | Vasily the bear has got a large square white table of *n* rows and *n* columns. The table has got a black border around this table.
Vasily the bear wants to paint his square table in exactly *k* moves. Each move is sequence of actions:
1. The bear chooses some square inside his table. At that the square must have a ... | The first line contains integer *q* (1<=≤<=*q*<=≤<=105) — the number of test data.
Each of the following *q* lines contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*k*<=≤<=1000) — the size of the initial table and the number of moves for the corresponding test. | For each test from the input print the answer to the problem modulo 7340033. Print the answers to the tests in the order in which the tests are given in the input. | [
"8\n1 0\n1 1\n3 0\n3 1\n2 0\n2 1\n3 2\n7 2\n"
] | [
"1\n0\n1\n1\n1\n0\n0\n4\n"
] | All possible painting ways for the test *n* = 7 and *k* = 2 are: | 3,000 | [
{
"input": "8\n1 0\n1 1\n3 0\n3 1\n2 0\n2 1\n3 2\n7 2",
"output": "1\n0\n1\n1\n1\n0\n0\n4"
}
] | 1,691,707,589 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1691707589.5916927")# 1691707589.5917084 | Title: Painting Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has got a large square white table of *n* rows and *n* columns. The table has got a black border around this table.
Vasily the bear wants to paint his square table in exactly *k* moves. Each move is seq... | ```python
print("_RANDOM_GUESS_1691707589.5916927")# 1691707589.5917084
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
334 | B | Eight Point Sets | PROGRAMMING | 1,400 | [
"sortings"
] | null | null | Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int... | The input consists of eight lines, the *i*-th line contains two space-separated integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). You do not have any other conditions for these points. | In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. | [
"0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n",
"0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n",
"1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n"
] | [
"respectable\n",
"ugly\n",
"ugly\n"
] | none | 1,000 | [
{
"input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2",
"output": "respectable"
},
{
"input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0",
"output": "ugly"
},
{
"input": "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2",
"output": "ugly"
},
{
"input": "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0... | 1,606,361,388 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 248 | 409,600 | from collections import defaultdict
maps = defaultdict(int)
maps1 = defaultdict(int)
arr = []
distinct_count = distinct_count1 = 0
for i in range(8):
temp = list(map(int, input().split()))
if temp[0] not in maps:
distinct_count += 1
if temp[1] not in maps1:
distinct_count1 += 1
... | Title: Eight Point Sets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizonta... | ```python
from collections import defaultdict
maps = defaultdict(int)
maps1 = defaultdict(int)
arr = []
distinct_count = distinct_count1 = 0
for i in range(8):
temp = list(map(int, input().split()))
if temp[0] not in maps:
distinct_count += 1
if temp[1] not in maps1:
distinct_count... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
977 | B | Two-gram | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters... | The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters. | Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times. | [
"7\nABACABA\n",
"5\nZZZAA\n"
] | [
"AB\n",
"ZZ\n"
] | In the first example "BA" is also valid answer.
In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times. | 0 | [
{
"input": "7\nABACABA",
"output": "AB"
},
{
"input": "5\nZZZAA",
"output": "ZZ"
},
{
"input": "26\nQWERTYUIOPASDFGHJKLZXCVBNM",
"output": "AS"
},
{
"input": "2\nQA",
"output": "QA"
},
{
"input": "2\nWW",
"output": "WW"
},
{
"input": "11\nGGRRAATTZZZ",... | 1,695,741,383 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 77 | 2,764,800 | from collections import Counter
_ = input()
s = input()
c = Counter()
for i in range(1,len(s)):
if s[i] >= s[i-1]:
c[s[i-1:i+1]]+=1
mmax = max(c.values())
for k,v in c.items():
if v == mmax:
print(k)
break
| Title: Two-gram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to f... | ```python
from collections import Counter
_ = input()
s = input()
c = Counter()
for i in range(1,len(s)):
if s[i] >= s[i-1]:
c[s[i-1:i+1]]+=1
mmax = max(c.values())
for k,v in c.items():
if v == mmax:
print(k)
break
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,417,424,184 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 154 | 0 | from sys import stdin
def main():
n = int(stdin.readline().strip()) // 2
l = list(map(int, stdin.readline().strip()))
return ('NO', 'YES')[sum(l[:n]) == sum(l[n:]) and all(c in (4, 7) for c in l)]
print(main())
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
from sys import stdin
def main():
n = int(stdin.readline().strip()) // 2
l = list(map(int, stdin.readline().strip()))
return ('NO', 'YES')[sum(l[:n]) == sum(l[n:]) and all(c in (4, 7) for c in l)]
print(main())
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,493,335,665 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,608,000 | list = list(map(int, input().split(" ")))
list.sort()
count=1
index =[]
list.insert(0,-1)
for i in range(len(list)-1):
if list[i]==list[i+1]:
count = count+1
if count==4:
print("Bear")
elif count==5:
print('Elephant')
else:
print('Alien') | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
list = list(map(int, input().split(" ")))
list.sort()
count=1
index =[]
list.insert(0,-1)
for i in range(len(list)-1):
if list[i]==list[i+1]:
count = count+1
if count==4:
print("Bear")
elif count==5:
print('Elephant')
else:
print('Alien')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,616,251,830 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 108 | 2,969,600 | def equiv(a, b):
return sorted(list(a)) == sorted(list(b))
def ans(a, b):
if a == b:
return True
else:
a1 = a[:len(a) // 2]
a2 = a[len(a) // 2:]
b1 = b[:len(b) // 2]
b2 = b[len(b) // 2:]
return equiv(a1, b1) and equiv(a2, b2) or equiv(a1, b2)... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def equiv(a, b):
return sorted(list(a)) == sorted(list(b))
def ans(a, b):
if a == b:
return True
else:
a1 = a[:len(a) // 2]
a2 = a[len(a) // 2:]
b1 = b[:len(b) // 2]
b2 = b[len(b) // 2:]
return equiv(a1, b1) and equiv(a2, b2) or equ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,677,331,495 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 62 | 3,379,200 | n,k,d=map(int,input().split())
def fun(n,k,d,f,dp):
if n==0:
if f==1:
return 1
return 0
if n<0:
return 0
if dp[n][f]!=-1:
return dp[n][f]
ans=0
mod=10**9+7
for i in range(1,k+1):
if i<d:
ans=(ans+fun(n-i,k,d,f,dp))%m... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
n,k,d=map(int,input().split())
def fun(n,k,d,f,dp):
if n==0:
if f==1:
return 1
return 0
if n<0:
return 0
if dp[n][f]!=-1:
return dp[n][f]
ans=0
mod=10**9+7
for i in range(1,k+1):
if i<d:
ans=(ans+fun(n-i,k,... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,607,335,154 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 93 | 0 | # n = number of people
# k = number of wins in a row
# p = power of player
n, k = map(int, input().split())
p = list(map(int, input().split()))
current_player_power = p[0]
current_player_wins = 0
for i in range(1, n):
if p[i] < current_player_power:
current_player_wins +=1
else:
current_play... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
# n = number of people
# k = number of wins in a row
# p = power of player
n, k = map(int, input().split())
p = list(map(int, input().split()))
current_player_power = p[0]
current_player_wins = 0
for i in range(1, n):
if p[i] < current_player_power:
current_player_wins +=1
else:
cu... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
391 | A | Genetic Engineering | PROGRAMMING | 0 | [
"implementation",
"two pointers"
] | null | null | You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
... | The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length. | [
"GTTAAAG\n",
"AACCAACCAAAAC\n"
] | [
"1\n",
"5\n"
] | In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein. | 3 | [
{
"input": "GTTAAAG",
"output": "1"
},
{
"input": "AACCAACCAAAAC",
"output": "5"
},
{
"input": "GTGAATTTCC",
"output": "2"
},
{
"input": "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA",
"output": "7"
},
{
"input": "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGC... | 1,587,438,633 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | arr = input()
count = 0
insertion = 0
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
count += 1
else:
if (count+1) % 2 == 0:
insertion += 1
count = 0
print(insertion) | Title: Genetic Engineering
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one prot... | ```python
arr = input()
count = 0
insertion = 0
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
count += 1
else:
if (count+1) % 2 == 0:
insertion += 1
count = 0
print(insertion)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
145 | A | Lucky Conversion | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 500 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,420,450,926 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 216 | 1,433,600 | a = input()
b = input()
s = ''.join(x if x != y else '' for x, y in zip(a, b))
fours = s.count('4')
sevens = s.count('7')
print(min(fours, sevens) + abs(fours - sevens))
| Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no... | ```python
a = input()
b = input()
s = ''.join(x if x != y else '' for x, y in zip(a, b))
fours = s.count('4')
sevens = s.count('7')
print(min(fours, sevens) + abs(fours - sevens))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,632,578,532 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 45,977,600 | a=2**int(input())
if a>30:
print(input())
else:
print(int(input())%a) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
a=2**int(input())
if a>30:
print(input())
else:
print(int(input())%a)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
739 | B | Alyona and a tree | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dfs and similar",
"graphs",
"trees"
] | null | null | Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).
Let's define *dist*(*v*,<=*u*) as the ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the integers written in the vertices.
The next (*n*<=-<=1) lines contain two integers each. The *i*-th of these lines contains integers *p**i* and *w**i* (1<=≤<=*... | Print *n* integers — the *i*-th of these numbers should be equal to the number of vertices that the *i*-th vertex controls. | [
"5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6\n",
"5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1\n"
] | [
"1 0 1 0 0\n",
"4 3 2 1 0\n"
] | In the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5). | 1,000 | [
{
"input": "5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6",
"output": "1 0 1 0 0"
},
{
"input": "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1",
"output": "4 3 2 1 0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 1\n1 1",
"output": "1 0"
},
{
"input": "10\n40 77 65 14 86 16 2 51 ... | 1,480,432,159 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 50,995,200 | from sys import stdin
from sys import stdout
n = int(stdin.readline().strip())
a = [int(x) for x in stdin.readline().split()]
def couple(x):
s = x.split()
return int(s[0])-1, int(s[1])
pw = [couple(line) for line in stdin]
v = [-1 for _ in range(n)]
v[0] = 0
stack = [0]
listeAdiacenza = [[] for i in range(n)]
... | Title: Alyona and a tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge... | ```python
from sys import stdin
from sys import stdout
n = int(stdin.readline().strip())
a = [int(x) for x in stdin.readline().split()]
def couple(x):
s = x.split()
return int(s[0])-1, int(s[1])
pw = [couple(line) for line in stdin]
v = [-1 for _ in range(n)]
v[0] = 0
stack = [0]
listeAdiacenza = [[] for i in ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,639,098,564 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 716,800 | n = int(input())
lista = []
for i in range(n):
entrada = input()
if entrada in lista:
lista.remove(entrada)
lista.insert(0, entrada)
print(*lista, sep="\n")
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
n = int(input())
lista = []
for i in range(n):
entrada = input()
if entrada in lista:
lista.remove(entrada)
lista.insert(0, entrada)
print(*lista, sep="\n")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,668,689,874 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | def f(m):
return sum([int(i) for i in str(m)])
n,s=map(int,input().split())
ng,ok=n,0
while abs(ng-ok)>1:
mid=(ng+ok)//2
if mid-f(mid)<s:
ok=mid
else:
ng=mid
print(n-ok) | Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
def f(m):
return sum([int(i) for i in str(m)])
n,s=map(int,input().split())
ng,ok=n,0
while abs(ng-ok)>1:
mid=(ng+ok)//2
if mid-f(mid)<s:
ok=mid
else:
ng=mid
print(n-ok)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,637,255,724 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | n=int(input())
a=input()
count=0
# b=""
i=0
while(i<n):
if i!=n-1 and a[i] != a[i+1]:
# b+="D"
# print(i,a[i],a[i+1])
if i+1==n-2:
i+=2
count+=2
# b+=str(a[i])
break
else:
i+=2
count+=1
... | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
n=int(input())
a=input()
count=0
# b=""
i=0
while(i<n):
if i!=n-1 and a[i] != a[i+1]:
# b+="D"
# print(i,a[i],a[i+1])
if i+1==n-2:
i+=2
count+=2
# b+=str(a[i])
break
else:
i+=2
count+=1
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,687,495,816 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | w = int(input()) # Read the weight of the watermelon
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
print("YES") # Watermelon can be divided into two even parts
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w = int(input()) # Read the weight of the watermelon
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
print("YES") # Watermelon can be divided into two even parts
else:
print("NO")
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,619,983,433 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 109 | 10,649,600 | na, nb = map(int, input().split())
k, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A[k - 1] >= B[len(B) - m]:
print("NO")
else:
print("YES") | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
na, nb = map(int, input().split())
k, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A[k - 1] >= B[len(B) - m]:
print("NO")
else:
print("YES")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,672,069,803 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 92 | 0 | #https://codeforces.com/problemset/problem/218/B
#min heap for minimim
#max heap for maximum
import heapq
n , m =map(int,input().split())
l =list(map(int,input().split()))
h1=[]
h2=[]
heapq.heapify(h1)
for i in l:
heapq.heappush(h1,i)
heapq.heappush(h2,-i)
s1=0
s2 =0
c1=0
c2=0
while(c1<n ... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
#https://codeforces.com/problemset/problem/218/B
#min heap for minimim
#max heap for maximum
import heapq
n , m =map(int,input().split())
l =list(map(int,input().split()))
h1=[]
h2=[]
heapq.heapify(h1)
for i in l:
heapq.heappush(h1,i)
heapq.heappush(h2,-i)
s1=0
s2 =0
c1=0
c2=0
w... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,676,600,155 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | y=int(input())
f=sorted([int(i) for i in input().split()])
c=0
h=0
for i in f:
if i>=h:
c+=1
h+=i
print(c) | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
y=int(input())
f=sorted([int(i) for i in input().split()])
c=0
h=0
for i in f:
if i>=h:
c+=1
h+=i
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,532,077,842 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | a, b = map(int, input().split())
pr = 1
if b-a>=10: pr = 0
else:
for i in range(a+1, b+1):
pr+=1
print(pr) | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
a, b = map(int, input().split())
pr = 1
if b-a>=10: pr = 0
else:
for i in range(a+1, b+1):
pr+=1
print(pr)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,617,635,705 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 0 | a = input()
b = input() .split()
if "1" in b :
print ("-1")
else :
print ("1") | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
a = input()
b = input() .split()
if "1" in b :
print ("-1")
else :
print ("1")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
55 | D | Beautiful numbers | PROGRAMMING | 2,500 | [
"dp",
"number theory"
] | D. Beautiful numbers | 4 | 256 | Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges. | The first line of the input contains the number of cases *t* (1<=≤<=*t*<=≤<=10). Each of the next *t* lines contains two natural numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=9<=·1018).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %... | Output should contain *t* numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from *l**i* to *r**i*, inclusively). | [
"1\n1 9\n",
"1\n12 15\n"
] | [
"9\n",
"2\n"
] | none | 2,000 | [
{
"input": "1\n1 9",
"output": "9"
},
{
"input": "1\n12 15",
"output": "2"
},
{
"input": "1\n25 53",
"output": "7"
},
{
"input": "1\n1 1000",
"output": "138"
},
{
"input": "1\n1 100000",
"output": "4578"
},
{
"input": "2\n234 59843\n46 3243",
"outp... | 1,554,562,344 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 0 | n = int(input())
ans = []
for i in range(n):
l, r = [int(elt) for elt in input().split(" ")]
s = 0
for j in range(l,r+1):
nbr = [int(elt) for elt in str(j)]
k = 0
lon = len(nbr)
while k < lon and j % nbr[k] == 0:
k += 1
if k == lon:
... | Title: Beautiful numbers
Time Limit: 4 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count ... | ```python
n = int(input())
ans = []
for i in range(n):
l, r = [int(elt) for elt in input().split(" ")]
s = 0
for j in range(l,r+1):
nbr = [int(elt) for elt in str(j)]
k = 0
lon = len(nbr)
while k < lon and j % nbr[k] == 0:
k += 1
if k == lon:
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,677,501,981 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 202 | 18,022,400 | # https://codeforces.com/problemset/problem/567/A
input()
seq = tuple(map(int, input().split()))
for i in range(len(seq)):
if i == 0:
print(seq[1] - seq[0], seq[-1] - seq[0])
continue
if i == len(seq) - 1:
print(seq[-1] - seq[-2], seq[-1] - seq[0])
continue
print(... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
# https://codeforces.com/problemset/problem/567/A
input()
seq = tuple(map(int, input().split()))
for i in range(len(seq)):
if i == 0:
print(seq[1] - seq[0], seq[-1] - seq[0])
continue
if i == len(seq) - 1:
print(seq[-1] - seq[-2], seq[-1] - seq[0])
continue
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
61 | B | Hard Work | PROGRAMMING | 1,300 | [
"strings"
] | B. Hard Work | 2 | 256 | After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!
Some days before the contest, the teacher took a very simple-looking exam and all his *n* students took part in the exam. The teach... | The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively.
In the fourth line there is a single integer *n* (0<=≤<=*n*<=≤<=1000), the number of stud... | For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK. | [
"Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful\n",
"Shapur;;\nis___\na_genius\n3\nShapur__a_is___geniUs\nis___shapu... | [
"ACC\nACC\nACC\nWA\nACC\nACC\nWA\n",
"WA\nACC\nACC\n"
] | none | 1,000 | [
{
"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful",
"output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"
},
... | 1,642,633,597 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 17 | 233 | 12,902,400 | #! /usr/bin/env python3
import sys
import re
def main():
inpt = []
str_list = []
answers = []
for line in sys.stdin:
inpt.append(line.rstrip("\n"))
str_list = [re.sub("[-_;]", "", word).lower() for word in inpt[:3]]
answers = [re.sub("[-_;]", "", word).lower() for word in inpt[4:]]
... | Title: Hard Work
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!
Some days before the contest, the teache... | ```python
#! /usr/bin/env python3
import sys
import re
def main():
inpt = []
str_list = []
answers = []
for line in sys.stdin:
inpt.append(line.rstrip("\n"))
str_list = [re.sub("[-_;]", "", word).lower() for word in inpt[:3]]
answers = [re.sub("[-_;]", "", word).lower() for word in in... | 0 | MatrixStudio/Codeforces-Python-Submissions |
741 | C | Arpa’s overnight party and Mehrdad’s silent entering | PROGRAMMING | 2,600 | [
"constructive algorithms",
"dfs and similar",
"graphs"
] | null | null | Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw *n* pairs of friends sitting around a table. *i*-th pair consisted of a boy, sitting on the *a**i*-th chair, and his girlfriend, sitting on the *b**i*-th chair. Th... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=<=≤<=<=105) — the number of pairs of guests.
The *i*-th of the next *n* lines contains a pair of integers *a**i* and *b**i* (1<=<=≤<=*a**i*,<=*b**i*<=≤<=<=2*n*) — the number of chair on which the boy in the *i*-th pair was sitting and the number of chair on which ... | If there is no solution, print -1.
Otherwise print *n* lines, the *i*-th of them should contain two integers which represent the type of food for the *i*-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, other... | [
"3\n1 4\n2 5\n3 6\n"
] | [
"1 2\n2 1\n1 2\n"
] | none | 1,250 | [
{
"input": "3\n1 4\n2 5\n3 6",
"output": "1 2\n2 1\n1 2"
},
{
"input": "6\n3 2\n5 11\n7 12\n6 9\n8 4\n1 10",
"output": "1 2\n1 2\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "19\n30 27\n6 38\n10 28\n20 5\n14 18\n32 2\n36 29\n12 1\n31 24\n15 4\n35 11\n3 7\n21 17\n25 19\n16 8\n23 22\n37 33\n13 9\n34... | 1,632,320,099 | 2,147,483,647 | PyPy 3 | OK | TESTS | 94 | 467 | 49,459,200 | import sys
input = sys.stdin.buffer.readline
def is_bipartite(graph):
n = len(graph)
cols = [-1] * n
cnts = []
for v in range(n):
if cols[v] != -1:
continue
cols[v] = 0
cnt = [1, 0]
stack = [v]
while stack:
v = stack.pop()
... | Title: Arpa’s overnight party and Mehrdad’s silent entering
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw *n* pairs of friends sitt... | ```python
import sys
input = sys.stdin.buffer.readline
def is_bipartite(graph):
n = len(graph)
cols = [-1] * n
cnts = []
for v in range(n):
if cols[v] != -1:
continue
cols[v] = 0
cnt = [1, 0]
stack = [v]
while stack:
v = st... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,572,417,571 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | a = int(input())
arr = list(map(int, input().split()))
k1 = 0
k2 = 0
for i in range(len(arr)):
if arr[i] % 2 == 0:
k1 += 1
else:
k2 += 1
if k1 >= k2:
for i in range(len(arr)):
if arr[i] % 2 == 1:
print(i + 1)
else:
for i in range(len(arr)):
if a... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
a = int(input())
arr = list(map(int, input().split()))
k1 = 0
k2 = 0
for i in range(len(arr)):
if arr[i] % 2 == 0:
k1 += 1
else:
k2 += 1
if k1 >= k2:
for i in range(len(arr)):
if arr[i] % 2 == 1:
print(i + 1)
else:
for i in range(len(arr)):
... | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,636,784,856 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 202 | 42,905,600 |
import math
import itertools
import random
s=input()
o=0
q=0
ans='abcdefghijklmnopqrstuvwxyz'
for l in s:
ans=ans[o:]+ans[:o]
a=ans.index(l)+1
o=a
p=min(len(ans)-a,a)
q+=p
if 'a' in s:
print(q-1)
else:
print(q+1)
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
import math
import itertools
import random
s=input()
o=0
q=0
ans='abcdefghijklmnopqrstuvwxyz'
for l in s:
ans=ans[o:]+ans[:o]
a=ans.index(l)+1
o=a
p=min(len(ans)-a,a)
q+=p
if 'a' in s:
print(q-1)
else:
print(q+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,693,235,259 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | # s = input()
# s1 = s.lower()
# s2 = 'aeiouy'
# l = list(s1)
# l1 = []
# for i in range(len(l)):
# if l[i] in s2:
# l1.append(i)
# print(l1)
# for i in range(len(l)):
# if i in l1:
s = input()
s1 = s.lower()
s2 = 'aeiouy'
s3 = ''
for char in s1:
if char in s2:
s3+='... | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
# s = input()
# s1 = s.lower()
# s2 = 'aeiouy'
# l = list(s1)
# l1 = []
# for i in range(len(l)):
# if l[i] in s2:
# l1.append(i)
# print(l1)
# for i in range(len(l)):
# if i in l1:
s = input()
s1 = s.lower()
s2 = 'aeiouy'
s3 = ''
for char in s1:
if char in s2:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For e... | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
... | 1,632,695,740 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 202 | 20,172,800 |
currentString = input()
array = []
for char in currentString:
array.append(char)
state = True
while(state):
state = False
idx = 0
while(idx < len(array) - 1):
currentNum = int(array[idx])
secondNum = int(array[idx + 1])
if currentNum == 1:
if secondN... | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ... | ```python
currentString = input()
array = []
for char in currentString:
array.append(char)
state = True
while(state):
state = False
idx = 0
while(idx < len(array) - 1):
currentNum = int(array[idx])
secondNum = int(array[idx + 1])
if currentNum == 1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
593 | E | Strange Calculation and Cats | PROGRAMMING | 2,400 | [
"dp",
"matrices"
] | null | null | Gosha's universe is a table consisting of *n* rows and *m* columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (*r*,<=*c*) to denote a cell located in the row *r* and column *c*.
Gosha is often invited somewhere. Every time he gets an invitation, he first calculates t... | The first line of the input contains three positive integers *n*, *m* and *q* (1<=≤<=*n*·*m*<=≤<=20,<=1<=≤<=*q*<=≤<=10<=000) — the number of rows and columns in the table and the number of events respectively.
Next *q* lines describe the events, each description contains four integers *tp**i*, *x**i*, *y**i* and *t**i... | For each invitation *i* (that is, *tp**i*<==<=1) calculate the number of ways to get to cell (*x**i*,<=*y**i*) at the moment of time *t**i*. Respond to the invitations chronologically, that is, in the order they appear in the input. | [
"1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7\n",
"3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7\n",
"4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15\n"
] | [
"5\n",
"2\n42\n",
"490902\n10598759\n"
] | Explanation of the first sample. Each picture specifies the number of ways to arrive at the cell at the appropriate time. (X stands for a cell blocked at this particular moment of time) | 3,000 | [
{
"input": "1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7",
"output": "5"
},
{
"input": "3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7",
"output": "2\n42"
},
{
"input": "4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15",
"output": "490902\n10598759"
},
{
"input": "1 1 1\n1 1 1 2",
"output": "1... | 1,537,082,317 | 6,517 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 4,000 | 1,126,400 | import sys
from contextlib import contextmanager
from io import StringIO
M = 10**9 + 7
def process(n, m, events):
s = {(r, c): 0 for r in range(1, n+1) for c in range(1, m+1)}
s[1,1] = 1
t = 1
for event in events:
ee, er, ec, et = event
while t < et:
s_ = s.copy()
... | Title: Strange Calculation and Cats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gosha's universe is a table consisting of *n* rows and *m* columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (*r*,<=*c*) to denote a cell located in the ... | ```python
import sys
from contextlib import contextmanager
from io import StringIO
M = 10**9 + 7
def process(n, m, events):
s = {(r, c): 0 for r in range(1, n+1) for c in range(1, m+1)}
s[1,1] = 1
t = 1
for event in events:
ee, er, ec, et = event
while t < et:
s_ = s.copy... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,684,247,447 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | x = input()
out = ''
for i in range(len(x)):
if i == 0 and x[i] == '9':
pass
if x[i] >= '5':
n = 9-int(x[i])
out += str(n)
else:
out += x[i]
print(out) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
x = input()
out = ''
for i in range(len(x)):
if i == 0 and x[i] == '9':
pass
if x[i] >= '5':
n = 9-int(x[i])
out += str(n)
else:
out += x[i]
print(out)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,692,009,160 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 310 | 4,608,000 | ans = 0
d1,d2 = 0,0
c1,c2 = 0,0
for _ in range(int(input())):
s1, s2 = input().split()
if s1 == "0":
d1 += 1
else :
d2 += 1
if s2 == "0":
c1 += 1
else :
c2 += 1
if d1 > d2 :
ans += d2
else :
ans += d1
if c1 > c2 :
ans += c2
else :
a... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
ans = 0
d1,d2 = 0,0
c1,c2 = 0,0
for _ in range(int(input())):
s1, s2 = input().split()
if s1 == "0":
d1 += 1
else :
d2 += 1
if s2 == "0":
c1 += 1
else :
c2 += 1
if d1 > d2 :
ans += d2
else :
ans += d1
if c1 > c2 :
ans += c2
els... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
847 | K | Travel Cards | PROGRAMMING | 1,800 | [
"greedy",
"implementation",
"sortings"
] | null | null | In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t... | The first line contains five integers *n*,<=*a*,<=*b*,<=*k*,<=*f* (1<=≤<=*n*<=≤<=300, 1<=≤<=*b*<=<<=*a*<=≤<=100, 0<=≤<=*k*<=≤<=300, 1<=≤<=*f*<=≤<=1000) where:
- *n* — the number of Polycarp trips, - *a* — the cost of a regualar single trip, - *b* — the cost of a trip after a transshipment, - *k* — the maximum n... | Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than *k* travel cards. | [
"3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank\n",
"4 2 1 300 1000\na A\nA aa\naa AA\nAA a\n"
] | [
"11\n",
"5\n"
] | In the first example Polycarp can buy travel card for the route "BerBank <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ecc94b07e73defe233bfe831f3977337706a2d27.png" style="max-width: 100.0%;max-height: 100.0%;"/> University" and spend 8 burles. Note that his second trip "University" <img ... | 0 | [
{
"input": "3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank",
"output": "11"
},
{
"input": "4 2 1 300 1000\na A\nA aa\naa AA\nAA a",
"output": "5"
},
{
"input": "2 2 1 0 1\naca BCBA\nBCBA aca",
"output": "3"
},
{
"input": "2 2 1 2 1\nBDDB C\nC BDDB",
... | 1,506,769,604 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 307,200 | n, a, b, k, f = map(int, input().split())
slov = dict()
temp = input().split()
slov[frozenset(temp)] = a
for i in range(1, n):
temp2 = input().split()
try:
if temp2[0] == temp[1]:
slov[frozenset(temp2)] += b
else:
slov[frozenset(temp2)] += a
except KeyE... | Title: Travel Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus... | ```python
n, a, b, k, f = map(int, input().split())
slov = dict()
temp = input().split()
slov[frozenset(temp)] = a
for i in range(1, n):
temp2 = input().split()
try:
if temp2[0] == temp[1]:
slov[frozenset(temp2)] += b
else:
slov[frozenset(temp2)] += a
e... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,695,894,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | # n = int(input())
# values = [int(x) for x in input().split(' ')]
# valuesSorted = sorted(values)
# numQueries = int(input())
# for _ in range(numQueries):
# type, left, right = [int(x) for x in input().split(" ")]
# # Left index must be start
# # Right index must be 1 more than the end position
... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
# n = int(input())
# values = [int(x) for x in input().split(' ')]
# valuesSorted = sorted(values)
# numQueries = int(input())
# for _ in range(numQueries):
# type, left, right = [int(x) for x in input().split(" ")]
# # Left index must be start
# # Right index must be 1 more than the end ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,666,115,095 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, k, *_ = list(map(int, input().split()))
a = list(map(int, input().split()))
rights = dict()
lefts = dict()
for i in a:
rights[i] = rights.get(i, 0)+1
k1 = 0
k2 = 0
ans = 0
for i in a:
if i%k==0:
k1=lefts.get(i/k, 0)
rights[i] -= 1
k2= rights.get(i*k, 0);
ans+= k1*k2
lefts[i] = lefts.get(i,0... | Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
n, k, *_ = list(map(int, input().split()))
a = list(map(int, input().split()))
rights = dict()
lefts = dict()
for i in a:
rights[i] = rights.get(i, 0)+1
k1 = 0
k2 = 0
ans = 0
for i in a:
if i%k==0:
k1=lefts.get(i/k, 0)
rights[i] -= 1
k2= rights.get(i*k, 0);
ans+= k1*k2
lefts[i] = lef... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,601,780,895 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 108 | 0 | string=input()
hello="hello "
i=0
for letter in string:
if letter==hello[i]:
i=i+1
if i==5:
print("YES")
else :
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
string=input()
hello="hello "
i=0
for letter in string:
if letter==hello[i]:
i=i+1
if i==5:
print("YES")
else :
print("NO")
``` | 3.946 | MatrixStudio/Codeforces-Python-Submissions |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,676,427,093 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 4 | 717 | 268,390,400 | X = int(input())
L = []
for i in range(1, X + 1):
for j in str(i):
L.append(j)
print(len(L)) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
X = int(input())
L = []
for i in range(1, X + 1):
for j in str(i):
L.append(j)
print(len(L))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,652,168,394 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | import math as m
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c=int(input())
sum1=a[0]+a[1]+a[2]
sum2=b[0]+b[1]+b[2]
sl=m.ceil(sum1//5)
sl2=m.ceil(sum2//10)
if(sl+sl2<=c):
print("YES")
else:
print("NO") | Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
import math as m
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c=int(input())
sum1=a[0]+a[1]+a[2]
sum2=b[0]+b[1]+b[2]
sl=m.ceil(sum1//5)
sl2=m.ceil(sum2//10)
if(sl+sl2<=c):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,695,111,571 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | def distance_between_characters(ch1, ch2):
distance_clockwise = abs(ord(ch1) - ord(ch2))
distance_counterclockwise = 26 - distance_clockwise
return min(distance_counterclockwise, distance_clockwise)
current_ch = 'a'
s = input()
total_steps = 0
for ch in s:
total_steps += distance_between... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
def distance_between_characters(ch1, ch2):
distance_clockwise = abs(ord(ch1) - ord(ch2))
distance_counterclockwise = 26 - distance_clockwise
return min(distance_counterclockwise, distance_clockwise)
current_ch = 'a'
s = input()
total_steps = 0
for ch in s:
total_steps += distan... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,571,129,005 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | def if_string_ok(needed_string='hello'):
s = input()
i = 0
j = 0
while i < len(s) and j != len(needed_string):
if s[i] == needed_string[j]:
j += 1
i += 1
if j == len(needed_string):
return 'YES'
else:
return 'NO'
print(if_string_ok())
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
def if_string_ok(needed_string='hello'):
s = input()
i = 0
j = 0
while i < len(s) and j != len(needed_string):
if s[i] == needed_string[j]:
j += 1
i += 1
if j == len(needed_string):
return 'YES'
else:
return 'NO'
print(if_string_ok())
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,517,239,546 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 171 | 5,632,000 | temp = input().split()
num = int(temp[0])
mod = int(temp[1])
runningtotal=0
for i in range(1,num+1):
runningtotal+=int(str(i)+str(i)[::-1])
print(runningtotal%mod) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thi... | ```python
temp = input().split()
num = int(temp[0])
mod = int(temp[1])
runningtotal=0
for i in range(1,num+1):
runningtotal+=int(str(i)+str(i)[::-1])
print(runningtotal%mod)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,688,488,132 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | M, N = map(int, input().split())
ts = M * N
mh = ts // 2
mv= ts // 2
md = min(mh, mv)
print(md) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M, N = map(int, input().split())
ts = M * N
mh = ts // 2
mv= ts // 2
md = min(mh, mv)
print(md)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,670,939,727 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | def combinatoria(num):
if num == 0:
return 0
sef = num ** 2
return (sef-num)/2
num = int(input())
test = [0] * num
test2 = [0] * num
for i in range(num):
stri = str(input())
sefc = 0
for j, grea in enumerate(stri):
if grea == 'C':
test2[j] += 1
sefc += 1
test[i] = sefc
cont =... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
def combinatoria(num):
if num == 0:
return 0
sef = num ** 2
return (sef-num)/2
num = int(input())
test = [0] * num
test2 = [0] * num
for i in range(num):
stri = str(input())
sefc = 0
for j, grea in enumerate(stri):
if grea == 'C':
test2[j] += 1
sefc += 1
test[i] = sefc... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,593,842,402 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 312 | 0 | n = int(input())
lis = [int(_) for _ in input().split()]
dic = {0:[], 1:[]}
for i,x in enumerate(lis):
dic[x&1].append(i+1)
if len(dic[0]) == 1:
print(dic[0][0])
else:
print(dic[1][0])
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
lis = [int(_) for _ in input().split()]
dic = {0:[], 1:[]}
for i,x in enumerate(lis):
dic[x&1].append(i+1)
if len(dic[0]) == 1:
print(dic[0][0])
else:
print(dic[1][0])
``` | 3.922 | MatrixStudio/Codeforces-Python-Submissions |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,670,252,700 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 46 | 0 | s=input()
# nineteen
# nnneeeit
n=s.count('n')+1
i=s.count('i')
e=s.count('e')
t=s.count('t')
ans1=min(n,e)
ans2=min(i,t)
ans=min(ans2,ans1//3)
print(ans) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
s=input()
# nineteen
# nnneeeit
n=s.count('n')+1
i=s.count('i')
e=s.count('e')
t=s.count('t')
ans1=min(n,e)
ans2=min(i,t)
ans=min(ans2,ans1//3)
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,679,054,635 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 108 | 9,216,000 | input()
d={0:-1}
a=b=0
for i,c in enumerate(input()):
b+=2*int(c)-1
d[b]=x=d.get(b,i)
a=max(a,i-x)
print(a) | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
input()
d={0:-1}
a=b=0
for i,c in enumerate(input()):
b+=2*int(c)-1
d[b]=x=d.get(b,i)
a=max(a,i-x)
print(a)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 0 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
... | 1,449,784,616 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 124 | 9,830,400 | def pick_bigger(key_position_dict, kil_elements):
last_position = 0
moved = 0
for i in range(1, kil_elements + 1):
if key_position_dict[i] < last_position:
moved += 1
else:
last_position = key_position_dict[i]
return moved
def pick_smaller(key_positio... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increa... | ```python
def pick_bigger(key_position_dict, kil_elements):
last_position = 0
moved = 0
for i in range(1, kil_elements + 1):
if key_position_dict[i] < last_position:
moved += 1
else:
last_position = key_position_dict[i]
return moved
def pick_smaller(k... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,607,010,539 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 2,150,400 | lis = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968]
n = int(input())
print(lis[i-1... | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
De... | ```python
lis = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968]
n = int(input())
pri... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,695,336,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n = int(input())
steps = list(map(int,input().split()))
done = False
score = 0
odd_score=0
even_score=0
for i in range(n):
if i%2==0:
even_score+=steps[i]
else:
odd_score+=steps[i]
while not done:
items = sorted(steps,reverse=True)
if items[0]==-1:
done=True
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
steps = list(map(int,input().split()))
done = False
score = 0
odd_score=0
even_score=0
for i in range(n):
if i%2==0:
even_score+=steps[i]
else:
odd_score+=steps[i]
while not done:
items = sorted(steps,reverse=True)
if items[0]==-1:
don... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,689,905,457 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | name = input()
min = 0
for i in range(len(name)):
asc = ord(name[i])
if i==0:
if asc-97 > 122-asc+1:
min+=(122-asc+1)
else:
min+=(asc-97)
else:
diff=asc-ord(name[i-1])
if diff>=0:
diff=diff
else:
diff=-diff... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
name = input()
min = 0
for i in range(len(name)):
asc = ord(name[i])
if i==0:
if asc-97 > 122-asc+1:
min+=(122-asc+1)
else:
min+=(asc-97)
else:
diff=asc-ord(name[i-1])
if diff>=0:
diff=diff
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,699,051,639 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | n,t = list(map(int, input().split()))
s = int(str(t)+"0"*(n-len(str(t))))
print(s if len(str(s)) == n else -1) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n,t = list(map(int, input().split()))
s = int(str(t)+"0"*(n-len(str(t))))
print(s if len(str(s)) == n else -1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,681,530,969 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 184 | 0 | s = input()
mapping = {'.': '0', '-.': '1', '--': '2'}
result = ''
i = 0
while i < len(s):
if s[i:i+2] in mapping:
result += mapping[s[i:i+2]]
i += 2
else:
result += mapping[s[i]]
i += 1
print(result) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
s = input()
mapping = {'.': '0', '-.': '1', '--': '2'}
result = ''
i = 0
while i < len(s):
if s[i:i+2] in mapping:
result += mapping[s[i:i+2]]
i += 2
else:
result += mapping[s[i]]
i += 1
print(result)
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,601,657,840 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 0 | x = set()
for i in range(1,501):
x.add(i * (i+1)/2)
n = int(input())
if i in x:
print('YES')
else:
print('NO') | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
x = set()
for i in range(1,501):
x.add(i * (i+1)/2)
n = int(input())
if i in x:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,672,576,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | ##def solve():
## n = int(input())
## x = input()
## if 'CC' in x:
## return 'No'
## if 'MM' in x:
## return 'No'
## if 'YY' in x:
## return 'No'
##
## for i in range(n):
## if i > 0 and i < n - 1:
## if x[i] == '?':
## left = x[i-... | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
##def solve():
## n = int(input())
## x = input()
## if 'CC' in x:
## return 'No'
## if 'MM' in x:
## return 'No'
## if 'YY' in x:
## return 'No'
##
## for i in range(n):
## if i > 0 and i < n - 1:
## if x[i] == '?':
## l... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,515,051,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 6,553,600 | cmap = dict()
def countStmt(a, l):
if (len(a)==1):
return 1
if (a,l) in cmap:
return cmap[(a,l)]
s = 0
if a[0]=='s':
for i in range(l+1):
s+=countStmt(a[1:], i)
else:
s = countStmt(a[1:], l+1)
cmap[(a,l)] = s
return s
n = int(input())
a = ""
for i in range(n):
s = input... | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
cmap = dict()
def countStmt(a, l):
if (len(a)==1):
return 1
if (a,l) in cmap:
return cmap[(a,l)]
s = 0
if a[0]=='s':
for i in range(l+1):
s+=countStmt(a[1:], i)
else:
s = countStmt(a[1:], l+1)
cmap[(a,l)] = s
return s
n = int(input())
a = ""
for i in range(n):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,640,659,859 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 404 | 0 | y,k,n = map(int,input().split())
r = 0
fst = k-(y%k)
if y>=n:
print(-1)
exit()
while fst+y <= n:
print(fst,end=" ")
fst += k
r = 1
if r == 0:
print(-1) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n = map(int,input().split())
r = 0
fst = k-(y%k)
if y>=n:
print(-1)
exit()
while fst+y <= n:
print(fst,end=" ")
fst += k
r = 1
if r == 0:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,685,179,021 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 498 | 102,400 | def count_spells(n):
count = 0
while n >= 10:
n = sum(int(digit) for digit in str(n))
count += 1
return count
n = int(input())
spell_count = count_spells(n)
print(spell_count)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def count_spells(n):
count = 0
while n >= 10:
n = sum(int(digit) for digit in str(n))
count += 1
return count
n = int(input())
spell_count = count_spells(n)
print(spell_count)
``` | 3.875316 | MatrixStudio/Codeforces-Python-Submissions |
234 | G | Practice | PROGRAMMING | 1,600 | [
"constructive algorithms",
"divide and conquer",
"implementation"
] | null | null | Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ... | A single input line contains integer *n* (2<=≤<=*n*<=≤<=1000). | In the first line print *m* — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in *m* lines.
In the *i*-th of those lines print *f**i* — the number of players in the first team during the *i*-th practice (1<=≤<=*f**i*<=<<=*n*), and *f**i* numbers from 1 t... | [
"2\n",
"3\n"
] | [
"1\n1 1\n",
"2\n2 1 2\n1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1\n1 1"
},
{
"input": "3",
"output": "2\n2 1 2\n1 1"
},
{
"input": "4",
"output": "2\n2 1 2\n2 1 3"
},
{
"input": "5",
"output": "3\n3 1 2 3\n3 1 2 4\n1 1"
},
{
"input": "6",
"output": "3\n3 1 2 3\n4 1 2 4 5\n2 1 4"
},
{
"inp... | 1,650,875,490 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
n2 = n//2
if n==2:
print("1\n1 1")
else:
print(2)
print(n2, *range(1, n2+1))
print(n2, *range(1, n2), n2+1)
| Title: Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* p... | ```python
n = int(input())
n2 = n//2
if n==2:
print("1\n1 1")
else:
print(2)
print(n2, *range(1, n2+1))
print(n2, *range(1, n2), n2+1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,441,571,241 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 920 | 9,523,200 | __author__ = 'pxy'
n=int(input())
c=[int(i) for i in input().split()]
for j in range(n):
while c[j] % 2 == 0:
c[j]=c[j]// 2
while c[j] % 3 == 0:
c[j]=c[j]// 3
f=True
for j in range(n-1):
if(c[j]!=c[j+1]):
f=False
break
if f:
print('Yes')
else:
print('No') | Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid wit... | ```python
__author__ = 'pxy'
n=int(input())
c=[int(i) for i in input().split()]
for j in range(n):
while c[j] % 2 == 0:
c[j]=c[j]// 2
while c[j] % 3 == 0:
c[j]=c[j]// 3
f=True
for j in range(n-1):
if(c[j]!=c[j+1]):
f=False
break
if f:
print('Yes')
else:
print('No')
`... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,627,496,423 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 140 | 12,902,400 | from sys import exit
epcount = int(input())
epwatched = input().split()
for i in range(epcount-1):
epwatched[i] = int(epwatched[i])
epwatched = sorted(epwatched)
for i in range(epcount-1):
if epwatched[i] != i+1:
print(i+1)
exit(0)
print(epcount)
| Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
from sys import exit
epcount = int(input())
epwatched = input().split()
for i in range(epcount-1):
epwatched[i] = int(epwatched[i])
epwatched = sorted(epwatched)
for i in range(epcount-1):
if epwatched[i] != i+1:
print(i+1)
exit(0)
print(epcount)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,627,216,106 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 6,656,000 | import sys
dimension = input()
r = int(dimension[0])
c = int(dimension[1])
ans = int((r * c) / 2)
print(ans)
sys.exit(0) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import sys
dimension = input()
r = int(dimension[0])
c = int(dimension[1])
ans = int((r * c) / 2)
print(ans)
sys.exit(0)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,677,773,896 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x,m=map(int,input().split(" "))
n=m*x
if n %2==0:
sum=x*m/2
else:
sum=(n-1)/2
print(sum) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
x,m=map(int,input().split(" "))
n=m*x
if n %2==0:
sum=x*m/2
else:
sum=(n-1)/2
print(sum)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,693,405,525 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = int(input())
if (a[0]+a[1]+a[2]+4)//5 + (b[0]+b[1]+b[2]+9)//10 > n:
print("NO")
else:
print("YES") | Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = int(input())
if (a[0]+a[1]+a[2]+4)//5 + (b[0]+b[1]+b[2]+9)//10 > n:
print("NO")
else:
print("YES")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,621,378,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | s =input()
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0 # Index of str1
i = 0 # Index of str2
while j < m and i < n:
if str1[j] == str2[i]:
j = j+1
i = i + 1
return j == m
if isSubSequence('heidi',s):
print('YES')
else:
print('N0'... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s =input()
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0 # Index of str1
i = 0 # Index of str2
while j < m and i < n:
if str1[j] == str2[i]:
j = j+1
i = i + 1
return j == m
if isSubSequence('heidi',s):
print('YES')
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,616,065,663 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 307,200 | def check(s):
for i in range(1, n):
if s[i]==s[i-1] and s[i]!="?":
return False
return True
n = int(input())
s = input()
if not check(s):
print ("NO")
exit()
ans = "NO"
if s[0]=="?" or s[-1]=="?":
print ("YES")
exit()
for i in range(n-1):
if (s[i]=="?" and s[i+1]=="?") or (i>0 and s[i-1]==s[i+1]):
ans =... | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
def check(s):
for i in range(1, n):
if s[i]==s[i-1] and s[i]!="?":
return False
return True
n = int(input())
s = input()
if not check(s):
print ("NO")
exit()
ans = "NO"
if s[0]=="?" or s[-1]=="?":
print ("YES")
exit()
for i in range(n-1):
if (s[i]=="?" and s[i+1]=="?") or (i>0 and s[i-1]==s[i+1]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
245 | E | Mishap in Club | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. | Print the sought minimum number of people | [
"+-+-+\n",
"---"
] | [
"1\n",
"3"
] | none | 0 | [
{
"input": "+-+-+",
"output": "1"
},
{
"input": "---",
"output": "3"
},
{
"input": "-",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "---",
"output": "3"
},
{
"input": "----",
"output": "4"
},
{
"input": "---+",
"output... | 1,586,775,730 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 278 | 0 | a = input()
n = len(a)
ans = []
cnt = 1
m = 1 #for max
ans.append(1)
for i in range(1,n):
if(a[i] == a[0]):
cnt+=1
else:
cnt -=1
ans.append(cnt)
m = max(m,cnt)
# print(ans)
print(m)
| Title: Mishap in Club
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitor... | ```python
a = input()
n = len(a)
ans = []
cnt = 1
m = 1 #for max
ans.append(1)
for i in range(1,n):
if(a[i] == a[0]):
cnt+=1
else:
cnt -=1
ans.append(cnt)
m = max(m,cnt)
# print(ans)
print(m)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal stra... | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input"... | 1,668,302,966 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a,b=map(int,input().split())
c=input().split()
list=[]
for i in range(a):
c[i]=int(c[i])
c.sort()
if b>0:
for i in range (a):
if c[i]-c[1]<=b:
list.append(i+1)
if c[i]-c[1]>b:
for j in range(i):
if c[i]-c[j]<=b:
list.append(i-j+1)
... | Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest dista... | ```python
a,b=map(int,input().split())
c=input().split()
list=[]
for i in range(a):
c[i]=int(c[i])
c.sort()
if b>0:
for i in range (a):
if c[i]-c[1]<=b:
list.append(i+1)
if c[i]-c[1]>b:
for j in range(i):
if c[i]-c[j]<=b:
list.append(i-... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,512,812,642 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 5,529,600 | binary = input()
cnt = 0
lst = []
for i in range(len(binary)):
if binary[i] == '0' and cnt == 0:
cnt += 1
continue
lst.append(binary[i])
print(''.join(lst))
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
binary = input()
cnt = 0
lst = []
for i in range(len(binary)):
if binary[i] == '0' and cnt == 0:
cnt += 1
continue
lst.append(binary[i])
print(''.join(lst))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,677,741,978 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a = int(input())
s,q=[],[]
ans=0
for i in range(a):
s.append(input())
for i in range(a):
for j in range(1,a-i):
if s[i]==s[i+j]and s[i]!=-2:
q.append(s[i+j])
for t in range(i+1,a):
if s[t]==s[i]:
s[t]=-2
print(a-s.count(-2))
... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
a = int(input())
s,q=[],[]
ans=0
for i in range(a):
s.append(input())
for i in range(a):
for j in range(1,a-i):
if s[i]==s[i+j]and s[i]!=-2:
q.append(s[i+j])
for t in range(i+1,a):
if s[t]==s[i]:
s[t]=-2
print(a-s.count(-2... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,682,436,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 102,400 | from collections import deque
di=[-1,0,1,0]
dj=[0,-1,0,1]
n,m,k= list(map(int,input().split()))
nb=0
maze=[]
for i in range(n):
s=input()
l=[]
for s1 in s :
for j in s1:
l.append(j)
if j=='.' : nb+=1
maze.append(l)
nb-=k
def canMove(i,j):
return i>... | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
from collections import deque
di=[-1,0,1,0]
dj=[0,-1,0,1]
n,m,k= list(map(int,input().split()))
nb=0
maze=[]
for i in range(n):
s=input()
l=[]
for s1 in s :
for j in s1:
l.append(j)
if j=='.' : nb+=1
maze.append(l)
nb-=k
def canMove(i,j):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d... | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is... | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n99... | 1,458,203,400 | 84,600 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 62 | 0 | n, b = [int(x) for x in input().split()]
busy = 0
path = []
queue = []
for i in range(n):
t, d = [int(x) for x in input().split()]
if len(queue) > 0 and t >= path[-1]:
x = queue.pop(0)
path.append(x)
while len(queue) > 0:
if t >= queue[0]:
x = queue.pop(0)
... | Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* ar... | ```python
n, b = [int(x) for x in input().split()]
busy = 0
path = []
queue = []
for i in range(n):
t, d = [int(x) for x in input().split()]
if len(queue) > 0 and t >= path[-1]:
x = queue.pop(0)
path.append(x)
while len(queue) > 0:
if t >= queue[0]:
x = queue.pop(0)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,595,139,997 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 389 | 43,827,200 | n = int(input())
l = list(map(int,input().split()))
l.sort()
s = sum(l)
ans = s
for i in range(n-1):
s-=l[i]
ans+=l[i]
ans += s
print(ans) | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n = int(input())
l = list(map(int,input().split()))
l.sort()
s = sum(l)
ans = s
for i in range(n-1):
s-=l[i]
ans+=l[i]
ans += s
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*... | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
... | 1,605,123,966 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 109 | 307,200 | S=list(input())
t=[]
top=-1
u=''
while len(S)>0:
if top==-1 :
e = S.pop(0)
t.append(e)
top+=1
else:
if min(S)>t[top]:
u+=t.pop()
top-=1
else:
e = S.pop(0)
t.append(e)
top+=1
while top!=-1:
u... | Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first char... | ```python
S=list(input())
t=[]
top=-1
u=''
while len(S)>0:
if top==-1 :
e = S.pop(0)
t.append(e)
top+=1
else:
if min(S)>t[top]:
u+=t.pop()
top-=1
else:
e = S.pop(0)
t.append(e)
top+=1
while top!=... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,627,379,459 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 6,758,400 | n=input()
m=input()
r=''
for i in range(len(n)):
if n[i]==m[i]:
r=r+'0'
else:
r=r+'1'
print(r)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n=input()
m=input()
r=''
for i in range(len(n)):
if n[i]==m[i]:
r=r+'0'
else:
r=r+'1'
print(r)
``` | 3.968161 | MatrixStudio/Codeforces-Python-Submissions |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,673,504,672 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | l, b = input().split()
length = int(l)
breadth = int(b)
number_of_squares = length*breadth
print(number_of_squares // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
l, b = input().split()
length = int(l)
breadth = int(b)
number_of_squares = length*breadth
print(number_of_squares // 2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,699,026,146 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 307,200 | q = input()
w = input()
if q != w:
print(max(len(q), len(w)))
else:
print(-1) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
q = input()
w = input()
if q != w:
print(max(len(q), len(w)))
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n100101101... | 1,688,147,127 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | import sys
def solve(airports, a, b):
return 0 if airports[a - 1] == airports[b - 1] else 1
def main():
input_data = sys.stdin.readlines()
a = int(input_data[0])
b = int(input_data[1])
airports = input_data[2].strip()
print(solve(airports, a, b))
if __name__ == '__main__':
... | Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o... | ```python
import sys
def solve(airports, a, b):
return 0 if airports[a - 1] == airports[b - 1] else 1
def main():
input_data = sys.stdin.readlines()
a = int(input_data[0])
b = int(input_data[1])
airports = input_data[2].strip()
print(solve(airports, a, b))
if __name__ == '__... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,646,464,553 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, k = list(map(int,input().split()))
k1 = 0
k2 = set(map(str, range(k+1)))
for x in range(n):
z = set(input())
if k2.is_subset(z):
c += 1
print(k1) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = list(map(int,input().split()))
k1 = 0
k2 = set(map(str, range(k+1)))
for x in range(n):
z = set(input())
if k2.is_subset(z):
c += 1
print(k1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
250 | A | Paper Work | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | 500 | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 1,699,719,243 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 69 | 124 | 0 | n = int(input())
a = list(map(int, input().split()))
b = []
cn = 0
count = 0
for i in range(len(a)):
if a[i] < 0 and cn == 2:
b.append(count)
cn = 1
count = 1
else:
count += 1
if a[i] < 0:
cn += 1
b.append(count)
print(len(b))
print(*b)
| Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know tha... | ```python
n = int(input())
a = list(map(int, input().split()))
b = []
cn = 0
count = 0
for i in range(len(a)):
if a[i] < 0 and cn == 2:
b.append(count)
cn = 1
count = 1
else:
count += 1
if a[i] < 0:
cn += 1
b.append(count)
print(len(b))
p... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,618,191,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | string = str(input())
counter = 0
l = ['0','2','4','6','8','a','i','o','u','e']
for ch in string:
if ch in l:
counter += 1
print(counter)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
string = str(input())
counter = 0
l = ['0','2','4','6','8','a','i','o','u','e']
for ch in string:
if ch in l:
counter += 1
print(counter)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,665,475,520 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | s = input()
s1 = input()
s2 = input()
print(s1[2])
if s[0]==s2[2] and s[1]==s2[1] and s[2]==s2[0] and s1[0]==s1[2]:
print('YES')
else:
print('NO') | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
s = input()
s1 = input()
s2 = input()
print(s1[2])
if s[0]==s2[2] and s[1]==s2[1] and s[2]==s2[0] and s1[0]==s1[2]:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n5100... | 1,524,930,550 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 171 | 14,848,000 | v = 'aiouey'
n = int(input())
a = list(map(int,input().split()))
fr = 1000000
mi = 0
for i in a:
mi = max(min(fr-i,i-1),mi)
print(mi) | Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di... | ```python
v = 'aiouey'
n = int(input())
a = list(map(int,input().split()))
fr = 1000000
mi = 0
for i in a:
mi = max(min(fr-i,i-1),mi)
print(mi)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,612,248,813 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 204,800 | s1 = set()
s2 = set()
n = int(input())
arr = []
for i in range(n):
line = input()
line = list(line)
arr.append(line)
for i in range(n):
for j in range(n):
if i == j:
s1.add(arr[i][j])
elif i + j == n-1:
s2.add(arr[i][j])
flag = True
if len(s1) == len(s2):
f... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
s1 = set()
s2 = set()
n = int(input())
arr = []
for i in range(n):
line = input()
line = list(line)
arr.append(line)
for i in range(n):
for j in range(n):
if i == j:
s1.add(arr[i][j])
elif i + j == n-1:
s2.add(arr[i][j])
flag = True
if len(s1) == len(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,604,147,008 | 388 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | s = input()
k = int(input())
ans = 'YES'
for i in range(k):
x = s[(len(s) // k) * i: (len(s) // k) * (i + 1)]
if x != x[::-1]:
ans = 'NO'
print(ans) | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
s = input()
k = int(input())
ans = 'YES'
for i in range(k):
x = s[(len(s) // k) * i: (len(s) // k) * (i + 1)]
if x != x[::-1]:
ans = 'NO'
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,566,678,724 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | s=input()
ans=0
for i in range(0,len(s)):
if s[i]=='1' or s[i]=='3' or s[i]=='5' or s[i]=='7' or s[i]=='9' or s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
ans+=1
print(ans) | Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s=input()
ans=0
for i in range(0,len(s)):
if s[i]=='1' or s[i]=='3' or s[i]=='5' or s[i]=='7' or s[i]=='9' or s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
ans+=1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,664,004,042 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 512,000 | n = int(input())
s = input()
keyToBuy = 0
keys = []
for i in range(len(s)):
if i % 2 == 0:
keys.append(s[i])
else:
key = s[i].lower()
if key in keys:
keys.remove(key)
else:
keyToBuy += 1
print(keyToBuy)
| Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n = int(input())
s = input()
keyToBuy = 0
keys = []
for i in range(len(s)):
if i % 2 == 0:
keys.append(s[i])
else:
key = s[i].lower()
if key in keys:
keys.remove(key)
else:
keyToBuy += 1
print(keyToBuy)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
39 | D | Cubical Planet | PROGRAMMING | 1,100 | [
"math"
] | D. Cubical Planet | 2 | 64 | You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the mom... | The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. | Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". | [
"0 0 0\n0 1 0\n",
"1 1 0\n0 1 0\n",
"0 0 0\n1 1 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "0 0 0\n1 0 0",
"output": "YES"
},
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 ... | 1,699,435,605 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | # LUOGU_RID: 133989877
a=[i for i in map(int,input().split( ))]
b=[i for i in map(int,input().split( ))]
for i in range(0,3):
if a[i]==b[i]:
for j in rang(i,3):
if a[j]==b[j]:
break
print(YES)
else:
print(NO) | Title: Cubical Planet
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite v... | ```python
# LUOGU_RID: 133989877
a=[i for i in map(int,input().split( ))]
b=[i for i in map(int,input().split( ))]
for i in range(0,3):
if a[i]==b[i]:
for j in rang(i,3):
if a[j]==b[j]:
break
print(YES)
else:
print(NO)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,651,946,304 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 156 | 5,120,000 | import sys
input = sys.stdin.readline
n = int(input())
w = input()[:-1].split()
b, c = 0, 0
for i in range(n):
if w[i] == '25':
c += 1
elif w[i] == '50':
b += 1
c -= 1
else:
if b > 0:
b -= 1
c -= 1
else:
c -= 3
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = input()[:-1].split()
b, c = 0, 0
for i in range(n):
if w[i] == '25':
c += 1
elif w[i] == '50':
b += 1
c -= 1
else:
if b > 0:
b -= 1
c -= 1
else:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «... | В первой строке входных данных записаны два целых числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=100) — количество строк и столбцов в схематичном изображении соответственно.
Далее следуют *n* строк по *m* символов в каждой — схематичное изображение горного хребта. Каждый символ схематичного изображения — это либо «.», либо «*».... | Выведите через пробел два целых числа:
- величину наибольшего подъёма за день (или 0, если в профиле горного хребта нет ни одного подъёма), - величину наибольшего спуска за день (или 0, если в профиле горного хребта нет ни одного спуска). | [
"6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n",
"5 5\n....*\n...**\n..***\n.****\n*****\n",
"8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******\n"
] | [
"3 4\n",
"1 0\n",
"6 2\n"
] | В первом тестовом примере высоты гор равны: 3, 4, 1, 1, 2, 1, 1, 1, 2, 5, 1. Наибольший подъем равен 3 и находится между горой номер 9 (её высота равна 2) и горой номер 10 (её высота равна 5). Наибольший спуск равен 4 и находится между горой номер 10 (её высота равна 5) и горой номер 11 (её высота равна 1).
Во втором ... | 0 | [
{
"input": "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********",
"output": "3 4"
},
{
"input": "5 5\n....*\n...**\n..***\n.****\n*****",
"output": "1 0"
},
{
"input": "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******",
"outpu... | 1,458,746,502 | 1,302 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 77 | 4,608,000 | n, m = map(int, input().split())
lines = [input() for i in range(n)]
profile = [[symbol for symbol in line.strip()] for line in lines[1:]]
heights = [[line[i] for line in profile].count('*') for i in range(m)]
max_up = 0
max_down = 0
for i in range(1, len(heights)):
delta = heights[i] - heights[i-1]
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо... | ```python
n, m = map(int, input().split())
lines = [input() for i in range(n)]
profile = [[symbol for symbol in line.strip()] for line in lines[1:]]
heights = [[line[i] for line in profile].count('*') for i in range(m)]
max_up = 0
max_down = 0
for i in range(1, len(heights)):
delta = heights[i] - heigh... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
847 | K | Travel Cards | PROGRAMMING | 1,800 | [
"greedy",
"implementation",
"sortings"
] | null | null | In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t... | The first line contains five integers *n*,<=*a*,<=*b*,<=*k*,<=*f* (1<=≤<=*n*<=≤<=300, 1<=≤<=*b*<=<<=*a*<=≤<=100, 0<=≤<=*k*<=≤<=300, 1<=≤<=*f*<=≤<=1000) where:
- *n* — the number of Polycarp trips, - *a* — the cost of a regualar single trip, - *b* — the cost of a trip after a transshipment, - *k* — the maximum n... | Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than *k* travel cards. | [
"3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank\n",
"4 2 1 300 1000\na A\nA aa\naa AA\nAA a\n"
] | [
"11\n",
"5\n"
] | In the first example Polycarp can buy travel card for the route "BerBank <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ecc94b07e73defe233bfe831f3977337706a2d27.png" style="max-width: 100.0%;max-height: 100.0%;"/> University" and spend 8 burles. Note that his second trip "University" <img ... | 0 | [
{
"input": "3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank",
"output": "11"
},
{
"input": "4 2 1 300 1000\na A\nA aa\naa AA\nAA a",
"output": "5"
},
{
"input": "2 2 1 0 1\naca BCBA\nBCBA aca",
"output": "3"
},
{
"input": "2 2 1 2 1\nBDDB C\nC BDDB",
... | 1,648,281,986 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 92 | 0 | n,a,b,k,f = map(int,input().split())
poezd = {}
sum = 0
prev = ""
for i in range(n):
ost =ost_key= input()
ost_arr = ost.split()
if ost not in poezd.keys():
if ost_arr[1]+" "+ost_arr[0] in poezd.keys():
ost_key = ost_arr[1]+" "+ost_arr[0]
else:
poezd[ost_ke... | Title: Travel Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus... | ```python
n,a,b,k,f = map(int,input().split())
poezd = {}
sum = 0
prev = ""
for i in range(n):
ost =ost_key= input()
ost_arr = ost.split()
if ost not in poezd.keys():
if ost_arr[1]+" "+ost_arr[0] in poezd.keys():
ost_key = ost_arr[1]+" "+ost_arr[0]
else:
po... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,647,110,680 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 61 | 1,945,600 | for _ in range(int(input())):
n = int(input())
result = n * (n + 1) // 2
p = 1
while p <= n:
result -= 2 * p
p *= 2
print(result)
| Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
for _ in range(int(input())):
n = int(input())
result = n * (n + 1) // 2
p = 1
while p <= n:
result -= 2 * p
p *= 2
print(result)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,681,409,632 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 0 | list = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9,
'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17,
'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
input = input()
sum = 0
temp = 0
if ((list[input[0]] - li... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
list = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9,
'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17,
'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
input = input()
sum = 0
temp = 0
if ((list[inpu... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,548,493,665 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n=int(input())
res=0
arr=[4,7,44,47,74,77]
c=0
if(n>2):
f=n//(100)
res+=(f*6)
f=n%(f*100)
for i in range (6):
if f==arr[i]:
c=i+1
break
res+=c
print (res)
else:
for i in range (6):
if n==arr[i]:
c=i+1
break
... | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
n=int(input())
res=0
arr=[4,7,44,47,74,77]
c=0
if(n>2):
f=n//(100)
res+=(f*6)
f=n%(f*100)
for i in range (6):
if f==arr[i]:
c=i+1
break
res+=c
print (res)
else:
for i in range (6):
if n==arr[i]:
c=i+1
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
452 | B | 4-point polyline | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"geometry",
"trees"
] | null | null | You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of... | The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points. | Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10<=-<=6 precision. | [
"1 1\n",
"0 10\n"
] | [
"1 1\n0 0\n1 0\n0 1\n",
"0 1\n0 10\n0 0\n0 9\n"
] | none | 1,000 | [
{
"input": "1 1",
"output": "0 0\n1 1\n0 1\n1 0"
},
{
"input": "0 10",
"output": "0 1\n0 10\n0 0\n0 9"
},
{
"input": "10 10",
"output": "10 9\n0 0\n10 10\n1 0"
},
{
"input": "100 100",
"output": "0 1\n100 100\n0 0\n99 100"
},
{
"input": "10 100",
"output": "9 ... | 1,406,482,538 | 2,138 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | # -- code beginning
n, m = map(int, input().split())
if (m < n and m > 0) or n == 0:
print("0 1\n%d %d\n0 0\n%d %d" % (n, m, n, m - 1))
else:
print("1 0\n%d %d\n0 0\n%d %d" % (n, m, n - 1, m))
# -- code ending
| Title: 4-point polyline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyl... | ```python
# -- code beginning
n, m = map(int, input().split())
if (m < n and m > 0) or n == 0:
print("0 1\n%d %d\n0 0\n%d %d" % (n, m, n, m - 1))
else:
print("1 0\n%d %d\n0 0\n%d %d" % (n, m, n - 1, m))
# -- code ending
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,451,179,536 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 482 | 21,401,600 | n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
s=0
for i in range(len(a)):
if i==len(a)-1:
s+=(i+1)*a[i]
else:
s+=(i+2)*a[i]
print(s)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
s=0
for i in range(len(a)):
if i==len(a)-1:
s+=(i+1)*a[i]
else:
s+=(i+2)*a[i]
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic pro... | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output... | 1,572,589,204 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | input(); *a, b, c = input().split()
print(2 * int(c) - int(b))
| Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya ... | ```python
input(); *a, b, c = input().split()
print(2 * int(c) - int(b))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.