contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
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 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,540,349,518 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 140 | 0 | def foobar(n):
list = [0]*n
for i in range(n+1):
l = n - i + 1
for j in range(n-l+1):
for k in range(j, j+l):
list[k] += 1
max = 0
for i in list:
max = max if max > i else i
print(max)
n = input()
foobar(int(n))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in se... | ```python
def foobar(n):
list = [0]*n
for i in range(n+1):
l = n - i + 1
for j in range(n-l+1):
for k in range(j, j+l):
list[k] += 1
max = 0
for i in list:
max = max if max > i else i
print(max)
n = input()
foobar(int(n))
``` | 3 | |
846 | F | Random Query | PROGRAMMING | 1,800 | [
"data structures",
"math",
"probabilities",
"two pointers"
] | null | null | You are given an array *a* consisting of *n* positive integers. You pick two integer numbers *l* and *r* from 1 to *n*, inclusive (numbers are picked randomly, equiprobably and independently). If *l*<=><=*r*, then you swap values of *l* and *r*. You have to calculate the expected value of the number of unique elemen... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integer numbers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one number — the expected number of unique elements in chosen segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=4 — formally, the answer is correct if , where *x* is jury's answer, and *y* is your answer. | [
"2\n1 2\n",
"2\n2 2\n"
] | [
"1.500000\n",
"1.000000\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "1.500000"
},
{
"input": "2\n2 2",
"output": "1.000000"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "3.100000"
},
{
"input": "20\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21",
"output": "7.010000"
},
{
"input": "1... | 1,678,960,541 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 1,091 | 85,811,200 | n=int(input())
a=list(map(int,input().split()))
lastocc=[0]*1000006
ans=[0]*n
ans[0]=1
lastocc[a[0]]=1
for i in range(1,n):
ans[i]=ans[i-1]+(i+1-lastocc[a[i]])
lastocc[a[i]]=i+1
print((2*sum(ans)-n)/(n*n))
| Title: Random Query
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* positive integers. You pick two integer numbers *l* and *r* from 1 to *n*, inclusive (numbers are picked randomly, equiprobably and independently). If *l*<=><=*r*, then you s... | ```python
n=int(input())
a=list(map(int,input().split()))
lastocc=[0]*1000006
ans=[0]*n
ans[0]=1
lastocc[a[0]]=1
for i in range(1,n):
ans[i]=ans[i-1]+(i+1-lastocc[a[i]])
lastocc[a[i]]=i+1
print((2*sum(ans)-n)/(n*n))
``` | 3 | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,557,036,636 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n, m = map(int, input().split())
print(n,m)
a = [[0] * n for l in range(m)]
for i in range(n):
for j, k in enumerate(input()):
a[j][i] = k
res = set()
for j in range(m):
best = set()
max_k = max(a[j])
for i in range(n):
if a[j][i] == max_k:
best.add(i)
res.update(best)
pr... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n, m = map(int, input().split())
print(n,m)
a = [[0] * n for l in range(m)]
for i in range(n):
for j, k in enumerate(input()):
a[j][i] = k
res = set()
for j in range(m):
best = set()
max_k = max(a[j])
for i in range(n):
if a[j][i] == max_k:
best.add(i)
res.updat... | 0 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,699,800,143 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | letters = str("abcdefghijklmnopqrstuvwxyz")
strInputFirst = str(input()).lower()
strInputSecond = str(input()).lower()
sum1,sum2 = 0,0
for i in range(len(strInputFirst)):
sum1 += letters.find(strInputFirst[i])
sum2 += letters.find(strInputSecond[i])
if sum1 < sum2: print(-1)
elif sum1 > sum2: pr... | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
letters = str("abcdefghijklmnopqrstuvwxyz")
strInputFirst = str(input()).lower()
strInputSecond = str(input()).lower()
sum1,sum2 = 0,0
for i in range(len(strInputFirst)):
sum1 += letters.find(strInputFirst[i])
sum2 += letters.find(strInputSecond[i])
if sum1 < sum2: print(-1)
elif sum1 ... | 0 |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,597,901,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | from sys import stdin, stdout
#input = stdin.buffer.readline
#print = stdout.write
for i in range(2, 11):
print(i, flush=True)
s = input()
if s[0] == 'y':
print('composite', flush=True)
break
else:
print('prime', flush=True)
| Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i... | ```python
from sys import stdin, stdout
#input = stdin.buffer.readline
#print = stdout.write
for i in range(2, 11):
print(i, flush=True)
s = input()
if s[0] == 'y':
print('composite', flush=True)
break
else:
print('prime', flush=True)
``` | 0 | |
990 | E | Post Lamps | PROGRAMMING | 2,100 | [
"brute force",
"greedy"
] | null | null | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are bloc... | The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2,... | Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1. | [
"6 2 3\n1 3\n1 2 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"5 1 5\n0\n3 3 3 3 3\n",
"7 4 3\n2 4 5 6\n3 14 15\n"
] | [
"6\n",
"1000\n",
"-1\n",
"-1\n"
] | none | 0 | [
{
"input": "6 2 3\n1 3\n1 2 3",
"output": "6"
},
{
"input": "4 3 4\n1 2 3\n1 10 100 1000",
"output": "1000"
},
{
"input": "5 1 5\n0\n3 3 3 3 3",
"output": "-1"
},
{
"input": "7 4 3\n2 4 5 6\n3 14 15",
"output": "-1"
},
{
"input": "1 0 1\n\n1000000",
"output": ... | 1,528,628,715 | 3,615 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 106,803,200 | import sys
n, m, k = map(int, input().split())
blocked = list(map(int, input().split()))
costs = list(map(int, input().split()))
greedy = []
if 0 in blocked:
print(-1)
else:
#greedy
for i in range(len(costs)):
greedy.append((i, costs[i] / (i + 1)))
greedy.sort(key=lambda a: a[1])
# ... | Title: Post Lamps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they corres... | ```python
import sys
n, m, k = map(int, input().split())
blocked = list(map(int, input().split()))
costs = list(map(int, input().split()))
greedy = []
if 0 in blocked:
print(-1)
else:
#greedy
for i in range(len(costs)):
greedy.append((i, costs[i] / (i + 1)))
greedy.sort(key=lambda a: ... | 0 | |
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,631,018,500 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,963,200 | s=input()
sb=0
ss=0
for i in s:
if i.upper()==i:
sb+=1
elif i!=i.upper():
ss+=1
if sb>ss:
v=s.upper()
print(v)
elif sb<ss:
v=s.lower()
print(v)
elif sb==ss:
v=s.lower()
print(v) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
sb=0
ss=0
for i in s:
if i.upper()==i:
sb+=1
elif i!=i.upper():
ss+=1
if sb>ss:
v=s.upper()
print(v)
elif sb<ss:
v=s.lower()
print(v)
elif sb==ss:
v=s.lower()
print(v)
``` | 3.94853 |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,697,903,140 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | num = input().split(" ")
i=0
a,b = int(num[0]),int(num[1])
while(True):
a *= 3
b *= 2
i += 1
if(a>b):
print(i)
break | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
num = input().split(" ")
i=0
a,b = int(num[0]),int(num[1])
while(True):
a *= 3
b *= 2
i += 1
if(a>b):
print(i)
break
``` | 3 | |
566 | F | Clique in the Divisibility Graph | PROGRAMMING | 1,500 | [
"dp",
"math",
"number theory"
] | null | null | As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are conn... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106), that sets the size of set *A*.
The second line contains *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — elements of subset *A*. The numbers in the line follow in the ascending order. | Print a single number — the maximum size of a clique in a divisibility graph for set *A*. | [
"8\n3 4 6 8 10 18 21 24\n"
] | [
"3\n"
] | In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph. | 500 | [
{
"input": "8\n3 4 6 8 10 18 21 24",
"output": "3"
},
{
"input": "5\n2 3 4 8 16",
"output": "4"
},
{
"input": "2\n10 20",
"output": "2"
},
{
"input": "2\n10 21",
"output": "1"
},
{
"input": "5\n250000 333333 500000 666666 1000000",
"output": "3"
},
{
"... | 1,658,896,857 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
m = a[-1]
where = dict()
for i in range(n):
where[a[i]] = i
edges = [[] for _ in range(n)]
dp = [1]*n
for i in range(n):
x = a[i]
dp[i] = 1 + max([0] + [dp[j] for j in edges[i]])
y = 2*x
while y < m:
... | Title: Clique in the Divisibility Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a cli... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
m = a[-1]
where = dict()
for i in range(n):
where[a[i]] = i
edges = [[] for _ in range(n)]
dp = [1]*n
for i in range(n):
x = a[i]
dp[i] = 1 + max([0] + [dp[j] for j in edges[i]])
y = 2*x
while y ... | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,604,593,861 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 374 | 2,150,400 | for _ in range(int(input())):
a1, a2, a3 = map(int, input().split())
s1, s2, s3 = int((a2*a3//a1)**0.5), int((a1*a3//a2)**0.5), int((a1*a2//a3)**0.5)
print(4*(s1+s2+s3)) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
for _ in range(int(input())):
a1, a2, a3 = map(int, input().split())
s1, s2, s3 = int((a2*a3//a1)**0.5), int((a1*a3//a2)**0.5), int((a1*a2//a3)**0.5)
print(4*(s1+s2+s3))
``` | -1 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,653,112,927 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 512,000 | import enum
s=input()
n = len(s)
dp = [0] * n
st, ans = 0, 0
for (idx, v) in enumerate(s):
if v == '(':
st += 1
else:
if st == 0:
continue
else:
st -= 1
dp[idx] = 2
if idx - 1 >= 0 and s[idx - 1] == ')':
... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
import enum
s=input()
n = len(s)
dp = [0] * n
st, ans = 0, 0
for (idx, v) in enumerate(s):
if v == '(':
st += 1
else:
if st == 0:
continue
else:
st -= 1
dp[idx] = 2
if idx - 1 >= 0 and s[idx - 1] == ')':
... | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 0 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,511,163,394 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 1
while True:
s = str(t)
flag1 = False
flag2 = False
# print(t)
for x in s:
if int(x) in a:
flag1 = True
if int(x) in b:
flag2 = True
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 1
while True:
s = str(t)
flag1 = False
flag2 = False
# print(t)
for x in s:
if int(x) in a:
flag1 = True
if int(x) in b:
flag2 =... | 0 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,617,042,493 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 93 | 1,433,600 | from collections import Counter
massage, newspaper = input(), input()
massageCounter, newsCounter = Counter(massage), Counter(newspaper)
yay, whoops = 0, 0
for i in range(ord('a'), ord('z')+1):
yay += min(massageCounter[chr(i)], newsCounter[chr(i)])
for i in range(ord('A'), ord('Z')+1):
yay += min(ma... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
from collections import Counter
massage, newspaper = input(), input()
massageCounter, newsCounter = Counter(massage), Counter(newspaper)
yay, whoops = 0, 0
for i in range(ord('a'), ord('z')+1):
yay += min(massageCounter[chr(i)], newsCounter[chr(i)])
for i in range(ord('A'), ord('Z')+1):
yay... | 3 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,627,142,839 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 109 | 20,172,800 | import math
def main_function():
n, x = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
counter = 0
for i in range(x):
if not i in a:
counter+= 1
if x in a:
counter += 1
print(counter)
main_function() | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
import math
def main_function():
n, x = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
counter = 0
for i in range(x):
if not i in a:
counter+= 1
if x in a:
counter += 1
print(counter)
main_function()
``... | 3 | |
161 | B | Discounts | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape... | The first input line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=103) — the number of items in the supermarket and the number of carts, correspondingly. Next *n* lines describe the items as "*c**i* *t**i*" (without the quotes), where *c**i* (1<=≤<=*c**i*<=≤<=109) is an integer denoting the price of the *i*... | In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following *k* lines print the descriptions of the items in the carts. In the *i*-th line print the description of the *i*-th cart as "*t* *b*1 *b*2 ... *b**t*" (without t... | [
"3 2\n2 1\n3 2\n3 1\n",
"4 3\n4 1\n1 2\n2 2\n3 2\n"
] | [
"5.5\n2 1 2\n1 3\n",
"8.0\n1 1\n2 4 2\n1 3\n"
] | In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | 1,000 | [
{
"input": "3 2\n2 1\n3 2\n3 1",
"output": "5.5\n2 1 2\n1 3"
},
{
"input": "4 3\n4 1\n1 2\n2 2\n3 2",
"output": "8.0\n1 1\n1 2\n2 3 4"
},
{
"input": "1 1\n1 1",
"output": "0.5\n1 1"
},
{
"input": "1 1\n1 2",
"output": "1.0\n1 1"
},
{
"input": "10 1\n1 1\n2 2\n1 1\... | 1,595,850,613 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 6,656,000 | l=[]
for i in range(5):
l.append(list(map(int,input().split())))
def myIndex(l):
for i in l:
if 1 in i:
return (i.index(1),l.index(i))
x,y=myIndex(l)
print(abs(2-x)+abs(2-y))
| Title: Discounts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the cust... | ```python
l=[]
for i in range(5):
l.append(list(map(int,input().split())))
def myIndex(l):
for i in l:
if 1 in i:
return (i.index(1),l.index(i))
x,y=myIndex(l)
print(abs(2-x)+abs(2-y))
``` | -1 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,573,380,442 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | n, k = map(int, input().split())
t = 1
while k%2 == 0:
k //= 2
t += 1
print(t)
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n, k = map(int, input().split())
t = 1
while k%2 == 0:
k //= 2
t += 1
print(t)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,681,886,498 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | from math import ceil
n = int(input())
m = int(input())
a = int(input())
if a == 0 or m == 0 or n == 0:
print(0)
elif m == a and n == a:
print(1)
elif m == n and a == 1:
print(n*m)
elif a > m and a > n:
print(1)
elif m == n and a < n:
if (m+n) < a ** a:
if ceil((m+n)%a) == 0:... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
from math import ceil
n = int(input())
m = int(input())
a = int(input())
if a == 0 or m == 0 or n == 0:
print(0)
elif m == a and n == a:
print(1)
elif m == n and a == 1:
print(n*m)
elif a > m and a > n:
print(1)
elif m == n and a < n:
if (m+n) < a ** a:
if ceil((m+n... | -1 |
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). | Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 2492213340204320744986569... | 1,437,429,111 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 61 | 0 | a = int(input())
x = (45 * 18 * 10**17) % a
print(a - x, a - x + 10**18 - 1)
| Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X ... | ```python
a = int(input())
x = (45 * 18 * 10**17) % a
print(a - x, a - x + 10**18 - 1)
``` | 3 | |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"ou... | 1,606,435,813 | 2,147,483,647 | Python 3 | OK | TESTS | 271 | 109 | 0 | # https://codeforces.com/problemset/problem/808/A
# 900
import math
n = input()
ln = len(n)
n = int(n)
m = int("1" + ("0"*(ln-1)))
nxt = math.ceil((n+1)/m) * m
print(nxt - n) | Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 1... | ```python
# https://codeforces.com/problemset/problem/808/A
# 900
import math
n = input()
ln = len(n)
n = int(n)
m = int("1" + ("0"*(ln-1)))
nxt = math.ceil((n+1)/m) * m
print(nxt - n)
``` | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,691,354,628 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 62 | 0 | ch = input()
def f(ch):
if ch.isupper():
return ch.lower()
if (ch[0].islower() and ch[1:].isupper()) or (len(ch)==1 and ch.islower()):
return ch[0].upper()+ch[1:].lower()
else:return ch
print(f(ch)) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
ch = input()
def f(ch):
if ch.isupper():
return ch.lower()
if (ch[0].islower() and ch[1:].isupper()) or (len(ch)==1 and ch.islower()):
return ch[0].upper()+ch[1:].lower()
else:return ch
print(f(ch))
``` | 3 | |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,401,464,606 | 806 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 0 | #!/usr/bin/python3
import sys
n,m = [int(nbr) for nbr in sys.stdin.readline().split()]
groups = [int(nbr) for nbr in sys.stdin.readline().split()]
currentBusFilling = 0
nbrOfBusses = 0
for group in groups:
if group + currentBusFilling <= m:
currentBusFilling += group
else:
nbrOfBusses += 1
currentBusFilling ... | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand... | ```python
#!/usr/bin/python3
import sys
n,m = [int(nbr) for nbr in sys.stdin.readline().split()]
groups = [int(nbr) for nbr in sys.stdin.readline().split()]
currentBusFilling = 0
nbrOfBusses = 0
for group in groups:
if group + currentBusFilling <= m:
currentBusFilling += group
else:
nbrOfBusses += 1
currentB... | 0 | |
552 | C | Vanya and Scales | PROGRAMMING | 1,900 | [
"brute force",
"dp",
"greedy",
"math",
"meet-in-the-middle",
"number theory"
] | null | null | Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scale... | The first line contains two integers *w*,<=*m* (2<=≤<=*w*<=≤<=109, 1<=≤<=*m*<=≤<=109) — the number defining the masses of the weights and the mass of the item. | Print word 'YES' if the item can be weighted and 'NO' if it cannot. | [
"3 7\n",
"100 99\n",
"100 50\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can ha... | 1,500 | [
{
"input": "3 7",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "100 50",
"output": "NO"
},
{
"input": "1000000000 1",
"output": "YES"
},
{
"input": "100 10002",
"output": "NO"
},
{
"input": "4 7",
"output": "NO"
},
{
... | 1,455,473,975 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 93 | 0 | w,m = map(int,input().split())
def solve(m,curw):
cursum = 0
for i in range(curw):
cursum += w**i
if cursum==m : return 1
if cursum>m or w**i==m: return solve(abs(w**i-m),i)
return 0
print('YES' if solve(m,100) else 'NO')
| Title: Vanya and Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can wei... | ```python
w,m = map(int,input().split())
def solve(m,curw):
cursum = 0
for i in range(curw):
cursum += w**i
if cursum==m : return 1
if cursum>m or w**i==m: return solve(abs(w**i-m),i)
return 0
print('YES' if solve(m,100) else 'NO')
``` | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,668,491,196 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a,b = map(int,input().split())
c = list(map(int,input().split()))
k = []
for x in range(len(c)):
if c[x]+b<=5:
k.append(c[x])
print(len(k)//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
a,b = map(int,input().split())
c = list(map(int,input().split()))
k = []
for x in range(len(c)):
if c[x]+b<=5:
k.append(c[x])
print(len(k)//3)
``` | 3 | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is 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. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,550,936,445 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 |
import time
n = int(input())
def l(n):
z = 1
x = 0
while(z <= n):
x += z
z += 1
return x
x = 1
q = 1
while l(x) < n:
q = l(x)
x += 1
print(n - q) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
import time
n = int(input())
def l(n):
z = 1
x = 0
while(z <= n):
x += z
z += 1
return x
x = 1
q = 1
while l(x) < n:
q = l(x)
x += 1
print(n - q)
``` | 0 | |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,583,410,199 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | n = int(input())
l = list(map(int,input().split()))
count = 0
p = 0
if n == 1 :
print(1)
exit()
else:
for i in range(len(l)-1):
if l[i] == 1 and l[i+1] ==1 or l[i] == 1 and l[i+1] == 0 or l[i] == 0 and l[i+1] == 1 :
count +=1
if l[i] == 0 and l[i+1] == 0 :
... | Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
n = int(input())
l = list(map(int,input().split()))
count = 0
p = 0
if n == 1 :
print(1)
exit()
else:
for i in range(len(l)-1):
if l[i] == 1 and l[i+1] ==1 or l[i] == 1 and l[i+1] == 0 or l[i] == 0 and l[i+1] == 1 :
count +=1
if l[i] == 0 and l[i+1] == ... | 0 | |
593 | C | Beautiful Function | PROGRAMMING | 2,200 | [
"constructive algorithms",
"math"
] | null | null | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=50) — the number of circles Ruslan thinks of. Next follow *n* lines, each of them containing three integers *x**i*, *y**i* and *r**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=50, 2<=≤<=*r**i*<=≤<=50) — the coordinates of the center and the raduis of the *i*-th circle. | In the first line print a correct function *f*(*t*). In the second line print a correct function *g*(*t*). The set of the points (*x**t*<==<=*f*(*t*),<=*y**t*<==<=*g*(*t*)) (0<=≤<=*t*<=≤<=50) must satisfy the condition, that there is at least one point inside or on the border of each of the circles, Ruslan thinks of at... | [
"3\n0 10 4\n10 0 4\n20 10 4\n"
] | [
"t \nabs((t-10))"
] | Correct functions:
1. 101. (1+2)1. ((*t*-3)+(*t**4))1. *abs*((*t*-10))1. (*abs*((((23-*t*)*(*t***t*))+((45+12)*(*t***t*))))*((5**t*)+((12**t*)-13)))1. *abs*((*t*-(*abs*((*t**31))+14))))
Incorrect functions:
1. 3+5+7 (not enough brackets, it should be ((3+5)+7) or (3+(5+7))) 1. *abs*(*t*-3) (not enough brackets,... | 3,000 | [
{
"input": "3\n0 10 4\n10 0 4\n20 10 4",
"output": "(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((5*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(5*((1-abs((t-2)))+abs((abs((t-2))-1)))))"... | 1,589,506,508 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 156 | 20,172,800 | n = int(input())
cxes = []
cyes = []
for i in range(n):
x, y, r = map(int, input().split())
for dx in range(2):
for dy in range(2):
if (x+dx)%2 == 0 and (y+dy)%2 == 0:
cxes.append((x+dx)//2)
cyes.append((y+dy)//2)
rx = ""
ry = ""
for i in range(n):
t = i+1
s = f"((abs((t-{t-1}))-(2*abs(... | Title: Beautiful Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful se... | ```python
n = int(input())
cxes = []
cyes = []
for i in range(n):
x, y, r = map(int, input().split())
for dx in range(2):
for dy in range(2):
if (x+dx)%2 == 0 and (y+dy)%2 == 0:
cxes.append((x+dx)//2)
cyes.append((y+dy)//2)
rx = ""
ry = ""
for i in range(n):
t = i+1
s = f"((abs((t-{t-1}... | 0 | |
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann... | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are p... | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ... | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
... | 1,610,015,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
t=sum(a[-1*k:])
l=[1]*(k-1)
l.append(n-(k-1))
print(t)
print(*l) | Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
t=sum(a[-1*k:])
l=[1]*(k-1)
l.append(n-(k-1))
print(t)
print(*l)
``` | 0 | |
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,641,206,675 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | l = list(map(int,input().split()))
l.sort()
a = l[0]
b = l[1]
c = l[2]
d = l[3]
if(a+b>c or b+c>d or a+c > d or a+b > d):
print('TRIANGLE')
elif(a+b == c or b+c == d or a+c == d or a+b == d):
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
l = list(map(int,input().split()))
l.sort()
a = l[0]
b = l[1]
c = l[2]
d = l[3]
if(a+b>c or b+c>d or a+c > d or a+b > d):
print('TRIANGLE')
elif(a+b == c or b+c == d or a+c == d or a+b == d):
print("SEGMENT")
else:
print("IMPOSSIBLE")
``` | 3.969 |
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,681,623,844 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n,k,l,c,d,p,nl,np=map(int,input().split())
m=min((k*l)//nl,c*d)
m=min(m,p//np)
print(m//n) | 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())
m=min((k*l)//nl,c*d)
m=min(m,p//np)
print(m//n)
``` | 3 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,691,068,362 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 124 | 0 | k = int(input())
l = list(map(int, input().split()))
ans = int()
s = int()
if sum(l) < k:
ans = -1
else:
while s < k:
s += max(l)
l.remove(max(l))
ans += 1
print(ans)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
k = int(input())
l = list(map(int, input().split()))
ans = int()
s = int()
if sum(l) < k:
ans = -1
else:
while s < k:
s += max(l)
l.remove(max(l))
ans += 1
print(ans)
``` | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,679,474,420 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | code = input()
code_nums = []
pwd = ""
for i in range(10):
code_num = input()
code_nums.append(code_num)
for i in range(0, 71, 10):
for j in range(len(code_nums)):
if code_nums[j] == code[i:i+10]:
pwd += str(j)
print(pwd)
| Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
code = input()
code_nums = []
pwd = ""
for i in range(10):
code_num = input()
code_nums.append(code_num)
for i in range(0, 71, 10):
for j in range(len(code_nums)):
if code_nums[j] == code[i:i+10]:
pwd += str(j)
print(pwd)
``` | 3.969 |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,619,873,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | t,x1,y1,x2,y2=map(int,input().split())
l=input()
x=x2-x1
y=y2-y1
if x>=0:
a='E'
else:
a='W'
if y>=0:
b='N'
else:
b='S'
x=abs(x)
y=abs(y)
for i in range(t):
if x==0 and y==0:
print(i)
break
if l[i]==a:
x-=1
if l[i]==b:
y-=1
if i==t-1... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
t,x1,y1,x2,y2=map(int,input().split())
l=input()
x=x2-x1
y=y2-y1
if x>=0:
a='E'
else:
a='W'
if y>=0:
b='N'
else:
b='S'
x=abs(x)
y=abs(y)
for i in range(t):
if x==0 and y==0:
print(i)
break
if l[i]==a:
x-=1
if l[i]==b:
y-=1
... | 0 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,594,705,660 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 280 | 21,504,000 | n,m=map(int,input().split());x=[];y=[];k,l=0,0
for i in range(n):
s=input()
for j in range(m):
if s[j]=='*':
x.append(i);y.append(j)
while k<3:
if x.count(x[k])==1:
print(x[k]+1,end=" ");break
k+=1
while l<3:
if y.count(y[l])==1:
print(y[l]+1);break
... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n,m=map(int,input().split());x=[];y=[];k,l=0,0
for i in range(n):
s=input()
for j in range(m):
if s[j]=='*':
x.append(i);y.append(j)
while k<3:
if x.count(x[k])==1:
print(x[k]+1,end=" ");break
k+=1
while l<3:
if y.count(y[l])==1:
print(y[l]+1... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,508,058,712 | 4,012 | Python 3 | OK | TESTS | 55 | 78 | 13,721,600 | import sys
def maxofmin(a,n,m):
if m==1:
return min(a)
elif m==2:
return max(a[0], a[-1])
else:
return max(a)
def main():
n,m = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
a = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
print(maxofmin(a... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
import sys
def maxofmin(a,n,m):
if m==1:
return min(a)
elif m==2:
return max(a[0], a[-1])
else:
return max(a)
def main():
n,m = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
a = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
print(... | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,694,526,489 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import math
p=2
a=int(input())
for x in range(1,int(math.sqrt(a))+1):
if a%x==0:
m=list(str(x))
n=list(str(a//x))
for i in m:
if i!='4' and i!='7':
p-=1
for j in n:
if j!='4' and j!='7':
p-=1
if p==1 or p ==2:
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
import math
p=2
a=int(input())
for x in range(1,int(math.sqrt(a))+1):
if a%x==0:
m=list(str(x))
n=list(str(a//x))
for i in m:
if i!='4' and i!='7':
p-=1
for j in n:
if j!='4' and j!='7':
p-=1
if p==1 or p ... | 0 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,586,016,023 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 140 | 2,457,600 | def cal_cell(a, d, i, j):
t = a[i][j]
if t[0]:
return {0: True, 'd': 'U'}
else:
t_u = d[i - 1][j]
s_u = t[2] + t_u[2] + t[5] + t_u[5]
if t_u[0]:
m_u = 1
else:
m_u = min(t[2] + t_u[2], t[5] + t_u[5])
t_l = d[i][j - 1]
... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
def cal_cell(a, d, i, j):
t = a[i][j]
if t[0]:
return {0: True, 'd': 'U'}
else:
t_u = d[i - 1][j]
s_u = t[2] + t_u[2] + t[5] + t_u[5]
if t_u[0]:
m_u = 1
else:
m_u = min(t[2] + t_u[2], t[5] + t_u[5])
t_l = d[i][j - 1... | 0 |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,673,683,643 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 77 | 1,740,800 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
memo = dict()
for _ in range(n):
data = input().split()
memo[data[1]] = data[0]
for _ in range(m):
data = input().split()
print(data[0] + " " + data[1] + " #" + memo[data[1][:-1]])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
memo = dict()
for _ in range(n):
data = input().split()
memo[data[1]] = data[0]
for _ in range(m):
data = input().split()
print(data[0] + " " + data[1] + " #" + memo[data[1][:-1]])
``` | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,590,259,344 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,150,400 | a=int(input())
b=int(input())
n=int(input())
i=0
k=0
j=0
while i<n:
while j<10:
a=a*10+j
if a%b==0:
i=i+1;
if i==n:
break
j=0
else:
a=a//10
j=j+1
if j==10:
k=1
print(-1)
break
if k==0:
print(a)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a=int(input())
b=int(input())
n=int(input())
i=0
k=0
j=0
while i<n:
while j<10:
a=a*10+j
if a%b==0:
i=i+1;
if i==n:
break
j=0
else:
a=a//10
j=j+1
if j==10:
k=1
print(-1)
break
if k==0:
print(a)
``` | -1 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,673,117,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 92 | 0 | s = input()
for i in range(len(s)-7):
_slice = s[i:i+7]
if _slice == "1111111" or _slice == "0000000":
print("YES")
exit()
print("NO")
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s = input()
for i in range(len(s)-7):
_slice = s[i:i+7]
if _slice == "1111111" or _slice == "0000000":
print("YES")
exit()
print("NO")
``` | 0 |
722 | B | Verse Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guarant... | If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | 500 | [
{
"input": "3\n2 2 3\nintel\ncode\nch allenge",
"output": "YES"
},
{
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz",
"output": "NO"
},
{
"input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageo... | 1,500,618,656 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 4,608,000 | vowels = ["a", "e", "i", "o", "u", "y"]
n = int(input())
string = input()
numbers = list(map(int, string.split()))
results = "YES"
for x in range(n):
string = input()
if results == "YES":
words = string.split()
a = 0
for y in words:
for z in vowels:
... | Title: Verse Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary num... | ```python
vowels = ["a", "e", "i", "o", "u", "y"]
n = int(input())
string = input()
numbers = list(map(int, string.split()))
results = "YES"
for x in range(n):
string = input()
if results == "YES":
words = string.split()
a = 0
for y in words:
for z in vowels:
... | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,650,885,741 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,318,400 | n = int(input())
list = [int(i) for i in input().split()]
amount = int(input())
search_list = [int(i) for i in input().split()]
Vasya, Petya = 0,0
for elements in search_list:
pos = list.index(elements)
Vasya += pos + 1
Petya += n - pos
print(Vasya, Petya)
| Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
list = [int(i) for i in input().split()]
amount = int(input())
search_list = [int(i) for i in input().split()]
Vasya, Petya = 0,0
for elements in search_list:
pos = list.index(elements)
Vasya += pos + 1
Petya += n - pos
print(Vasya, Petya)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of... | The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=≤<=*n*<=≤<=1000,<=<=1<=≤<=*m*<=≤<=10<=000,<=<=1<=≤<=*L*<=≤<=109,<=<=0<=≤<=*s*,<=*t*<=≤<=*n*<=-<=1,<=<=*s*<=≠<=*t*) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, ... | Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u*... | [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n"
] | [
"YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"YES\n0 1 123456789\n",
"NO\n"
] | Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456... | 0 | [
{
"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4",
"output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"
},
{
"input": "2 1 123456789 0 1\n0 1 0",
"output": "YES\n0 1 123456789"
},
{
"input": "2 1 999999999 1 0\n0 1 1000000000",
"output": "NO"
},
{
"input": "4 5 10 1 2\... | 1,655,484,932 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 512,000 | # author: violist
# created: 17.06.2022 18:44:43
import sys
import heapq
input = sys.stdin.readline
def dijkstra(g, s, d):
dist = [inf] * len(g)
dist[0] = 0
queue = []
heapq.heappush(queue, (0, s))
while (queue):
w, n = heapq.heappop(queue)
if (n == d):
return dist[d... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that s... | ```python
# author: violist
# created: 17.06.2022 18:44:43
import sys
import heapq
input = sys.stdin.readline
def dijkstra(g, s, d):
dist = [inf] * len(g)
dist[0] = 0
queue = []
heapq.heappush(queue, (0, s))
while (queue):
w, n = heapq.heappop(queue)
if (n == d):
ret... | 0 | |
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,652,939,903 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 4,300,800 | n = input()
n = n.split()
a = int(n[0])*int(n[1])
if a%2 == 0:
print(int(a/2))
else:
print(int((a-1)/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 = input()
n = n.split()
a = int(n[0])*int(n[1])
if a%2 == 0:
print(int(a/2))
else:
print(int((a-1)/2))
``` | 3.968989 |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,645,034,073 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
lst_in = [int(x) for x in input().split()]
count = 0
for i in lst_in:
if i == 0:
count += 1
if count >= 2:
print("NO")
break
if count == 1:
print("YES") | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
n = int(input())
lst_in = [int(x) for x in input().split()]
count = 0
for i in lst_in:
if i == 0:
count += 1
if count >= 2:
print("NO")
break
if count == 1:
print("YES")
``` | 0 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,626,881,684 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 6,758,400 | n = int(input())
a = list(map(int, input().split()))
ans, prev = 0, 0
for x in a:
if x == 0 or x == prev:
prev = 0
ans += 1
elif x == 1 or x == 2:
prev = x
elif x == 3:
prev = 3 - prev
print(ans)
| Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
a = list(map(int, input().split()))
ans, prev = 0, 0
for x in a:
if x == 0 or x == prev:
prev = 0
ans += 1
elif x == 1 or x == 2:
prev = x
elif x == 3:
prev = 3 - prev
print(ans)
``` | 0 | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,481,992,742 | 242 | PyPy 3 | OK | TESTS | 28 | 108 | 23,142,400 | s = input()
n = len(s)
s += s
dl = len(s)
d = set()
ans = 0
for i in range(dl - n):
str = s[i : i + n ]
if not str in d:
ans += 1
d.add(str)
print(ans)
| Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
s = input()
n = len(s)
s += s
dl = len(s)
d = set()
ans = 0
for i in range(dl - n):
str = s[i : i + n ]
if not str in d:
ans += 1
d.add(str)
print(ans)
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,654,230,215 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | k=int(input())
s=input()
res={}
for i in s:
if i in res:
res[i]+=1
else:
res[i]=1
flag=0
for key,value in res.items():
if value==k:
continue
else:
flag=1
break
arr=[]
for key,value in res.items():
arr.append(key)
string=""
n=int(len(s)/k)
f... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k=int(input())
s=input()
res={}
for i in s:
if i in res:
res[i]+=1
else:
res[i]=1
flag=0
for key,value in res.items():
if value==k:
continue
else:
flag=1
break
arr=[]
for key,value in res.items():
arr.append(key)
string=""
n=int(le... | 0 | |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,671,623,868 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 62 | 409,600 | from re import sub;input();print(len(sub('[0]{2,}' , '' , "".join(input().strip('0').split())).strip('0')))
| Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
from re import sub;input();print(len(sub('[0]{2,}' , '' , "".join(input().strip('0').split())).strip('0')))
``` | 3 | |
106 | A | Card Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Card Game | 2 | 256 | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ... | The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the... | Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes). | [
"H\nQH 9S\n",
"S\n8D 6D\n",
"C\n7H AS\n"
] | [
"YES\n",
"YES",
"NO"
] | none | 500 | [
{
"input": "H\nQH 9S",
"output": "YES"
},
{
"input": "S\n8D 6D",
"output": "YES"
},
{
"input": "C\n7H AS",
"output": "NO"
},
{
"input": "C\nKC 9C",
"output": "YES"
},
{
"input": "D\n7D KD",
"output": "NO"
},
{
"input": "H\n7H KD",
"output": "YES"
... | 1,634,999,876 | 2,147,483,647 | Python 3 | OK | TESTS | 78 | 92 | 4,505,600 |
def solve(k,f,s):
p="6789TJQKA"
if s[1]==k:
if f[1]==k:
if p.index(f[0])>p.index(s[0]):
return True
return False
return False
else:
if f[1]==k:
return True
if f[1]!=s[1]:
return False
if p.... | Title: Card Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselve... | ```python
def solve(k,f,s):
p="6789TJQKA"
if s[1]==k:
if f[1]==k:
if p.index(f[0])>p.index(s[0]):
return True
return False
return False
else:
if f[1]==k:
return True
if f[1]!=s[1]:
return False
... | 3.968608 |
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,619,860,116 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 561 | 37,785,600 | from collections import Counter
_ = input()
first = Counter(input().split())
second = Counter(input().split())
third = Counter(input().split())
print(next((first-second).elements()))
print(next((second-third).elements()))
| 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
from collections import Counter
_ = input()
first = Counter(input().split())
second = Counter(input().split())
third = Counter(input().split())
print(next((first-second).elements()))
print(next((second-third).elements()))
``` | 3 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,935,535 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | #2300011786
n=int(input())
lst=input().split()
lstd=[]
s=0
bro=0
for i in range(len(lst)):
s+=int(lst[i])
while len(lst)>0:
a=max(lst)
lstd.append(a)
lst.remove(a)
for j in range(len(lstd)):
bro+=int(lstd[j])
if bro*2>s:
print(j+1)
break | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
#2300011786
n=int(input())
lst=input().split()
lstd=[]
s=0
bro=0
for i in range(len(lst)):
s+=int(lst[i])
while len(lst)>0:
a=max(lst)
lstd.append(a)
lst.remove(a)
for j in range(len(lstd)):
bro+=int(lstd[j])
if bro*2>s:
print(j+1)
break
``` | 0 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,651,721,046 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | n, m = map(int, input().split(' '))
a = n // m
b = n % m
c = n - m + 1
print((m - b) * (a * (a - 1) // 2) + b * (a * (a + 1)) // 2, end=' ')
print(c * (c - 1) // 2)
| Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
n, m = map(int, input().split(' '))
a = n // m
b = n % m
c = n - m + 1
print((m - b) * (a * (a - 1) // 2) + b * (a * (a + 1)) // 2, end=' ')
print(c * (c - 1) // 2)
``` | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,696,846,829 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | n = int(input()) # Number of contests
points = list(map(int, input().split())) # List of earned points
amazing_count = 0 # Initialize the count of amazing performances
best = worst = points[0] # Initialize the best and worst performances with the first contest's points
for i in range(1, n):
if points[i... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input()) # Number of contests
points = list(map(int, input().split())) # List of earned points
amazing_count = 0 # Initialize the count of amazing performances
best = worst = points[0] # Initialize the best and worst performances with the first contest's points
for i in range(1, n):
i... | 3 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,631,819,878 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 22,220,800 | n = int(input())
distances = [int(x) for x in input().split(" ")]
def merge_sort(arr):
length = len(arr)
if length <= 1:
return arr
middle = length // 2
left = merge_sort(arr[0:middle])
right = merge_sort(arr[middle:length])
a = b = 0
res = []
while a < len... | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
n = int(input())
distances = [int(x) for x in input().split(" ")]
def merge_sort(arr):
length = len(arr)
if length <= 1:
return arr
middle = length // 2
left = merge_sort(arr[0:middle])
right = merge_sort(arr[middle:length])
a = b = 0
res = []
whi... | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,694,194,429 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | d=int(input())
s=list(map(int,input().split()))
a=b=0
for i in range(d):
e=max(s[0],s[d-i-1])
if i%2==0:
a+=e
else:b+=e
s.remove(max(s[0],s[d-i-1]))
print(a,b) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
d=int(input())
s=list(map(int,input().split()))
a=b=0
for i in range(d):
e=max(s[0],s[d-i-1])
if i%2==0:
a+=e
else:b+=e
s.remove(max(s[0],s[d-i-1]))
print(a,b)
``` | 3 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,679,881,418 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 124 | 8,089,600 | n = int(input())
nums = list(map(int, input().split()))
even_sum = sum(filter(lambda x: x % 2 == 0, nums))
odd_nums = sorted(filter(lambda x: x % 2 != 0, nums), reverse=True)
if len(odd_nums) % 2 == 0:
even_sum += sum(odd_nums)
else:
even_sum += sum(odd_nums[:-1])
print(even_sum)
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
nums = list(map(int, input().split()))
even_sum = sum(filter(lambda x: x % 2 == 0, nums))
odd_nums = sorted(filter(lambda x: x % 2 != 0, nums), reverse=True)
if len(odd_nums) % 2 == 0:
even_sum += sum(odd_nums)
else:
even_sum += sum(odd_nums[:-1])
print(even_sum)
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,696,437,605 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | # Read Yakko's and Wakko's rolls
Y, W = map(int, input().split())
# Calculate the total favorable outcomes
total_favorable_outcomes = (6 - max(Y, W)) + 2
# Calculate the total possible outcomes
total_possible_outcomes = 36
# Calculate the greatest common divisor (gcd) to simplify the fraction
from math imp... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
# Read Yakko's and Wakko's rolls
Y, W = map(int, input().split())
# Calculate the total favorable outcomes
total_favorable_outcomes = (6 - max(Y, W)) + 2
# Calculate the total possible outcomes
total_possible_outcomes = 36
# Calculate the greatest common divisor (gcd) to simplify the fraction
fro... | 0 |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | 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*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,640,093,970 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | n = int(input())
a = list (map(int,input().split()))
if n == 1:
print('YES')
elif a[0]<=a[1] and a[-1]<=a[-2]:
print('YES')
else:
print('NO') | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
n = int(input())
a = list (map(int,input().split()))
if n == 1:
print('YES')
elif a[0]<=a[1] and a[-1]<=a[-2]:
print('YES')
else:
print('NO')
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 0 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,514,041,786 | 3,886 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 61 | 5,939,200 | def alf(s):
a = set()
for i in s:
if i not in a:
a.add(i)
return a
n = int(input())
ind = 0
k = 0
hto = set()
for i in range(n):
s = input()
if s[0] == '?':
if i == n - 1:
ind = 1
else:
if ind == 1:
k += 1
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter... | ```python
def alf(s):
a = set()
for i in s:
if i not in a:
a.add(i)
return a
n = int(input())
ind = 0
k = 0
hto = set()
for i in range(n):
s = input()
if s[0] == '?':
if i == n - 1:
ind = 1
else:
if ind == 1:
... | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,658,350,783 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 1,808 | 0 | def sum(n):
s,f=str(n),0
for i in s:f+=int(i)
return f
n=int(input())
if n//10==0:print(0)
else:
s,f=n,0
while(1):
s=sum(s)
f+=1
if s//10==0:break
print(f) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def sum(n):
s,f=str(n),0
for i in s:f+=int(i)
return f
n=int(input())
if n//10==0:print(0)
else:
s,f=n,0
while(1):
s=sum(s)
f+=1
if s//10==0:break
print(f)
``` | 3.548 |
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,695,323,805 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 42,700,800 | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n=int(input())
a=list(map(int,input().split()))
import copy
h=copy.deepcopy(a)
a.sort()
flaf=True
i=0
v=1
while i < len(a)-1:
if a[i]== a[i+1]:
v+=1
elif a[i] != a[i+1]:
if v % 2 == 1 :
... | 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
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n=int(input())
a=list(map(int,input().split()))
import copy
h=copy.deepcopy(a)
a.sort()
flaf=True
i=0
v=1
while i < len(a)-1:
if a[i]== a[i+1]:
v+=1
elif a[i] != a[i+1]:
if v % 2 == 1 ... | 0 | |
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,593,240,991 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 218 | 6,963,200 | def solve():
n,m=list(map(int,input().split()))
l=list()
for i in range(n):
l.append(input())
flag,row,col=1,0,0
for i in range(n):
for j in range(m):
if(l[i][j]=="S"):
flag=0
if(flag):
row+=1
flag=1
flag=1
... | 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
def solve():
n,m=list(map(int,input().split()))
l=list()
for i in range(n):
l.append(input())
flag,row,col=1,0,0
for i in range(n):
for j in range(m):
if(l[i][j]=="S"):
flag=0
if(flag):
row+=1
flag=1
f... | 3 | |
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,611,647,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | word=input("")
count1=0
count2=0
for i in word:
if(i.islower()):
count1=count1+1
elif(i.isupper()):
count2=count2+1
if count1 == count2:
print(word.lower())
elif count1 <= 1:
print(word.upper())
elif count1 > 1:
print(word.lower())
elif word.isupper():
pri... | 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
word=input("")
count1=0
count2=0
for i in word:
if(i.islower()):
count1=count1+1
elif(i.isupper()):
count2=count2+1
if count1 == count2:
print(word.lower())
elif count1 <= 1:
print(word.upper())
elif count1 > 1:
print(word.lower())
elif word.isuppe... | 0 |
398 | B | Painting The Wall | PROGRAMMING | 0 | [
"dp",
"probabilities"
] | null | null | User ainta decided to paint a wall. The wall consists of *n*2 tiles, that are arranged in an *n*<=×<=*n* table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
1. Firstly user ainta looks at the wall. If there is at least one painted cell on each ro... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=2·103; 0<=≤<=*m*<=≤<=*min*(*n*2,<=2·104)) — the size of the wall and the number of painted cells.
Next *m* lines goes, each contains two integers *r**i* and *c**i* (1<=≤<=*r**i*,<=*c**i*<=≤<=*n*) — the position of the painted cell. It is guaranteed that t... | In a single line print the expected time to paint the wall in minutes. Your answer will be considered correct if it has at most 10<=-<=4 absolute or relative error. | [
"5 2\n2 3\n4 1\n",
"2 2\n1 1\n1 2\n",
"1 1\n1 1\n"
] | [
"11.7669491886\n",
"2.0000000000\n",
"0.0000000000\n"
] | none | 1,000 | [] | 1,542,286,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 623 | 512,000 | import time
from random import randint
n, m = map(int, input().split(' '))
cols = [0 for i in range(n)]
rows = [0 for i in range(n)]
for i in range(m):
x, y = map(int, input().split(' '))
cols[x - 1] = 1
rows[y - 1] = 1
rounds = 0
sums = 0
answer = 0
t0 = time.time()
while time.time() - t0 < 0.5:
colsc... | Title: Painting The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta decided to paint a wall. The wall consists of *n*2 tiles, that are arranged in an *n*<=×<=*n* table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the r... | ```python
import time
from random import randint
n, m = map(int, input().split(' '))
cols = [0 for i in range(n)]
rows = [0 for i in range(n)]
for i in range(m):
x, y = map(int, input().split(' '))
cols[x - 1] = 1
rows[y - 1] = 1
rounds = 0
sums = 0
answer = 0
t0 = time.time()
while time.time() - t0 < 0.5:... | 0 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,167,437 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | s = int(input())
s+=1
while(True):
t = [x for x in str(s)]
f = set(t)
if len(t) != len(f):
s+=1
else:
break
print(s)
| Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
s = int(input())
s+=1
while(True):
t = [x for x in str(s)]
f = set(t)
if len(t) != len(f):
s+=1
else:
break
print(s)
``` | 3 | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,699,272,742 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | RoomNo = int(input())
count = 0
for i in range(RoomNo):
a, b = map(int, input().split())
if b - a >= 2:
count += 1
print(count) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
RoomNo = int(input())
count = 0
for i in range(RoomNo):
a, b = map(int, input().split())
if b - a >= 2:
count += 1
print(count)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,588,699,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | x,y,z=map(int, input().split())
r=int(x/3)
g=int(y/3)
b=int(z/3)
total=int(r+g+b)
f=0
r=x%3
g=y%3
b=z%3
if r==1 or g==1 or b==1:
f=f+1
elif r==2 and g==2 and b==2:
f=f+2
else:
f=f
print(total+f)
| Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
x,y,z=map(int, input().split())
r=int(x/3)
g=int(y/3)
b=int(z/3)
total=int(r+g+b)
f=0
r=x%3
g=y%3
b=z%3
if r==1 or g==1 or b==1:
f=f+1
elif r==2 and g==2 and b==2:
f=f+2
else:
f=f
print(total+f)
``` | 0 | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,607,416,308 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 186 | 0 | s=input().split()
print(int(s[0])*(int(s[0])-1)*6+1) | Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
s=input().split()
print(int(s[0])*(int(s[0])-1)*6+1)
``` | 3 | ||
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,613,025,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 204,800 | mcqs = {}
coding = {0:"A",1:"B",2:"C",3:"D"}
for i in range(4):
opt = input()
mcqs[i] = len(opt)-2
# print(mcqs)
sorted_mcqs = sorted(mcqs,key=mcqs.get)
# print(sorted_mcqs)
minn,maxx = mcqs[sorted_mcqs[0]] , mcqs[sorted_mcqs[-1]]
if(maxx / minn <2):
print("C here ", maxx,minn)
else:
ismin... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
mcqs = {}
coding = {0:"A",1:"B",2:"C",3:"D"}
for i in range(4):
opt = input()
mcqs[i] = len(opt)-2
# print(mcqs)
sorted_mcqs = sorted(mcqs,key=mcqs.get)
# print(sorted_mcqs)
minn,maxx = mcqs[sorted_mcqs[0]] , mcqs[sorted_mcqs[-1]]
if(maxx / minn <2):
print("C here ", maxx,minn)
else:
... | 0 | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th... | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,687,504,655 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 92 | 0 | k=int(input())
s=input()
strlen=len(s);l_=[]
for i in range(strlen):
if s[i]=="1":l_.append(i)
ans=0;lenny=len(l_)
for i in range(lenny-k+1):
l=0;r=0
if i!=0:l=l_[i]-l_[i-1]-1
else:l=l_[i]
if i!=lenny-k:r=l_[i+k]-l_[i+k-1]-1
else:r=strlen-l_[i+k-1]-1
ans+=l+r+l*r+1
print(ans... | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, ... | ```python
k=int(input())
s=input()
strlen=len(s);l_=[]
for i in range(strlen):
if s[i]=="1":l_.append(i)
ans=0;lenny=len(l_)
for i in range(lenny-k+1):
l=0;r=0
if i!=0:l=l_[i]-l_[i-1]-1
else:l=l_[i]
if i!=lenny-k:r=l_[i+k]-l_[i+k-1]-1
else:r=strlen-l_[i+k-1]-1
ans+=l+r+l*r+1
... | -1 | |
774 | D | Lie or Truth | PROGRAMMING | 1,500 | [
"*special",
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cub... | The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order.
... | Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). | [
"5 2 4\n3 4 2 3 1\n3 2 3 4 1\n",
"3 1 2\n1 2 3\n3 1 2\n",
"4 2 4\n1 1 1 1\n1 1 1 1\n"
] | [
"TRUTH\n",
"LIE\n",
"TRUTH\n"
] | In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and... | 0 | [
{
"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1",
"output": "TRUTH"
},
{
"input": "3 1 2\n1 2 3\n3 1 2",
"output": "LIE"
},
{
"input": "4 2 4\n1 1 1 1\n1 1 1 1",
"output": "TRUTH"
},
{
"input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2",
"output": "TRUTH"
},
{
"input": "7 1 4\n2 5 5 5... | 1,518,925,397 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 280 | 16,998,400 | n, a, b = map(int, input().split())
ar1 = list(map(int, input().split()))
ar2 = list(map(int, input().split()))
truth = True
for i in range(n):
if i not in range(a - 1, b):
if ar1[i] != ar2[i]:
truth = False
break
if truth:
nums = dict()
for i in range(a - 1, ... | Title: Lie or Truth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,... | ```python
n, a, b = map(int, input().split())
ar1 = list(map(int, input().split()))
ar2 = list(map(int, input().split()))
truth = True
for i in range(n):
if i not in range(a - 1, b):
if ar1[i] != ar2[i]:
truth = False
break
if truth:
nums = dict()
for i in ran... | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,677,082,578 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 500 | 0 | n, k = map(int, input().split())
sum = 1
while True:
check = k*sum
if check>n:
print(check)
break
else:
sum+=1
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
n, k = map(int, input().split())
sum = 1
while True:
check = k*sum
if check>n:
print(check)
break
else:
sum+=1
``` | 0 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,601,580,216 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | def findCircle(x1, y1, x2, y2, x3, y3) :
try:
x12 = x1 - x2
x13 = x1 - x3
y12 = y1 - y2
y13 = y1 - y3
y31 = y3 - y1
y21 = y2 - y1
x31 = x3 - x1
x21 = x2 - x1
sx13 = x1**2 - x3**2
... | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
def findCircle(x1, y1, x2, y2, x3, y3) :
try:
x12 = x1 - x2
x13 = x1 - x3
y12 = y1 - y2
y13 = y1 - y3
y31 = y3 - y1
y21 = y2 - y1
x31 = x3 - x1
x21 = x2 - x1
sx13 = x1**2 - x3**2
... | 0 | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,415,210,796 | 5,796 | Python 3 | OK | TESTS | 45 | 77 | 0 | n = int(input())
mx=10000000000
my=10000000000
vx=-10000000000
vy=-10000000000
for i in range(n):
a, b = map(int, input().split())
mx = min(mx,a)
vx = max(vx,a)
my = min(my,b)
vy = max(vy,b)
print(max(vx-mx,vy-my)*max(vx-mx,vy-my)) | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
n = int(input())
mx=10000000000
my=10000000000
vx=-10000000000
vy=-10000000000
for i in range(n):
a, b = map(int, input().split())
mx = min(mx,a)
vx = max(vx,a)
my = min(my,b)
vy = max(vy,b)
print(max(vx-mx,vy-my)*max(vx-mx,vy-my))
``` | 3 | |
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,612,116,556 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 93 | 0 | n1=list(map(int,input()))
n2=list(map(int,input()))
for k in range(len(n1)):
n1[k]=n1[k]^n2[k]
for k in n1:
print(k,end="") | 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
n1=list(map(int,input()))
n2=list(map(int,input()))
for k in range(len(n1)):
n1[k]=n1[k]^n2[k]
for k in n1:
print(k,end="")
``` | 3.97675 |
333 | A | Secrets | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of o... | The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017).
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. | In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buye... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "3"
},
{
"input": "10",
"output": "4"
},
{
"input": "100000000000000000",
"output": "33333333333333334"
},
{
"input... | 1,670,734,069 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 154 | 0 | import sys
input = sys.stdin.readline
n = int(input())
for i in range(50000):
if n % (3**i) == 0:
continue
else:
print(n//(3**i)+1)
break | Title: Secrets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations th... | ```python
import sys
input = sys.stdin.readline
n = int(input())
for i in range(50000):
if n % (3**i) == 0:
continue
else:
print(n//(3**i)+1)
break
``` | 3 | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,688,721,892 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | import sys
#sys.setrecursionlimit(10**7)
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,inp... | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
import sys
#sys.setrecursionlimit(10**7)
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(m... | 3 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,698,829,908 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 7,884,800 | n = input()
d = ''
a = max(n)
f = int(n)
t = 0
if f >= 0:
print(f)
else:
while t != 1:
for i in n:
if i != a:
d += i
else:
t += 1
if d == '-0':
print(0)
else:
print(d) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n = input()
d = ''
a = max(n)
f = int(n)
t = 0
if f >= 0:
print(f)
else:
while t != 1:
for i in n:
if i != a:
d += i
else:
t += 1
if d == '-0':
print(0)
else:
print(d)
``` | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,587,107,177 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 312 | 0 | s = max(list(map(int, input().split())))
p = (7-s)/6
if p == 0:
print("0/1")
elif p == 1/6:
print("1/6")
elif p == 2/6:
print("1/3")
elif p == 3/6:
print("1/2")
elif p == 4/6:
print("2/3")
elif p == 5/6:
print("5/6")
else:
print("1/1") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
s = max(list(map(int, input().split())))
p = (7-s)/6
if p == 0:
print("0/1")
elif p == 1/6:
print("1/6")
elif p == 2/6:
print("1/3")
elif p == 3/6:
print("1/2")
elif p == 4/6:
print("2/3")
elif p == 5/6:
print("5/6")
else:
print("1/1")
``` | 3.844 |
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**... | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
... | 1,620,532,978 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 217 | 31,027,200 | import sys
from copy import deepcopy
input = sys.stdin.readline
v, e, g = map(int, input().split())
f = [set() for index in range(v)]
z = list(map(int, input().split()))
for index in range(e):
x,y = map(int, input().split())
f[x-1].add(y)
f[y-1].add(x)
arrayLen = []
for index in z:
mapX = {index... | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* e... | ```python
import sys
from copy import deepcopy
input = sys.stdin.readline
v, e, g = map(int, input().split())
f = [set() for index in range(v)]
z = list(map(int, input().split()))
for index in range(e):
x,y = map(int, input().split())
f[x-1].add(y)
f[y-1].add(x)
arrayLen = []
for index in z:
map... | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,539,176,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | t=int(input())
a=list(map(int,input().strip().split(" ")))[:t]
c=0
if t==1:
print(1)
else:
for i in range(len(a)):
c+=a[i]
avg=c//2
c1=0
if c%2!=0:
for j in range(len(a)):
c1+=a[i]
if c1==avg:
print(j)
break
... | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
t=int(input())
a=list(map(int,input().strip().split(" ")))[:t]
c=0
if t==1:
print(1)
else:
for i in range(len(a)):
c+=a[i]
avg=c//2
c1=0
if c%2!=0:
for j in range(len(a)):
c1+=a[i]
if c1==avg:
print(j)
... | 0 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,547,224,665 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 140 | 3,891,200 | n = int(input())
l = [0 for i in range(0,26)]
s=input()
nb=0
d=0
for e in 'abcdefghijklmnopqrstuvwxyz':
t=s.count(e)
if t > 1:
nb+=t-1
if t > 0:
d+=1
s=s.replace(e,'')
if (26-d) < nb:
print(-1)
else:
print(nb) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
l = [0 for i in range(0,26)]
s=input()
nb=0
d=0
for e in 'abcdefghijklmnopqrstuvwxyz':
t=s.count(e)
if t > 1:
nb+=t-1
if t > 0:
d+=1
s=s.replace(e,'')
if (26-d) < nb:
print(-1)
else:
print(nb)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,488,860,679 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 187 | 16,691,200 | # coding:utf-8
# __author__ = '凯'
n = int(input())
b = set()
m = 0
count = 0
for i in input().split():
if i not in b:
b.add(i)
count += 1
if count > m:
m = count
else:
b.remove(i)
count -= 1
print(m)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
# coding:utf-8
# __author__ = '凯'
n = int(input())
b = set()
m = 0
count = 0
for i in input().split():
if i not in b:
b.add(i)
count += 1
if count > m:
m = count
else:
b.remove(i)
count -= 1
print(m)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | BigData Inc. is a corporation that has *n* data centers indexed from 1 to *n* that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feature of services offered by BigData Inc. is the access availability guarantee even under th... | The first line of input contains three integers *n*, *m* and *h* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000, 2<=≤<=*h*<=≤<=100<=000), the number of company data centers, number of clients and the day length of day measured in hours.
The second line of input contains *n* integers *u*1,<=*u*2,<=...,<=*u**n* (0<=≤<... | In the first line print the minimum possible number of data centers *k* (1<=≤<=*k*<=≤<=*n*) that have to be included in an experiment in order to keep the data available for any client.
In the second line print *k* distinct integers *x*1,<=*x*2,<=...,<=*x**k* (1<=≤<=*x**i*<=≤<=*n*), the indices of data centers whose m... | [
"3 3 5\n4 4 0\n1 3\n3 2\n3 1\n",
"4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n"
] | [
"1\n3 ",
"4\n1 2 3 4 "
] | Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour.
On the other hand... | 0 | [
{
"input": "3 3 5\n4 4 0\n1 3\n3 2\n3 1",
"output": "1\n3 "
},
{
"input": "4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3",
"output": "4\n1 2 3 4 "
},
{
"input": "5 5 4\n0 1 2 3 3\n1 2\n2 3\n3 4\n4 1\n3 5",
"output": "1\n5 "
},
{
"input": "2 1 2\n1 0\n1 2",
"output": "2\n1 2 "
... | 1,603,279,437 | 8,637 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 512,000 | # Codeforces Submission
# User : sudoSieg
# Time : 16:40:10
# Date : 21/10/2020
import io
import os
import collections
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m, h = map(int, input().split())
u = [*map(int, input().split())]
client_data = [[int(i) for i in input().split()] for i in ran... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
BigData Inc. is a corporation that has *n* data centers indexed from 1 to *n* that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feat... | ```python
# Codeforces Submission
# User : sudoSieg
# Time : 16:40:10
# Date : 21/10/2020
import io
import os
import collections
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m, h = map(int, input().split())
u = [*map(int, input().split())]
client_data = [[int(i) for i in input().split()] fo... | 0 | |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. | Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,637,843,814 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | n=int(input())
A=[]
B=list(map(int,input().split()))
for i in range(n):
A.append([B[i],i])
A.sort(key = lambda x: x[0])
for i in range(n):
A[i][0] = i+1
for i in range(n):
B[A[i][1]]=A[i][0]
print(*B) | Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
n=int(input())
A=[]
B=list(map(int,input().split()))
for i in range(n):
A.append([B[i],i])
A.sort(key = lambda x: x[0])
for i in range(n):
A[i][0] = i+1
for i in range(n):
B[A[i][1]]=A[i][0]
print(*B)
``` | 0 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,664,985,988 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 140 | 10,649,600 | n, m = map( int, input().split() )
joy_types = set( map( int, input().split() ) )
ans = []
for i in range(1, 10**9 + 1):
if i not in joy_types:
if m >= i:
m -= i
ans.append(i)
else:
break
print(len(ans))
print(*ans) | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
n, m = map( int, input().split() )
joy_types = set( map( int, input().split() ) )
ans = []
for i in range(1, 10**9 + 1):
if i not in joy_types:
if m >= i:
m -= i
ans.append(i)
else:
break
print(len(ans))
print(*ans)
``` | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,561,781,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | import math
n, x, y = map(int, input().split())
clones = math.ceil(y/100 * n)
print(int(abs(clones-x)))
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
import math
n, x, y = map(int, input().split())
clones = math.ceil(y/100 * n)
print(int(abs(clones-x)))
``` | 0 | |
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,691,766,508 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | a = int(input())+1
b = sum(map(int, input().split()))
print(sum((b+i) % a != 1 for i in range(1, 6)))
# 1 is that person..
| 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
a = int(input())+1
b = sum(map(int, input().split()))
print(sum((b+i) % a != 1 for i in range(1, 6)))
# 1 is that person..
``` | 3 | |
631 | B | Print Check | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr... | The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next *k* lines contains the description of exactly one query:
- 1 *r**i* *a**i* ... | Print *n* lines containing *m* integers each — the resulting table after all operations are applied. | [
"3 3 3\n1 1 3\n2 2 1\n1 2 2\n",
"5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n"
] | [
"3 1 3 \n2 2 2 \n0 1 0 \n",
"1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n"
] | The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray. | 1,000 | [
{
"input": "3 3 3\n1 1 3\n2 2 1\n1 2 2",
"output": "3 1 3 \n2 2 2 \n0 1 0 "
},
{
"input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1",
"output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 "
},
{
"input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1",
"output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1... | 1,589,960,038 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 1,000 | 12,595,200 | n,m,k = map(int, input().split())
l = [0]*m*n
for i in range(k):
t, num, color = map(int, input().split())
num = num - 1
rs = num*m
if t == 1:
l[rs:rs+m]=[color]*m
else:
l[num::m]=[color]*n
print(*l, sep=" ") | Title: Print Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built a... | ```python
n,m,k = map(int, input().split())
l = [0]*m*n
for i in range(k):
t, num, color = map(int, input().split())
num = num - 1
rs = num*m
if t == 1:
l[rs:rs+m]=[color]*m
else:
l[num::m]=[color]*n
print(*l, sep=" ")
``` | 0 | |
596 | B | Wilbur and Array | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 ... | 1,447,607,952 | 2,652 | Python 3 | WRONG_ANSWER | PRETESTS | 10 | 171 | 7,782,400 | n=int(input())
A=list(map(int,input().split()))
x=A[0]
for i in range(1,n):
x+=abs(A[i]-A[i-1])
print(x) | Title: Wilbur and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+... | ```python
n=int(input())
A=list(map(int,input().split()))
x=A[0]
for i in range(1,n):
x+=abs(A[i]-A[i-1])
print(x)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 0 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,547,055,516 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | v,a,b=list(map(int,input().split()))
c=2
m=1
for i in range(8):
if abs(a-b)<c:
print(m)
break
else:
c*=2
m+=1
if m==8:
print("Final!") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the ord... | ```python
v,a,b=list(map(int,input().split()))
c=2
m=1
for i in range(8):
if abs(a-b)<c:
print(m)
break
else:
c*=2
m+=1
if m==8:
print("Final!")
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know l... | The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. | On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes.
Print suffixes in lexicographical (alphabetical) order. | [
"abacabaca\n",
"abaca\n"
] | [
"3\naca\nba\nca\n",
"0\n"
] | The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix. | 0 | [
{
"input": "abacabaca",
"output": "3\naca\nba\nca"
},
{
"input": "abaca",
"output": "0"
},
{
"input": "gzqgchv",
"output": "1\nhv"
},
{
"input": "iosdwvzerqfi",
"output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer"
},
{
"input": "oawtxikrpvfuzugjweki",
"output... | 1,461,954,566 | 6,866 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 62 | 4,608,000 |
def C():
s = input()
s = s[5::]
w = set()
l = len(s)
w = syf(s)
d = syf(s[1::])
w = w | d
wl = list(w)
print(len(w))
wl.sort()
for i in wl:
print(i)
def syf(li = ""):
ret = []
tr = set()
dw = set()
res = set()
l = len(li)
if(len(li) - 3 != 1 ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in differ... | ```python
def C():
s = input()
s = s[5::]
w = set()
l = len(s)
w = syf(s)
d = syf(s[1::])
w = w | d
wl = list(w)
print(len(w))
wl.sort()
for i in wl:
print(i)
def syf(li = ""):
ret = []
tr = set()
dw = set()
res = set()
l = len(li)
if(len(li)... | 0 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,623,915,649 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 154 | 0 | n = int(input())
a = list(map(int,input().split()))
count = 0
if sum(a)%2==1:
for i in range(n):
if a[i]%2==1:
count = count+1
print(count)
else:
for i in range(n):
if a[i]%2==0:
count = count+1
print(count)
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
a = list(map(int,input().split()))
count = 0
if sum(a)%2==1:
for i in range(n):
if a[i]%2==1:
count = count+1
print(count)
else:
for i in range(n):
if a[i]%2==0:
count = count+1
print(count)
``` | 3 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,428,877,757 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 109 | 819,200 | n = int(input())
res = ([],[i for i in range(2,n+1,2)]) [n > 3] + [i for i in range(1,n+1,2)]
print(len(res))
print(' '.join(map(str,res))) | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
n = int(input())
res = ([],[i for i in range(2,n+1,2)]) [n > 3] + [i for i in range(1,n+1,2)]
print(len(res))
print(' '.join(map(str,res)))
``` | 3 | |
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,651,056,433 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n,x=map(int,input().split())
k=0
for i in range(n):
a,t= input().split()
t=int(t)
if a=="+":
x+=t
else:
if t>x:
k+=1
else:
x-=t
print(x," ",k,sep="")
| 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
n,x=map(int,input().split())
k=0
for i in range(n):
a,t= input().split()
t=int(t)
if a=="+":
x+=t
else:
if t>x:
k+=1
else:
x-=t
print(x," ",k,sep="")
``` | 3 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,625,614,827 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 77 | 0 | s, f,g = map(int,input().split())
if s < 0:
f += abs(s)
s = 0
if f < 0 and g > 0 or f > 0 and g< 0:
print('NO')
exit()
if s == f:
print('YES')
exit()
if g == 0:
print('NO')
exit()
print('YES' if (f-s)%g == 0 else 'NO') | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
s, f,g = map(int,input().split())
if s < 0:
f += abs(s)
s = 0
if f < 0 and g > 0 or f > 0 and g< 0:
print('NO')
exit()
if s == f:
print('YES')
exit()
if g == 0:
print('NO')
exit()
print('YES' if (f-s)%g == 0 else 'NO')
``` | 0 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,616,901,043 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | s, t = list(input()), input()
c = 1
for i in range(len(s) - 1, -1, -1):
x = ord(s[i]) + c
s[i], c = (chr(x), 0) if x <= ord('z') else ('z', 1)
s = ''.join(s)
print('No such string' if s == t else s)
| Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s, t = list(input()), input()
c = 1
for i in range(len(s) - 1, -1, -1):
x = ord(s[i]) + c
s[i], c = (chr(x), 0) if x <= ord('z') else ('z', 1)
s = ''.join(s)
print('No such string' if s == t else s)
``` | 0 | |
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,502,537,140 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 6,144,000 | #"from dust i have come, dust i will be"
n,m=map(int,input().split())
s=[str(input()) for i in range(n)]
count=0
for i in range(n):
for j in range(m):
if s[i][j]=='*':
count+=1
for i in range(n):
for j in range(m):
sum=0
#from (i,j) to the right
fo... | 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
#"from dust i have come, dust i will be"
n,m=map(int,input().split())
s=[str(input()) for i in range(n)]
count=0
for i in range(n):
for j in range(m):
if s[i][j]=='*':
count+=1
for i in range(n):
for j in range(m):
sum=0
#from (i,j) to the right
... | 0 | |
417 | D | Cunning Gena | PROGRAMMING | 1,900 | [
"bitmasks",
"dp",
"greedy",
"sortings"
] | null | null | A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his *n* friends that they will solve the problems for him.
The participants are offered *m* problems on the contest. For each friend, Gena knows wha... | The first line contains three integers *n*, *m* and *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=20; 1<=≤<=*b*<=≤<=109) — the number of Gena's friends, the number of problems and the cost of a single monitor.
The following 2*n* lines describe the friends. Lines number 2*i* and (2*i*<=+<=1) contain the information about the *... | Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved. | [
"2 2 1\n100 1 1\n2\n100 2 1\n1\n",
"3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2\n",
"1 2 1\n1 1 1\n1\n"
] | [
"202\n",
"205\n",
"-1\n"
] | none | 2,000 | [
{
"input": "2 2 1\n100 1 1\n2\n100 2 1\n1",
"output": "202"
},
{
"input": "3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2",
"output": "205"
},
{
"input": "1 2 1\n1 1 1\n1",
"output": "-1"
},
{
"input": "4 2 1\n62 91 1\n1\n2 18 1\n1\n33 76 1\n1\n23 58 1\n1",
"output": "-1"
... | 1,622,899,655 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 1,000 | 9,216,000 | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in fil... | Title: Cunning Gena
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his *n* friends that they will solve the problems f... | ```python
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = ... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,658,357 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | num=input().split()
k=int(num[0])
n=int(num[1])
w=int(num[2])
money=int(k*w*(w+1)/2)
if money>n:
x=money-n
else:
x=0
print(x) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
num=input().split()
k=int(num[0])
n=int(num[1])
w=int(num[2])
money=int(k*w*(w+1)/2)
if money>n:
x=money-n
else:
x=0
print(x)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.