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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,683,917,481 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n, k, l, c, d, p, nl, np = map(int, input().split())
slices = c*d
drink_mili_litres = k*l
salt = p
num1 = drink_mili_litres//(nl*n)
num2 = slices//n
num3 = p//(np*n)
print(min([num1, num2, num3])) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n, k, l, c, d, p, nl, np = map(int, input().split())
slices = c*d
drink_mili_litres = k*l
salt = p
num1 = drink_mili_litres//(nl*n)
num2 = slices//n
num3 = p//(np*n)
print(min([num1, num2, num3]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,692,696,375 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n = int(input())
levelsX = set(map(int, input().split()[1:]))
levelsY = set(map(int, input().split()[1:]))
a = levelsX.union(levelsY)
if len(a) == n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
levelsX = set(map(int, input().split()[1:]))
levelsY = set(map(int, input().split()[1:]))
a = levelsX.union(levelsY)
if len(a) == n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,636,654,656 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 59,494,400 | import sys
# For getting input from input.txt file
sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
sys.stdout = open('output.txt', 'w')
from collections import Counter
n=int(input())
l2=list(map(int,input().split()))
l=[]
c=list(Counter(l2).values())
lx=[c[i]%2==0 for i in range... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
import sys
# For getting input from input.txt file
sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
sys.stdout = open('output.txt', 'w')
from collections import Counter
n=int(input())
l2=list(map(int,input().split()))
l=[]
c=list(Counter(l2).values())
lx=[c[i]%2==0 for ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
29 | D | Ant on the Tree | PROGRAMMING | 2,000 | [
"constructive algorithms",
"dfs and similar",
"trees"
] | D. Ant on the Tree | 2 | 256 | Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.
An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=300) — amount of vertexes in the tree. Next *n*<=-<=1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has numbe... | If the required route doesn't exist, output -1. Otherwise, output 2*n*<=-<=1 numbers, describing the route. Every time the ant comes to a vertex, output it's index. | [
"3\n1 2\n2 3\n3\n",
"6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n",
"6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n"
] | [
"1 2 3 2 1 ",
"1 2 4 5 4 6 4 2 1 3 1 ",
"-1\n"
] | none | 2,000 | [
{
"input": "3\n1 2\n2 3\n3",
"output": "1 2 3 2 1 "
},
{
"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3",
"output": "1 2 4 5 4 6 4 2 1 3 1 "
},
{
"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6",
"output": "-1"
},
{
"input": "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4... | 1,630,866,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 |
def checkKey(dict1, key):
if key in dict1:
return True;
return False
def graph_maker():
n = int(input(""));
obj = {};
for i in range(0 , n-1):
data = input("");
data = data.split(" ");
if(checkKey(obj , int(data[0])) == False):
obj[int(data[0])] = [];
if(checkKey(obj , i... | Title: Ant on the Tree
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.
An ant stands at the root of some tree. He sees that there are *n* vertexes... | ```python
def checkKey(dict1, key):
if key in dict1:
return True;
return False
def graph_maker():
n = int(input(""));
obj = {};
for i in range(0 , n-1):
data = input("");
data = data.split(" ");
if(checkKey(obj , int(data[0])) == False):
obj[int(data[0])] = [];
if(checkK... | 0 | MatrixStudio/Codeforces-Python-Submissions |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,493,983,640 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 4,198,400 | import re
string = input()
string = re.search(r'a[ab]*b', string).group()
n = 0
x = 0
for i in string[::-1]:
if i is 'b':
x = x + 1
else:
n = n + x
x = 2*x
print(n%(10**9+7))
| Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
import re
string = input()
string = re.search(r'a[ab]*b', string).group()
n = 0
x = 0
for i in string[::-1]:
if i is 'b':
x = x + 1
else:
n = n + x
x = 2*x
print(n%(10**9+7))
``` | 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,677,864,374 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | t=input()
u=0
l=0
for letter in word():
if letter.isupper():
u+=1
else:
l+=1
if u>l:
print(t.u())
else:
print(t.l()) | 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
t=input()
u=0
l=0
for letter in word():
if letter.isupper():
u+=1
else:
l+=1
if u>l:
print(t.u())
else:
print(t.l())
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,622,869,940 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | pai=3.1415926536
n=eval(input())
a=list(map(eval,input().split()))
a.sort()
a=a[::-1]
b=0
c=0
for i in range(n-1,-1,-1):
b+=a[i]**2*(-1)**c
c=c^1
print(b)
print(b*pai)
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
pai=3.1415926536
n=eval(input())
a=list(map(eval,input().split()))
a.sort()
a=a[::-1]
b=0
c=0
for i in range(n-1,-1,-1):
b+=a[i]**2*(-1)**c
c=c^1
print(b)
print(b*pai)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,537,477,718 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 0 | print(int(input()) - len(set(list(map(int, input().split()))))) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
print(int(input()) - len(set(list(map(int, input().split())))))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXX... | 1,633,581,343 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 109 | 20,172,800 | n=int(input())
a=input()
x=a.count('x')
if 2*x>n:
a=a.replace('x','X',x-n//2)
else:
a=a.replace('X','x',n//2-x)
print(abs(2*x-n)//2)
print(a) | Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to ... | ```python
n=int(input())
a=input()
x=a.count('x')
if 2*x>n:
a=a.replace('x','X',x-n//2)
else:
a=a.replace('X','x',n//2-x)
print(abs(2*x-n)//2)
print(a)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,594,279,237 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | n=int(input())
str=input()
ans=0
for j in range(n):
if(ord(str[j])<=90 and ord(str[j])>=65):
ans+=1
print(ans) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n=int(input())
str=input()
ans=0
for j in range(n):
if(ord(str[j])<=90 and ord(str[j])>=65):
ans+=1
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
327 | B | Hungry Sequence | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in i... | The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | 500 | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ... | 1,652,018,748 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 280 | 1,945,600 | n=int(input())
print(*range(n, 2*n)) | Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1... | ```python
n=int(input())
print(*range(n, 2*n))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,487,065,743 | 6,242 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 5,120,000 | import re
import math
ipt = str(input())
lst = ipt.split(' ')
k = int(lst[0])
a = int(lst[1])
b = int(lst[2])
if( a == b and a > k):
print(a // k + 1)
exit()
if(a == b):
print(-1)
exit()
mx = max(a,b)
mn = min(a,b)
if(mx // k > 0 and mn >= k):
if(mx - mn < mx // k):
... | Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
import re
import math
ipt = str(input())
lst = ipt.split(' ')
k = int(lst[0])
a = int(lst[1])
b = int(lst[2])
if( a == b and a > k):
print(a // k + 1)
exit()
if(a == b):
print(-1)
exit()
mx = max(a,b)
mn = min(a,b)
if(mx // k > 0 and mn >= k):
if(mx - mn < mx // k... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX"... | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
... | 1,625,316,258 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 108 | 0 | n = int(input())
home = input()
k = 0
for i in range(n):
temp = input()
if n % 2 == 0:
print("home")
else:
print("contest") | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei... | ```python
n = int(input())
home = input()
k = 0
for i in range(n):
temp = input()
if n % 2 == 0:
print("home")
else:
print("contest")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,601,030,447 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 187 | 3,072,000 | s = input().split()
for i in range(int(input())):
print(s[0], s[1])
s1 = input().split()
s[s.index(s1[0])] = s1[1]
print(s[0], s[1])
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
s = input().split()
for i in range(int(input())):
print(s[0], s[1])
s1 = input().split()
s[s.index(s1[0])] = s1[1]
print(s[0], s[1])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,682,771,186 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 780 | 8,089,600 | def mai(n,lis):
dis=set();ans=[];count=0
for i in range(n-1,-1,-1):
if lis[i] not in dis:
count+=1
dis.add(lis[i])
ans.append(count)
return ans[::-1]
n,m=map(int,input().split())
lis=list(map(int,input().split()))
lis=mai(n,lis)
for i in range(m):
... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
def mai(n,lis):
dis=set();ans=[];count=0
for i in range(n-1,-1,-1):
if lis[i] not in dis:
count+=1
dis.add(lis[i])
ans.append(count)
return ans[::-1]
n,m=map(int,input().split())
lis=list(map(int,input().split()))
lis=mai(n,lis)
for i in range... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,626,931,330 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 77 | 6,758,400 | [a, b] = map(int, input().split())
[c, d] = map(int, input().split())
max = max(abs(c - a), abs(b - d))
print(max)
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
[a, b] = map(int, input().split())
[c, d] = map(int, input().split())
max = max(abs(c - a), abs(b - d))
print(max)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,662,910,470 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 77 | 2,150,400 | import sys
def readArray(line):
array = [int(x) for x in line.split()]
return array
input = [x.strip() for x in sys.stdin.readlines()]
n,m,pColor = input[0].split()
n = int(n)
m = int(m)
matrix = []
for r in range(1, len(input)):
row = input[r]
matrix.append(row)
set = set()
for i in ... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
import sys
def readArray(line):
array = [int(x) for x in line.split()]
return array
input = [x.strip() for x in sys.stdin.readlines()]
n,m,pColor = input[0].split()
n = int(n)
m = int(m)
matrix = []
for r in range(1, len(input)):
row = input[r]
matrix.append(row)
set = set()
... | 3.964728 | MatrixStudio/Codeforces-Python-Submissions |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,687,944,499 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | a, b = map(int, input().split())
x = 1
for i in range(1,min(a,b)+1):
x *= i
print(x) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
a, b = map(int, input().split())
x = 1
for i in range(1,min(a,b)+1):
x *= i
print(x)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,536,175,351 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 0 | p = input()
print((len(p)+1)*26 -len(p)) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
p = input()
print((len(p)+1)*26 -len(p))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,677,926,108 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
sizes = [int(input()) for i in range(n)]
# sort the kangaroos by size in descending order
sorted_sizes = sorted(sizes, reverse=True)
# use a dictionary to keep track of which kangaroos are held by others
held_by = {}
# iterate over the sorted kangaroos and try to place each kangaroo in the ... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
n = int(input())
sizes = [int(input()) for i in range(n)]
# sort the kangaroos by size in descending order
sorted_sizes = sorted(sizes, reverse=True)
# use a dictionary to keep track of which kangaroos are held by others
held_by = {}
# iterate over the sorted kangaroos and try to place each kangar... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,619,607,397 | 1,597 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n = int(input())
s = input()
one = s.count("1")
zero = s.count("0")
hanare = 0
renzoku = 0
hanare_max = 0
renzoku_max = 0
if one < zero:
for i in range(n):
if s[i] == "1":
hanare_max = max(hanare_max, hanare)
hanare = 0
renzoku += 1
else:
... | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n = int(input())
s = input()
one = s.count("1")
zero = s.count("0")
hanare = 0
renzoku = 0
hanare_max = 0
renzoku_max = 0
if one < zero:
for i in range(n):
if s[i] == "1":
hanare_max = max(hanare_max, hanare)
hanare = 0
renzoku += 1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,610,586,357 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 2,150,400 | n,m=map(int,input().split())
s=list(input())
for i in range(m):
l,r,c1,c2=input().split()
for i in range(l-1,r):
if(s[i]==c1):
s[i]=c2 | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,m=map(int,input().split())
s=list(input())
for i in range(m):
l,r,c1,c2=input().split()
for i in range(l-1,r):
if(s[i]==c1):
s[i]=c2
``` | -1 | 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,669,482,891 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n = int(input())
l = set();l2 = set();c = 0
for i in range(n):
a = input()
for i in range(n):
if i == c or i == n-c-1:
l2.add(a[i])
else:
l.add(a[i])
c += 1
if len(l) == len(l2) == 1 and l!=l2:
print('YES')
else:
print('NO')
| 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())
l = set();l2 = set();c = 0
for i in range(n):
a = input()
for i in range(n):
if i == c or i == n-c-1:
l2.add(a[i])
else:
l.add(a[i])
c += 1
if len(l) == len(l2) == 1 and l!=l2:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
618 | C | Constellation | PROGRAMMING | 1,600 | [
"geometry",
"implementation"
] | null | null | Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would lik... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000).
Each of the next *n* lines contains two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line. | Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them. | [
"3\n0 1\n1 0\n1 1\n",
"5\n0 0\n0 2\n2 0\n2 2\n1 1\n"
] | [
"1 2 3\n",
"1 3 5\n"
] | In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border). | 1,500 | [
{
"input": "3\n0 1\n1 0\n1 1",
"output": "1 2 3"
},
{
"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1",
"output": "1 3 5"
},
{
"input": "3\n819934317 939682125\n487662889 8614219\n-557136619 382982369",
"output": "1 3 2"
},
{
"input": "10\n25280705 121178189\n219147240 -570920213\n-8298... | 1,454,092,482 | 5,082 | Python 3 | WRONG_ANSWER | CHALLENGES | 0 | 498 | 10,956,800 | n = int(input())
v = []
for i in range(n):
x, y = map(int, input().split())
v.append((x, y, i+1))
v = sorted(v)
a = v[0]
for i in range(1, n):
if v[i][0] != a[0]:
b = v[i]
c = v[i+1]
break
print("%i %i %i" % (a[2], b[2], c[2]))
| Title: Constellation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are locate... | ```python
n = int(input())
v = []
for i in range(n):
x, y = map(int, input().split())
v.append((x, y, i+1))
v = sorted(v)
a = v[0]
for i in range(1, n):
if v[i][0] != a[0]:
b = v[i]
c = v[i+1]
break
print("%i %i %i" % (a[2], b[2], c[2]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,659,414,499 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 218 | 15,564,800 | n = int(input())
game = []
for i in range(n):
round = {}
temp = input().split()
if i == 0:
round[temp[0]] = int(temp[1])
else:
round = game[i - 1].copy()
if temp[0] not in round:
round[temp[0]] = int(temp[1])
else:
round[temp[0]] += int(temp[1])
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
game = []
for i in range(n):
round = {}
temp = input().split()
if i == 0:
round[temp[0]] = int(temp[1])
else:
round = game[i - 1].copy()
if temp[0] not in round:
round[temp[0]] = int(temp[1])
else:
round[temp[0]] += int(... | 3.775033 | 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,635,689,544 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 28,364,800 | def solve():
num1 = input()
num2 = input()
num1List = []
num2List = []
for ele1 in num1:
num1List.append(ele1)
for ele2 in num2:
num2List.append(ele2)
for i in range(0,len(num1List)):
if num1List[i] == num2List[i]:
num1List[i] = '0'
e... | 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
def solve():
num1 = input()
num2 = input()
num1List = []
num2List = []
for ele1 in num1:
num1List.append(ele1)
for ele2 in num2:
num2List.append(ele2)
for i in range(0,len(num1List)):
if num1List[i] == num2List[i]:
num1List[i] = '0'
... | 3.931666 | 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,608,972,917 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 2,150,400 | s=input()
l=[h,e,l,l,o]
j=0
for i in range(0,len(s)):
if s[i]==l[j]:
j=j+1
if j==5:
print("YES")
break
if j!=5:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
l=[h,e,l,l,o]
j=0
for i in range(0,len(s)):
if s[i]==l[j]:
j=j+1
if j==5:
print("YES")
break
if j!=5:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,643,939,733 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 31 | 1,126,400 | import sys
s = input()
t = input()
#checking if the string is greater than the other string.
if len(s) >= len(t):
if len(s) == len(t):
count = 0
while(s != t):
s = s[1:]
t = t[1:]
count += 1
print(count*2)
else:
r = len(s) - l... | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
import sys
s = input()
t = input()
#checking if the string is greater than the other string.
if len(s) >= len(t):
if len(s) == len(t):
count = 0
while(s != t):
s = s[1:]
t = t[1:]
count += 1
print(count*2)
else:
r = ... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,572,765,403 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | n = int(input())
s = input()
cnt = 1
if s[0] == '0':
print(1)
else:
for i in range(1, n):
if s[i] == '1':
cnt += 1
elif s[i] == '0':
print(cnt + 1)
break
if i == n - 1:
print(cnt)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
s = input()
cnt = 1
if s[0] == '0':
print(1)
else:
for i in range(1, n):
if s[i] == '1':
cnt += 1
elif s[i] == '0':
print(cnt + 1)
break
if i == n - 1:
print(cnt)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,627,314,507 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 186 | 20,172,800 | print('/' + '/'.join(filter(bool, input().split('/')))) | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
print('/' + '/'.join(filter(bool, input().split('/'))))
``` | 3.803201 | MatrixStudio/Codeforces-Python-Submissions |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,647,342,982 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | def main():
ans=0
n=int(input())
a=[int(x)**2 for x in input().split()]
a.sort(key=lambda x:-x)
for i in range(0,n-1,2):
ans+=a[i]-a[i+1]
ans+=a[n-1]
ans=ans*pi
print(ans)
main() | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
def main():
ans=0
n=int(input())
a=[int(x)**2 for x in input().split()]
a.sort(key=lambda x:-x)
for i in range(0,n-1,2):
ans+=a[i]-a[i+1]
ans+=a[n-1]
ans=ans*pi
print(ans)
main()
``` | -1 | 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,697,955,843 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
a=[]
b=[]
e=0
for x in range(n):
q=input().split(" ")
c=q[0]
d=q[1]
a.append(c)
b.append(d)
for x in range(n):
for q in b:
if q==a[x]:
e=e+1
print(e) | 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())
a=[]
b=[]
e=0
for x in range(n):
q=input().split(" ")
c=q[0]
d=q[1]
a.append(c)
b.append(d)
for x in range(n):
for q in b:
if q==a[x]:
e=e+1
print(e)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit an... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities in USC.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is the number of the parent city of city number *i* in the tree, meaning there is a road between cities... | In the first and only line of output print *n* numbers, where *i*-th number is the expected value of starting_time[i].
Your answer for each city will be considered correct if its absolute or relative error does not exceed 10<=-<=6. | [
"7\n1 2 1 1 4 4\n",
"12\n1 1 2 2 4 4 3 3 1 10 8\n"
] | [
"1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n",
"1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n"
] | none | 0 | [
{
"input": "7\n1 2 1 1 4 4",
"output": "1.0 4.0 5.0 3.5 4.5 5.0 5.0 "
},
{
"input": "12\n1 1 2 2 4 4 3 3 1 10 8",
"output": "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 "
},
{
"input": "3\n1 2",
"output": "1.0 2.0 3.0 "
},
{
"input": "8\n1 1 2 2 3 6 1",
"output": "1.0... | 1,468,883,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n=int(input())
x=input().split(' ')
x.insert(0, 0)
x.insert(0, 0)
print(x)
for i in range(len(x)): x[i]=int(x[i])
print(x, '\n')
C=[[] for i in range(n+1)]
w=2
for i in x[2:]:
C[i].append(w)
w+=1
print(C)
E=[0, 1]+[0 for i in range(n-1)]
ch=[0 for i in range (n+1)]
for i in range(1, n+1):
k... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the ... | ```python
n=int(input())
x=input().split(' ')
x.insert(0, 0)
x.insert(0, 0)
print(x)
for i in range(len(x)): x[i]=int(x[i])
print(x, '\n')
C=[[] for i in range(n+1)]
w=2
for i in x[2:]:
C[i].append(w)
w+=1
print(C)
E=[0, 1]+[0 for i in range(n-1)]
ch=[0 for i in range (n+1)]
for i in range(1,... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,634,630,749 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 61 | 0 | n,m = map(int,input().split())
s = set()
for i in range(n):
lis = input().split()
s = s|set(lis[1:])
if len(s) == m:
print('YES')
else:
print('NO') | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m = map(int,input().split())
s = set()
for i in range(n):
lis = input().split()
s = s|set(lis[1:])
if len(s) == m:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,682,932,064 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | num=int(input())
line=list(map(int,input().split()))
a=max(line)
b=min(line)
step1=line.index(a)
line.reverse()
step2=line.index(b)
line.reverse()
print([step1+step2,step1+step2-1][step1>step2]) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
num=int(input())
line=list(map(int,input().split()))
a=max(line)
b=min(line)
step1=line.index(a)
line.reverse()
step2=line.index(b)
line.reverse()
print([step1+step2,step1+step2-1][step1>step2])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,626,332,239 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 216 | 20,172,800 | for i in range(3):
line = input()
o = "YES"
count = 0
count += line.count("a")
count += line.count("e")
count += line.count("i")
count += line.count("o")
count += line.count("u")
if i == 1:
if count != 7:
o = "NO"
break
else:
... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
for i in range(3):
line = input()
o = "YES"
count = 0
count += line.count("a")
count += line.count("e")
count += line.count("i")
count += line.count("o")
count += line.count("u")
if i == 1:
if count != 7:
o = "NO"
break
e... | 3.908425 | MatrixStudio/Codeforces-Python-Submissions |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,628,341,925 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 1,559 | 27,136,000 | def binsearch(a,n,l,r):
while(l<=r):
m=(l+r)//2
if a[m]>n:
r=m-1
else:
l=m+1
return l
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
a.sort()
for i in b:
print(binsearch(a,i,0,n-1),end=" ")
... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def binsearch(a,n,l,r):
while(l<=r):
m=(l+r)//2
if a[m]>n:
r=m-1
else:
l=m+1
return l
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
a.sort()
for i in b:
print(binsearch(a,i,0,n-1),end=" ")
... | 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,634,813,420 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 92 | 4,505,600 | n,k=[int(x) for x in input().split(' ')]
l=[int(x) for x in input().split(' ')]
ll=[]
for i in l:
if i<0:
ll.append(i)
ll.sort(reverse=True)
sum=0;
for i in ll:
if k==0:
break
else:
sum+=i
k-=1;
print(abs(sum))
| 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,k=[int(x) for x in input().split(' ')]
l=[int(x) for x in input().split(' ')]
ll=[]
for i in l:
if i<0:
ll.append(i)
ll.sort(reverse=True)
sum=0;
for i in ll:
if k==0:
break
else:
sum+=i
k-=1;
print(abs(sum))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,681,690,690 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n,m = map(int,input().split())
a = list(map(lambda q:int(q), input().split(" ")))
r = len(set(a))
t=[]
q=[]
for i in range(n):
t.append(r)
if a[i] in q:
r-=1
q.append(a[i])
t[n-1]=1
print(t)
for i in range(m):
l=int(input())
print(t[l-1])
| Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m = map(int,input().split())
a = list(map(lambda q:int(q), input().split(" ")))
r = len(set(a))
t=[]
q=[]
for i in range(n):
t.append(r)
if a[i] in q:
r-=1
q.append(a[i])
t[n-1]=1
print(t)
for i in range(m):
l=int(input())
print(t[l-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,587,292,013 | 293 | PyPy 3 | OK | TESTS | 42 | 498 | 11,878,400 | import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,m=M()
i=0
while(True):
if(i%2==0):
... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,m=M()
i=0
while(True):
if(i%2==0... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
101 | A | Homework | PROGRAMMING | 1,200 | [
"greedy"
] | A. Homework | 2 | 256 | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to... | The first input data line contains a string whose length is equal to *n* (1<=≤<=*n*<=≤<=105). The string consists of lowercase Latin letters. The second line contains the number *k* (0<=≤<=*k*<=≤<=105). | Print on the first line the only number *m* — the least possible number of different characters that could remain in the given string after it loses no more than *k* characters.
Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly *m* distinct character... | [
"aaaaa\n4\n",
"abacaba\n4\n",
"abcdefgh\n10\n"
] | [
"1\naaaaa\n",
"1\naaaa\n",
"0\n\n"
] | In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.
In the second sample you are allowed to delete 4 characters. You cann... | 500 | [
{
"input": "aaaaa\n4",
"output": "1\naaaaa"
},
{
"input": "abacaba\n4",
"output": "1\naaaa"
},
{
"input": "abcdefgh\n10",
"output": "0"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa\n19",
"output": "1\naaaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdefghijjihgedcba\n0",
"outpu... | 1,567,700,702 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 0 | s = input()
n = int(input())
lis = []
dic = {}
if len(s) < n:
print(0)
else:
for i in s:
if i not in dic:
dic[i] = 0
else:
dic[i] += 1
for k,v in dic.items():
lis.append(v)
for k,v in dic.items():
if v == max(lis):
print(1)
... | Title: Homework
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the s... | ```python
s = input()
n = int(input())
lis = []
dic = {}
if len(s) < n:
print(0)
else:
for i in s:
if i not in dic:
dic[i] = 0
else:
dic[i] += 1
for k,v in dic.items():
lis.append(v)
for k,v in dic.items():
if v == max(lis):
print(1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 1,500 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,597,001,940 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 872 | 30,617,600 | import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
x = 0
for i in range(m):
w, h = map(int, sys.stdin.readline().split())
x = max(x, l[w-1])
sys.stdout.write(str(x)+'\n')
x += h | Title: Dima and Staircase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the st... | ```python
import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
x = 0
for i in range(m):
w, h = map(int, sys.stdin.readline().split())
x = max(x, l[w-1])
sys.stdout.write(str(x)+'\n')
x += h
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,552,753,221 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 2 | 1,294 | 268,390,400 | v = input().split()
lista = []
for i in range(int(v[0]),int(v[1])+1):
lista.append(i)
valor = 0
cont = 0
t = 0
while(valor<=int(v[1])):
valor = int(v[2])**cont
if valor in lista:
print(valor,end=" ")
t = 1
cont+=1
if t == 0:
print("-1")
| Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
v = input().split()
lista = []
for i in range(int(v[0]),int(v[1])+1):
lista.append(i)
valor = 0
cont = 0
t = 0
while(valor<=int(v[1])):
valor = int(v[2])**cont
if valor in lista:
print(valor,end=" ")
t = 1
cont+=1
if t == 0:
print("-1")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,669,360,620 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def run(n1:str, n2:str):
sum1 = int(f"{(int(n1)+int(n2))}".replace("0", ''))
print(n1, n2)
a = int(n1.replace('0', ''))
b =int(n2.replace('0', ''))
sum2 = a + b
if sum1 == sum2:
print("YES")
else:
print("NO")
if __name__ == "__main__":
a = input()
b ... | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
def run(n1:str, n2:str):
sum1 = int(f"{(int(n1)+int(n2))}".replace("0", ''))
print(n1, n2)
a = int(n1.replace('0', ''))
b =int(n2.replace('0', ''))
sum2 = a + b
if sum1 == sum2:
print("YES")
else:
print("NO")
if __name__ == "__main__":
a = input... | 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,694,691,048 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 77 | 0 | s=input()
m=""
for i in s:
if m=="":
if i=='h':
m+='h'
elif m=="h":
if i=="e":
m+='e'
elif m=='he':
if i=='l':
m+='l'
elif m=='hel':
if i=='l':
m+=i
elif m=='hell':
if i=='o':
m+=i
i... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
m=""
for i in s:
if m=="":
if i=='h':
m+='h'
elif m=="h":
if i=="e":
m+='e'
elif m=='he':
if i=='l':
m+='l'
elif m=='hel':
if i=='l':
m+=i
elif m=='hell':
if i=='o':
... | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,670,435,259 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | ev , ic = input().split()
z3lan = 0
for i in range(ev):
a ,b= input().split()
b = int(b)
if a == '+':
ic += b
else:
if ic >= b:
ic-=b
else:
z3lan += 1
print(ic , z3lan)
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
ev , ic = input().split()
z3lan = 0
for i in range(ev):
a ,b= input().split()
b = int(b)
if a == '+':
ic += b
else:
if ic >= b:
ic-=b
else:
z3lan += 1
print(ic , z3lan)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains thr... | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
... | 1,620,978,598 | 1,078 | PyPy 3 | OK | TESTS | 24 | 218 | 30,105,600 | temp = [0] * 10000
def shift_cycle(a, left, right, k):
start = left + (k % (right - left + 1))
for i in range(left, right + 1):
temp[start] = a[i]
start = left + ((start - left + 1) % (right - left + 1))
for i in range(left, right + 1):
a[i] = temp[i]
s = list(input()... | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**... | ```python
temp = [0] * 10000
def shift_cycle(a, left, right, k):
start = left + (k % (right - left + 1))
for i in range(left, right + 1):
temp[start] = a[i]
start = left + ((start - left + 1) % (right - left + 1))
for i in range(left, right + 1):
a[i] = temp[i]
s = li... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,621,261,976 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | x,y=map(int,input().split())
m=0
if x>0 and y>0:
m=-1
y1=y-m*x
x2=y1
print(0,y1,x2,0)
elif x>0 and y<0:
m=1
y1=y-m*x
x2=y1
print(0,y1,x2,0)
elif x<0 and y<0:
m=-1
y2=y-m*x
x1=y2
print(x1,0,0,y2)
else:
m=1
y2=y-m*x
x1=-y2
print(x1,0,0,y... | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x,y=map(int,input().split())
m=0
if x>0 and y>0:
m=-1
y1=y-m*x
x2=y1
print(0,y1,x2,0)
elif x>0 and y<0:
m=1
y1=y-m*x
x2=y1
print(0,y1,x2,0)
elif x<0 and y<0:
m=-1
y2=y-m*x
x1=y2
print(x1,0,0,y2)
else:
m=1
y2=y-m*x
x1=-y2
prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,587,459,463 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 21 | 156 | 1,433,600 | n=int(input())
k=[]
l=[]
for i in range(n):
a,b=[int(i) for i in input().split()]
l.append(a)
k.append(b)
s=set(l)
c=set(k)
if(s!=c):
print("rated")
else:
f=sorted(l,reverse=True)
if(f==l):
print('maybe')
else:
print('unrated')
| Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
n=int(input())
k=[]
l=[]
for i in range(n):
a,b=[int(i) for i in input().split()]
l.append(a)
k.append(b)
s=set(l)
c=set(k)
if(s!=c):
print("rated")
else:
f=sorted(l,reverse=True)
if(f==l):
print('maybe')
else:
print('unrated')
``` | 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,568,813,039 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | s1 = input()
j = k = 0
for i in s1:
if (i >= 'a') and i <= 'z':
j += 1
elif (i >= 'A') and i <= 'Z':
k += 1
if k > j:
print(s1.upper())
else:
print(s1.lower()) | 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
s1 = input()
j = k = 0
for i in s1:
if (i >= 'a') and i <= 'z':
j += 1
elif (i >= 'A') and i <= 'Z':
k += 1
if k > j:
print(s1.upper())
else:
print(s1.lower())
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,676,905,203 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 51 | 154 | 0 | def check(numbers):
possibilities = list(range(1, 10))
for i in numbers:
if i in possibilities:
possibilities.remove(i)
else:
return False
return True
r1, r2 = [int(x) for x in input().split()]
c1, c2 = [int(x) for x in input().split()]
d1, d2 = [int(x) ... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
def check(numbers):
possibilities = list(range(1, 10))
for i in numbers:
if i in possibilities:
possibilities.remove(i)
else:
return False
return True
r1, r2 = [int(x) for x in input().split()]
c1, c2 = [int(x) for x in input().split()]
d1, d2 ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl... | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
... | 1,477,589,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 46 | 0 | liste = input().split(" ")
n = int(liste[0])
a = int(liste[1])
b = int(liste[2])
p = int(liste[3])
q = int(liste[4])
m = max(p,q)
res = 0
multa = a
multb = b
# for i in range (1,n+1) :
# auxa = False
# auxb = False
# if i == multa :
# auxa = True
# multa += a
# if i... | Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpai... | ```python
liste = input().split(" ")
n = int(liste[0])
a = int(liste[1])
b = int(liste[2])
p = int(liste[3])
q = int(liste[4])
m = max(p,q)
res = 0
multa = a
multb = b
# for i in range (1,n+1) :
# auxa = False
# auxb = False
# if i == multa :
# auxa = True
# multa += a
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,689,013,062 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 154 | 0 | n=int(input(''))
b=input('')
m=b.split(' ')
a=[]
for i in m:
a.append(int(i))
c=[]
d=[]
for i in a:
if i not in c:
c.append(i)
d.append(a.count(i))
else:
continue
if n&1==1 and max(d)<=n//2+1:
print("YES")
elif n&1==0 and max(d)<=n//2:
print("YES")
else:
print("NO") | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
n=int(input(''))
b=input('')
m=b.split(' ')
a=[]
for i in m:
a.append(int(i))
c=[]
d=[]
for i in a:
if i not in c:
c.append(i)
d.append(a.count(i))
else:
continue
if n&1==1 and max(d)<=n//2+1:
print("YES")
elif n&1==0 and max(d)<=n//2:
print("YES")
else:
print("NO")
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
421 | A | Pasha and Hamsters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams... | The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line... | Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. | [
"4 2 3\n1 2\n2 3 4\n",
"5 5 2\n3 4 1 2 5\n2 3\n"
] | [
"1 1 2 2\n",
"1 1 1 1 1\n"
] | none | 500 | [
{
"input": "4 2 3\n1 2\n2 3 4",
"output": "1 1 2 2"
},
{
"input": "5 5 2\n3 4 1 2 5\n2 3",
"output": "1 1 1 1 1"
},
{
"input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7... | 1,569,001,194 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 139 | 0 | def main():
n, a, b = [int(v) for v in input().split()]
vals1 = [int(v) for v in input().split()]
vals2 = [int(v) for v in input().split()]
data = []
for i in range(1, n+1):
if i in vals1:
data.append("1")
else:
data.append("2")
print(" ".join(da... | Title: Pasha and Hamsters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between... | ```python
def main():
n, a, b = [int(v) for v in input().split()]
vals1 = [int(v) for v in input().split()]
vals2 = [int(v) for v in input().split()]
data = []
for i in range(1, n+1):
if i in vals1:
data.append("1")
else:
data.append("2")
print("... | 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,694,082,740 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s=input()
sh='hello'
c=0
for i in range(len(s)):
if c<5:
if s[i]==sh[c]:
c+=1
if c==5:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
sh='hello'
c=0
for i in range(len(s)):
if c<5:
if s[i]==sh[c]:
c+=1
if c==5:
print("YES")
else:
print("NO")
``` | 3.977 | 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,635,358,421 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 4,505,600 | r, c = [int(i) for i in input().split()]
cake = []
res = 0
for j in range(r):
cake.append(input())
for ca in cake:
if not 'S' in ca:
res += len(ca)
cake.remove(ca)
for i in range(c):
if all(cake[j][i] != 'S' for j in range(len(cake))):
res += len(cake)
print(res)
... | 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
r, c = [int(i) for i in input().split()]
cake = []
res = 0
for j in range(r):
cake.append(input())
for ca in cake:
if not 'S' in ca:
res += len(ca)
cake.remove(ca)
for i in range(c):
if all(cake[j][i] != 'S' for j in range(len(cake))):
res += len(cake)
p... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
675 | B | Restoring Painting | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,... | The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. | Print one integer — the number of distinct valid squares. | [
"2 1 1 1 2\n",
"3 3 1 2 3\n"
] | [
"2\n",
"6\n"
] | Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.... | 1,000 | [
{
"input": "2 1 1 1 2",
"output": "2"
},
{
"input": "3 3 1 2 3",
"output": "6"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1000 522 575 426 445",
"output": "774000"
},
{
"input": "99000 52853 14347 64237 88869",
"output": "1296306000"
},
{
... | 1,464,118,609 | 3,109 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 4,608,000 | l=input().split(" ")
n=int(l[0])
a=int(l[1])
b=int(l[2])
c=int(l[3])
d=int(l[4])
x=1
y=n
m=min(x+b-c,x+a-d,a+b-c-d+x)
g=max(x+b-c,x+a-d,a+b-c-d+x)
if m<1:
x+=1-m
if g>n:
y+=n-g
if x>y:
print(0)
else:
print(n*(y-x+1)) | Title: Restoring Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some ... | ```python
l=input().split(" ")
n=int(l[0])
a=int(l[1])
b=int(l[2])
c=int(l[3])
d=int(l[4])
x=1
y=n
m=min(x+b-c,x+a-d,a+b-c-d+x)
g=max(x+b-c,x+a-d,a+b-c-d+x)
if m<1:
x+=1-m
if g>n:
y+=n-g
if x>y:
print(0)
else:
print(n*(y-x+1))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,554,490,006 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 0 | n = int(input())
left_apples = []
left_pos = []
right_apples = []
right_pos = []
for _ in range(n):
p, q = input().split()
if int(p) < 0:
left_pos.append(abs(int(p)))
left_apples.append(int(q))
else:
right_pos.append(int(p))
right_apples.append(int(q))
# print(left_apples)
# print(left_pos)
left_apple... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n = int(input())
left_apples = []
left_pos = []
right_apples = []
right_pos = []
for _ in range(n):
p, q = input().split()
if int(p) < 0:
left_pos.append(abs(int(p)))
left_apples.append(int(q))
else:
right_pos.append(int(p))
right_apples.append(int(q))
# print(left_apples)
# print(left_pos)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,... | In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutio... | [
"5 3\n1 3\n2 5\n4 5\n",
"4 2\n1 4\n2 4\n"
] | [
"2\n1 0 2 1 0\n",
"3\n5 2 0 1"
] | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | 0 | [
{
"input": "5 3\n1 3\n2 5\n4 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "4 2\n1 4\n2 4",
"output": "3\n0 1 2 0"
},
{
"input": "1 1\n1 1",
"output": "1\n0"
},
{
"input": "2 1\n2 2",
"output": "1\n0 0"
},
{
"input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3",
"output":... | 1,689,921,600 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 69 | 842 | 27,648,000 | n, m = list(map(int, input().split()))
A = []
Aset = set()
for _ in range(m):
Aset.add(tuple(map(int, input().split())))
A = [Aset.pop() for _ in range(len(Aset))]
A.sort(key=lambda x: x[1] - x[0])
m = len(A)
mex = A[0][1] - A[0][0] + 1
res = [i % mex for i in range(n)]
print(mex)
print(*res) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some... | ```python
n, m = list(map(int, input().split()))
A = []
Aset = set()
for _ in range(m):
Aset.add(tuple(map(int, input().split())))
A = [Aset.pop() for _ in range(len(Aset))]
A.sort(key=lambda x: x[1] - x[0])
m = len(A)
mex = A[0][1] - A[0][0] + 1
res = [i % mex for i in range(n)]
print(mex)
print(*res)... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,671,445,063 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,m=list(map(int,input().split()))
r=m*n
print(r//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
n,m=list(map(int,input().split()))
r=m*n
print(r//2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
370 | A | Rook, Bishop and King | PROGRAMMING | 1,100 | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of... | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb... | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | 500 | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "... | 1,621,653,462 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | import math
r1, c1, r2, c2 = [int(item) for item in input().split()]
# rei pode se movimentar para todos os lados
# r1 - r2 é quanto ele precisa se movimentar na linha
# c1 - c2 é quanto ele precisa se movimentar na coluna
ReiMovimentoLinha = abs(r1-r2)
ReiMovimentoColuna = abs(c1-c2)
reiResposta = math.ceil(... | Title: Rook, Bishop and King
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=... | ```python
import math
r1, c1, r2, c2 = [int(item) for item in input().split()]
# rei pode se movimentar para todos os lados
# r1 - r2 é quanto ele precisa se movimentar na linha
# c1 - c2 é quanto ele precisa se movimentar na coluna
ReiMovimentoLinha = abs(r1-r2)
ReiMovimentoColuna = abs(c1-c2)
reiResposta = ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,582,875,836 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 248 | 0 | s=sorted([int(x) for x in input().split()])
if s[0]+s[1]>s[2] or s[1]+s[2]>s[3]:print('TRIANGLE')
else:
if s[0]+s[1]==s[2] or s[1]+s[2]==s[3]:print('SEGMENT')
else:print('IMPOSSIBLE') | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
s=sorted([int(x) for x in input().split()])
if s[0]+s[1]>s[2] or s[1]+s[2]>s[3]:print('TRIANGLE')
else:
if s[0]+s[1]==s[2] or s[1]+s[2]==s[3]:print('SEGMENT')
else:print('IMPOSSIBLE')
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,666,698,775 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a=int(input())
if a&1==1:
print(-1)
else:
res=[i+1 for i in range(a)]
for i in range(0,len(res),2):
print(res[i+1],end=" ")
print(res[i],end=" ") | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
a=int(input())
if a&1==1:
print(-1)
else:
res=[i+1 for i in range(a)]
for i in range(0,len(res),2):
print(res[i+1],end=" ")
print(res[i],end=" ")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
185 | A | Plant | PROGRAMMING | 1,300 | [
"math"
] | null | null | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7). | [
"1\n",
"2\n"
] | [
"3\n",
"10\n"
] | The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | 500 | [
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "10"
},
{
"input": "385599124",
"output": "493875375"
},
{
"input": "989464295",
"output": "31966163"
},
{
"input": "376367012",
"output": "523204186"
},
{
"input": "529357306",
"output": "... | 1,628,748,059 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 186 | 20,172,800 | n, N = int(input()), 1000000007;print((pow(2, n, N) + 1) * pow(2, n - 1, N)) | Title: Plant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poi... | ```python
n, N = int(input()), 1000000007;print((pow(2, n, N) + 1) * pow(2, n - 1, N))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
452 | B | 4-point polyline | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"geometry",
"trees"
] | null | null | You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of... | The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points. | Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10<=-<=6 precision. | [
"1 1\n",
"0 10\n"
] | [
"1 1\n0 0\n1 0\n0 1\n",
"0 1\n0 10\n0 0\n0 9\n"
] | none | 1,000 | [
{
"input": "1 1",
"output": "0 0\n1 1\n0 1\n1 0"
},
{
"input": "0 10",
"output": "0 1\n0 10\n0 0\n0 9"
},
{
"input": "10 10",
"output": "10 9\n0 0\n10 10\n1 0"
},
{
"input": "100 100",
"output": "0 1\n100 100\n0 0\n99 100"
},
{
"input": "10 100",
"output": "9 ... | 1,406,481,720 | 1,320 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | n, m = map(int,input().split())
if n==0:
print(0,1)
print(0,m)
print(0,0)
print(0,m-1)
elif m ==0:
print(1,0)
print(n,0)
print(0,0)
print(n-1,0)
else:
if n>m:
print(0,0)
print(n,m)
print(0,m)
print(n,0)
else:
print(0,0)
... | Title: 4-point polyline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyl... | ```python
n, m = map(int,input().split())
if n==0:
print(0,1)
print(0,m)
print(0,0)
print(0,m-1)
elif m ==0:
print(1,0)
print(n,0)
print(0,0)
print(n-1,0)
else:
if n>m:
print(0,0)
print(n,m)
print(0,m)
print(n,0)
else:
p... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},... | 1,697,208,348 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 78 | 13,619,200 | n = int(input())
a = list(map(int,input().split()))
a.sort()
ok = 0
for i in range(n-2):
if a[i] + a[i+1] > a[i+2]:
ok = 1
break
print(["NO",'YES'][ok]) | Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca... | ```python
n = int(input())
a = list(map(int,input().split()))
a.sort()
ok = 0
for i in range(n-2):
if a[i] + a[i+1] > a[i+2]:
ok = 1
break
print(["NO",'YES'][ok])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,696,261,317 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a = int(input())
b = a // 5
r = a % 5
if r < 4:
c = 1
else:
c = 0
if r == 0:
print(b)
else:
total = b + c
print(total)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
a = int(input())
b = a // 5
r = a % 5
if r < 4:
c = 1
else:
c = 0
if r == 0:
print(b)
else:
total = b + c
print(total)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
60 | A | Where Are My Flakes? | PROGRAMMING | 1,300 | [
"implementation",
"two pointers"
] | A. Where Are My Flakes? | 2 | 256 | One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*m*<=≤<=1000) which represent the number of boxes and the number of hints correspondingly. Next *m* lines contain hints like "To the left of *i*" and "To the right of *i*", where *i* is integer (1<=≤<=*i*<=≤<=*n*). The hints may coincide. | The answer should contain exactly one integer — the number of boxes that should necessarily be checked or "-1" if the hints are contradictory. | [
"2 1\nTo the left of 2\n",
"3 2\nTo the right of 1\nTo the right of 2\n",
"3 1\nTo the left of 3\n",
"3 2\nTo the left of 2\nTo the right of 1\n"
] | [
"1\n",
"1\n",
"2\n",
"-1\n"
] | none | 500 | [
{
"input": "2 1\nTo the left of 2",
"output": "1"
},
{
"input": "3 2\nTo the right of 1\nTo the right of 2",
"output": "1"
},
{
"input": "3 1\nTo the left of 3",
"output": "2"
},
{
"input": "3 2\nTo the left of 2\nTo the right of 1",
"output": "-1"
},
{
"input": "... | 1,662,930,968 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n, m = map(int, input().split())
left, right = list(), list()
left.append(n+1)
right.append(0)
for _ in range(m):
s = input()
idx = int(s.split()[4])
if s[7] == 'l':
left.append(idx)
else:
right.append(idx)
left.sort()
right.sort()
res = left[0] - right[-1] - 1
if res < 0:
res = -1
print(res) | Title: Where Are My Flakes?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are... | ```python
n, m = map(int, input().split())
left, right = list(), list()
left.append(n+1)
right.append(0)
for _ in range(m):
s = input()
idx = int(s.split()[4])
if s[7] == 'l':
left.append(idx)
else:
right.append(idx)
left.sort()
right.sort()
res = left[0] - right[-1] - 1
if res < 0:
res = -1
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
577 | B | Modulo Sum | PROGRAMMING | 1,900 | [
"combinatorics",
"data structures",
"dp",
"two pointers"
] | null | null | You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*. | The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist. | [
"3 5\n1 2 3\n",
"1 6\n5\n",
"4 6\n3 1 1 3\n",
"6 6\n5 5 5 5 5 5\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two number... | 1,250 | [
{
"input": "3 5\n1 2 3",
"output": "YES"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "4 6\n3 1 1 3",
"output": "YES"
},
{
"input": "6 6\n5 5 5 5 5 5",
"output": "YES"
},
{
"input": "4 5\n1 1 1 1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",... | 1,666,996,707 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
de... | Title: Modulo Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
In... | ```python
import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
630 | I | Parking Lot | PROGRAMMING | 1,700 | [
"combinatorics",
"math"
] | null | null | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of ... | The only line of the input contains one integer *n* (3<=≤<=*n*<=≤<=30) — the amount of successive cars of the same make. | Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way. | [
"3\n"
] | [
"24"
] | Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For *n* = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Orig... | 0 | [
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "132"
},
{
"input": "5",
"output": "672"
},
{
"input": "6",
"output": "3264"
},
{
"input": "7",
"output": "15360"
},
{
"input": "12",
"output": "27525120"
},
{
"input": "15",
"... | 1,698,222,727 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
print(2*4*3*4**(n-3) + (n-3)*9*4**(n-3)) | Title: Parking Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before t... | ```python
n = int(input())
print(2*4*3*4**(n-3) + (n-3)*9*4**(n-3))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,516,697,854 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 46 | 5,632,000 | n=int(input())
a=[int(x) for x in input()]
res=[]
r=0
for i in range(n):
r+=a[i]
if a[i]==0:
res.append(r)
r=0
res.append(r)
for i in range(len(res)):
print(res[i],end='') | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
n=int(input())
a=[int(x) for x in input()]
res=[]
r=0
for i in range(n):
r+=a[i]
if a[i]==0:
res.append(r)
r=0
res.append(r)
for i in range(len(res)):
print(res[i],end='')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
741 | B | Arpa's weak amphitheater and Mehrdad's valuable Hoses | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp",
"dsu"
] | null | null | Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if... | The first line contains integers *n*, *m* and *w* (1<=<=≤<=<=*n*<=<=≤<=<=1000, , 1<=≤<=*w*<=≤<=1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=1000) — the weights of the ... | Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*. | [
"3 1 5\n3 2 5\n2 4 2\n1 2\n",
"4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n"
] | [
"6\n",
"7\n"
] | In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hose... | 1,000 | [
{
"input": "3 1 5\n3 2 5\n2 4 2\n1 2",
"output": "6"
},
{
"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3",
"output": "7"
},
{
"input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5",
"output": "238... | 1,585,381,621 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 56 | 1,000 | 71,168,000 | INF = 1e18
n, m, W = map(int, input().split())
w = list(map(int, input().split()))
b = list(map(int, input().split()))
G = [[] for _ in range(n)]
for i in range(m):
u, v = map(lambda x: int(x) - 1, input().split())
G[u].append(v)
G[v].append(u)
group = [-1] * n
def dfs(u, z):
group[u] = z... | Title: Arpa's weak amphitheater and Mehrdad's valuable Hoses
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. ... | ```python
INF = 1e18
n, m, W = map(int, input().split())
w = list(map(int, input().split()))
b = list(map(int, input().split()))
G = [[] for _ in range(n)]
for i in range(m):
u, v = map(lambda x: int(x) - 1, input().split())
G[u].append(v)
G[v].append(u)
group = [-1] * n
def dfs(u, z):
gr... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,622,950,722 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | t = int(input())
ls1 = list(map(int, input().strip().split()))
sm = sum(ls1)
ct = 0
for i in range(1,6):
if (sm+i)%(t+1) != 1:
ct+=1
print(ct)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
t = int(input())
ls1 = list(map(int, input().strip().split()))
sm = sum(ls1)
ct = 0
for i in range(1,6):
if (sm+i)%(t+1) != 1:
ct+=1
print(ct)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
699 | B | One Bomb | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls ... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field.
The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", ... | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple an... | [
"3 4\n.*..\n....\n.*..\n",
"3 3\n..*\n.*.\n*..\n",
"6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n"
] | [
"YES\n1 2\n",
"NO\n",
"YES\n3 3\n"
] | none | 1,000 | [
{
"input": "3 4\n.*..\n....\n.*..",
"output": "YES\n1 2"
},
{
"input": "3 3\n..*\n.*.\n*..",
"output": "NO"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "1 10\n**********",
"output": "YES\n1 1"
},
{
"input": "10... | 1,495,428,232 | 2,147,483,647 | PyPy 3 | OK | TESTS | 172 | 265 | 6,144,000 | ##n = int(input())
##a = list(map(int, input().split()))
##print(" ".join(map(str, res)))
[n, m] = list(map(int, input().split()))
s = []
for i in range(n):
s.append(input())
r = []
c = []
tot = 0
for x in range(n):
cnt = 0
for y in range(m):
if s[x][y] == '*':
cnt += 1... | Title: One Bomb
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the ce... | ```python
##n = int(input())
##a = list(map(int, input().split()))
##print(" ".join(map(str, res)))
[n, m] = list(map(int, input().split()))
s = []
for i in range(n):
s.append(input())
r = []
c = []
tot = 0
for x in range(n):
cnt = 0
for y in range(m):
if s[x][y] == '*':
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,621,163,587 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | M,N=input().split()
print(int(int(M)*int(N)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M,N=input().split()
print(int(int(M)*int(N)/2))
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,483,435,541 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 77 | 4,608,000 | l,r=input().split('|')
m=input()
ll=len(l)
lr=len(r)
imp=False
if ll > lr:
if len(m)>=ll-lr:
r+=m[:ll-lr]
m=m[ll-lr:]
else:
imp=True
else:
if len(m)>=lr-ll:
l+=m[:lr-ll]
m=m[lr-ll:]
else:
imp=True
if len(m):
if len(m)&1==0:
while m:
l+=m[0]
r+=m[1]
m=m[2:]
el... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
l,r=input().split('|')
m=input()
ll=len(l)
lr=len(r)
imp=False
if ll > lr:
if len(m)>=ll-lr:
r+=m[:ll-lr]
m=m[ll-lr:]
else:
imp=True
else:
if len(m)>=lr-ll:
l+=m[:lr-ll]
m=m[lr-ll:]
else:
imp=True
if len(m):
if len(m)&1==0:
while m:
l+=m[0]
r+=m[1]
m=... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
350 | B | Resort | PROGRAMMING | 1,500 | [
"graphs"
] | null | null | Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of objects.
The second line contains *n* space-separated integers *type*1,<=*type*2,<=...,<=*type**n* — the types of the objects. If *type**i* equals zero, then the *i*-th object is the mountain. If *type**i* equals one, then the *i*-th object is the... | In the first line print *k* — the maximum possible path length for Valera. In the second line print *k* integers *v*1,<=*v*2,<=...,<=*v**k* — the path. If there are multiple solutions, you can print any of them. | [
"5\n0 0 0 0 1\n0 1 2 3 4\n",
"5\n0 0 1 0 1\n0 1 2 2 4\n",
"4\n1 0 0 0\n2 3 4 2\n"
] | [
"5\n1 2 3 4 5\n",
"2\n4 5\n",
"1\n1\n"
] | none | 1,000 | [
{
"input": "5\n0 0 0 0 1\n0 1 2 3 4",
"output": "5\n1 2 3 4 5"
},
{
"input": "5\n0 0 1 0 1\n0 1 2 2 4",
"output": "2\n4 5"
},
{
"input": "4\n1 0 0 0\n2 3 4 2",
"output": "1\n1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2",
"output": "2\n2 10"
},
{
... | 1,524,998,258 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 3 | 1,028 | 268,390,400 | tamanho = int(input())
hm = list(map(int, input().split()))
ways = list(map(int, input().split()))
matriz = [[0] * 2 for i in range(tamanho)]
if(ways[0] == 0):
for i in range(1, tamanho):
matriz[ways[i] -1][1] += 1
matriz[i][0] += 1
else:
for i in range(tamanho):
matriz[ways[i] -1][1] += 1... | Title: Resort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n*... | ```python
tamanho = int(input())
hm = list(map(int, input().split()))
ways = list(map(int, input().split()))
matriz = [[0] * 2 for i in range(tamanho)]
if(ways[0] == 0):
for i in range(1, tamanho):
matriz[ways[i] -1][1] += 1
matriz[i][0] += 1
else:
for i in range(tamanho):
matriz[ways[i] -... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,574,664,616 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 1,126,400 | n, m = map(int, input().split())
connected_component = []
to_add = 0
for _ in range(n):
a = list(map(int, input().split()))
if a[0] == 0:
to_add += 1
else:
connected_component.append(set(a[1:]))
i = 0
while i < len(connected_component):
for j in connected_component[i+1:]:
... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
n, m = map(int, input().split())
connected_component = []
to_add = 0
for _ in range(n):
a = list(map(int, input().split()))
if a[0] == 0:
to_add += 1
else:
connected_component.append(set(a[1:]))
i = 0
while i < len(connected_component):
for j in connected_component[i... | 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,608,529,710 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 | from sys import stdin,stdout
input=stdin.readline
import math,bisect
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(m):
if l[i]<0:
ans+=abs(l[i])
else:
break
print(ans) | 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
from sys import stdin,stdout
input=stdin.readline
import math,bisect
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(m):
if l[i]<0:
ans+=abs(l[i])
else:
break
print(ans)
``` | 3.93 | MatrixStudio/Codeforces-Python-Submissions |
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ... | 1,529,555,580 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 500 | 512,000 | x = input()
y = input()
y = list(y.split())
z = 1
for i in range(int(x)):
z*= int(y[i])
print(z)
| Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac... | ```python
x = input()
y = input()
y = list(y.split())
z = 1
for i in range(int(x)):
z*= int(y[i])
print(z)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,653,826,629 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
mods = [0]*5
for i in range(1, m+1):
mods[i % 5] += 1
ans = 0
for i in range(1, n+1):
curmod = i % 5
ans += mods[5 - curmod - 1]
print(ans)
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
mods = [0]*5
for i in range(1, m+1):
mods[i % 5] += 1
ans = 0
for i in range(1, n+1):
curmod = i % 5
ans += mods[5 - curmod - 1]
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.
A bar of chocolate can be presented as an *n*<=×<=*n* table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to *n* from left to right and the r... | The first line contains integers *n* (1<=≤<=*n*<=≤<=109) and *q* (1<=≤<=*q*<=≤<=2·105) — the size of the chocolate bar and the number of actions.
Next *q* lines contain the descriptions of the actions: the *i*-th of them contains numbers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=+<=*y**i*<==<=*n*<=+<=1... | Print *q* lines, the *i*-th of them should contain the number of eaten pieces as a result of the *i*-th action. | [
"6 5\n3 4 U\n6 1 L\n2 5 L\n1 6 U\n4 3 U\n",
"10 6\n2 9 U\n10 1 U\n1 10 U\n8 3 L\n10 1 L\n6 5 U\n"
] | [
"4\n3\n2\n1\n2\n",
"9\n1\n10\n6\n0\n2\n"
] | Pictures to the sample tests:
<img class="tex-graphics" src="https://espresso.codeforces.com/2ce2eba5359eb520eb9b09725b638508b03473a8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The pieces that were eaten in the same action are painted the same color. The pieces lying on the anti-diagonal contain the numbers... | 0 | [] | 1,692,157,700 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692157700.319084")# 1692157700.3190994 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.
A bar of chocolate can be presented as an *n*<=×<=*n* table, where each cell represents one piece of c... | ```python
print("_RANDOM_GUESS_1692157700.319084")# 1692157700.3190994
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,581,674,219 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | s = input()
vowels = ['a','e','i','o','u']
evens = ['0','2','4','6','8']
c = 0
for i in s:
if i in vowels:
c+=1
if i not in evens:
c+=1
print(c) | Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s = input()
vowels = ['a','e','i','o','u']
evens = ['0','2','4','6','8']
c = 0
for i in s:
if i in vowels:
c+=1
if i not in evens:
c+=1
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,588,436,006 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 1,228,800 | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost=0
while n>1:
if n<k:
cost+=((n-1)*a)
break
rem=(n%k)
n-=rem
cost+=(a*rem)
aa=n - n//k
if (aa)*a<=b:
cost+=(aa)*a
else:
cost+=b
n=n//k
print(cost) | Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost=0
while n>1:
if n<k:
cost+=((n-1)*a)
break
rem=(n%k)
n-=rem
cost+=(a*rem)
aa=n - n//k
if (aa)*a<=b:
cost+=(aa)*a
else:
cost+=b
n=n//k
print(cost) ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,588,072,532 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 218 | 307,200 | #<https://codeforces.com/problemset/problem/251/A>
import math
count, bounds = [int(x) for x in input().split(" ")]
total = 0
left_index = 0
right_index = 2
current = 0
lst = [int(x) for x in input().split(" ")]
if lst[0] < 0:
delta = 1 - lst[0]
lst = [x + delta for x in lst]
if count <= 2:
print(0)
wh... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
#<https://codeforces.com/problemset/problem/251/A>
import math
count, bounds = [int(x) for x in input().split(" ")]
total = 0
left_index = 0
right_index = 2
current = 0
lst = [int(x) for x in input().split(" ")]
if lst[0] < 0:
delta = 1 - lst[0]
lst = [x + delta for x in lst]
if count <= 2:
pr... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
858 | B | Which floor? | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory.
*m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*... | Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. | [
"10 3\n6 2\n2 1\n7 3\n",
"8 4\n3 1\n6 2\n5 2\n2 1\n"
] | [
"4\n",
"-1\n"
] | In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-... | 750 | [
{
"input": "10 3\n6 2\n2 1\n7 3",
"output": "4"
},
{
"input": "8 4\n3 1\n6 2\n5 2\n2 1",
"output": "-1"
},
{
"input": "8 3\n7 2\n6 2\n1 1",
"output": "2"
},
{
"input": "4 2\n8 3\n3 1",
"output": "2"
},
{
"input": "11 4\n16 4\n11 3\n10 3\n15 4",
"output": "3"
... | 1,665,355,915 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 77 | 0 | n,m=[int(x) for x in input().split()]
mp=dict()
for i in range(m):
a,b=[int(x) for x in input().split()]
mp[a]=b
ans=list()
for i in range(1,105):
flag=0
for j in mp:
md=j%i
if md:tmp=(j//i)+1
else:tmp=j//i
if tmp!=mp[j]:flag=1; break
if flag==0:ans.appen... | Title: Which floor?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to u... | ```python
n,m=[int(x) for x in input().split()]
mp=dict()
for i in range(m):
a,b=[int(x) for x in input().split()]
mp[a]=b
ans=list()
for i in range(1,105):
flag=0
for j in mp:
md=j%i
if md:tmp=(j//i)+1
else:tmp=j//i
if tmp!=mp[j]:flag=1; break
if flag==0... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,694,875,697 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | def main():
user_i = input().split()
number = int(user_i[0])
k = int(user_i[1])
while k > 0:
if number % 10 != 0:
number -= 1
else:
number /= 10
k -= 1
print(int(number))
if __name__ == "__main__":
main() | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
def main():
user_i = input().split()
number = int(user_i[0])
k = int(user_i[1])
while k > 0:
if number % 10 != 0:
number -= 1
else:
number /= 10
k -= 1
print(int(number))
if __name__ == "__main__":
main()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
677 | E | Vanya and Balloons | PROGRAMMING | 2,300 | [
"binary search",
"brute force",
"dp",
"implementation"
] | null | null | Vanya plays a game of balloons on the field of size *n*<=×<=*n*, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. There are two types of crosses: normal and rotated. For example:
or
... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows and columns in the table with balloons.
The each of the following *n* lines contains *n* characters '0', '1', '2' or '3' — the description of the values in balloons. | Print the maximum possible product modulo 109<=+<=7. Note, that you are not asked to maximize the remainder modulo 109<=+<=7, but to find the maximum value and print it this modulo. | [
"4\n1233\n0213\n2020\n0303\n",
"5\n00300\n00300\n33333\n00300\n00300\n",
"5\n00003\n02030\n00300\n03020\n30000\n",
"5\n21312\n10003\n10002\n10003\n23231\n",
"5\n12131\n12111\n12112\n21311\n21212\n"
] | [
"108\n",
"19683\n",
"108\n",
"3\n",
"24\n"
] | In the first sample, the maximum product is achieved for a rotated cross with a center in the cell (3, 3) and radius 1: 2·2·3·3·3 = 108. | 2,250 | [] | 1,692,524,195 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692524194.971414")# 1692524194.9714265 | Title: Vanya and Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya plays a game of balloons on the field of size *n*<=×<=*n*, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons... | ```python
print("_RANDOM_GUESS_1692524194.971414")# 1692524194.9714265
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,634,835,809 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 41 | 124 | 4,505,600 | import math
n,*m=input().split()
n=int(n)
m=int(*m)
a,b=0,0
if n==m:
print(2)
else:
solCount=0
bSols=[]
for i in range(n+1):
if m-b**2 == math.sqrt(n-b):
solCount+=1
bSols.append(b)
b+=1
print(solCount) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
import math
n,*m=input().split()
n=int(n)
m=int(*m)
a,b=0,0
if n==m:
print(2)
else:
solCount=0
bSols=[]
for i in range(n+1):
if m-b**2 == math.sqrt(n-b):
solCount+=1
bSols.append(b)
b+=1
print(solCount)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
416 | B | Art Union | PROGRAMMING | 1,300 | [
"brute force",
"dp",
"implementation"
] | null | null | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color... | The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), ... | Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture. | [
"5 1\n1\n2\n3\n4\n5\n",
"4 2\n2 5\n3 1\n5 3\n10 1\n"
] | [
"1 3 6 10 15 ",
"7 8 13 21 "
] | none | 1,000 | [
{
"input": "5 1\n1\n2\n3\n4\n5",
"output": "1 3 6 10 15 "
},
{
"input": "4 2\n2 5\n3 1\n5 3\n10 1",
"output": "7 8 13 21 "
},
{
"input": "1 1\n66",
"output": "66 "
},
{
"input": "2 2\n1 1\n1 1",
"output": "2 3 "
},
{
"input": "2 2\n10 1\n10 1",
"output": "11 2... | 1,664,025,464 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 420 | 9,932,800 | p,s=map(int,input().split())
arr=[]
for _ in range(p):
v=list(map(int,input().split()))
arr.append(v)
for i in range(1,s):
arr[0][i]+=arr[0][i-1]
for j in range(1,p):
arr[j][0]+=arr[j-1][0]
for i in range(1,p):
for j in range(1,s):
arr[i][j]+=max(arr[i-1][j],arr[i][j-1])
for k in range(p):
print(ar... | Title: Art Union
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned t... | ```python
p,s=map(int,input().split())
arr=[]
for _ in range(p):
v=list(map(int,input().split()))
arr.append(v)
for i in range(1,s):
arr[0][i]+=arr[0][i-1]
for j in range(1,p):
arr[j][0]+=arr[j-1][0]
for i in range(1,p):
for j in range(1,s):
arr[i][j]+=max(arr[i-1][j],arr[i][j-1])
for k in range(p):
... | 3 | 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,681,327,176 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 155 | 14,438,400 | # -*- coding: utf-8 -*-
"""
Created on Thu Apr 13 00:46:31 2023
@author: Srusty Sahoo
"""
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
e1=sum(arr1)-sum(arr2)
e2=sum(arr2)-sum(arr3)
print(e1)
print(e2) | 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
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 13 00:46:31 2023
@author: Srusty Sahoo
"""
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
e1=sum(arr1)-sum(arr2)
e2=sum(arr2)-sum(arr3)
print(e1)
print(e2)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,429,766 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 670 | 14,438,400 | n,m=map(int,input().split())
list1=list(map(int,input().split()))
set1=set()
list2=[]
for i in range(-1,-1-n,-1):
set1.add(list1[i])
list2.append(len(set1))
list2.reverse()
for i in range(m):
print(list2[int(input())-1]) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m=map(int,input().split())
list1=list(map(int,input().split()))
set1=set()
list2=[]
for i in range(-1,-1-n,-1):
set1.add(list1[i])
list2.append(len(set1))
list2.reverse()
for i in range(m):
print(list2[int(input())-1])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,660,654,531 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | x = int(input())
sol = 0
while x > 0:
if x % 2 == 1:
sol += 1
x //= 2
print(sol)
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
x = int(input())
sol = 0
while x > 0:
if x % 2 == 1:
sol += 1
x //= 2
print(sol)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da... | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI... | 1,591,612,897 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 280 | 1,228,800 | n=int(input())
c=0
for i in range(n):
s=str(input())
if(s[0] in '0123456789' ):
s=int(s)
if(s>=18):
pass
else:
c=c+1
else:
if(s in ['ABSINTH','BEER','BRANDY','CHAMPAGNE','GIN','RUM',"SAKE",'TEQUILA','VODKA','WHISKEY','WINE']):
c... | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
n=int(input())
c=0
for i in range(n):
s=str(input())
if(s[0] in '0123456789' ):
s=int(s)
if(s>=18):
pass
else:
c=c+1
else:
if(s in ['ABSINTH','BEER','BRANDY','CHAMPAGNE','GIN','RUM',"SAKE",'TEQUILA','VODKA','WHISKEY','WINE']):
... | 3.927711 | MatrixStudio/Codeforces-Python-Submissions |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,617,998,602 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 154 | 409,600 | import sys
import math
from collections import Counter
n, k = list(map(int, input().split()))
near = k / n
if near.is_integer():
print(n) if near == 2 else print(0)
sys.exit()
possibles = list(map(int, (n * f'{math.floor(near)} ').split()))
for i, number in enumerate(possibles):
possibles[i] = possibles... | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
import sys
import math
from collections import Counter
n, k = list(map(int, input().split()))
near = k / n
if near.is_integer():
print(n) if near == 2 else print(0)
sys.exit()
possibles = list(map(int, (n * f'{math.floor(near)} ').split()))
for i, number in enumerate(possibles):
possibles[i] =... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
938 | E | Max History | PROGRAMMING | 2,300 | [
"combinatorics",
"math"
] | null | null | You are given an array *a* of length *n*. We define *f**a* the following way:
- Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=<<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*.
Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 1... | The first line contains integer *n* (1<=≤<=*n*<=≤<=<=1 000 000) — the size of array *a*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=<=*a**i*<=≤<=<=109). | Print the only integer, the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7. | [
"2\n1 3\n",
"3\n1 1 2\n"
] | [
"1",
"4"
] | For the second example all the permutations are:
- *p* = [1, 2, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [1, 3, 2] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 1, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 3, 1] : *f*<sub class="lower-index"... | 0 | [
{
"input": "2\n1 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "4"
},
{
"input": "6\n1 4 5 2 3 3",
"output": "2928"
},
{
"input": "8\n8 7 5 4 6 6 6 6",
"output": "351360"
},
{
"input": "8\n1 2 3 9 100 100 100 100",
"output": "109296"
},
{
"inpu... | 1,698,316,756 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 27 | 3,000 | 23,859,200 | mod = 10**9 + 7
def add(a, b):
a += b
if a >= mod:
a -= mod
return a
def sub(a, b):
a -= b
if a < 0:
a += mod
return a
def mul(a, b):
return (a * b) % mod
def pow(a, b):
c = 1
while b > 0:
if b & 1:
c = mul(c, a)
a... | Title: Max History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* of length *n*. We define *f**a* the following way:
- Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=<<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then s... | ```python
mod = 10**9 + 7
def add(a, b):
a += b
if a >= mod:
a -= mod
return a
def sub(a, b):
a -= b
if a < 0:
a += mod
return a
def mul(a, b):
return (a * b) % mod
def pow(a, b):
c = 1
while b > 0:
if b & 1:
c = mul(c, a)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,664,732,927 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | def switch(n: int):
if n == 1:
return 0
elif n == 0:
return 1
lights = []
for i in range(3):
lights.append([1, 1, 1])
first, second, third = map(int, input().split())
if first % 2 == 1:
lights[0][0] = switch(lights[0][0])
lights[0][1] = switch(lights[0][1])
lights[1][0] = swit... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
def switch(n: int):
if n == 1:
return 0
elif n == 0:
return 1
lights = []
for i in range(3):
lights.append([1, 1, 1])
first, second, third = map(int, input().split())
if first % 2 == 1:
lights[0][0] = switch(lights[0][0])
lights[0][1] = switch(lights[0][1])
lights[1]... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,660,327,668 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 61 | 0 | def indice(i):
ch="098765432109876543210"
l=list()
for j in range(len(ch)):
if ch[j]==i:
l.append(j)
return(l)
x=int(input())
ch1=input()
ch2=input()
s=0
for i in range(x):
l=list()
l.append(abs(max(indice(ch2[i]))-max(indice(ch1[i]))))
l.append(abs(max(indi... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
def indice(i):
ch="098765432109876543210"
l=list()
for j in range(len(ch)):
if ch[j]==i:
l.append(j)
return(l)
x=int(input())
ch1=input()
ch2=input()
s=0
for i in range(x):
l=list()
l.append(abs(max(indice(ch2[i]))-max(indice(ch1[i]))))
l.append(ab... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,449,140 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | # Read the input
x = int(input())
# Calculate the minimum number of moves
moves = (x + 4) // 5
# Output the result
print(moves)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
# Read the input
x = int(input())
# Calculate the minimum number of moves
moves = (x + 4) // 5
# Output the result
print(moves)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000... | 1,593,269,917 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 171 | 24,268,800 | k=int(input())
n=input()
dig=[]
for x in n:
dig.append(int(x))
dig.sort()
s=sum(dig)
count=0
l=0
while s<k:
#print(dig)
#print(s)
count+=1
s+=9-dig[l]
l+=1
print(count)
| Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th... | ```python
k=int(input())
n=input()
dig=[]
for x in n:
dig.append(int(x))
dig.sort()
s=sum(dig)
count=0
l=0
while s<k:
#print(dig)
#print(s)
count+=1
s+=9-dig[l]
l+=1
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.