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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,637,227,223 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | vowels="a","e","i","o","u"
consonants="b","c","d","f","g","h","j","k","l","m","p","q","r","s","t","v","w","x","y","z"
count_yes=0
count_no=0
text=input()
a=len(text)
for i in range(0,a-1):
if text[i]=="n":
if text[i+1] in consonants or text[i+1] in vowels:
count_yes+=1
elif text[i]... | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
vowels="a","e","i","o","u"
consonants="b","c","d","f","g","h","j","k","l","m","p","q","r","s","t","v","w","x","y","z"
count_yes=0
count_no=0
text=input()
a=len(text)
for i in range(0,a-1):
if text[i]=="n":
if text[i+1] in consonants or text[i+1] in vowels:
count_yes+=1
el... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
327 | B | Hungry Sequence | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in i... | The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | 500 | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ... | 1,695,910,356 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 154 | 10,854,400 | n=int(input())
ans=[]
n3=n*3
for i in range(n):
ans+=[str(n3+i)]
print(' '.join(ans)) | Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1... | ```python
n=int(input())
ans=[]
n3=n*3
for i in range(n):
ans+=[str(n3+i)]
print(' '.join(ans))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,599,068,744 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 0 | n = int(input())
m = 1
while True:
aux = n*m + 1
i = 2
while True:
if aux % i == 0:
break
i += 1
if i == aux:
m += 1
else:
print(m)
break
| Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
n = int(input())
m = 1
while True:
aux = n*m + 1
i = 2
while True:
if aux % i == 0:
break
i += 1
if i == aux:
m += 1
else:
print(m)
break
``` | 3 | 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,692,094 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 0 | n=int(input())
s=input()
for i in range (n):
l=s.find('UR')
m=s.find('RU')
if(l>m):
x=s.replace('UR','D')
y=x.replace('RU','D')
if(m>l):
x=s.replace('RU','D')
y=x.replace('UR','D')
print(len(y)) | 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())
s=input()
for i in range (n):
l=s.find('UR')
m=s.find('RU')
if(l>m):
x=s.replace('UR','D')
y=x.replace('RU','D')
if(m>l):
x=s.replace('RU','D')
y=x.replace('UR','D')
print(len(y))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,551,572,783 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include<stack>
#include<string.>
using namespace std;
int main()
{stack<char> pile;
int n=0;
string ch;
cin>>ch;
for (int i=0;i<ch.length();i++)
{
if(ch[i]=='(')
pile.push(ch[i]);
else if (ch[i]==')' && !pile.empty())
{
pile... | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
#include <iostream>
#include<stack>
#include<string.>
using namespace std;
int main()
{stack<char> pile;
int n=0;
string ch;
cin>>ch;
for (int i=0;i<ch.length();i++)
{
if(ch[i]=='(')
pile.push(ch[i]);
else if (ch[i]==')' && !pile.empty())
{
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,689,005,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n=int(input())
pi=input().split()
d={}
ls=[]
for i in range(1,n+1):
d[i]=pi[i-1]
for k in sorted(d,key=d.__getitem__):
ls.append(str(k))
print(' '.join(ls))
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
pi=input().split()
d={}
ls=[]
for i in range(1,n+1):
d[i]=pi[i-1]
for k in sorted(d,key=d.__getitem__):
ls.append(str(k))
print(' '.join(ls))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,630,168,755 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 22,220,800 | def partition(T, p, r):
pivot = T[r]
i = p - 1
for j in range(p, r):
if T[j] <= pivot:
i += 1
T[i], T[j] = T[j], T[i]
T[i + 1], T[r] = T[r], T[i + 1]
return i + 1
def quicksort(T, p, r):
while p < r:
q = partition(T, p, r)
if q - p ... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
def partition(T, p, r):
pivot = T[r]
i = p - 1
for j in range(p, r):
if T[j] <= pivot:
i += 1
T[i], T[j] = T[j], T[i]
T[i + 1], T[r] = T[r], T[i + 1]
return i + 1
def quicksort(T, p, r):
while p < r:
q = partition(T, p, r)
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,592,590,835 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 140 | 0 | a , b , c = input().split()
a = int(a)
if c == 'month':
if a == 30 :
print('11')
elif a == 31 :
print('7')
else:
print('12')
else:
if a == 5 or a == 6 :
print('53')
else:
print('52') | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
a , b , c = input().split()
a = int(a)
if c == 'month':
if a == 30 :
print('11')
elif a == 31 :
print('7')
else:
print('12')
else:
if a == 5 or a == 6 :
print('53')
else:
print('52')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,690,727,100 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 108 | 2,457,600 | tania = input()
jornal = input()
dict_tanya = {}
dict_jornal = {}
for char1 in tania:
dict_tanya[char1] = dict_tanya.get(char1, 0) + 1
for char2 in jornal:
dict_jornal[char2] = dict_jornal.get(char2, 0) + 1
cont_1 = 0
cont_2 = 0
for char, count in dict_tanya.items():
if char in dict_jor... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
tania = input()
jornal = input()
dict_tanya = {}
dict_jornal = {}
for char1 in tania:
dict_tanya[char1] = dict_tanya.get(char1, 0) + 1
for char2 in jornal:
dict_jornal[char2] = dict_jornal.get(char2, 0) + 1
cont_1 = 0
cont_2 = 0
for char, count in dict_tanya.items():
if char i... | 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,595,179,222 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 6,963,200 | def sol(arr, n):
sequence = [arr[i] - arr[i + 1] for i in range(n - 1)]
mid = sum(sequence) / (n - 1)
for i in range(n):
if sequence[i] != mid:
return i + 2
n = int(input())
arr = input().split()
for i in range(len(arr)):
arr[i] = int(arr[i])
print(sol(arr... | 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
def sol(arr, n):
sequence = [arr[i] - arr[i + 1] for i in range(n - 1)]
mid = sum(sequence) / (n - 1)
for i in range(n):
if sequence[i] != mid:
return i + 2
n = int(input())
arr = input().split()
for i in range(len(arr)):
arr[i] = int(arr[i])
pri... | 0 | MatrixStudio/Codeforces-Python-Submissions |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,587,934,830 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 22 | 280 | 1,843,200 | import io, os
import sys
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def next_str():
global tokens, tokens_next
while tokens_next >= len(token... | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
import io, os
import sys
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def next_str():
global tokens, tokens_next
while tokens_next >=... | 0 | MatrixStudio/Codeforces-Python-Submissions |
143 | B | Help Kingdom of Far Far Away 2 | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio... | The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:
- The number's notation only contains characters from the set {"0" – "9... | Print the number given in the input in the financial format by the rules described in the problem statement. | [
"2012\n",
"0.000\n",
"-0.00987654321\n",
"-12345678.9\n"
] | [
"$2,012.00",
"$0.00",
"($0.00)",
"($12,345,678.90)"
] | Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financi... | 1,000 | [
{
"input": "2012",
"output": "$2,012.00"
},
{
"input": "0.000",
"output": "$0.00"
},
{
"input": "-0.00987654321",
"output": "($0.00)"
},
{
"input": "-12345678.9",
"output": "($12,345,678.90)"
},
{
"input": "0.99999999999999999999",
"output": "$0.99"
},
{
... | 1,663,208,828 | 2,147,483,647 | PyPy 3 | OK | TESTS | 100 | 186 | 0 | def parse_int(num:int):
to_str=str(num)
count=0
sumstr=''
for one_str in to_str[::-1]:
count += 1
if count %3==0 and count != len(to_str):
one_str = ',' + one_str
sumstr = one_str + sumstr
else:
sumstr = one_str + sumstr
return s... | Title: Help Kingdom of Far Far Away 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more e... | ```python
def parse_int(num:int):
to_str=str(num)
count=0
sumstr=''
for one_str in to_str[::-1]:
count += 1
if count %3==0 and count != len(to_str):
one_str = ',' + one_str
sumstr = one_str + sumstr
else:
sumstr = one_str + sumstr
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
195 | B | After Training | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. | Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. | [
"4 3\n",
"3 1\n"
] | [
"2\n1\n3\n2\n",
"1\n1\n1\n"
] | none | 1,000 | [
{
"input": "4 3",
"output": "2\n1\n3\n2"
},
{
"input": "3 1",
"output": "1\n1\n1"
},
{
"input": "10 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2"
},
{
"input": "6 5",
"output": "3\n2\n4\n1\n5\n3"
},
{
"input": "2 6",
"output": "3\n4"
},
{
"input": "5 2"... | 1,610,543,072 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 372 | 8,601,600 | from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr():
n,k=lst()
ans=[(1+k)//2]
ln=1;val=1
while ln<k:
ans+=[(1+k)//2-(val if k&1 else -val)]
ln+=1
if ln==k:break
ans+=[(1+k)//2+(v... | Title: After Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are posi... | ```python
from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr():
n,k=lst()
ans=[(1+k)//2]
ln=1;val=1
while ln<k:
ans+=[(1+k)//2-(val if k&1 else -val)]
ln+=1
if ln==k:break
ans+=[(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,639,044,262 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 |
def main():
n, a, b = map(int, input().split())
x = find_x(n, a, b)
print(x)
def find_x(plates, a_pieces, b_pieces):
x = (a_pieces + b_pieces) // plates
while not x_works(plates, a_pieces, b_pieces, x):
x -= 1
return x
def x_works(plates, a_pieces, b_pieces, x):
... | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
def main():
n, a, b = map(int, input().split())
x = find_x(n, a, b)
print(x)
def find_x(plates, a_pieces, b_pieces):
x = (a_pieces + b_pieces) // plates
while not x_works(plates, a_pieces, b_pieces, x):
x -= 1
return x
def x_works(plates, a_pieces, b_pieces,... | 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,674,311,925 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x = (input())
cur = ""
for idx, char in enumerate(x):
if int(char) == 9 and idx == 0:
continue
elif int(char) > 4:
cur += str(9 - int(char))
else:
cur += char
print(cur)
| 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())
cur = ""
for idx, char in enumerate(x):
if int(char) == 9 and idx == 0:
continue
elif int(char) > 4:
cur += str(9 - int(char))
else:
cur += char
print(cur)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,623,214,783 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | c=0
n=int(input())
a,b=map(int,input().split())
c=a
for _ in range(n-1):
a,b=map(int,input().split())
if (c-a)/b>0:
c+=math.ceil((c-a)/b)
else:
c+=1
print(c)
| Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
c=0
n=int(input())
a,b=map(int,input().split())
c=a
for _ in range(n-1):
a,b=map(int,input().split())
if (c-a)/b>0:
c+=math.ceil((c-a)/b)
else:
c+=1
print(c)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,596,622,930 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 109 | 6,963,200 | from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
b=list(combinations(a,n-1))
s=[]
c=[]
for val in b:
if val[0]==a[0] and val[-1]==a[-1]:
c.append(val)
for val in c:
f=0
for i in range(len(val)-1):
if f==0:
diff=(val[i+1]-va... | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
b=list(combinations(a,n-1))
s=[]
c=[]
for val in b:
if val[0]==a[0] and val[-1]==a[-1]:
c.append(val)
for val in c:
f=0
for i in range(len(val)-1):
if f==0:
diff=(v... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
803 | D | Magazine Ad | PROGRAMMING | 1,900 | [
"binary search",
"greedy"
] | null | null | The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th... | The first line contains number *k* (1<=≤<=*k*<=≤<=105).
The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. | Output minimal width of the ad. | [
"4\ngarage for sa-le\n",
"4\nEdu-ca-tion-al Ro-unds are so fun\n"
] | [
"7\n",
"10\n"
] | Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
The second example: | 0 | [
{
"input": "4\ngarage for sa-le",
"output": "7"
},
{
"input": "4\nEdu-ca-tion-al Ro-unds are so fun",
"output": "10"
},
{
"input": "1\nj",
"output": "1"
},
{
"input": "10\nb",
"output": "1"
},
{
"input": "1\nQGVsfZevMD",
"output": "10"
},
{
"input": "1... | 1,667,862,004 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | def f(q, a):
now_str = ""
cnt_str = 1
for i in a:
if len(i) + len(now_str) + 1 < q:
now_str += i + " "
elif len(i) + len(now_str) + 1 == q:
cnt_str += 1
now_str = ""
else:
cnt_str += 1
now_str = i + " "
return cnt_str
k = int(input())
a = (input().replace("-", " ")).split()
l... | Title: Magazine Ad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen... | ```python
def f(q, a):
now_str = ""
cnt_str = 1
for i in a:
if len(i) + len(now_str) + 1 < q:
now_str += i + " "
elif len(i) + len(now_str) + 1 == q:
cnt_str += 1
now_str = ""
else:
cnt_str += 1
now_str = i + " "
return cnt_str
k = int(input())
a = (input().replace("-", " ")).... | 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,651,156,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | import math
a,b = map(int,input().split())
print(0 if a > 100 and b > 100 else str(math.factorial(b) // math.factorial(a))[-1]) | 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
import math
a,b = map(int,input().split())
print(0 if a > 100 and b > 100 else str(math.factorial(b) // math.factorial(a))[-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
478 | A | Initial Bet | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program ... | The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=≤<=100). | Print the only line containing a single positive integer *b* — the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity). | [
"2 5 4 0 4\n",
"4 5 9 2 1\n"
] | [
"3\n",
"-1\n"
] | In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to... | 500 | [
{
"input": "2 5 4 0 4",
"output": "3"
},
{
"input": "4 5 9 2 1",
"output": "-1"
},
{
"input": "0 0 0 0 0",
"output": "-1"
},
{
"input": "1 2 1 2 3",
"output": "-1"
},
{
"input": "100 0 0 0 0",
"output": "20"
},
{
"input": "2 3 4 5 6",
"output": "4"... | 1,689,095,192 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 62 | 0 | a,b,c,d,e = map(int,input().split())
s = a+b+c+d+e
k = s / 5
if int(k) == k and k > 0:
print(int(k))
else:
print(-1)
| Title: Initial Bet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for severa... | ```python
a,b,c,d,e = map(int,input().split())
s = a+b+c+d+e
k = s / 5
if int(k) == k and k > 0:
print(int(k))
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,691,672,506 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 61 | 0 | # Wadea #
a1,a2 = map(int,input().split())
c = 0
if a1 == 1 and a2 == 1:
print(0)
else:
while a1 != 0 and a2 != 0:
if a1 <= a2:
a1 += 1
a2 -= 2
elif a2 < a1:
a2 += 1
a1 -= 2
c += 1
print(c)
| Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
# Wadea #
a1,a2 = map(int,input().split())
c = 0
if a1 == 1 and a2 == 1:
print(0)
else:
while a1 != 0 and a2 != 0:
if a1 <= a2:
a1 += 1
a2 -= 2
elif a2 < a1:
a2 += 1
a1 -= 2
c += 1
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
383 | B | Volcanoes | PROGRAMMING | 2,500 | [
"binary search",
"implementation",
"sortings",
"two pointers"
] | null | null | Iahub got lost in a very big desert. The desert can be represented as a *n*<=×<=*n* square matrix, where each cell is a zone of the desert. The cell (*i*,<=*j*) represents the cell at row *i* and column *j* (1<=≤<=*i*,<=*j*<=≤<=*n*). Iahub can go from one cell (*i*,<=*j*) only down or right, that is to cells (*i*<=+<=1... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=109) and *m* (1<=≤<=*m*<=≤<=105). Each of the next *m* lines contains a pair of integers, *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*), representing the coordinates of the volcanoes.
Consider matrix rows are numbered from 1 to *n* from top to bottom, and matrix columns ... | Print one integer, the minimum time in which Iahub can arrive at cell (*n*,<=*n*). If no solution exists (there is no path to the final cell), print -1. | [
"4 2\n1 3\n1 4\n",
"7 8\n1 6\n2 6\n3 5\n3 6\n4 3\n5 1\n5 2\n5 3\n",
"2 2\n1 2\n2 1\n"
] | [
"6\n",
"12\n",
"-1\n"
] | Consider the first sample. A possible road is: (1, 1) → (1, 2) → (2, 2) → (2, 3) → (3, 3) → (3, 4) → (4, 4). | 1,500 | [
{
"input": "4 2\n1 3\n1 4",
"output": "6"
},
{
"input": "7 8\n1 6\n2 6\n3 5\n3 6\n4 3\n5 1\n5 2\n5 3",
"output": "12"
},
{
"input": "2 2\n1 2\n2 1",
"output": "-1"
},
{
"input": "1000000000 9\n1 2\n3 1\n3 2\n999999998 999999999\n999999998 1000000000\n999999999 999999999\n9999... | 1,449,579,098 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | # n, m = (4, 2)
# v = [(1, 3), (1, 4)]
# # v = []
# n, m = (7, 8)
# v =[(1, 6), (2, 6), (3, 5), (3, 6), (4, 3), (5, 1), (5, 2), (5, 3)]
# n, m = (2, 2)
# v = [(1, 2), (2, 1)]
# n = input()
# a = [map(int, raw_input().split()) for i in xrange(n)]
# print sum([[j[1] for j in a].count(i[0]) for i in a])
... | Title: Volcanoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub got lost in a very big desert. The desert can be represented as a *n*<=×<=*n* square matrix, where each cell is a zone of the desert. The cell (*i*,<=*j*) represents the cell at row *i* and column *j* (1<=≤<=*i*,<=*j*<=... | ```python
# n, m = (4, 2)
# v = [(1, 3), (1, 4)]
# # v = []
# n, m = (7, 8)
# v =[(1, 6), (2, 6), (3, 5), (3, 6), (4, 3), (5, 1), (5, 2), (5, 3)]
# n, m = (2, 2)
# v = [(1, 2), (2, 1)]
# n = input()
# a = [map(int, raw_input().split()) for i in xrange(n)]
# print sum([[j[1] for j in a].count(i[0]) for ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
467 | B | Fedor and New Game | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20; 1<=≤<=*m*<=≤<=1000).
The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≤<=*x**i*<=≤<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player. | Print a single integer — the number of Fedor's potential friends. | [
"7 3 1\n8\n5\n111\n17\n",
"3 3 3\n1\n2\n3\n4\n"
] | [
"0\n",
"3\n"
] | none | 1,000 | [
{
"input": "7 3 1\n8\n5\n111\n17",
"output": "0"
},
{
"input": "3 3 3\n1\n2\n3\n4",
"output": "3"
},
{
"input": "4 2 2\n5\n6\n7",
"output": "2"
},
{
"input": "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10",
"output": "7"
},
{
"input": "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1",
"out... | 1,687,881,810 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n, m, k = map(int, input().split())
lst = []
for i in range(m+1):
lst.append(int(input()))
p = lst.pop()
ans = 0
for i in lst:
qualifier = format(i^p, f'0{n}b')
if qualifier.count('1') <= k:
ans += 1
print(ans)
| Title: Fedor and New Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Play... | ```python
n, m, k = map(int, input().split())
lst = []
for i in range(m+1):
lst.append(int(input()))
p = lst.pop()
ans = 0
for i in lst:
qualifier = format(i^p, f'0{n}b')
if qualifier.count('1') <= k:
ans += 1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,620,037,311 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 296 | 11,571,200 | import string
import random
n,k = [int(i) for i in input().split()]
letters = string.ascii_lowercase
password = ""
while n > 0:
if k > 0:
password = password + random.choice(letters)
k -= 1
elif k <=0:
password = password + password[-1]
n -= 1
print(password)
| Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import string
import random
n,k = [int(i) for i in input().split()]
letters = string.ascii_lowercase
password = ""
while n > 0:
if k > 0:
password = password + random.choice(letters)
k -= 1
elif k <=0:
password = password + password[-1]
n -= 1
print(password)
... | 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,699,164,073 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | word = input().lower()
wordlist = []
for i in word:
wordlist.append(i)
vowels = ["a", "o", "y", "e", "u", "i"]
for i in range(len(wordlist)-1):
for j in vowels:
if wordlist[i] == j:
wordlist.remove(j)
for i in wordlist:
print(i)
| 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
word = input().lower()
wordlist = []
for i in word:
wordlist.append(i)
vowels = ["a", "o", "y", "e", "u", "i"]
for i in range(len(wordlist)-1):
for j in vowels:
if wordlist[i] == j:
wordlist.remove(j)
for i in wordlist:
print(i)
``` | -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,641,119,776 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n, m = map(int, input().split())
c = 0
k = [str(x) for x in range(m+1)]
for _ in range(n):
flag = True
a = input()
for i in k:
if i not in a:
flag = False
break
if flag:
c += 1
print(c) | 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, m = map(int, input().split())
c = 0
k = [str(x) for x in range(m+1)]
for _ in range(n):
flag = True
a = input()
for i in k:
if i not in a:
flag = False
break
if flag:
c += 1
print(c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,632,836,675 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n, x = map(int, input().split())
arr = list(map(int, input().split()))
ans1 = 0
ans2 = 0
tmp1 = x
tmp2 = x
for i in range(n):
ans1 += arr[i] * tmp1
tmp1 -= 1
arr.sort()
for i in range(n):
ans2 += arr[i] * tmp2
tmp2 -= 1
if ans1 > 0 and ans2 > 0:
print(min(ans1, ans2))
else:
if an... | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n, x = map(int, input().split())
arr = list(map(int, input().split()))
ans1 = 0
ans2 = 0
tmp1 = x
tmp2 = x
for i in range(n):
ans1 += arr[i] * tmp1
tmp1 -= 1
arr.sort()
for i in range(n):
ans2 += arr[i] * tmp2
tmp2 -= 1
if ans1 > 0 and ans2 > 0:
print(min(ans1, ans2))
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,445,763,933 | 333 | Python 3 | OK | TESTS | 45 | 62 | 0 | s = int(input())
v1 = int(input())
v2 = int(input())
s1 = s*v1
s1 = s1 / (v1+v2)
print(s1)
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
s = int(input())
v1 = int(input())
v2 = int(input())
s1 = s*v1
s1 = s1 / (v1+v2)
print(s1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
113 | B | Petr# | PROGRAMMING | 2,000 | [
"brute force",
"data structures",
"hashing",
"strings"
] | B. Petr# | 2 | 256 | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* and ending with the *s**end* (it is possible *s**begin*<==<=*s**end*), the given string... | The input file consists of three lines. The first line contains string *t*. The second and the third lines contain the *s**begin* and *s**end* identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. | Output the only number — the amount of different substrings of *t* that start with *s**begin* and end with *s**end*. | [
"round\nro\nou\n",
"codeforces\ncode\nforca\n",
"abababab\na\nb\n",
"aba\nab\nba\n"
] | [
"1\n",
"0\n",
"4\n",
"1\n"
] | In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab.
In the fourth sample identificators intersect. | 1,000 | [
{
"input": "round\nro\nou",
"output": "1"
},
{
"input": "codeforces\ncode\nforca",
"output": "0"
},
{
"input": "abababab\na\nb",
"output": "4"
},
{
"input": "aba\nab\nba",
"output": "1"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nabc\nxyz",
"output": "1"
},
... | 1,657,363,841 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef string str;
struct H{
long long h[2002],ppw[2002];
const int m, p;
H(int m=1000000007,int p=103):m(m),p(p){};
void prc(int n){
ppw[0]=1;
for(int i=1;i<n;i++){
ppw[i]=ppw[i-1]*p%m;
}
}
long long ... | Title: Petr#
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* ... | ```python
#include<bits/stdc++.h>
using namespace std;
typedef string str;
struct H{
long long h[2002],ppw[2002];
const int m, p;
H(int m=1000000007,int p=103):m(m),p(p){};
void prc(int n){
ppw[0]=1;
for(int i=1;i<n;i++){
ppw[i]=ppw[i-1]*p%m;
}
}
... | -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,634,475,034 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | m=int(input())
n=int(input())
if 1<=n<=16 and 1<=m<=16:
print(int((m*n)/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
m=int(input())
n=int(input())
if 1<=n<=16 and 1<=m<=16:
print(int((m*n)/2))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
234 | C | Weather | PROGRAMMING | 1,300 | [
"dp",
"implementation"
] | null | null | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single space... | Print a single integer — the answer to the given task. | [
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] | [
"1\n",
"2\n"
] | Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number. | 0 | [
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "... | 1,620,637,168 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 124 | 6,963,200 |
# get the data
with open('input.txt') as fh:
n = int(fh.readline()) # nums of temps
temps = fh.readline().split() # list of temps
x = [int(i) for i in temps]
zero = 0
z = []
for i in x:
if i != 0:
z.append(i)
else:
zero += 1
z_copy = z[:]
z_copy.sort()
counter = 0
i = 0
while True:
... | Title: Weather
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to ... | ```python
# get the data
with open('input.txt') as fh:
n = int(fh.readline()) # nums of temps
temps = fh.readline().split() # list of temps
x = [int(i) for i in temps]
zero = 0
z = []
for i in x:
if i != 0:
z.append(i)
else:
zero += 1
z_copy = z[:]
z_copy.sort()
counter = 0
i = 0
whil... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,666,867,758 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 8,396,800 | n = int(input())
b = list(map(int, input().split()))
b.sort()
b[:]=(x for x in b if x != max(b))
b[:]=(x for x in b if x != min(b))
print(len(b))
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n = int(input())
b = list(map(int, input().split()))
b.sort()
b[:]=(x for x in b if x != max(b))
b[:]=(x for x in b if x != min(b))
print(len(b))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,774,409 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 77 | 4,608,000 | import sys
month=[31,28,31,30,31,30,31,31,30,31,30,31]
day=[7,6,5,4,3,2,1]
m,d=map(int,input().split())
d1=day[d-1]
m1=month[m-1]
a = m1 - d1
if( a % 7 == 0 ):
res = 1 + (a / 7)
else:
res =int( 2 + (a / 7))
print (int(res))
| Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
import sys
month=[31,28,31,30,31,30,31,31,30,31,30,31]
day=[7,6,5,4,3,2,1]
m,d=map(int,input().split())
d1=day[d-1]
m1=month[m-1]
a = m1 - d1
if( a % 7 == 0 ):
res = 1 + (a / 7)
else:
res =int( 2 + (a / 7))
print (int(res))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,565,573,853 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 296 | 1,126,400 | def muda_case(letra):
if letra.isupper():
return letra.lower()
else:
return letra.upper()
a = input()
b = input()
contagem1 = { i : 0 for i in a }
contagem2 = { i : 0 for i in b }
for e in a:
contagem1[e] += 1
for e in b:
contagem2[e] += 1
YAY = WHOOPS = 0
for e in contagem1:
i... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
def muda_case(letra):
if letra.isupper():
return letra.lower()
else:
return letra.upper()
a = input()
b = input()
contagem1 = { i : 0 for i in a }
contagem2 = { i : 0 for i in b }
for e in a:
contagem1[e] += 1
for e in b:
contagem2[e] += 1
YAY = WHOOPS = 0
for e in contag... | 3 | 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,651,882,285 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 0 |
w1 = input()
w2 = input()
words = sorted([w1, w2], key=len)
if w1 != w2:
print(len(words[1]))
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
w1 = input()
w2 = input()
words = sorted([w1, w2], key=len)
if w1 != w2:
print(len(words[1]))
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,494,378 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
s = n
for i in range(n):
str = input().split(' ')
if int(str[0])+int(str[1])+int(str[2]) < 2:
s -= 1
print(s) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
s = n
for i in range(n):
str = input().split(' ')
if int(str[0])+int(str[1])+int(str[2]) < 2:
s -= 1
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,685,190,136 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 124 | 0 | n,m=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
li.sort()
i=0
j=n-1
ans=li[j]-li[i]
while j<m:
an=li[j]-li[i]
ans=min(ans,an)
j+=1
i+=1
print(ans)
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
li.sort()
i=0
j=n-1
ans=li[j]-li[i]
while j<m:
an=li[j]-li[i]
ans=min(ans,an)
j+=1
i+=1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,625,679,235 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = input()
inp = input()
arr = list(map(int, inp.split()))
if len(arr) <= 2:
print('YES')
exit()
m = arr[0]
for i in range(1, len(arr)):
if arr[i] != m:
m = abs(arr[i] - m)
break
for i in range(1, len(arr) - 1):
if arr[i] != arr[i + 1] and abs(arr[i] - arr[i + 1]) !=... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
n = input()
inp = input()
arr = list(map(int, inp.split()))
if len(arr) <= 2:
print('YES')
exit()
m = arr[0]
for i in range(1, len(arr)):
if arr[i] != m:
m = abs(arr[i] - m)
break
for i in range(1, len(arr) - 1):
if arr[i] != arr[i + 1] and abs(arr[i] - arr[... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
255 | B | Code Parsing | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime:
1. Find two consecutive characters in the string, such that the first of them equals "y", and the ... | The first line contains a non-empty string *s*.
It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string *s*. | [
"x\n",
"yxyxy\n",
"xxxxxy\n"
] | [
"x\n",
"y\n",
"xxxx\n"
] | In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.
In the second test the transformation will be like this:
1. string "yxyxy" transforms into string "xyyxy"; 1. string "xyyxy" transforms into string "xyxyy"; 1. ... | 1,000 | [
{
"input": "x",
"output": "x"
},
{
"input": "yxyxy",
"output": "y"
},
{
"input": "xxxxxy",
"output": "xxxx"
},
{
"input": "yxyyxyyx",
"output": "yy"
},
{
"input": "yxxyxyx",
"output": "x"
},
{
"input": "xxx",
"output": "xxx"
},
{
"input": "... | 1,579,970,217 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
//delete xy or yx
string s;
int c, c1;
int main() {
cin>>s;
for(int i=0; i<s.size(); i++){
if(s[i]=='y'){
c++;
}
else{
c1++;
}
}
if(c>c1){
for(int j=0; j<c-c1; j++){
cout<<"y";
}
cout<<"\n";
}
... | Title: Code Parsing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime:
1... | ```python
#include <bits/stdc++.h>
using namespace std;
//delete xy or yx
string s;
int c, c1;
int main() {
cin>>s;
for(int i=0; i<s.size(); i++){
if(s[i]=='y'){
c++;
}
else{
c1++;
}
}
if(c>c1){
for(int j=0; j<c-c1; j++){
cout<<"y";
}
cout<<"\n"... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,700,072,907 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | k,n,w=map(int,input().split())
p=max(0,w*(w+1)*k//-n)
print(p) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w=map(int,input().split())
p=max(0,w*(w+1)*k//-n)
print(p)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
686 | B | Little Robber Girl's Zoo | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — number of animals in the robber girl's zoo.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the height of the animal occupying the *i*-th place. | Print the sequence of operations that will rearrange the animals by non-decreasing height.
The output should contain several lines, *i*-th of the lines should contain two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*) — descriptions of segments the robber girl should name. The segments... | [
"4\n2 1 4 3\n",
"7\n36 28 57 39 66 69 68\n",
"5\n1 2 1 2 1\n"
] | [
"1 4\n",
"1 4\n6 7\n",
"2 5\n3 4\n1 4\n1 4\n"
] | Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed. | 1,000 | [
{
"input": "4\n2 1 4 3",
"output": "1 2\n3 4"
},
{
"input": "7\n36 28 57 39 66 69 68",
"output": "1 2\n3 4\n6 7"
},
{
"input": "5\n1 2 1 2 1",
"output": "2 3\n4 5\n3 4"
},
{
"input": "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38... | 1,653,115,250 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 102,400 | import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
w = deque(map(int, input().split()))
for i in range(n):
m = w.index(min(w))
if m == 0:
w.popleft()
else:
if m % 2:
if m < (n-i)/2:
w.rotate(-m)
fo... | Title: Little Robber Girl's Zoo
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in th... | ```python
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
w = deque(map(int, input().split()))
for i in range(n):
m = w.index(min(w))
if m == 0:
w.popleft()
else:
if m % 2:
if m < (n-i)/2:
w.rotate(-m)
... | 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,477,311 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | e=int(input())
s=input()
x=s.count('RU')
a=s.count('RUR')
b=s.count('URU')
print(e-(x))
| 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
e=int(input())
s=input()
x=s.count('RU')
a=s.count('RUR')
b=s.count('URU')
print(e-(x))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,621,601,304 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n,t=map(int,input().split())
a=list(map(int,input().split()));c=0
for i in range(n) :
if t==0 :
break
else :
t-=(86400-a[i])
c+=1
print(c)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n,t=map(int,input().split())
a=list(map(int,input().split()));c=0
for i in range(n) :
if t==0 :
break
else :
t-=(86400-a[i])
c+=1
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,670,885,397 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | def solve():
a = list(input())
n = len(a)
m = -1
for i in range(n-1):
if not int(a[i]) % 2:
m = i
if m == -1:
return m
a[-1],a[m] = a[m],a[-1]
return ''.join(a)
print(solve()) | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
def solve():
a = list(input())
n = len(a)
m = -1
for i in range(n-1):
if not int(a[i]) % 2:
m = i
if m == -1:
return m
a[-1],a[m] = a[m],a[-1]
return ''.join(a)
print(solve())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th... | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,600,160,121 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 51 | 2,000 | 26,828,800 | k = int(input())
num = '1' + input() + '1'
num_one = [i for i,v in enumerate(num) if int(v)]
sum_num = 0
#print(len(num_one))
for i in range(1,len(num_one) - k) :
if k == 0:
temp = num_one[i] - num_one[i-1] - 1
sum_num += temp * (temp + 1) // 2
else :
#print(i)
temp = ... | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, ... | ```python
k = int(input())
num = '1' + input() + '1'
num_one = [i for i,v in enumerate(num) if int(v)]
sum_num = 0
#print(len(num_one))
for i in range(1,len(num_one) - k) :
if k == 0:
temp = num_one[i] - num_one[i-1] - 1
sum_num += temp * (temp + 1) // 2
else :
#print(i)
... | 0 | 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,524,345,316 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 218 | 7,065,600 | # import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
a, b = map(int, input().split(' '))
hlf = "1"
sum = 0
for i in range(a):
cur = hlf + hlf[::-1]
sum += int(cur)
hlf = str(int(hlf) + 1)
print(sum % b)
| 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
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
a, b = map(int, input().split(' '))
hlf = "1"
sum = 0
for i in range(a):
cur = hlf + hlf[::-1]
sum += int(cur)
hlf = str(int(hlf) + 1)
print(sum % b)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
834 | A | The Useless Toy | PROGRAMMING | 900 | [
"implementation"
] | null | null | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s... | There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated... | Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. | [
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] | [
"cw\n",
"ccw\n",
"undefined\n"
] | none | 500 | [
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
... | 1,545,753,864 | 3,084 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 |
s,e=map(str,input().split())
n=int(input())
def clk(st,n,lis):
sti=lis.index(st)
n=n-n//5
p=4-sti
if(n<=p):
return(lis[sti+n])
else:
n=n-p
return(lis[n])
def aclk(st,n,lis):
sti=lis.index(st)+1
n=n-n//5
if(n<=sti):
return(lis[sti-n])
else:
n=n-sti
return(lis[-n])... | Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bough... | ```python
s,e=map(str,input().split())
n=int(input())
def clk(st,n,lis):
sti=lis.index(st)
n=n-n//5
p=4-sti
if(n<=p):
return(lis[sti+n])
else:
n=n-p
return(lis[n])
def aclk(st,n,lis):
sti=lis.index(st)+1
n=n-n//5
if(n<=sti):
return(lis[sti-n])
else:
n=n-sti
retur... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,615,483,032 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | r=list(map(int,input().split()))
c=list(map(int,input().split()))
d=list(map(int,input().split()))
for i in range(1,10):
ans1=[0,0]
ans2=[0,0]
if i<d[0] and i<r[0] and i<c[0]:
ans1[0]=i
ans2[1]=d[0]-ans1[0]
ans1[1]=r[0]-ans1[0]
if ans1[1]+ans2[1]==c[1]:
... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
r=list(map(int,input().split()))
c=list(map(int,input().split()))
d=list(map(int,input().split()))
for i in range(1,10):
ans1=[0,0]
ans2=[0,0]
if i<d[0] and i<r[0] and i<c[0]:
ans1[0]=i
ans2[1]=d[0]-ans1[0]
ans1[1]=r[0]-ans1[0]
if ans1[1]+ans2[1]==c[1]:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,546,948,336 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 8 17:17:04 2019
@author: umang
"""
def calc_points(p, t):
return max(3*p/10, p - p*t/250)
a, b, c, d = map(int, input().split())
if calc_points(a, c) > calc_points(b, d):
print("Misha")
elif calc_points(a, c) < calc_points(b, d):
pri... | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 8 17:17:04 2019
@author: umang
"""
def calc_points(p, t):
return max(3*p/10, p - p*t/250)
a, b, c, d = map(int, input().split())
if calc_points(a, c) > calc_points(b, d):
print("Misha")
elif calc_points(a, c) < calc_points(b, d... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
825 | D | Suitable Replacement | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation"
] | null | null | You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=106).
The second line contains string *t* (1<=≤<=|*t*|<=≤<=106). | Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
If there are multiple strings with maximal suitability then print any of them. | [
"?aa?\nab\n",
"??b?\nza\n",
"abcd\nabacaba\n"
] | [
"baab\n",
"azbz\n",
"abcd\n"
] | In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.
In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
In the third exam... | 0 | [
{
"input": "?aa?\nab",
"output": "baab"
},
{
"input": "??b?\nza",
"output": "azbz"
},
{
"input": "abcd\nabacaba",
"output": "abcd"
},
{
"input": "mqwstphetbfrsyxuzdww\nrutseqtsbh",
"output": "mqwstphetbfrsyxuzdww"
},
{
"input": "????????????????????\nxwkxsxlrre",
... | 1,516,792,093 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 18,944,000 | s=input()
t=input()
n=len(s)
m=len(t)
k=0
for i in range(n):
if s[i]=='?':
k+=1
d={}
for i in range(m):
if t[i] not in d:
d[t[i]]=[1,0]
else:
d[t[i]][0]+=1
for i in range(n):
if s[i] in d:
d[s[i]][1]+=1
l,r=0,n+1
while l+1!=r:
c=(l+r)//2
e=m*c
for x in d:
... | Title: Suitable Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped po... | ```python
s=input()
t=input()
n=len(s)
m=len(t)
k=0
for i in range(n):
if s[i]=='?':
k+=1
d={}
for i in range(m):
if t[i] not in d:
d[t[i]]=[1,0]
else:
d[t[i]][0]+=1
for i in range(n):
if s[i] in d:
d[s[i]][1]+=1
l,r=0,n+1
while l+1!=r:
c=(l+r)//2
e=m*c
for x ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,469,033,559 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 16,793,600 | n=int(input())
s=list(input())
l=list(map(int,input().split()))
ans=0
if not ("R" in s[:-1] and "L" in s[1:]):
print(-1)
else:
while sorted(l)==l and len(set(l))==n:
ans+=1
for i in range(n):
if s[i]=="R":
l[i]+=1
else: l[i]-=1
print(ans) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n=int(input())
s=list(input())
l=list(map(int,input().split()))
ans=0
if not ("R" in s[:-1] and "L" in s[1:]):
print(-1)
else:
while sorted(l)==l and len(set(l))==n:
ans+=1
for i in range(n):
if s[i]=="R":
l[i]+=1
else: l[i]-=1
p... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
}... | 1,641,402,050 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 342 | 8,294,400 | from collections import deque
n=int(input())
X=deque(map(int,input().split()))
A=0
B=0
while X:
#print(X,A,B)
if X[0]<=X[-1]:
A+=1
X[-1]-=X[0]
X.popleft()
if len(X)==1:
B+=1
break
else:
B+=1
X[0]-=X[-1]
X.... | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo... | ```python
from collections import deque
n=int(input())
X=deque(map(int,input().split()))
A=0
B=0
while X:
#print(X,A,B)
if X[0]<=X[-1]:
A+=1
X[-1]-=X[0]
X.popleft()
if len(X)==1:
B+=1
break
else:
B+=1
X[0]-=X[-1]
... | 3.852702 | MatrixStudio/Codeforces-Python-Submissions |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,518,614,950 | 5,050 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 61 | 6,553,600 | k=int(input())
if k%2==0:
l='8'*(k//2)
print(l)
else:
l='8'*(k//2)
l=l+'0'
print(l) | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k=int(input())
if k%2==0:
l='8'*(k//2)
print(l)
else:
l='8'*(k//2)
l=l+'0'
print(l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,697,790,417 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 31 | 0 |
n = int(input().strip())
r = 0
if n%2 == 0: r = n//2
else: r = -(n+1)//2
print(r)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input().strip())
r = 0
if n%2 == 0: r = n//2
else: r = -(n+1)//2
print(r)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,640,089,393 | 913 | PyPy 3-64 | OK | TESTS | 31 | 280 | 8,396,800 | import sys
input = sys.stdin.readline
from collections import defaultdict, deque
p = print
r = range
def I(): return int(input())
def II(): return list(map(int, input().split()))
def S(): return input()[:-1]
def M(n): return [list(map(int, input().split())) for ___ in r(n)]
def pb(b): print('YES' if b else 'NO... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
import sys
input = sys.stdin.readline
from collections import defaultdict, deque
p = print
r = range
def I(): return int(input())
def II(): return list(map(int, input().split()))
def S(): return input()[:-1]
def M(n): return [list(map(int, input().split())) for ___ in r(n)]
def pb(b): print('YES' if ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
645 | B | Mischievous Mess Makers | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible mess... | 1,000 | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "1000... | 1,458,325,689 | 6,789 | PyPy 3 | OK | TESTS | 92 | 124 | 0 | n, k = list(map(int, input().split()))
if k >= n // 2:
print(n * (n - 1) // 2)
else:
print(k * (2 * n - 3) - 2 *(k - 1) *(k)) | Title: Mischievous Mess Makers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from... | ```python
n, k = list(map(int, input().split()))
if k >= n // 2:
print(n * (n - 1) // 2)
else:
print(k * (2 * n - 3) - 2 *(k - 1) *(k))
``` | 3 | 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,626,516,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 6,963,200 | import math
with open('input.txt', 'r') as inp:
with open('output.txt', '+w') as out:
n = int(inp.readline())
n_match = int(math.log2(n - 1) + 1)
for column in range(n_match):
# At one round
team_1 = []
for i in range(n):
if i % (2 ** (column + 1)) == 0:
team_1.appen... | 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
import math
with open('input.txt', 'r') as inp:
with open('output.txt', '+w') as out:
n = int(inp.readline())
n_match = int(math.log2(n - 1) + 1)
for column in range(n_match):
# At one round
team_1 = []
for i in range(n):
if i % (2 ** (column + 1)) == 0:
te... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,659,158,227 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | a=input()
b=input()
c=input()
if (b not in a) and (c not in a):
print('fantasy')
elif not (a.count(b)==1 and a.count(c)==1):
print('both')
elif a.index(b)<a.index(c):
print('forward')
else:
print('backward') | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
a=input()
b=input()
c=input()
if (b not in a) and (c not in a):
print('fantasy')
elif not (a.count(b)==1 and a.count(c)==1):
print('both')
elif a.index(b)<a.index(c):
print('forward')
else:
print('backward')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,685,706,035 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 72 | 77 | 0 | input()
a = [int(i) for i in input().split()]
b = []
c = []
for i in a:
if i >= 0:
b.append(i)
elif i < 0:
c.append(i)
print(sum(b) - sum(c)) | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
input()
a = [int(i) for i in input().split()]
b = []
c = []
for i in a:
if i >= 0:
b.append(i)
elif i < 0:
c.append(i)
print(sum(b) - sum(c))
``` | 3 | 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,638,618,381 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 6,963,200 | n = int(input())
arr = list(map(int,input().split()))
number = 0
for i in arr:
min = 2147483647
max = 0
for q in arr:
if(q != i):
if q > 0 and i < 0:
number = q - i;
elif i > 0 and q < 0:
number = i - q;
else:
... | 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
n = int(input())
arr = list(map(int,input().split()))
number = 0
for i in arr:
min = 2147483647
max = 0
for q in arr:
if(q != i):
if q > 0 and i < 0:
number = q - i;
elif i > 0 and q < 0:
number = i - q;
else... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,405,279,373 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 0 | p, n = map(int, input().split())
coll_id = -1
hash = [False for i in range(p)]
for i in range(n):
x = int(input()) % p
if (not hash[x]):
hash[x] = True
else:
coll_id = i + 1
break
print(coll_id)
| Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
p, n = map(int, input().split())
coll_id = -1
hash = [False for i in range(p)]
for i in range(n):
x = int(input()) % p
if (not hash[x]):
hash[x] = True
else:
coll_id = i + 1
break
print(coll_id)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,532,619,041 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | n, k, M, D = map(int, input().split())
ans = 0
for i in range(1, D+1):
x = min(M, n // (k*(i-1)+1))
ans = max(ans, i * x)
print(ans)
| Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
n, k, M, D = map(int, input().split())
ans = 0
for i in range(1, D+1):
x = min(M, n // (k*(i-1)+1))
ans = max(ans, i * x)
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,676,636,823 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s=input()
result=''
i=0
while(i<len(s)):
if s[i:i+3]!="WUB":
result+=s[i]
i+=1
else:
result+=' '
i+=3
count=j=0
while(j<len(s)):
if s[j:j+3]=="WUB":
count+=1
else:
break
j+=3
print(result[count:])
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s=input()
result=''
i=0
while(i<len(s)):
if s[i:i+3]!="WUB":
result+=s[i]
i+=1
else:
result+=' '
i+=3
count=j=0
while(j<len(s)):
if s[j:j+3]=="WUB":
count+=1
else:
break
j+=3
print(result[count:])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,499,748,336 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 62 | 5,529,600 | import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
s=sum(a)
while s/n < k-0.5:
s+=k
n+=1
ans+=1
print(ans)
| Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
s=sum(a)
while s/n < k-0.5:
s+=k
n+=1
ans+=1
print(ans)
``` | 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,602,429,854 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | def add_count(c):
return c + 1
entry = input()
count = 0
switcher = {
"a": add_count, "e": add_count, "i": add_count, "o": add_count, "u": add_count,
"1": add_count, "3": add_count, "5": add_count, "7": add_count, "9": add_count
}
for letter in entry:
func = switcher.get(letter) or "Erro"
if func != "Erro":
co... | 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
def add_count(c):
return c + 1
entry = input()
count = 0
switcher = {
"a": add_count, "e": add_count, "i": add_count, "o": add_count, "u": add_count,
"1": add_count, "3": add_count, "5": add_count, "7": add_count, "9": add_count
}
for letter in entry:
func = switcher.get(letter) or "Erro"
if func != "E... | 3 | 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,600,276,969 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 218 | 0 | #rOkY
#FuCk
################################## kOpAl #####################################
t=int(input())
f=0
for i in range(1,t+1,1):
if(i*(i+1)//2 ==t):
f=1
break
if(f):
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
#rOkY
#FuCk
################################## kOpAl #####################################
t=int(input())
f=0
for i in range(1,t+1,1):
if(i*(i+1)//2 ==t):
f=1
break
if(f):
print('YES')
else:
print('NO')
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,560,945,255 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 748 | 0 | n,m=map(int,input().split())
count=0
for i in range(1,n+1):
temp=i%5
req=5-temp
res=(m-req)//5
count+=(res+1)
print(count)
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n,m=map(int,input().split())
count=0
for i in range(1,n+1):
temp=i%5
req=5-temp
res=(m-req)//5
count+=(res+1)
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,679,286,425 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 1,843,200 | import math
A, B = map(int, input().split())
# calculate factorials of A and B
fact_A = math.factorial(A)
fact_B = math.factorial(B)
# find the GCD of A! and B! using Euclid's algorithm
while fact_B:
fact_A, fact_B = fact_B, fact_A % fact_B
print(fact_A)
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
A, B = map(int, input().split())
# calculate factorials of A and B
fact_A = math.factorial(A)
fact_B = math.factorial(B)
# find the GCD of A! and B! using Euclid's algorithm
while fact_B:
fact_A, fact_B = fact_B, fact_A % fact_B
print(fact_A)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,454,139,893 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 233 | 819,200 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
m = {
0: 6,
1: 2,
2: 5,
3: 5,
4: 4,
5: 5,
6: 6,
7: 3,
8: 7,
9: 6
}
def get_segments(a):
globa... | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
m = {
0: 6,
1: 2,
2: 5,
3: 5,
4: 4,
5: 5,
6: 6,
7: 3,
8: 7,
9: 6
}
def get_segments(a):... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
815 | B | Karen and Test | PROGRAMMING | 2,200 | [
"brute force",
"combinatorics",
"constructive algorithms",
"math"
] | null | null | Karen has just arrived at school, and she has a math test today!
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are *... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=200000), the number of numbers written on the first row.
The next line contains *n* integers. Specifically, the *i*-th one among these is *a**i* (1<=≤<=*a**i*<=≤<=109), the *i*-th number on the first row. | Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 109<=+<=7. | [
"5\n3 6 9 12 15\n",
"4\n3 7 5 2\n"
] | [
"36\n",
"1000000006\n"
] | In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows:
The non-negative remainder after dividing the final number by 10<sup class="upper-index">9</sup> + 7 is still 36, so this is the correct output.
In the second test case, the numbers written ... | 1,250 | [
{
"input": "5\n3 6 9 12 15",
"output": "36"
},
{
"input": "4\n3 7 5 2",
"output": "1000000006"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 49879255... | 1,685,408,394 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 306,688,000 | n=int(input())
arrs=[[int(x) for x in input().split()],
[0 for _ in range(n)]]
add,sz,sw=True,n,0
while sz>1:
for i in range(sz-1):
arrs[1-sw][i]=(arrs[sw][i]+arrs[sw][i+1] if add \
else arrs[sw][i]-arrs[sw][i+1])
add=not add
sz-=1;sw=1-sw
print(arrs[sw][0]%1000000007) | Title: Karen and Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Karen has just arrived at school, and she has a math test today!
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make a... | ```python
n=int(input())
arrs=[[int(x) for x in input().split()],
[0 for _ in range(n)]]
add,sz,sw=True,n,0
while sz>1:
for i in range(sz-1):
arrs[1-sw][i]=(arrs[sw][i]+arrs[sw][i+1] if add \
else arrs[sw][i]-arrs[sw][i+1])
add=not add
sz-=1;sw=1-sw
print(arrs[sw][0]%10... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,671,827,198 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | def main():
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
shift = -1 if input() == "R" else 1
message = input()
answer = ""
for letter in message:
index = keyboard.find(letter)
answer += keyboard[index + shift]
print(answer)
if __name__ == "__main__":
main()
| Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
def main():
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
shift = -1 if input() == "R" else 1
message = input()
answer = ""
for letter in message:
index = keyboard.find(letter)
answer += keyboard[index + shift]
print(answer)
if __name__ == "__main__":
main... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,694,656,011 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def length_sum_maxmin(length,sum):
n=length
flag=True
result1=[]
result2=[]
if sum<1 or sum>length*9:
result1=['-1']
result2=['-1']
else:
while sum>9:
sum-=9
length-=1
result1.append('9')
result1.append(str(sum))
... | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
def length_sum_maxmin(length,sum):
n=length
flag=True
result1=[]
result2=[]
if sum<1 or sum>length*9:
result1=['-1']
result2=['-1']
else:
while sum>9:
sum-=9
length-=1
result1.append('9')
result1.append(st... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,493,886,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import math
n=int(input())
res=0
for i in range(1,n+1):
for j in range(1,n+1):
c=int(math.sqrt(i*i+j*j))
if(c*c==i*i+j*j and c<=n):
res+=1
print(res) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
import math
n=int(input())
res=0
for i in range(1,n+1):
for j in range(1,n+1):
c=int(math.sqrt(i*i+j*j))
if(c*c==i*i+j*j and c<=n):
res+=1
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,693,500,129 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n, m, a, b = int(input()) ,int(input()),int(input()),int(input())
max1 = n*a
if (n%m == 0):
cost =(n/m)*b
if(max1>cost):
print(cost)
else:
print(max1)
else:
mod = n%m
max2 =(b*m)+(mod*a)
if max1>max2:
print(max2)
else:
print(max1)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n, m, a, b = int(input()) ,int(input()),int(input()),int(input())
max1 = n*a
if (n%m == 0):
cost =(n/m)*b
if(max1>cost):
print(cost)
else:
print(max1)
else:
mod = n%m
max2 =(b*m)+(mod*a)
if max1>max2:
print(max2)
else:
print(max1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,600,191,995 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 409,600 | import math
from collections import defaultdict
from collections import Counter
import itertools
def solve(s,t):
if s[::-1] == t:
return "YES"
else:
return "NO"
s = input()
t = input()
print(solve(s,t)) | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
import math
from collections import defaultdict
from collections import Counter
import itertools
def solve(s,t):
if s[::-1] == t:
return "YES"
else:
return "NO"
s = input()
t = input()
print(solve(s,t))
``` | 3.937237 | MatrixStudio/Codeforces-Python-Submissions |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,655,718,357 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 154 | 614,400 | import math
import sys
# from pyrsistent import get_in
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_list_str(): return list(map(str, sys.stdin.readline().strip().split()))
from collections import Count... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
import math
import sys
# from pyrsistent import get_in
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_list_str(): return list(map(str, sys.stdin.readline().strip().split()))
from collections im... | 3.960356 | 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,659,209,298 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 0 | def Geralt(arr):
if 1 in arr:
return -1
else:
return 1
n = int(input())
arr = list(map(int, input().split()))
print(Geralt(arr))
| 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
def Geralt(arr):
if 1 in arr:
return -1
else:
return 1
n = int(input())
arr = list(map(int, input().split()))
print(Geralt(arr))
``` | 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,664,306,133 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 124 | 1,843,200 | from sys import stdin
input=stdin.readline
pas,pla=map(int,input().split()) ; planes=list(map(int,input().split()))
planes2=planes[:] ; mini=0 ; maxi=0
for i in range(pas):
a=max(planes)
maxi+=a
ind=planes.index(a)
planes[ind]-=1
for i in range(pas):
a=min(planes2)
mini+=a
ind... | 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
from sys import stdin
input=stdin.readline
pas,pla=map(int,input().split()) ; planes=list(map(int,input().split()))
planes2=planes[:] ; mini=0 ; maxi=0
for i in range(pas):
a=max(planes)
maxi+=a
ind=planes.index(a)
planes[ind]-=1
for i in range(pas):
a=min(planes2)
mini+=... | 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,623,127,666 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | s=input()
a="hello"
p=0
z=0
for i in s:
if(i==a[p]):
p+=1
if(p==len(a)):
z=1
print("YES")
break
if(z==0):
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
s=input()
a="hello"
p=0
z=0
for i in s:
if(i==a[p]):
p+=1
if(p==len(a)):
z=1
print("YES")
break
if(z==0):
print("NO")
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,554,979,175 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 124 | 0 | x = input()
print(x+"".join([x[_] for _ in range(len(x)-1,-1,-1)]))
| Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
x = input()
print(x+"".join([x[_] for _ in range(len(x)-1,-1,-1)]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe... | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70... | 1,531,995,711 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 5 | 763 | 268,390,400 | # -*- coding: utf-8 -*-
"""
Created on Thu Jul 19 13:14:26 2018
@author: User
"""
N = 998244353
n = int(input())
a = list(map(int, input().split(" ")))
b = [1]
deg = 1
k = 3
for i in range(n-1) :
b.append(deg*k)
deg *= 2
k += 1
res = 0
for i in range(n) :
res += b[i]*a[n-1-i]
... | Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not... | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 19 13:14:26 2018
@author: User
"""
N = 998244353
n = int(input())
a = list(map(int, input().split(" ")))
b = [1]
deg = 1
k = 3
for i in range(n-1) :
b.append(deg*k)
deg *= 2
k += 1
res = 0
for i in range(n) :
res += b[i]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,651,626,147 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 62 | 0 | n, s = map(int, input().split())
ans = 0
floors = [[s,0]]
for i in range(n):
floor, tim = map(int, input().split())
floors.append([floor, tim])
floors.append([0,0])
floors.sort(key=lambda x: -x[0])
for i in range(1, len(floors)):
ans += floors[i-1][0] - floors[i][0]
if ans < floors[i][1]:
... | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n, s = map(int, input().split())
ans = 0
floors = [[s,0]]
for i in range(n):
floor, tim = map(int, input().split())
floors.append([floor, tim])
floors.append([0,0])
floors.sort(key=lambda x: -x[0])
for i in range(1, len(floors)):
ans += floors[i-1][0] - floors[i][0]
if ans < floors[i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,650,259,945 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n=input()
count=0
for i in range(len(n)):
for j in range((i+1),len(n)):
if n[i]=='Q' and n[j]=='Q':
count+=n[(i+1):j].count('A')
print(count) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
n=input()
count=0
for i in range(len(n)):
for j in range((i+1),len(n)):
if n[i]=='Q' and n[j]=='Q':
count+=n[(i+1):j].count('A')
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,618,617,238 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | preco = 101
result = 0
for i in range(int(input())):
x,y = input().split(" ")
x = int(x)
y = int(y)
if(preco>y):
preco = y
result += preco * x
print(result) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
preco = 101
result = 0
for i in range(int(input())):
x,y = input().split(" ")
x = int(x)
y = int(y)
if(preco>y):
preco = y
result += preco * x
print(result)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the inf... | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,557,128,460 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 452 | 2,048,000 | def f(s):
s = ''.join(s).split('0')
return max(len(i) for i in s)
n, m, q = map(int, input().split())
arr = [input().split() for i in range(n)]
b = [f(s) for s in arr]
for i in range(q):
x, y = map(int, input().split())
x -= 1 ; y -= 1
arr[x][y] = str(1 - int(arr[x][y]))
b[x] = f(arr[x... | Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ... | ```python
def f(s):
s = ''.join(s).split('0')
return max(len(i) for i in s)
n, m, q = map(int, input().split())
arr = [input().split() for i in range(n)]
b = [f(s) for s in arr]
for i in range(q):
x, y = map(int, input().split())
x -= 1 ; y -= 1
arr[x][y] = str(1 - int(arr[x][y]))
b[x]... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,588,668,863 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 218 | 307,200 | s = input()
# associate values on 2 coordinates
d = {'U':(0,1), 'D':(0,-1), 'L':(-1,0), 'R':(1,0)}
p = [(0,0)]
for x in s:
# get last point
a = p[-1]
# get current point
b = d[x]
# compute next coordinate
c = (a[0]+b[0], a[1]+b[1])
z = 0
# check for arriving in the same spot
for y in d.values():
... | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
s = input()
# associate values on 2 coordinates
d = {'U':(0,1), 'D':(0,-1), 'L':(-1,0), 'R':(1,0)}
p = [(0,0)]
for x in s:
# get last point
a = p[-1]
# get current point
b = d[x]
# compute next coordinate
c = (a[0]+b[0], a[1]+b[1])
z = 0
# check for arriving in the same spot
for y in d.... | 3.943211 | MatrixStudio/Codeforces-Python-Submissions |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,591,210,015 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 280 | 0 | l=[]
f=0
for i in range(8):
l.append(input())
for i in range(8):
for j in range(8):
if l[i][j%8]==l[i][(j+1)%8]==l[i][(j+2)%8]:
f=1
if f==1:
print("NO")
else:
print("YES")
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e... | ```python
l=[]
f=0
for i in range(8):
l.append(input())
for i in range(8):
for j in range(8):
if l[i][j%8]==l[i][(j+1)%8]==l[i][(j+2)%8]:
f=1
if f==1:
print("NO")
else:
print("YES")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,688,371,270 | 2,147,483,647 | Python 3 | OK | TESTS | 103 | 732 | 13,619,200 | import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
q=int(input())
for i in range(q):
m=int(input())
print(bisect.bisect_right(a,m)) | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
q=int(input())
for i in range(q):
m=int(input())
print(bisect.bisect_right(a,m))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
777 | D | Cloud of Hashtags | PROGRAMMING | 1,800 | [
"binary search",
"greedy",
"implementation",
"strings"
] | null | null | Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now.
Each of the next *n* lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#... | Print the resulting hashtags in any of the optimal solutions. | [
"3\n#book\n#bigtown\n#big\n",
"3\n#book\n#cool\n#cold\n",
"4\n#car\n#cart\n#art\n#at\n",
"3\n#apple\n#apple\n#fruit\n"
] | [
"#b\n#big\n#big\n",
"#book\n#co\n#cold\n",
"#\n#\n#art\n#at\n",
"#apple\n#apple\n#fruit\n"
] | Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of... | 2,000 | [
{
"input": "3\n#book\n#bigtown\n#big",
"output": "#b\n#big\n#big"
},
{
"input": "3\n#book\n#cool\n#cold",
"output": "#book\n#co\n#cold"
},
{
"input": "4\n#car\n#cart\n#art\n#at",
"output": "#\n#\n#art\n#at"
},
{
"input": "3\n#apple\n#apple\n#fruit",
"output": "#apple\n#ap... | 1,623,835,444 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 1,903 | 19,558,400 | def compareHesh(heshBottom, heshTop):
lenB, lenT = len(heshBottom), len(heshTop)
flag = True
for i in range(1, lenT):
if i+1 > lenB:
return i
elif heshTop[i] > heshBottom[i]:
return i
elif heshTop[i] < heshBottom[i]:
return 0
... | Title: Cloud of Hashtags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to m... | ```python
def compareHesh(heshBottom, heshTop):
lenB, lenT = len(heshBottom), len(heshTop)
flag = True
for i in range(1, lenT):
if i+1 > lenB:
return i
elif heshTop[i] > heshBottom[i]:
return i
elif heshTop[i] < heshBottom[i]:
return 0 ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,612,529,854 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 93 | 1,536,000 |
n =int(input())
k = 0
li =[]
def sum_of_digit(i):
result = sum([int(digit) for digit in str(i)])
return result
sum_of_digits = 0
for i in range(max(1,n-200),n):
sum_of_digits = sum_of_digit(i)
# print(sum_of_digits,i)
if (sum_of_digits + i) == n:
k+=1
li.append(i)
pr... | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
n =int(input())
k = 0
li =[]
def sum_of_digit(i):
result = sum([int(digit) for digit in str(i)])
return result
sum_of_digits = 0
for i in range(max(1,n-200),n):
sum_of_digits = sum_of_digit(i)
# print(sum_of_digits,i)
if (sum_of_digits + i) == n:
k+=1
li.app... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,697,262,315 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | a,b=map(int,input().split())
s=0
while b>=a:
a=a*3
b=b*2
s=s+1
print(s)
| Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
a,b=map(int,input().split())
s=0
while b>=a:
a=a*3
b=b*2
s=s+1
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000... | 1,699,547,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | k = int(input())
n = list(map(int, list(input())))
s = sum(n)
if s > k:
print(0)
else:
n.sort(reverse=True)
i = 0
cnt = 0
while s < k:
if n[i] < 9:
diff = 9 - n[i]
n[i] += diff
s += diff
cnt += 1
i += 1
print(cnt) | Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th... | ```python
k = int(input())
n = list(map(int, list(input())))
s = sum(n)
if s > k:
print(0)
else:
n.sort(reverse=True)
i = 0
cnt = 0
while s < k:
if n[i] < 9:
diff = 9 - n[i]
n[i] += diff
s += diff
cnt += 1
i += 1
print(cnt)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ... | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,591,198,210 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 30 | 187 | 2,048,000 | n,m = map(int,input().split())
winners = []
from collections import Counter
for i in range(m):
ar = input().split(' ')
ar = [int(i)for i in ar]
max_ = 0
max_i = 0
for i in range(n):
if ar[i]>max_:
max_ = ar[i]
max_i = i+1
winners.append(max_i)
c= Counter(winners)
c = c.most_common(len(c))
winner = c[0]... | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
n,m = map(int,input().split())
winners = []
from collections import Counter
for i in range(m):
ar = input().split(' ')
ar = [int(i)for i in ar]
max_ = 0
max_i = 0
for i in range(n):
if ar[i]>max_:
max_ = ar[i]
max_i = i+1
winners.append(max_i)
c= Counter(winners)
c = c.most_common(len(c))
win... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,421,694,710 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | x=int(input())
y=int(input())
if x>0 and y>0:
a=0
b=x+y
c=x+y
d=0
elif x<0 and y>0:
a=x-y
b=0
c=0
d=y-x
elif x<0 and y<0:
a=x+y
b=0
c=0
d=x+y
elif x>0 and y<0:
a=0
b=y-x
c=x-y
d=0
print(a,b,c,d) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x=int(input())
y=int(input())
if x>0 and y>0:
a=0
b=x+y
c=x+y
d=0
elif x<0 and y>0:
a=x-y
b=0
c=0
d=y-x
elif x<0 and y<0:
a=x+y
b=0
c=0
d=x+y
elif x>0 and y<0:
a=0
b=y-x
c=x-y
d=0
print(a,b,c,d)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,652,189,171 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | n=int(input())
r=n%4
if r==0:
print('6')
elif r==1:
print('8')
elif r==2:
print('4')
elif r==3:
print('2') | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n=int(input())
r=n%4
if r==0:
print('6')
elif r==1:
print('8')
elif r==2:
print('4')
elif r==3:
print('2')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,651,054,674 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 409,600 | from pprint import pprint
n = int(input())
matrix = [[1]*n]
for i in range(1, n):
l = []
for j in range(n):
l.append(matrix[i-1][j] + l[-1] if len(l) > 0 else matrix[i-1][j] + 0)
matrix.append(l)
print(matrix[-1][-1]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
from pprint import pprint
n = int(input())
matrix = [[1]*n]
for i in range(1, n):
l = []
for j in range(n):
l.append(matrix[i-1][j] + l[-1] if len(l) > 0 else matrix[i-1][j] + 0)
matrix.append(l)
print(matrix[-1][-1])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,589,887,831 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 280 | 0 | import sys
from math import sqrt
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
r,g,b... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
import sys
from math import sqrt
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,612,197,704 | 1,904 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 307,200 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
arr=[]
for i in a:
for j in b:
arr.append(i*j)
arr.sort(reverse=True)
print(arr[1])
| Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
arr=[]
for i in a:
for j in b:
arr.append(i*j)
arr.sort(reverse=True)
print(arr[1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
859 | B | Lazy Security Guard | PROGRAMMING | 1,000 | [
"brute force",
"geometry",
"math"
] | null | null | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ... | Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. | Print the minimum perimeter that can be achieved. | [
"4\n",
"11\n",
"22\n"
] | [
"8\n",
"14\n",
"20\n"
] | Here are some possible shapes for the examples:
<img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "4",
"output": "8"
},
{
"input": "11",
"output": "14"
},
{
"input": "22",
"output": "20"
},
{
"input": "3",
"output": "8"
},
{
"input": "1024",
"output": "128"
},
{
"input": "101",
"output": "42"
},
{
"input": "30",
"output":... | 1,641,835,451 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | import math
n = int(input())
print(2 * (math.ceil(2*math.sqrt(n)))) | Title: Lazy Security Guard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is... | ```python
import math
n = int(input())
print(2 * (math.ceil(2*math.sqrt(n))))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,688,233,532 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | x = int(input())
li = [int(x) for x in input().split()]
low = 0
high = 0
for i in range(x):
if li[i]>li[high]:
high = i
elif li[i]<li[low]:
low = i
if li[i]==li[low]:
low = i
if low<high:
print(x-low-2+high)
else:
print(x-low+high-1) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
x = int(input())
li = [int(x) for x in input().split()]
low = 0
high = 0
for i in range(x):
if li[i]>li[high]:
high = i
elif li[i]<li[low]:
low = i
if li[i]==li[low]:
low = i
if low<high:
print(x-low-2+high)
else:
print(x-low+high-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.