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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,681,161,227 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | from collections import defaultdict
import math
def pug_func(s: str) -> str:
n_lower = 0
n_upper = 0
for i in range(len(s)):
if s[i].islower():
n_lower += 1
else:
n_upper += 1
print(n_lower, n_upper)
if n_lower >= n_upper:
return s.... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
from collections import defaultdict
import math
def pug_func(s: str) -> str:
n_lower = 0
n_upper = 0
for i in range(len(s)):
if s[i].islower():
n_lower += 1
else:
n_upper += 1
print(n_lower, n_upper)
if n_lower >= n_upper:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,693,753,829 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 218 | 28,672,000 | n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
count_dict_l1 = {}
count_dict_l2 = {}
count_dict_l3 = {}
ans = [[], []]
for l in l1:
count_dict_l1[l] = count_dict_l1.get(l, 0) + 1
for l in l2:
count_dict_l... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
count_dict_l1 = {}
count_dict_l2 = {}
count_dict_l3 = {}
ans = [[], []]
for l in l1:
count_dict_l1[l] = count_dict_l1.get(l, 0) + 1
for l in l2:
co... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,583,328,197 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 3,276,800 | n=int(input())
n=2*(n-1)
a=[i for i in input()]
#print(a)
for i in range(1,n,2):
for j in range(0,i,2):
if((ord(a[j])-ord(a[i]))==32):
a[j]='0'
a[i]='0'
print((n-a.count('0'))//2)
| Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n=int(input())
n=2*(n-1)
a=[i for i in input()]
#print(a)
for i in range(1,n,2):
for j in range(0,i,2):
if((ord(a[j])-ord(a[i]))==32):
a[j]='0'
a[i]='0'
print((n-a.count('0'))//2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,657,700,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | s = input()
if len(s) > 5 and 'heidi' in s:
print('YES')
else:
print('NO') | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
if len(s) > 5 and 'heidi' in s:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
483 | B | Friends and Presents | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the... | The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=<<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=<<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime. | Print a single integer — the answer to the problem. | [
"3 1 2 3\n",
"1 3 2 3\n"
] | [
"5\n",
"4\n"
] | In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first... | 1,000 | [
{
"input": "3 1 2 3",
"output": "5"
},
{
"input": "1 3 2 3",
"output": "4"
},
{
"input": "916200 69682 2 3",
"output": "1832399"
},
{
"input": "808351 17767 433 509",
"output": "826121"
},
{
"input": "8851 901 20897 26183",
"output": "9752"
},
{
"input... | 1,414,174,913 | 4,913 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 2 | 1,000 | 0 | c1, c2, x, y = list(map(int, input().split()))
sumc = c1 + c2
i = c1 + c2
o1 = min(i // y - i // (x * y), c1)
o2 = min(i // x - i // (x * y), c2)
pub = i - i // (x * y) - (i // x) - i // (x * y) - (i // y) - i // (x * y)
while o1 + o2 + pub < sumc:
i += 1
o1 = min(i // y - i // (x * y), c1)
o2 = mi... | Title: Friends and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented num... | ```python
c1, c2, x, y = list(map(int, input().split()))
sumc = c1 + c2
i = c1 + c2
o1 = min(i // y - i // (x * y), c1)
o2 = min(i // x - i // (x * y), c2)
pub = i - i // (x * y) - (i // x) - i // (x * y) - (i // y) - i // (x * y)
while o1 + o2 + pub < sumc:
i += 1
o1 = min(i // y - i // (x * y), c1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,537,477,662 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | a,b,c,n = map(int, input().split())
pp = a+b-c
ff = n-pp
print (ff if ff>0 else -1) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
a,b,c,n = map(int, input().split())
pp = a+b-c
ff = n-pp
print (ff if ff>0 else -1)
``` | 0 | 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,528,907,999 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 216 | 409,600 | import collections
n=int(input())
a=[]
for i in range(0,n):
a.append(input())
d=collections.Counter(a)
m=0
ans='NULL'
for i in set(a):
if d[i]>m:
ans=i
print(ans) | 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 collections
n=int(input())
a=[]
for i in range(0,n):
a.append(input())
d=collections.Counter(a)
m=0
ans='NULL'
for i in set(a):
if d[i]>m:
ans=i
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,640,366,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = int(input())
pings = []
for i in range(n):
pings.append(tuple(input().split()))
a_sucs = 0
a_fails = 0
b_sucs = 0
b_fails = 0
for ping in pings:
if ping[0] == 1:
a_sucs += ping[1]
a_fails += ping[2]
elif ping[0] == 2:
b_sucs += ping[1]
b_fails += ping[2]
if a_sucs>=a_f... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n = int(input())
pings = []
for i in range(n):
pings.append(tuple(input().split()))
a_sucs = 0
a_fails = 0
b_sucs = 0
b_fails = 0
for ping in pings:
if ping[0] == 1:
a_sucs += ping[1]
a_fails += ping[2]
elif ping[0] == 2:
b_sucs += ping[1]
b_fails += ping[2]
if a... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
340 | E | Iahub and Permutations | PROGRAMMING | 2,000 | [
"combinatorics",
"math"
] | null | null | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer *n* (2<=≤<=*n*<=≤<=2000). On the second line, there are *n* integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers ... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109<=+<=7). | [
"5\n-1 -1 4 3 -1\n"
] | [
"2\n"
] | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | 3,000 | [
{
"input": "5\n-1 -1 4 3 -1",
"output": "2"
},
{
"input": "8\n2 4 5 3 -1 8 -1 6",
"output": "1"
},
{
"input": "7\n-1 -1 4 -1 7 1 6",
"output": "4"
},
{
"input": "6\n-1 -1 -1 -1 -1 -1",
"output": "265"
},
{
"input": "2\n-1 -1",
"output": "1"
},
{
"input... | 1,649,951,305 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 216 | 4,812,800 | import sys
def fact(be, en):
res, res2 = [1] * (en + 1), [1] * (en + 1)
for i in range(be, en + 1):
res[i] = mult(res[i - 1], i)
res2[i] = inv(res[i])
return res, res2
def ncr(n, r):
if n < r:
return 0
return mult(mult(facs[n], invs[n - r]), invs[r])
mo... | Title: Iahub and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubin... | ```python
import sys
def fact(be, en):
res, res2 = [1] * (en + 1), [1] * (en + 1)
for i in range(be, en + 1):
res[i] = mult(res[i - 1], i)
res2[i] = inv(res[i])
return res, res2
def ncr(n, r):
if n < r:
return 0
return mult(mult(facs[n], invs[n - r]), invs[r... | 3 | 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,671,212,784 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 122 | 0 | t=int(input())
mass=list()
k1=0
k2=0
for i in range(t):
mass.append(input())
nazv=list(set(mass))
for i in range(t):
if mass[i]==nazv[0]:
k1+=1
else:
k2+=1
if k1>k2:
print(nazv[0])
else:
print(nazv[1])
| 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
t=int(input())
mass=list()
k1=0
k2=0
for i in range(t):
mass.append(input())
nazv=list(set(mass))
for i in range(t):
if mass[i]==nazv[0]:
k1+=1
else:
k2+=1
if k1>k2:
print(nazv[0])
else:
print(nazv[1])
``` | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,516,196,180 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 5,632,000 | a = input()
a = a.split(' ')
n = int(a[0])
k = int(a[1])
d = []
a = input().split(' ')
for i in range(n):
if k%int(a[i]) == 0:
d.append(a[i])
sorted(d)
print(k//int(d[-1]))
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
a = input()
a = a.split(' ')
n = int(a[0])
k = int(a[1])
d = []
a = input().split(' ')
for i in range(n):
if k%int(a[i]) == 0:
d.append(a[i])
sorted(d)
print(k//int(d[-1]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,002,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | from math import sqrt
input()
for i in input().split():
print(['NO', 'YES'][sqrt(int(i)) % 1 == 0 and i != '1']) | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
from math import sqrt
input()
for i in input().split():
print(['NO', 'YES'][sqrt(int(i)) % 1 == 0 and i != '1'])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,693,752,681 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
mw = 0
cw = 0
for _ in range(n):
mi,ci = map(int,input().split())
if mi > ci:
mw += 1
elif mi < ci:
cw += 1
if mw > cw:
print("Mishka")
elif mw < cw:
print("Chris")
else:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
mw = 0
cw = 0
for _ in range(n):
mi,ci = map(int,input().split())
if mi > ci:
mw += 1
elif mi < ci:
cw += 1
if mw > cw:
print("Mishka")
elif mw < cw:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,655,783,771 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import sys
input = sys.stdin.readline
x, y = map(int, input().split())
if(y == 0 and x == 0):
print("Yes")
elif(y == 0 and x != 0):
print("No")
elif(y != 0 and x == 0):
if(y == 1):
print("Yes")
else:
print("No")
elif(x % 2 != y % 2):
print("Yes")
else:
print("No"... | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
import sys
input = sys.stdin.readline
x, y = map(int, input().split())
if(y == 0 and x == 0):
print("Yes")
elif(y == 0 and x != 0):
print("No")
elif(y != 0 and x == 0):
if(y == 1):
print("Yes")
else:
print("No")
elif(x % 2 != y % 2):
print("Yes")
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,651,725,590 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 68 | 62 | 512,000 | """
https://codeforces.com/problemset/problem/777/A
A. Shell Game
time limit per test0.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: ... | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
"""
https://codeforces.com/problemset/problem/777/A
A. Shell Game
time limit per test0.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,617,905,327 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 78 | 409,600 | import collections
a, b = map(int, input().split())
s = input()
count = collections.Counter(s).most_common(1)[0][1]
if count > b:
print("NO")
else:
print("YES") | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
import collections
a, b = map(int, input().split())
s = input()
count = collections.Counter(s).most_common(1)[0][1]
if count > b:
print("NO")
else:
print("YES")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
616 | D | Longest k-Good Segment | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"two pointers"
] | null | null | The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output... | The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. | Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right. | [
"5 5\n1 2 3 4 5\n",
"9 3\n6 5 1 2 3 2 1 4 5\n",
"3 1\n1 2 3\n"
] | [
"1 5\n",
"3 7\n",
"1 1\n"
] | none | 0 | [
{
"input": "5 5\n1 2 3 4 5",
"output": "1 5"
},
{
"input": "9 3\n6 5 1 2 3 2 1 4 5",
"output": "3 7"
},
{
"input": "3 1\n1 2 3",
"output": "1 1"
},
{
"input": "1 1\n747391",
"output": "1 1"
},
{
"input": "5 2\n171230 171230 171230 171230 171230",
"output": "1 ... | 1,699,728,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 307,200 | from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = r = ansl = ansr = 0
s = []
ss = set()
d = defaultdict(int)
while r >= l and r < n:
d[a[r]] += 1
ss.add(a[r])
if len(ss) <= k :
r += 1
continue
else:
ss.rem... | Title: Longest k-Good Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any... | ```python
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = r = ansl = ansr = 0
s = []
ss = set()
d = defaultdict(int)
while r >= l and r < n:
d[a[r]] += 1
ss.add(a[r])
if len(ss) <= k :
r += 1
continue
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,686,760,030 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
i = 0
l = []
while i < n:
lF = list(map(int, input().split()))
l.append(lF)
i +=1
j = 0
i = 0
num = 0
while i < n :
j = 0
while j < n:
if l[i][0] == l[j][1]:
num += 1
j +=1
i +=1
print(num) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n = int(input())
i = 0
l = []
while i < n:
lF = list(map(int, input().split()))
l.append(lF)
i +=1
j = 0
i = 0
num = 0
while i < n :
j = 0
while j < n:
if l[i][0] == l[j][1]:
num += 1
j +=1
i +=1
print(num)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,573,502,182 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 140 | 0 | # cf 915 A 900
n, k = map(int, input().split())
A = [*map(int, input().split())]
# k = length of garden
ans = 0
for a in sorted(A, reverse=True):
if k % a == 0:
ans = a
break
print(k // ans)
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
# cf 915 A 900
n, k = map(int, input().split())
A = [*map(int, input().split())]
# k = length of garden
ans = 0
for a in sorted(A, reverse=True):
if k % a == 0:
ans = a
break
print(k // ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
269 | B | Greenhouse Effect | PROGRAMMING | 1,700 | [
"dp"
] | null | null | Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each p... | The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000, *n*<=≥<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=≤<=*s**i*<=≤<=*m*), and one real number *x**i* (... | Output a single integer — the minimum number of plants to be replanted. | [
"3 2\n2 1\n1 2.0\n1 3.100\n",
"3 3\n1 5.0\n2 5.5\n3 6.0\n",
"6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed. | 1,000 | [
{
"input": "3 2\n2 1\n1 2.0\n1 3.100",
"output": "1"
},
{
"input": "3 3\n1 5.0\n2 5.5\n3 6.0",
"output": "0"
},
{
"input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125",
"output": "2"
},
{
"input": "1 1\n1 0",
"output": "0"
},
{
... | 1,463,998,730 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 4,608,000 | n, m = map( int, input().split() )
s = [0]
for i in range(n):
x, y = input().split()
s.append(int(x))
f = [0] * (n+1)
for i in range(1, n+1):
for j in range(i):
if s[i] >= s[j]:
f[i] = max( f[i], f[j] + 1 )
else:
f[i] = max( f[i], f[j] )
print(n-f[n]... | Title: Greenhouse Effect
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species n... | ```python
n, m = map( int, input().split() )
s = [0]
for i in range(n):
x, y = input().split()
s.append(int(x))
f = [0] * (n+1)
for i in range(1, n+1):
for j in range(i):
if s[i] >= s[j]:
f[i] = max( f[i], f[j] + 1 )
else:
f[i] = max( f[i], f[j] )
pr... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,454,860,662 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 61 | 0 | n, a, b, c = ( int(input()), int(input()), int(input()), int(input()) )
if a <= b-c:
print(n // a)
else:
bb = (n-b)//(b-c)
ans = (n-bb*(b-c))//min((a,b)) + bb
print(ans)
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
n, a, b, c = ( int(input()), int(input()), int(input()), int(input()) )
if a <= b-c:
print(n // a)
else:
bb = (n-b)//(b-c)
ans = (n-bb*(b-c))//min((a,b)) + bb
print(ans)
``` | 0 | 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,532,235,808 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 24,678,400 | R = lambda: map(int, input().split())
n = int(input())
ss = [input() for x in range(n)]
for i in range(n - 2, -1, -1):
curr, next = ss[i], ss[i + 1]
j = 0
while j < min(len(curr), len(next)) and curr[j] == next[j]:
j += 1
if (j == len(next) and j < len(curr)) or (j < len(curr) and next[j... | 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
R = lambda: map(int, input().split())
n = int(input())
ss = [input() for x in range(n)]
for i in range(n - 2, -1, -1):
curr, next = ss[i], ss[i + 1]
j = 0
while j < min(len(curr), len(next)) and curr[j] == next[j]:
j += 1
if (j == len(next) and j < len(curr)) or (j < len(curr) ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
333 | B | Chips | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | Gerald plays the following game. He has a checkered field of size *n*<=×<=*n* cells, where *m* various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for *n*<=-<=1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from ... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=1000, 0<=≤<=*m*<=≤<=105) — the size of the field and the number of banned cells. Next *m* lines each contain two space-separated integers. Specifically, the *i*-th of these lines contains numbers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<... | Print a single integer — the maximum points Gerald can earn in this game. | [
"3 1\n2 2\n",
"3 0\n",
"4 3\n3 1\n3 2\n3 3\n"
] | [
"0\n",
"1\n",
"1\n"
] | In the first test the answer equals zero as we can't put chips into the corner cells.
In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.
In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4). | 1,000 | [
{
"input": "3 1\n2 2",
"output": "0"
},
{
"input": "3 0",
"output": "1"
},
{
"input": "4 3\n3 1\n3 2\n3 3",
"output": "1"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 3\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "5 1\n3 2",
"output": ... | 1,689,167,552 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689167552.086519")# 1689167552.0865269 | Title: Chips
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald plays the following game. He has a checkered field of size *n*<=×<=*n* cells, where *m* various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for *n*<=-<=1 m... | ```python
print("_RANDOM_GUESS_1689167552.086519")# 1689167552.0865269
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,649,149,367 | 2,147,483,647 | Python 3 | OK | TESTS | 97 | 1,152 | 31,027,200 | def main():
p=s=input().strip()
n=len(s)
pi=[0]*n
j=0
for i in range(1, n):
while j>0 and p[i]!=p[j]: j=pi[j-1]
if p[i]==p[j]: j=j+1
pi[i]=j
if pi[-1]==0: return "Just a legend"
for i in range(n-1):
if pi[i]==pi[-1]: return s[:pi[-1]]
if pi[pi[... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
def main():
p=s=input().strip()
n=len(s)
pi=[0]*n
j=0
for i in range(1, n):
while j>0 and p[i]!=p[j]: j=pi[j-1]
if p[i]==p[j]: j=j+1
pi[i]=j
if pi[-1]==0: return "Just a legend"
for i in range(n-1):
if pi[i]==pi[-1]: return s[:pi[-1]]
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,526,370,272 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 6,963,200 | n, k = list(map(int, input().split()))
while k > n % 10:
k -= n%10 + 1
n //= 10
n -= k
print(n)
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n, k = list(map(int, input().split()))
while k > n % 10:
k -= n%10 + 1
n //= 10
n -= k
print(n)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,693,395,378 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
s=sorted(input())
k=s[:n]
if k==s:
print(''.join(k))
else:
-1 | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
n=int(input())
s=sorted(input())
k=s[:n]
if k==s:
print(''.join(k))
else:
-1
``` | 0 | 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,658,426,307 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | #jeboufckvrciukgjblrtujgbcolrtjcgb
p, q = map(int,input().split())
print((p*q)//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
#jeboufckvrciukgjblrtujgbcolrtjcgb
p, q = map(int,input().split())
print((p*q)//2)
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,644,755,713 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | def solve(n):
ans = ""
ans2 = ""
while n>7 and n%7:
ans+="4"
n-=4
while n:
if n==1:
return -1
n-=7
ans+="7"
return ans | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def solve(n):
ans = ""
ans2 = ""
while n>7 and n%7:
ans+="4"
n-=4
while n:
if n==1:
return -1
n-=7
ans+="7"
return ans
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,529,474,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n = int(input())
c = 0
for i in range(n) :
s,st,fin = map(str,input().split())
st = int(st);fin = int(fin)
if(st>=2400 and fin>st) :
print('YES')
else :
c += 1
if(c==n) :
print('NO') | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
n = int(input())
c = 0
for i in range(n) :
s,st,fin = map(str,input().split())
st = int(st);fin = int(fin)
if(st>=2400 and fin>st) :
print('YES')
else :
c += 1
if(c==n) :
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,676,911,308 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
flag = [None] * n
car1 , car2 = None, None
for i in range(n) :
row = input()
if i == 0 :
car1 , car2 = row[0] , row[1]
if i == round(n / 2) -1 :
if row.count(car1) == 1 and (row.count(car2) == n-1):
flag[i] == 'Yes'
else:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
flag = [None] * n
car1 , car2 = None, None
for i in range(n) :
row = input()
if i == 0 :
car1 , car2 = row[0] , row[1]
if i == round(n / 2) -1 :
if row.count(car1) == 1 and (row.count(car2) == n-1):
flag[i] == 'Yes'
else:
... | 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,699,949,343 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 12,492,800 | n=int(input())
x=list(map(int,input().split()))
q=int(input())
for i in range(q):
m=int(input())
num = sum(1 for j in x if j<=m)
print(num) | 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
n=int(input())
x=list(map(int,input().split()))
q=int(input())
for i in range(q):
m=int(input())
num = sum(1 for j in x if j<=m)
print(num)
``` | 0 | 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,657,169,581 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 |
from operator import mod
n=int(input())
n=mod(n,10)
print(mod(pow(1378,n),10))
| 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
from operator import mod
n=int(input())
n=mod(n,10)
print(mod(pow(1378,n),10))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,686,829,644 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
using namespace std;
int dp_matrix[4][101];
int recur_walk(int current_pos, int remaining_steps) {
if (current_pos != 3 && remaining_steps == 1) {
return 1;
} else if (current_pos != 3 && remaining_steps == 0) {
return 0;
} else if (current_... | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
#include <iostream>
#include <vector>
using namespace std;
int dp_matrix[4][101];
int recur_walk(int current_pos, int remaining_steps) {
if (current_pos != 3 && remaining_steps == 1) {
return 1;
} else if (current_pos != 3 && remaining_steps == 0) {
return 0;
} else if... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
20 | B | Equation | PROGRAMMING | 2,000 | [
"math"
] | B. Equation | 1 | 256 | You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | [
"1 -5 6\n"
] | [
"2\n2.0000000000\n3.0000000000"
] | none | 1,000 | [
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"inpu... | 1,685,016,293 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 30 | 0 | import math
a, b, c = map(int, input().split())
solutions = -1
delta = b ** 2 - 4 * a * c
if a == 0: print(-1)
elif delta < 0: print(0)
else:
square_root = math.sqrt(delta)
x1 = (- b - square_root) // 2 * a
x2 = (- b + square_root) // 2 * a
solutions = 1 if x1 == x2 else 2 if x1 != x2 else 0
prin... | Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=1... | ```python
import math
a, b, c = map(int, input().split())
solutions = -1
delta = b ** 2 - 4 * a * c
if a == 0: print(-1)
elif delta < 0: print(0)
else:
square_root = math.sqrt(delta)
x1 = (- b - square_root) // 2 * a
x2 = (- b + square_root) // 2 * a
solutions = 1 if x1 == x2 else 2 if x1 != x2 else ... | 0 | MatrixStudio/Codeforces-Python-Submissions |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,662,451,019 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | if __name__ == "__main__":
_ = int(input())
children = list(map(int, input().split()))
table = {1: [], 2: [], 3: []}
for i, child in enumerate(children):
table[child] = [i + 1] + table.get(child, [])
teams = []
currTeam = []
i = 1
while table[1] + table[... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
if __name__ == "__main__":
_ = int(input())
children = list(map(int, input().split()))
table = {1: [], 2: [], 3: []}
for i, child in enumerate(children):
table[child] = [i + 1] + table.get(child, [])
teams = []
currTeam = []
i = 1
while table[1... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,568,224,502 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 3,174,400 | n = int(input())
l = list(input())
a = l.count('1')
b = l.count('2')
# print(a,b)
if a!=0 and b!=0:
print(b)
if b==0 and a>0:
print(n//3)
if a==0:
print(0)
| Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
l = list(input())
a = l.count('1')
b = l.count('2')
# print(a,b)
if a!=0 and b!=0:
print(b)
if b==0 and a>0:
print(n//3)
if a==0:
print(0)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,641,754,374 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input()
uc=0
lc=0
for i in s:
if i.isupper() :
uc += 1
else :
lc += 1
if uc>=lc :
print(s.lower())
else :
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
uc=0
lc=0
for i in s:
if i.isupper() :
uc += 1
else :
lc += 1
if uc>=lc :
print(s.lower())
else :
print(s.upper())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,677,426,003 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 202 | 13,926,400 | input()
arr = list(map(int,input().split()))
st = set()
ans = 0
for i in arr:
if not i in st:
st.add(i)
else:
ans = max(ans,len(st))
st.remove(i)
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
input()
arr = list(map(int,input().split()))
st = set()
ans = 0
for i in arr:
if not i in st:
st.add(i)
else:
ans = max(ans,len(st))
st.remove(i)
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,678,285,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 10,444,800 | length = input()
numbers = tuple(int(i) for i in input().split())
maximum = max(numbers)
minimum = min(numbers)
print(maximum - minimum, numbers.count(maximum) * numbers.count(minimum)) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
length = input()
numbers = tuple(int(i) for i in input().split())
maximum = max(numbers)
minimum = min(numbers)
print(maximum - minimum, numbers.count(maximum) * numbers.count(minimum))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,653,299,647 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | if __name__ == '__main__':
s = input().split()
r = int(s[0])
c = int(s[1])
rows = []
cols = []
for i in range(r):
s = input()
for j in range(c):
if s[j] == 'S':
rows.append(i)
cols.append(j)
q = len(set(rows))
w = l... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
if __name__ == '__main__':
s = input().split()
r = int(s[0])
c = int(s[1])
rows = []
cols = []
for i in range(r):
s = input()
for j in range(c):
if s[j] == 'S':
rows.append(i)
cols.append(j)
q = len(set(rows))
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,698,514,250 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | t = int(input())
print(t)
print(str(t)[::-1]) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
t = int(input())
print(t)
print(str(t)[::-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,625,813,996 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | n, m = list(map(int, input().split()))
prices = list(map(int, input().split()))
prices.sort()
print(prices)
print(-1 * sum(prices[:m])) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, m = list(map(int, input().split()))
prices = list(map(int, input().split()))
prices.sort()
print(prices)
print(-1 * sum(prices[:m]))
``` | 0 | 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,640,054,959 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | s, t = input(), input()
if (len(s) != len(t)):
print("NO")
quit()
for index in range(len(s)):
if s[index] != t[len(s) - index - 1]:
print("NO")
quit()
print("YES") | 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
s, t = input(), input()
if (len(s) != len(t)):
print("NO")
quit()
for index in range(len(s)):
if s[index] != t[len(s) - index - 1]:
print("NO")
quit()
print("YES")
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
283 | A | Cows and Sequence | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of operations. The next *n* lines describe the operations. Each line will start with an integer *t**i* (1<=≤<=*t**i*<=≤<=3), denoting the type of the operation (see above). If *t**i*<==<=1, it will be followed by two integers *a**i*,<=*x**i... | Output *n* lines each containing the average of the numbers in the sequence after the corresponding operation.
The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"5\n2 1\n3\n2 3\n2 1\n3\n",
"6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n"
] | [
"0.500000\n0.000000\n1.500000\n1.333333\n1.500000\n",
"0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000\n"
] | In the second sample, the sequence becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fb5aaaa5dc516fe540cef52fd153768bfdb941c8.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "5\n2 1\n3\n2 3\n2 1\n3",
"output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"
},
{
"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3",
"output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"
},
{
"input": "1\n1 1 1",
"output": "1.000000"
},
{
... | 1,638,212,857 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,500 | 10,547,200 | import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return... | Title: Cows and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the i... | ```python
import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,626,266,230 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 1,185 | 35,942,400 | import math
def myhash(a,b):
return 'x'+str(a)+'y'+str(b)
n = int(input())
samesame= {}
x_d = {}
y_d = {}
copies = 0
ans = 0
for _ in range(n):
x,y = map(int,input().split())
if myhash(x,y) in samesame:
samesame[myhash(x,y)] += 1
else:
samesame[myhash(x,y)] = 1
if x in... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
import math
def myhash(a,b):
return 'x'+str(a)+'y'+str(b)
n = int(input())
samesame= {}
x_d = {}
y_d = {}
copies = 0
ans = 0
for _ in range(n):
x,y = map(int,input().split())
if myhash(x,y) in samesame:
samesame[myhash(x,y)] += 1
else:
samesame[myhash(x,y)] = 1
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,588,772,585 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 249 | 10,956,800 | o,a,b = map(int, input().split())
n = int(input())
l = [i for i in input().split() if int(i)> a and int(i)<b]
print(len(l)) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
o,a,b = map(int, input().split())
n = int(input())
l = [i for i in input().split() if int(i)> a and int(i)<b]
print(len(l))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,689,178,746 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 62 | 0 | a, b, c = map(int, input().split())
if 2 * (a + b) <= (a + b + c):
print(2 * (a + b))
elif 2 * (c + b) <= (a + b + c):
print(2 * (c + b))
elif 2 * (c + a) <= (a + b + c):
print(2 * (c + a))
elif a == b == c or 2 * (a + b) > (a + b + c):
print(a + b + c)
else:
print(2 * c + 2 * min(a, b))
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a, b, c = map(int, input().split())
if 2 * (a + b) <= (a + b + c):
print(2 * (a + b))
elif 2 * (c + b) <= (a + b + c):
print(2 * (c + b))
elif 2 * (c + a) <= (a + b + c):
print(2 * (c + a))
elif a == b == c or 2 * (a + b) > (a + b + c):
print(a + b + c)
else:
print(2 * c + 2 * mi... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,503,334,869 | 6,969 | Python 3 | WRONG_ANSWER | TESTS | 4 | 670 | 16,998,400 | def minn(nums):
minn = 1000000000
for i in range (len(nums)):
if nums[i][0] < minn:
minn = nums[i][0]
min_i = i
return minn, min_i
n = int(input())
nums = []
for i in range (n):
msg = input().split()
num = [int(msg[0]),int(msg[1])]
nums.append(num)
a_finish ... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
def minn(nums):
minn = 1000000000
for i in range (len(nums)):
if nums[i][0] < minn:
minn = nums[i][0]
min_i = i
return minn, min_i
n = int(input())
nums = []
for i in range (n):
msg = input().split()
num = [int(msg[0]),int(msg[1])]
nums.append(num)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,592,022,485 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 9,011,200 | import sys
input = lambda: sys.stdin.readline().strip("\r\n")
a, b, n = map(int, input().split())
flag = 0
while n > 0:
for i in range(10):
num = int(str(a) + str(i))
if num % b == 0:
a = num
n -= 1
break
else:
print(-1)
flag =... | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
import sys
input = lambda: sys.stdin.readline().strip("\r\n")
a, b, n = map(int, input().split())
flag = 0
while n > 0:
for i in range(10):
num = int(str(a) + str(i))
if num % b == 0:
a = num
n -= 1
break
else:
print(-1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,633,402,160 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 61 | 6,963,200 | #https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = True
co... | 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
#https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = T... | 3.95653 | MatrixStudio/Codeforces-Python-Submissions |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,661,527,171 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 0 | # cook your dish here
a,b,c,d = map(int,input().split())
s = input()
co = 0
for x in s:
if x=='1':
co += a
elif x=='2':
co+=b
elif x=='3':
co+=c
else:
co+=d
print(co) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
# cook your dish here
a,b,c,d = map(int,input().split())
s = input()
co = 0
for x in s:
if x=='1':
co += a
elif x=='2':
co+=b
elif x=='3':
co+=c
else:
co+=d
print(co)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op... | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111... | 1,645,320,518 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 14 | 46 | 0 | from time import sleep as sle
from math import *
from random import randint as ri
def gcd(a,b):
if a == b:
return a
elif a > b:
return gcd(a-b,b)
else:
return gcd(b,a)
def pr(x):
print()
for s in x:
print(s)
def solve():
n,d = map(int,input().split())
L = [[]]
for _ in range(d):
... | Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th... | ```python
from time import sleep as sle
from math import *
from random import randint as ri
def gcd(a,b):
if a == b:
return a
elif a > b:
return gcd(a-b,b)
else:
return gcd(b,a)
def pr(x):
print()
for s in x:
print(s)
def solve():
n,d = map(int,input().split())
L = [[]]
for _ in ... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,517,125,153 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 5,939,200 | n,m = [x for x in map(int, input().strip().split(" "))] # 3 5
req = list(map(int,input().strip().split(" "))) # 1 2 3
prep = list(map(int,input().strip().split(" "))) # 1 3 5 6 7
# 3 5
# 1 2 3
# 1 1 1 1 1
count = 0
j = 0
for i in range(0, n):
while (j < m):
if (req[i] == prep[j] or prep[j] > ... | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
n,m = [x for x in map(int, input().strip().split(" "))] # 3 5
req = list(map(int,input().strip().split(" "))) # 1 2 3
prep = list(map(int,input().strip().split(" "))) # 1 3 5 6 7
# 3 5
# 1 2 3
# 1 1 1 1 1
count = 0
j = 0
for i in range(0, n):
while (j < m):
if (req[i] == prep[j] or ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,698,226,853 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 140 | 13,619,200 | n = int(input())
if n == 1:
print(1)
else:
queue = list(map(int, input().split()))
least = min(queue) # 对于最小元问题单独处理
number_least = queue.count(least)
queue2 = set()
queue2.update(queue)
most=max(queue2)
queue = sorted(queue2)
sum_ = 0
ans = 0
if number_least > 1... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
n = int(input())
if n == 1:
print(1)
else:
queue = list(map(int, input().split()))
least = min(queue) # 对于最小元问题单独处理
number_least = queue.count(least)
queue2 = set()
queue2.update(queue)
most=max(queue2)
queue = sorted(queue2)
sum_ = 0
ans = 0
if number... | 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,553,794,849 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | input_string=str(input())
sets=set(input_string)
sorted_set=sorted(sets)
string1=set("hello")
sorted_string1=sorted(string1)
for i in range(len(sorted_set)):
if len(sorted_set)==4:
print("NO")
break
if sorted_set[i]=="e":
if sorted_set[i+1]=="h":
if sorted_set[i+2]... | 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
input_string=str(input())
sets=set(input_string)
sorted_set=sorted(sets)
string1=set("hello")
sorted_string1=sorted(string1)
for i in range(len(sorted_set)):
if len(sorted_set)==4:
print("NO")
break
if sorted_set[i]=="e":
if sorted_set[i+1]=="h":
if sorte... | 0 | MatrixStudio/Codeforces-Python-Submissions |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,647,817,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
s = list(input())
def function(s):
A = True
for i, letter in enumerate(s):
if i != 0 and s[i] == s[i-1] and A:
s.pop(i),i
A = False
if i != 0 and s[i] != s[i-1]:
A = False
return s
s = function(s)
s.reverse()
s = function(s)
print(len(s))
... | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
n = int(input())
s = list(input())
def function(s):
A = True
for i, letter in enumerate(s):
if i != 0 and s[i] == s[i-1] and A:
s.pop(i),i
A = False
if i != 0 and s[i] != s[i-1]:
A = False
return s
s = function(s)
s.reverse()
s = function(s)
print(len(s))
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make... | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
}... | 1,519,524,700 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | T=input()
X=[0]
n=0
j='a'
for i in T:
if i==j: X[n]+=1:
else:
n+=1
X[n]=1
j='a' if j=='b' else 'b'
ans=-1
for i in range(0,len(X)):
ans=max(ans,sum(X[i:i+3]))
print(ans) | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ... | ```python
T=input()
X=[0]
n=0
j='a'
for i in T:
if i==j: X[n]+=1:
else:
n+=1
X[n]=1
j='a' if j=='b' else 'b'
ans=-1
for i in range(0,len(X)):
ans=max(ans,sum(X[i:i+3]))
print(ans)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of... | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov... | 1,499,005,993 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 3,000 | 38,604,800 | S = []
A=set()
cnt = 0
r = 0
for i in range(2*int(input())):
cmd = input().split()
if cmd[0] == "add":
S.append(int(cmd[1]))
else:
r += 1
if S == []:
if r in A:
continue
elif S[-1] == r:
S.pop()
continue
else:
... | Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a... | ```python
S = []
A=set()
cnt = 0
r = 0
for i in range(2*int(input())):
cmd = input().split()
if cmd[0] == "add":
S.append(int(cmd[1]))
else:
r += 1
if S == []:
if r in A:
continue
elif S[-1] == r:
S.pop()
continue
el... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,497,253,025 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 124 | 921,600 | #! /bin/python3
a, b = [int(x) for x in input().strip().split(' ')]
c, d = [int(x) for x in input().strip().split(' ')]
# bf
R = set([])
M = set([])
for i in range(10000):
R.add(b + a * i)
M.add(d + c * i)
t = R & M
if len(t) > 0:
print(min(t))
else:
print(-1)
| Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
#! /bin/python3
a, b = [int(x) for x in input().strip().split(' ')]
c, d = [int(x) for x in input().strip().split(' ')]
# bf
R = set([])
M = set([])
for i in range(10000):
R.add(b + a * i)
M.add(d + c * i)
t = R & M
if len(t) > 0:
print(min(t))
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,596,276,055 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 216 | 6,656,000 | class Code:
def __init__(self):
self.n, self.m = list(map(int, input().split()))
self.arr = list(map(int, input().split()))
def process(self):
self.arr.sort()
earn = 0
for i in range(self.m):
if self.arr[i] <= 0:
earn += -self.arr[i]... | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
class Code:
def __init__(self):
self.n, self.m = list(map(int, input().split()))
self.arr = list(map(int, input().split()))
def process(self):
self.arr.sort()
earn = 0
for i in range(self.m):
if self.arr[i] <= 0:
earn += -s... | 3.933602 | MatrixStudio/Codeforces-Python-Submissions |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,649,703,110 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | s=input()
t=input()
l=0 ;r=0
while l < len(s) and r <len(t) :
# print(l,r)
if s[l]==t[r] :
l+=1
r+=1
else:
r+=1
print(l+1)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s=input()
t=input()
l=0 ;r=0
while l < len(s) and r <len(t) :
# print(l,r)
if s[l]==t[r] :
l+=1
r+=1
else:
r+=1
print(l+1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
427 | C | Checkposts | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"two pointers"
] | null | null | Your city has *n* junctions. There are *m* one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction *i* can protect junction *j... | In the first line, you will be given an integer *n*, number of junctions (1<=≤<=*n*<=≤<=105). In the next line, *n* space-separated integers will be given. The *i**th* integer is the cost of building checkpost at the *i**th* junction (costs will be non-negative and will not exceed 109).
The next line will contain an i... | Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109<=+<=7). | [
"3\n1 2 3\n3\n1 2\n2 3\n3 2\n",
"5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1\n",
"10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9\n",
"2\n7 91\n2\n1 2\n2 1\n"
] | [
"3 1\n",
"8 2\n",
"15 6\n",
"7 1\n"
] | none | 1,500 | [
{
"input": "3\n1 2 3\n3\n1 2\n2 3\n3 2",
"output": "3 1"
},
{
"input": "5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1",
"output": "8 2"
},
{
"input": "10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9",
"output": "15 6"
},
{
"input": ... | 1,684,777,910 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 70 | 795 | 50,892,800 | from collections import deque as dq
def topological(G):
n = len(G)
sort = []
visited = [False for _ in range(n)]
def dfs(G, u):
nonlocal sort
nonlocal visited
visited[u] = True
for v in G[u]:
if not visited[v]:
dfs(G,... | Title: Checkposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your city has *n* junctions. There are *m* one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts.... | ```python
from collections import deque as dq
def topological(G):
n = len(G)
sort = []
visited = [False for _ in range(n)]
def dfs(G, u):
nonlocal sort
nonlocal visited
visited[u] = True
for v in G[u]:
if not visited[v]:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,666,937,068 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | import numpy as np
n=int(input())
a=[eval(input().replace(' ',',')) for i in range(n)]
a=np.array(a)
out=n
for i,ai in enumerate(a):
if (ai[0] in a[:,1])and(ai[0]!=ai[1]) :
out -= 1
print(out) | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
import numpy as np
n=int(input())
a=[eval(input().replace(' ',',')) for i in range(n)]
a=np.array(a)
out=n
for i,ai in enumerate(a):
if (ai[0] in a[:,1])and(ai[0]!=ai[1]) :
out -= 1
print(out)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,689,940,359 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 233 | 25,190,400 | def Bin_search(ls,low,high,key):
while low <= high:
mid = (low+high)//2
if key >= ls[mid][0] and key<= ls[mid][-1] :
return mid
elif key>ls[mid][-1]:
low = mid+1
elif key<ls[mid][0]:
high = mid-1
return -1
n = int(input())
piles = list(map(int,... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
def Bin_search(ls,low,high,key):
while low <= high:
mid = (low+high)//2
if key >= ls[mid][0] and key<= ls[mid][-1] :
return mid
elif key>ls[mid][-1]:
low = mid+1
elif key<ls[mid][0]:
high = mid-1
return -1
n = int(input())
piles = lis... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,684,865,876 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | # Link: https://codeforces.com/contest/59/problem/A
string = input()
lowercases = uppercases = 0
for letter in string:
if letter.islower():
lowercases += 1
else:
uppercases += 1
if lowercases >= uppercases:
print(string.lower())
else:
print(string.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
# Link: https://codeforces.com/contest/59/problem/A
string = input()
lowercases = uppercases = 0
for letter in string:
if letter.islower():
lowercases += 1
else:
uppercases += 1
if lowercases >= uppercases:
print(string.lower())
else:
print(string.upper())
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
515 | B | Drazil and His Happy Friends | PROGRAMMING | 1,300 | [
"brute force",
"dsu",
"meet-in-the-middle",
"number theory"
] | null | null | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th ... | The first line contains two integer *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains integer *b* (0<=≤<=*b*<=≤<=*n*), denoting the number of happy boys among friends of Drazil, and then follow *b* distinct integers *x*1,<=*x*2,<=...,<=*x**b* (0<=≤<=*x**i*<=<<=*n*), denoting the list of indices of hap... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | [
"2 3\n0\n1 0\n",
"2 4\n1 0\n1 2\n",
"2 3\n1 0\n1 1\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/169ade208e6eb4f9263c57aaff716529d59c3288.png" style="max-width: 100.0%;max-height: 100.0%;"/> we define the remainder of integer division of *i* by *k*.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Bec... | 1,000 | [
{
"input": "2 3\n0\n1 0",
"output": "Yes"
},
{
"input": "2 4\n1 0\n1 2",
"output": "No"
},
{
"input": "2 3\n1 0\n1 1",
"output": "Yes"
},
{
"input": "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82",
"outpu... | 1,661,509,797 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | def GCD(a, b):
remain = 0
while b != 0:
remain = a % b
a = b
b = remain
return a
if __name__ == "__main__":
nBoys, nGirls = map(int, input().split())
lstB = list(map(int, input().split()))
lstG = list(map(int, input().split()))
numUnhappy = nBoys + nGirls... | Title: Drazil and His Happy Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among hi... | ```python
def GCD(a, b):
remain = 0
while b != 0:
remain = a % b
a = b
b = remain
return a
if __name__ == "__main__":
nBoys, nGirls = map(int, input().split())
lstB = list(map(int, input().split()))
lstG = list(map(int, input().split()))
numUnhappy = nBoy... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
560 | B | Gerald is into Art | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec... | The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. | If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). | [
"3 2\n1 3\n2 1\n",
"5 5\n3 3\n3 3\n",
"4 2\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | That's how we can place the pictures in the first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's how we can do it in the third one.
<img class="tex-graphics" src="https://espresso.codeforces... | 1,000 | [
{
"input": "3 2\n1 3\n2 1",
"output": "YES"
},
{
"input": "5 5\n3 3\n3 3",
"output": "NO"
},
{
"input": "4 2\n2 3\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 1",
"output": "YES"
},
{
"input": "1000 1000\n999 999\n1 1000",
"output": "YES"
},
{
"in... | 1,633,755,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 92 | 20,172,800 | from math import fabs
board,paintings=0,0
a=list(map(int,input().split()))
board=a[0]*a[1]
for i in range(2):
b=list(map(int,input().split()))
paintings+=b[0]*b[1]
#print(paintings,board)
if board==paintings or fabs(board-paintings)==1:
print("YES")
else:
print("NO") | Title: Gerald is into Art
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board ha... | ```python
from math import fabs
board,paintings=0,0
a=list(map(int,input().split()))
board=a[0]*a[1]
for i in range(2):
b=list(map(int,input().split()))
paintings+=b[0]*b[1]
#print(paintings,board)
if board==paintings or fabs(board-paintings)==1:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
916 | B | Jamie and Binary Sequence (changed after round) | PROGRAMMING | 2,000 | [
"bitmasks",
"greedy",
"math"
] | null | null | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. ... | The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence. | Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018]. | [
"23 5\n",
"13 2\n",
"1 2\n"
] | [
"Yes\n3 3 2 1 0 \n",
"No\n",
"Yes\n-1 -1 \n"
] | Sample 1:
2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1... | 1,000 | [
{
"input": "23 5",
"output": "Yes\n3 3 2 1 0 "
},
{
"input": "13 2",
"output": "No"
},
{
"input": "1 2",
"output": "Yes\n-1 -1 "
},
{
"input": "1 1",
"output": "Yes\n0 "
},
{
"input": "1000000000000000000 100000",
"output": "Yes\n44 44 44 44 44 44 44 44 44 44 ... | 1,516,378,153 | 5,653 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 249 | 12,800,000 | a,n=map(int,input().split())
st=1
while 2**st<a: st+=1;
st-=1
b=[]
while len(b)!=n and a!=0:
if (2**st<=a):
b.append(st)
a-=2**st
else: st-=1
if a!=0 and len(b)==n: print('No')
else:
l=len(b)
for i in range(n-l):
b[0]-=1
b.append(b[0])
if (b[0]<b[l... | Title: Jamie and Binary Sequence (changed after round)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such tha... | ```python
a,n=map(int,input().split())
st=1
while 2**st<a: st+=1;
st-=1
b=[]
while len(b)!=n and a!=0:
if (2**st<=a):
b.append(st)
a-=2**st
else: st-=1
if a!=0 and len(b)==n: print('No')
else:
l=len(b)
for i in range(n-l):
b[0]-=1
b.append(b[0])
if... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,505,656,490 | 2,989 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 46 | 0 | slovo = input()
num = int (0)
sog = int (0)
glasn = ['a', 'e', 'i', 'o', 'u']
for x in slovo:
num = num+1
if x not in glasn:
sog = sog + 1
else:
sog = 0
if sog == 3:
slovo = slovo[:num-1] + ' ' + slovo[num-1:]
print (slovo)
| Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (... | ```python
slovo = input()
num = int (0)
sog = int (0)
glasn = ['a', 'e', 'i', 'o', 'u']
for x in slovo:
num = num+1
if x not in glasn:
sog = sog + 1
else:
sog = 0
if sog == 3:
slovo = slovo[:num-1] + ' ' + slovo[num-1:]
print (slovo)
``` | 0 | 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,438,166,904 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 156 | 716,800 | import math
import os
import sys
import re
import itertools
import functools
import operator
a, b = input(), input()
if a == b[::-1]:
print('YES')
else:
print('NO') | 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
import os
import sys
import re
import itertools
import functools
import operator
a, b = input(), input()
if a == b[::-1]:
print('YES')
else:
print('NO')
``` | 3.959665 | MatrixStudio/Codeforces-Python-Submissions |
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ... | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000... | 1,598,556,415 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 78 | 0 | #rOkY
#FuCk
################################## kOpAl #####################################
a=int(input())
l=list(map(int,input().split()))
l.sort()
k=list(dict.fromkeys(l))
if(len(k)==1):
print(a)
else:
ma=max(l)
mi=min(l)
print(ma*mi +1)
| Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than ... | ```python
#rOkY
#FuCk
################################## kOpAl #####################################
a=int(input())
l=list(map(int,input().split()))
l.sort()
k=list(dict.fromkeys(l))
if(len(k)==1):
print(a)
else:
ma=max(l)
mi=min(l)
print(ma*mi +1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,691,395,035 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | for i in range(int(input())):
v=input()
x=0
y=0
for j in v:
if j=='A':
x+=1
elif j==D:
y+=1
if x>y:
print("Anton")
elif x<y:
print("Danik")
else:
print("Friendship")
| Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
for i in range(int(input())):
v=input()
x=0
y=0
for j in v:
if j=='A':
x+=1
elif j==D:
y+=1
if x>y:
print("Anton")
elif x<y:
print("Danik")
else:
print("Friendship")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,696,746,825 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,150,400 | w=input()
k=len(w)
for a in w:
k=k-k.count(a)+1
if k%2==0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
w=input()
k=len(w)
for a in w:
k=k-k.count(a)+1
if k%2==0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,656,154,412 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | x=input()
z=input()
x=x.lower()
z=z.lower()
lenz=0
if len(x)>len(z):
lenz=len(z)
else:
lenz=len(x)
flage=0
for i in range(lenz):
if x[i]>z[i]:
print(1)
flage=1
break
elif x[i]<z[i]:
print(-1)
flage=1
break
if flage==0:
if le... | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
x=input()
z=input()
x=x.lower()
z=z.lower()
lenz=0
if len(x)>len(z):
lenz=len(z)
else:
lenz=len(x)
flage=0
for i in range(lenz):
if x[i]>z[i]:
print(1)
flage=1
break
elif x[i]<z[i]:
print(-1)
flage=1
break
if flage==0:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,634,544,120 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
n, K = [int(j) for j in input().split()]
def FindKSmallest(n, k):
div1 = []
div2 = []
for i in range(1, math.ceil(n**0.5)):
if n % i == 0:
div1.append(i)
if i != math.ceil(math.sqrt(n)):
div2.append(n // i)
div2 = div2[::-1]
if k > ... | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
import math
n, K = [int(j) for j in input().split()]
def FindKSmallest(n, k):
div1 = []
div2 = []
for i in range(1, math.ceil(n**0.5)):
if n % i == 0:
div1.append(i)
if i != math.ceil(math.sqrt(n)):
div2.append(n // i)
div2 = div2[::-1]
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,587,499,902 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 156 | 0 | n=int(input())
t=list(map(int,input().split()))
t.sort()
if 1 in t:
print(-1)
else:
print(1) | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
n=int(input())
t=list(map(int,input().split()))
t.sort()
if 1 in t:
print(-1)
else:
print(1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,585,610,303 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 216 | 0 | a=int(input())
s=1
for i in range(0,a):
s+=i*12
print (s) | Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
a=int(input())
s=1
for i in range(0,a):
s+=i*12
print (s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | ||
602 | A | Two Bases | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. | The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the dig... | Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y* | [
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n"
] | [
"=\n",
"<\n",
">\n"
] | In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In ... | 500 | [
{
"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7",
"output": "="
},
{
"input": "3 3\n1 0 2\n2 5\n2 4",
"output": "<"
},
{
"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "2 2\n1 0\n2 3\n1 0",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n1"... | 1,448,383,207 | 307 | Python 3 | OK | TESTS | 118 | 62 | 0 | #!/usr/bin/python3
def make_num(lst, bx):
res = 0
for elem in lst:
res *= bx
res += elem
return res
n, bx = map(int, input().split())
num1 = make_num(map(int, input().split()), bx)
m, by = map(int, input().split())
num2 = make_num(map(int, input().split()), by)
if num1 < num2:
print('<')
elif num1 == num... | Title: Two Bases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* ... | ```python
#!/usr/bin/python3
def make_num(lst, bx):
res = 0
for elem in lst:
res *= bx
res += elem
return res
n, bx = map(int, input().split())
num1 = make_num(map(int, input().split()), bx)
m, by = map(int, input().split())
num2 = make_num(map(int, input().split()), by)
if num1 < num2:
print('<')
elif n... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,640,588,660 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | # import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
n = int(input())
i = 0
s1=["."]*n
while i<=(n-1):
s1[i]="c"
i+=2
s2 = ["."]*n
i=1
while i<=(n-1):
s2[i]="c"
i+=2
f=True
for i in range(n):
if f:
print("".join(s1)... | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
# import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
n = int(input())
i = 0
s1=["."]*n
while i<=(n-1):
s1[i]="c"
i+=2
s2 = ["."]*n
i=1
while i<=(n-1):
s2[i]="c"
i+=2
f=True
for i in range(n):
if f:
print("... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the st... | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The... | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"ou... | 1,451,207,895 | 2,147,483,647 | Python 3 | OK | TESTS | 72 | 62 | 0 | def gaseste(a,b,n):
gasit = False
k = 0
while k * a <= n and not gasit:
p = 0
while (p * b) + (k*a) <= n and not gasit:
if (p*b)+(k*a) == n:
gasit = True
else:
p+=1
if not gasit:
k+=1
return (-1,-1) i... | Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H... | ```python
def gaseste(a,b,n):
gasit = False
k = 0
while k * a <= n and not gasit:
p = 0
while (p * b) + (k*a) <= n and not gasit:
if (p*b)+(k*a) == n:
gasit = True
else:
p+=1
if not gasit:
k+=1
return... | 3 | 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,524,837,863 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 93 | 7,065,600 | n = int(input())
if n >36:
print(-1)
else :
a=[]
num1 = n//2
num2 = n-num1 *2
for i in range(num1):
print('8',end='')
for i in range(num2):
print('4',end='')
| 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
n = int(input())
if n >36:
print(-1)
else :
a=[]
num1 = n//2
num2 = n-num1 *2
for i in range(num1):
print('8',end='')
for i in range(num2):
print('4',end='')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,699,120,676 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = int(input())
c = input()
totake = 0
for i in range(n):
if i > 0 and c[i-1] == c[i]:
totake += 1
print(totake) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n = int(input())
c = input()
totake = 0
for i in range(n):
if i > 0 and c[i-1] == c[i]:
totake += 1
print(totake)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
13 | D | Triangles | PROGRAMMING | 2,600 | [
"dp",
"geometry"
] | D. Triangles | 2 | 64 | Little Petya likes to draw. He drew *N* red and *M* blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside. | The first line contains two non-negative integer numbers *N* and *M* (0<=≤<=*N*<=≤<=500, 0<=≤<=*M*<=≤<=500) — the number of red and blue points respectively. The following *N* lines contain two integer numbers each — coordinates of red points. The following *M* lines contain two integer numbers each — coordinates of bl... | Output one integer — the number of distinct triangles with vertices in red points which do not contain any blue point inside. | [
"4 1\n0 0\n10 0\n10 10\n5 4\n2 1\n",
"5 5\n5 10\n6 1\n8 6\n-6 -7\n7 -1\n5 -1\n10 -4\n-10 -8\n-10 5\n-2 -8\n"
] | [
"2\n",
"7\n"
] | none | 0 | [] | 1,690,479,220 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def is_right(c):
sides = [0, 0, 0]
sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3]) * (c[5] - c[3])
sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1]) * (c[5] - c[1])
sides[2] = (c[2] - c[0]) * (c[2] - c[0]) + (c[3] - c[1]) * (c[3] - c[1])
sides.sort()
if sides[0] > 0 and s... | Title: Triangles
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes to draw. He drew *N* red and *M* blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not... | ```python
def is_right(c):
sides = [0, 0, 0]
sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3]) * (c[5] - c[3])
sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1]) * (c[5] - c[1])
sides[2] = (c[2] - c[0]) * (c[2] - c[0]) + (c[3] - c[1]) * (c[3] - c[1])
sides.sort()
if sides[0]... | -1 | MatrixStudio/Codeforces-Python-Submissions |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,656,261,157 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 4,505,600 | n = int(input())
exercise = list(map(int, input().split()))
for i in range (n):
back = exercise [i]
chest = exercise [i]
biceps = exercise [i]
if (i+1)%3 == 0:
back = exercise [i] + back
if (i+1)%3 == 1:
chest = exercise [i] + chest
if (i+1)%3 == 2:
biceps = e... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
exercise = list(map(int, input().split()))
for i in range (n):
back = exercise [i]
chest = exercise [i]
biceps = exercise [i]
if (i+1)%3 == 0:
back = exercise [i] + back
if (i+1)%3 == 1:
chest = exercise [i] + chest
if (i+1)%3 == 2:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,699,889,322 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 12,492,800 | size_A , size_B = map(int , input().split())
k , m = map(int , input().split())
Array_A = list(map(int, input().split()))
Array_B = list(map(int, input().split()))
is_flag = True
for j in range(m):
for i in range(k):
if Array_A[i] >= Array_B[-(j+1)]:
is_flag = False
break... | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
size_A , size_B = map(int , input().split())
k , m = map(int , input().split())
Array_A = list(map(int, input().split()))
Array_B = list(map(int, input().split()))
is_flag = True
for j in range(m):
for i in range(k):
if Array_A[i] >= Array_B[-(j+1)]:
is_flag = False
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,641,565,643 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=int(input())
ar=list(map(int,input().split()))
ar.sort()
#print(ar[n//2-1],ar[n//2])
if ar[n//2-1]>=ar[n//2]:
print("NO")
else:
print("YES") | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
n=int(input())
ar=list(map(int,input().split()))
ar.sort()
#print(ar[n//2-1],ar[n//2])
if ar[n//2-1]>=ar[n//2]:
print("NO")
else:
print("YES")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
442 | A | Borya and Hanabi | PROGRAMMING | 1,700 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards exc... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Borya's cards. The next line contains the descriptions of *n* cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The... | Print a single integer — the minimum number of hints that the other players should make. | [
"2\nG3 G3\n",
"4\nG4 R4 R3 B3\n",
"5\nB1 Y1 W1 G1 R1\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample Borya already knows for each card that it is a green three.
In the second sample we can show all fours and all red cards.
In the third sample you need to make hints about any four colors. | 500 | [
{
"input": "2\nG3 G3",
"output": "0"
},
{
"input": "4\nG4 R4 R3 B3",
"output": "2"
},
{
"input": "5\nB1 Y1 W1 G1 R1",
"output": "4"
},
{
"input": "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1",
"output": "6"
},
{
"input": "3\nG4 G3 B4",
"output": "2"
},
{
"input"... | 1,422,125,454 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 1,918 | 0 | def check(hint, Card):
for i in Card :
for j in Card :
if i == j : continue
elif i[0] == j[0] :
if i[1] not in hint and j[1] not in hint :
return False
elif i[1] == j[1] :
if i[0] not in hint and j[0] not in hint... | Title: Borya and Hanabi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is... | ```python
def check(hint, Card):
for i in Card :
for j in Card :
if i == j : continue
elif i[0] == j[0] :
if i[1] not in hint and j[1] not in hint :
return False
elif i[1] == j[1] :
if i[0] not in hint and j[0] n... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,661,563,967 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 61 | 2,560,000 | import random
import time
def input_int():
return int(input())
def input_int_list():
return [int(_) for _ in input().split()]
def input_str():
return input()
def input_str_list():
return [_ for _ in input().split()]
def print_solution(solution_list):
for solution in solution_list:
... | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
import random
import time
def input_int():
return int(input())
def input_int_list():
return [int(_) for _ in input().split()]
def input_str():
return input()
def input_str_list():
return [_ for _ in input().split()]
def print_solution(solution_list):
for solution in solution_list... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,512,303,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,529,600 | def gcd(a,b):
while( a!= b):
if a > b:
a = a - b
if a < b :
b = b - a
if a == b:
return a
n = int(input())
for i in range(int(n/2), 1,-1):
if gcd(n-i,i) == 1:
print(str(i) + " " + str(n-i))
break
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
def gcd(a,b):
while( a!= b):
if a > b:
a = a - b
if a < b :
b = b - a
if a == b:
return a
n = int(input())
for i in range(int(n/2), 1,-1):
if gcd(n-i,i) == 1:
print(str(i) + " " + str(n-i))
break
``` | 0 | 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,665,892,337 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 62 | 0 | charecter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = ""
n, k = input().split()
charecter = charecter[:int(k)]
charecter = charecter * 100;
#print(charecter)
for i in range(int(n)):
s += charecter[i]
... | 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
charecter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = ""
n, k = input().split()
charecter = charecter[:int(k)]
charecter = charecter * 100;
#print(charecter)
for i in range(int(n)):
s += charect... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,657,683,862 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | password = input()
upper_characters = []
lower_characters = []
digits = []
for s in password:
if s.isupper():
upper_characters.append(s)
elif s.islower():
lower_characters.append(s)
elif s.isdigit():
digits.append(s)
if len(password) >= 5 and len(upper_characters) >= 1 and len(lowe... | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
password = input()
upper_characters = []
lower_characters = []
digits = []
for s in password:
if s.isupper():
upper_characters.append(s)
elif s.islower():
lower_characters.append(s)
elif s.isdigit():
digits.append(s)
if len(password) >= 5 and len(upper_characters) >= 1 an... | 3 | 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,694,337,058 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | k,n,w=input().split()
n=int(n)
k=int(k)
w=int(w)
sum=0
for i in range(w):
sum+=(i+1)*k
if w>=sum:
print("0")
else:
print(sum-n) | 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=input().split()
n=int(n)
k=int(k)
w=int(w)
sum=0
for i in range(w):
sum+=(i+1)*k
if w>=sum:
print("0")
else:
print(sum-n)
``` | 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,636,948,990 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | n=int(input())
s=input()
f=0
i=0
while i<n-1:
if (s[i]=='U' and s[i+1]=='R') or (s[i]=='R' and s[i+1]=='U'):
f=f+1
i=i+2
else:
i=i+1
print(n-f) | 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()
f=0
i=0
while i<n-1:
if (s[i]=='U' and s[i+1]=='R') or (s[i]=='R' and s[i+1]=='U'):
f=f+1
i=i+2
else:
i=i+1
print(n-f)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,697,472,297 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 186 | 14,336,000 | import sys
from os import path
if (path.exists('input.txt')):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt','w')
s = input()
if '0' not in s: print(s[:-1])
else:
l = list(s)
l.remove('0')
print(*l,sep='') | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
import sys
from os import path
if (path.exists('input.txt')):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt','w')
s = input()
if '0' not in s: print(s[:-1])
else:
l = list(s)
l.remove('0')
print(*l,sep='')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,597,809,112 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
n,m = map(int,input().split())
g = [set() for i in range(n)]
l = []
p = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
p[a]+=1
p[b]+=1
g[a].add(b)
g[b].add(a)
l.append(a,b)
ans = 1000000
for i,j in l:
for k in range(n):
... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
import sys
n,m = map(int,input().split())
g = [set() for i in range(n)]
l = []
p = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
p[a]+=1
p[b]+=1
g[a].add(b)
g[b].add(a)
l.append(a,b)
ans = 1000000
for i,j in l:
for k in ra... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,549,001,025 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 0 | a = input()
b = input()
output = [['1', '0'][a[i] == b[i]] for i in range(len(a))]
print(''.join(output)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a = input()
b = input()
output = [['1', '0'][a[i] == b[i]] for i in range(len(a))]
print(''.join(output))
``` | 3.97275 | 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,696,324,801 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x, y = map(int, input().split())
size = x * y
num = size // 2
num | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
x, y = map(int, input().split())
size = x * y
num = size // 2
num
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
160 | B | Unlucky Ticket | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches th... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The second line contains a string that consists of 2*n* digits and defines your ticket. | In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes). | [
"2\n2421\n",
"2\n0135\n",
"2\n3754\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2\n2421",
"output": "YES"
},
{
"input": "2\n0135",
"output": "YES"
},
{
"input": "2\n3754",
"output": "NO"
},
{
"input": "1\n33",
"output": "NO"
},
{
"input": "2\n3444",
"output": "NO"
},
{
"input": "3\n221323",
"output": "YES"
},
{... | 1,697,819,534 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 55 | 122 | 0 | n=int(input())
s=input()
S=sorted
print("NYOE S"[all(i<j for i,j in zip(*S([S(s[:n]),S(s[n:])])))::2])# 1697819534.027226 | Title: Unlucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket ... | ```python
n=int(input())
s=input()
S=sorted
print("NYOE S"[all(i<j for i,j in zip(*S([S(s[:n]),S(s[n:])])))::2])# 1697819534.027226
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,580,452,281 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 307,200 | n=int(input())
p=int(input())
k=int(input())
print(n,p,k)
s=" "
arr=[]
val="("+str(p)+")"
arr.append(val)
i=1
while(i<=k):
if((p+i)>n):
break
else:
arr.append(str(p+i))
i+=1
i=1
while(i<=k):
if((p-i)==0):
break
else:
arr.insert(0,str(... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
n=int(input())
p=int(input())
k=int(input())
print(n,p,k)
s=" "
arr=[]
val="("+str(p)+")"
arr.append(val)
i=1
while(i<=k):
if((p+i)>n):
break
else:
arr.append(str(p+i))
i+=1
i=1
while(i<=k):
if((p-i)==0):
break
else:
arr.ins... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
320 | B | Ping-Pong (Easy Version) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=<<=*a*<=<<=*d* or *c*<=<<=*b*<=<<=*d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a seq... | The first line of the input contains integer *n* denoting the number of queries, (1<=≤<=*n*<=≤<=100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | [
"5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n"
] | [
"NO\nYES\n"
] | none | 1,000 | [
{
"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2",
"output": "NO\nYES"
},
{
"input": "10\n1 -311 -186\n1 -1070 -341\n1 -1506 -634\n1 688 1698\n2 2 4\n1 70 1908\n2 1 2\n2 2 4\n1 -1053 1327\n2 5 4",
"output": "NO\nNO\nNO\nYES"
},
{
"input": "10\n1 -1365 -865\n1 1244 1834\n2 1 2\n1 -1508 -... | 1,632,476,836 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | def dfs(adj, vis, v):
global flag
vis[v] = True
for u in adj[v]:
if not vis[u]:
dfs(adj, vis, u)
n = int(input())
adj = []
intervals = []
icount = 0
for _ in range(n):
query = [int(x) for x in input().split()]
if query[0] == 1:
ls, x, y = [], query[1], query[2]
... | Title: Ping-Pong (Easy Version)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=<<=*a*<=<<=*d* or *c*<=<<=*b*<=&... | ```python
def dfs(adj, vis, v):
global flag
vis[v] = True
for u in adj[v]:
if not vis[u]:
dfs(adj, vis, u)
n = int(input())
adj = []
intervals = []
icount = 0
for _ in range(n):
query = [int(x) for x in input().split()]
if query[0] == 1:
ls, x, y = [], query[1], query[2... | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.