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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,005 | E1 | Median on Segments (Permutations Edition) | PROGRAMMING | 1,800 | [
"sortings"
] | null | null | You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t... | The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) — the length of the given sequence and the required value of the median.
The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. | Print the required number. | [
"5 4\n2 4 5 3 1\n",
"5 5\n1 2 3 4 5\n",
"15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n"
] | [
"4\n",
"1\n",
"48\n"
] | In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$. | 0 | [
{
"input": "5 4\n2 4 5 3 1",
"output": "4"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9",
"output": "48"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input... | 1,633,192,662 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 311 | 31,641,600 | from itertools import accumulate
from collections import Counter
s = input()
s = s.split(' ')
m = int(s[1])
t = input()
t = t.split(' ')
t = [int(x) for x in t]
location = t.index(m)
right = []
for i in range(location+1, len(t)):
if t[i] > m:
right.append(1)
else:
right.append(-1)
right_cum... | Title: Median on Segments (Permutations Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence.
Find the number of... | ```python
from itertools import accumulate
from collections import Counter
s = input()
s = s.split(' ')
m = int(s[1])
t = input()
t = t.split(' ')
t = [int(x) for x in t]
location = t.index(m)
right = []
for i in range(location+1, len(t)):
if t[i] > m:
right.append(1)
else:
right.append(-1)... | 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,674,410,539 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 |
_ = input()
k = tuple(map(int, input().split()))
kmax, kmin = k[0], k[0]
amazings = 0
for j in k[1::]:
if j < kmin:
kmin = j
amazings += 1
if j > kmax:
kmax = j
amazings += 1
print(amazings)
| 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
_ = input()
k = tuple(map(int, input().split()))
kmax, kmin = k[0], k[0]
amazings = 0
for j in k[1::]:
if j < kmin:
kmin = j
amazings += 1
if j > kmax:
kmax = j
amazings += 1
print(amazings)
``` | 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,623,395,256 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,830,400 | #%%
input()
nums = list(map(int, input().split(" ")))
input()
q = map(int, input().split(" "))
def findElem(lst, n):
for i in range(len(lst)):
if lst[i] == n: return i
return -1
com = [0, 0]
for num in q:
temp = findElem(nums, num)
com[0] += (temp + 1)
com[1] += (len(nu... | 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
#%%
input()
nums = list(map(int, input().split(" ")))
input()
q = map(int, input().split(" "))
def findElem(lst, n):
for i in range(len(lst)):
if lst[i] == n: return i
return -1
com = [0, 0]
for num in q:
temp = findElem(nums, num)
com[0] += (temp + 1)
com[1] ... | 0 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,518,705,629 | 329 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 5,632,000 | s = input()
s = s[0] + s + s[1::-1] + s[0]
print(s) | Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
s = input()
s = s[0] + s + s[1::-1] + s[0]
print(s)
``` | 0 | |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,513,526,084 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 5,529,600 | n=int(input())
a = [int(x) for x in input().split()]
f=0
if len(a)==1:
f=1
if f==0:
for i in range(1,len(a)):
if a[i]==a[i-1]:
if a[i]==30:
f=1
#print(1)
break
if f==0:
if a.count(29)>1:
f=1
#print(2)
if f==0:
... | Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
n=int(input())
a = [int(x) for x in input().split()]
f=0
if len(a)==1:
f=1
if f==0:
for i in range(1,len(a)):
if a[i]==a[i-1]:
if a[i]==30:
f=1
#print(1)
break
if f==0:
if a.count(29)>1:
f=1
#print(2)
if ... | 0 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,667,566,195 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 9,523,200 | n = int(input())
flowers = sorted([int(x) for x in input().split()])
print(flowers[-1] - flowers[0], flowers.count(flowers[-1])*flowers.count(flowers[0])) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
n = int(input())
flowers = sorted([int(x) for x in input().split()])
print(flowers[-1] - flowers[0], flowers.count(flowers[-1])*flowers.count(flowers[0]))
``` | 0 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,489,675,822 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 4,608,000 | a = int(input())
b=0
if "8" not in a:
while "8" not in str(a):
a+=1
b+=1
print(b)
else:
a+=1
b+=1
while "8" not in str(a):
a+=1
b+=1
print(b)
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
a = int(input())
b=0
if "8" not in a:
while "8" not in str(a):
a+=1
b+=1
print(b)
else:
a+=1
b+=1
while "8" not in str(a):
a+=1
b+=1
print(b)
``` | -1 | |
613 | D | Kingdom and its Cities | PROGRAMMING | 2,800 | [
"dfs and similar",
"divide and conquer",
"dp",
"graphs",
"sortings",
"trees"
] | null | null | Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.
The kingdom curren... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cities in the kingdom.
Each of the next *n*<=-<=1 lines contains two distinct integers *u**i*, *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) — the indices of the cities connected by the *i*-th road. It is guaranteed that you can get fro... | For each plan print a single integer — the minimum number of cities that the barbarians need to capture, or print <=-<=1 if all the barbarians' attempts to isolate important cities will not be effective. | [
"4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n",
"7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n"
] | [
"1\n-1\n1\n-1\n",
"2\n"
] | In the first sample, in the first and the third King's plan barbarians can capture the city 3, and that will be enough. In the second and the fourth plans all their attempts will not be effective.
In the second sample the cities to capture are 3 and 5. | 2,000 | [
{
"input": "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4",
"output": "1\n-1\n1\n-1"
},
{
"input": "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7",
"output": "2"
},
{
"input": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 5 7\n3 2 4 6\n2 1 7\n2 3 4\n3 1 6 7",
"output": "3\n2\n... | 1,666,993,941 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
namespace std {
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::f... | Title: Kingdom and its Cities
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King... | ```python
#include <bits/stdc++.h>
namespace std {
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*thi... | -1 | |
755 | C | PolandBall and Forest | PROGRAMMING | 1,300 | [
"dfs and similar",
"dsu",
"graphs",
"interactive",
"trees"
] | null | null | PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree.
There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls living in the forest.
The second line contains a sequence *p*1,<=*p*2,<=...,<=*p**n* of length *n*, where (1<=≤<=*p**i*<=≤<=*n*) holds and *p**i* denotes the most distant from Ball *i* relative living on the same tree. If there are se... | You should output the number of trees in the forest where PolandBall lives. | [
"5\n2 1 5 3 3",
"1\n1\n"
] | [
"2",
"1"
] | In the first sample testcase, possible forest is: 1-2 3-4-5.
There are 2 trees overall.
In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree. | 1,500 | [
{
"input": "5 3\n1 2\n3 4\n4 5",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "5 1\n4 5",
"output": "4"
},
{
"input": "10 3\n2 8\n5 9\n6 10",
"output": "7"
},
{
"input": "18 2\n9 17\n1 18",
"output": "16"
},
{
"input": "1 0",
"out... | 1,684,408,562 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 2,355,200 | from collections import deque
import sys
n = int(input())
p = list(map(lambda x: int(x) - 1, input().split()))
adj = [[] for _ in range(n)]
for i in range(n):
if i != p[i]:
adj[i].append(p[i])
adj[p[i]].append(i)
vis = [False] * n
def dfs(u):
vis[u] = True
for ... | Title: PolandBall and Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a val... | ```python
from collections import deque
import sys
n = int(input())
p = list(map(lambda x: int(x) - 1, input().split()))
adj = [[] for _ in range(n)]
for i in range(n):
if i != p[i]:
adj[i].append(p[i])
adj[p[i]].append(i)
vis = [False] * n
def dfs(u):
vis[u] = True... | 3 | |
432 | B | Football Kit | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this team has color *y**i* (*x**i*<=≠<=*y**i*).
In the tournament, each team plays exactly one home g... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of teams. Next *n* lines contain the description of the teams. The *i*-th line contains two space-separated numbers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=105; *x**i*<=≠<=*y**i*) — the color numbers for the home and away kits of the *i*-th... | For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input. | [
"2\n1 2\n2 1\n",
"3\n1 2\n2 1\n1 3\n"
] | [
"2 0\n2 0\n",
"3 1\n4 0\n2 2\n"
] | none | 1,000 | [
{
"input": "2\n1 2\n2 1",
"output": "2 0\n2 0"
},
{
"input": "3\n1 2\n2 1\n1 3",
"output": "3 1\n4 0\n2 2"
},
{
"input": "2\n1 2\n1 2",
"output": "1 1\n1 1"
},
{
"input": "2\n1 2\n3 4",
"output": "1 1\n1 1"
},
{
"input": "3\n1 100000\n1 100000\n100000 2",
"out... | 1,684,802,902 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 795 | 20,172,800 | n = int(input())
gos, dom,sol = [],{},[]
for i in range(0,n):
x , y = [int(x) for x in input().split()]
gos.append(y)
if x in dom:
dom.update({x:dom[x]+1})
else:
dom.update({x:1})
for i in range(0,len(gos)):
if gos[i] in dom:
x , y = (n-1 + dom[gos[... | Title: Football Kit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this... | ```python
n = int(input())
gos, dom,sol = [],{},[]
for i in range(0,n):
x , y = [int(x) for x in input().split()]
gos.append(y)
if x in dom:
dom.update({x:dom[x]+1})
else:
dom.update({x:1})
for i in range(0,len(gos)):
if gos[i] in dom:
x , y = (n-1 ... | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,698,288,588 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | a = input().split('+')
ordered = []
for i in range(len(a)):
ordered.append(int(a[i]))
ordered.sort()
s = ''
for i in range(len(ordered)):
s+=str(ordered[i])
if not(i==len(ordered)-1):
s+='+'
print(s)
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
a = input().split('+')
ordered = []
for i in range(len(a)):
ordered.append(int(a[i]))
ordered.sort()
s = ''
for i in range(len(ordered)):
s+=str(ordered[i])
if not(i==len(ordered)-1):
s+='+'
print(s)
``` | 3 | |
452 | C | Magic Trick | PROGRAMMING | 2,100 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal dec... | First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks. | On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6. | [
"2 2\n",
"4 4\n",
"1 2\n"
] | [
"0.6666666666666666\n",
"0.4000000000000000\n",
"1.0000000000000000\n"
] | In the first sample, with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/64c94d13eeb330b494061e86538db66574ad0f7d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick... | 1,000 | [
{
"input": "2 2",
"output": "0.6666666666666666"
},
{
"input": "4 4",
"output": "0.4000000000000000"
},
{
"input": "1 2",
"output": "1.0000000000000000"
},
{
"input": "2 1",
"output": "0.5000000000000000"
},
{
"input": "10 10",
"output": "0.1818181818181818"
... | 1,430,156,419 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 46 | 4,710,400 | n,m = map(float, input().split())
print([((1+(n-1)*(m-1)/(n*m-1))/n),1][n==1]) | Title: Magic Trick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs ... | ```python
n,m = map(float, input().split())
print([((1+(n-1)*(m-1)/(n*m-1))/n),1][n==1])
``` | -1 | |
846 | D | Monitor | PROGRAMMING | 1,900 | [
"binary search",
"data structures"
] | null | null | Recently Luba bought a monitor. Monitor is a rectangular matrix of size *n*<=×<=*m*. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square *k*<=×<=*k* consisting entirely of broken pixels. She knows that *q* pix... | The first line contains four integer numbers *n*,<=*m*,<=*k*,<=*q* (1<=≤<=*n*,<=*m*<=≤<=500,<=1<=≤<=*k*<=≤<=*min*(*n*,<=*m*),<=0<=≤<=*q*<=≤<=*n*·*m*) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pix... | Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these *q* pixels stopped working. | [
"2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2\n",
"3 3 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100\n"
] | [
"8\n",
"-1\n"
] | none | 0 | [
{
"input": "2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2",
"output": "8"
},
{
"input": "3 3 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100",
"output": "-1"
},
{
"input": "29 50 5 29\n21 42 1565821\n21 43 53275635\n21 44 2717830\n21 45 9579585\n21 46 20725775\n22 42 2568372\n22 43 9584662\n22 44... | 1,631,576,102 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
const int o=501;
int n,m,k,q,l=1,r,ans=-1,a[o],b[o],c[o],t[o][o];
void modify(int x,int y,int z){
for (int i=x;i<=n;i+=i&-i)
for (int j=y;j<=m;j+=j&-j)
t[i][j]+=z;
}
int query(int x,int y){
int z=0;
for (int i=x;i;i-=i&-i)
for (int j=y;j;j-=j&-j)
... | Title: Monitor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a monitor. Monitor is a rectangular matrix of size *n*<=×<=*m*. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when ... | ```python
#include<bits/stdc++.h>
using namespace std;
const int o=501;
int n,m,k,q,l=1,r,ans=-1,a[o],b[o],c[o],t[o][o];
void modify(int x,int y,int z){
for (int i=x;i<=n;i+=i&-i)
for (int j=y;j<=m;j+=j&-j)
t[i][j]+=z;
}
int query(int x,int y){
int z=0;
for (int i=x;i;i-=i&-i)
for (int j=y;j;... | -1 | |
570 | B | Simple Game | PROGRAMMING | 1,300 | [
"constructive algorithms",
"games",
"greedy",
"implementation",
"math"
] | null | null | One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n*... | The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively. | Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them. | [
"3 1\n",
"4 3\n"
] | [
"2",
"2"
] | In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0.
In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wi... | 1,000 | [
{
"input": "3 1",
"output": "2"
},
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "4"
},
{
"input": "10 5",
"output": "6"
},
{
"input": "20 13",
"output": "12"
},
{
"input": "51 1",
"output": "2"
},
{
"input": "100 50",
... | 1,496,473,072 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 62 | 0 | n, m = [int(x) for x in input().split()]
if n == 1:
print(1)
else:
print(m - 1 if m > n//2 else m + 1) | Title: Simple Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random gen... | ```python
n, m = [int(x) for x in input().split()]
if n == 1:
print(1)
else:
print(m - 1 if m > n//2 else m + 1)
``` | 3 | |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,549,107,325 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 218 | 0 | '''input
5 5 1
1 3 1 2 1
'''
def main():
n, m, k = map(int, input().split())
socets = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in socets:
if(m <= k):
print(ans)
return
else:
k = k + i - 1
ans += 1
print... | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
'''input
5 5 1
1 3 1 2 1
'''
def main():
n, m, k = map(int, input().split())
socets = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in socets:
if(m <= k):
print(ans)
return
else:
k = k + i - 1
ans += 1
... | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,679,545,464 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a,b = map(int,input().split())
sock = max(a,b)
differentDay = min(a,b)
sameDay = sock - min(a,b)
if sameDay % 2 ==0:
sameDay //= 2
else:
sameDay -=1
sameDay//=2
print(differentDay,sameDay) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b = map(int,input().split())
sock = max(a,b)
differentDay = min(a,b)
sameDay = sock - min(a,b)
if sameDay % 2 ==0:
sameDay //= 2
else:
sameDay -=1
sameDay//=2
print(differentDay,sameDay)
``` | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,619,440,066 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | 1 1 5
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
1 1 5
``` | -1 | |
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,461,434,665 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 5,120,000 | n = int(input())
result = ''
k = 0
if n == 1 or n == 2:
print('1')
print('1')
exit()
elif n == 3:
print('2')
print('3 1')
exit()
for i in reversed(range(1, n + 1, 2)):
result += "%s " % str(i)
k += 1
for j in reversed(range(2, n + 1, 2)):
result += "%s " % str(j)
... | 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())
result = ''
k = 0
if n == 1 or n == 2:
print('1')
print('1')
exit()
elif n == 3:
print('2')
print('3 1')
exit()
for i in reversed(range(1, n + 1, 2)):
result += "%s " % str(i)
k += 1
for j in reversed(range(2, n + 1, 2)):
result += "%s " % st... | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,697,007,674 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | input1=input()
str1=input1.split("+")
str1=sorted(str1)
plus="+"
result=plus.join(map(str,str1))
print(result) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
input1=input()
str1=input1.split("+")
str1=sorted(str1)
plus="+"
result=plus.join(map(str,str1))
print(result)
``` | 3 | |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | 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... | 500 | [
{
"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,587,620,542 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 307,200 | n,m=list(map(int,input().strip().split()))
l=list(map(int,input().strip().split()))
t=list(map(int,input().strip().split()))
l.sort()
t.sort()
k=[l[0],t[0]]
s=list(set(k))
s.sort()
for i in s:
print(i,end="")
print() | Title: Search for Pretty Integers
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 sm... | ```python
n,m=list(map(int,input().strip().split()))
l=list(map(int,input().strip().split()))
t=list(map(int,input().strip().split()))
l.sort()
t.sort()
k=[l[0],t[0]]
s=list(set(k))
s.sort()
for i in s:
print(i,end="")
print()
``` | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,696,151,732 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | word = input()
letters = []
for letter in word:
letters.append(letter)
letters[0] = letters[0].upper()
for i in letters:
print(i , end = "")
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
word = input()
letters = []
for letter in word:
letters.append(letter)
letters[0] = letters[0].upper()
for i in letters:
print(i , end = "")
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,689,077,432 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | x=input()
if x==2:
print("No")
else:
if x%2==0:
y=x/2
if y%2==0:
print("Yes")
else:
print("No")
else:
print("No")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
x=input()
if x==2:
print("No")
else:
if x%2==0:
y=x/2
if y%2==0:
print("Yes")
else:
print("No")
else:
print("No")
``` | -1 |
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 98... | 1,577,952,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | x = input()
x = int(x)
A = list(map(int,input().split()))
Min = min(A)
Max = max(A)
while Min != Max:
for i in A:
if Min < i:
A.remove(Min)
Min = min(A)
break
print(len(A))
| Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not pu... | ```python
x = input()
x = int(x)
A = list(map(int,input().split()))
Min = min(A)
Max = max(A)
while Min != Max:
for i in A:
if Min < i:
A.remove(Min)
Min = min(A)
break
print(len(A))
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,639,925,743 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 154 | 0 | t=int(input())
x=0
y=0
z=0
sum1=0
list1=[]
for i in range(0,t):
list2=list(map(int,input().split()))
list1.append(list2)
for i in range(0,t):
x=x+list1[i][0]
y=y+list1[i][1]
z=z+list1[i][2]
if x==0 and y==0 and z==0:
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
t=int(input())
x=0
y=0
z=0
sum1=0
list1=[]
for i in range(0,t):
list2=list(map(int,input().split()))
list1.append(list2)
for i in range(0,t):
x=x+list1[i][0]
y=y+list1[i][1]
z=z+list1[i][2]
if x==0 and y==0 and z==0:
print("YES")
else:
print("NO")
``` | 3.9615 |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,687,292,902 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | k=int(input()) #punched in the face with a frying pan
l=int(input()) #got his tail shut into the balcony door
m=int(input()) #got his paws trampled with sharp heels
n=int(input()) #threatened every n-th dragon to call her mom, and he withdrew in panic
d=int(input()) #total
damaged_dragons = 0
for i in range(1... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k=int(input()) #punched in the face with a frying pan
l=int(input()) #got his tail shut into the balcony door
m=int(input()) #got his paws trampled with sharp heels
n=int(input()) #threatened every n-th dragon to call her mom, and he withdrew in panic
d=int(input()) #total
damaged_dragons = 0
for i ... | 3 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,532,541,301 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | input()
games = [int(x) for x in input().split()]
wallet = [int(x) for x in input().split()]
numgames = 0
for game in games:
for i in range(len(wallet)):
bill = wallet[i]
if game < bill:
#print(bill)
del wallet[i]
#print(wallet)
numgames += 1
... | Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
input()
games = [int(x) for x in input().split()]
wallet = [int(x) for x in input().split()]
numgames = 0
for game in games:
for i in range(len(wallet)):
bill = wallet[i]
if game < bill:
#print(bill)
del wallet[i]
#print(wallet)
numgames += ... | 0 | |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 1,500 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,568,047,032 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 342 | 2,560,000 | n = int(input())
a = list(map(int,input().split()))
m = int(input())
MAX = float('inf')
for i in range(m):
w,h = map(int,input().split())
yy = max(a[w-1],M)
#yy = max(a[:w])
print(yy)
M = max(yy,M)
yy+=h
for j in range(w):
a[j]=yy
| Title: Dima and Staircase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the st... | ```python
n = int(input())
a = list(map(int,input().split()))
m = int(input())
MAX = float('inf')
for i in range(m):
w,h = map(int,input().split())
yy = max(a[w-1],M)
#yy = max(a[:w])
print(yy)
M = max(yy,M)
yy+=h
for j in range(w):
a[j]=yy
``` | -1 | |
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,668,525,236 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 122 | 0 | s=str(input())
ls=0
cs=0
for i in range(0,len(s)):
if s[i].islower():
ls+=1
else:
cs+=1
if ls>cs:
print(s.lower())
elif cs>ls:
print(s.upper())
elif cs==ls:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=str(input())
ls=0
cs=0
for i in range(0,len(s)):
if s[i].islower():
ls+=1
else:
cs+=1
if ls>cs:
print(s.lower())
elif cs>ls:
print(s.upper())
elif cs==ls:
print(s.lower())
``` | 3.9695 |
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the firs... | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9... | 1,496,898,157 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | """import _random
from urllib import urlopen
from BeautifulSoupTests import BeautifulSoup
import urllib
def down_image(url):
cv = urlopen(url)
file = cv.read()
dest = r"C:/Users/mohit rawat/Desktop/test.txt"
fw = open("C:/Users/mohit rawat/Desktop/test.txt","w")
p=""
for line in file:
... | Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her... | ```python
"""import _random
from urllib import urlopen
from BeautifulSoupTests import BeautifulSoup
import urllib
def down_image(url):
cv = urlopen(url)
file = cv.read()
dest = r"C:/Users/mohit rawat/Desktop/test.txt"
fw = open("C:/Users/mohit rawat/Desktop/test.txt","w")
p=""
for line... | 0 | |
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,493,197,639 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 12,595,200 | class bus:
n = 0
s = []
low = 0
count = 0
def __init__(self, n, s):
self.n = n
for i in range(n):
self.s.append(int(s.split(' ')[i]))
self.calc()
def calc(self):
for i in range(len(self.s)):
for j in range(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
class bus:
n = 0
s = []
low = 0
count = 0
def __init__(self, n, s):
self.n = n
for i in range(n):
self.s.append(int(s.split(' ')[i]))
self.calc()
def calc(self):
for i in range(len(self.s)):
for j in ... | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,666,343,493 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | d={".":"0","-.":"1","--":"2"}
s=input()
j=""
r=""
for i in s:
j+=i
if j not in d:
continue
else:
r+=d[j]
j=""
print(r) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
d={".":"0","-.":"1","--":"2"}
s=input()
j=""
r=""
for i in s:
j+=i
if j not in d:
continue
else:
r+=d[j]
j=""
print(r)
``` | 3.977 |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,591,442,953 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 2,764,800 | n=int(input())
def funk(n):
l=[]
res=0
for i in range(1,n):
res=res+i
l.append(res)
for i in l:
if n-i in l:
return 'YES'
else:
return 'NO'
print(funk(n)) | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n=int(input())
def funk(n):
l=[]
res=0
for i in range(1,n):
res=res+i
l.append(res)
for i in l:
if n-i in l:
return 'YES'
else:
return 'NO'
print(funk(n))
``` | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,634,946,115 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 4,505,600 | code = input()
#Caso 1 . = 0
#Caso 2 -.= 1
#Caso 3 --= 2
i = 0
while i < len(code):
if code[i] == ".":
print("0",end="")
i+=1
elif code[i] == "-":
if code[i+1] == ".":
print("1",end="")
elif code[i+1] == "-":
print("2",end="")
i+=2 | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
code = input()
#Caso 1 . = 0
#Caso 2 -.= 1
#Caso 3 --= 2
i = 0
while i < len(code):
if code[i] == ".":
print("0",end="")
i+=1
elif code[i] == "-":
if code[i+1] == ".":
print("1",end="")
elif code[i+1] == "-":
print("2",end="")
i+=2
``` | 3.968608 |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,508,920,930 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def main():
n = int(input())
games = [0]
games = games + list(map(int, input().split(' ')))
result = max([games[:i].count(0) + games[i:].count(1) for i in range(n+1)])
print(result)
if __name__ == "__main__":
main()
| Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
def main():
n = int(input())
games = [0]
games = games + list(map(int, input().split(' ')))
result = max([games[:i].count(0) + games[i:].count(1) for i in range(n+1)])
print(result)
if __name__ == "__main__":
main()
``` | 0 | |
639 | A | Bear and Displayed Friends | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Wint... | The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) ... | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | [
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n"
] | [
"NO\nYES\nNO\nYES\nYES\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We shou... | 500 | [
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3",
"output": "NO\nYES\nNO\nYES\nYES"
},
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 ... | 1,697,371,899 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 92 | 2,867,200 |
n,k,q=[int(x) for x in input().split()]
lst=list(map(int,input().split()))
freq={}
count=0
for i in range(q):
a,b=[int(x) for x in input().split()]
if(a==1):
if(b not in freq):
if(len(freq)==k):
ke=0
v=lst[b-1]
for key,val in freq.... | Title: Bear and Displayed Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this val... | ```python
n,k,q=[int(x) for x in input().split()]
lst=list(map(int,input().split()))
freq={}
count=0
for i in range(q):
a,b=[int(x) for x in input().split()]
if(a==1):
if(b not in freq):
if(len(freq)==k):
ke=0
v=lst[b-1]
for key,va... | -1 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,600,134,639 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,048,000 | N, K = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
Ac1 = [0]*(N+1)
Ac2 = [0]*(N+1)
resp = 0
for i in range(1, N+1):
Ac1[i] = Ac1[i-1] + A[i-1]
Ac2[i] = Ac2[i-1]
if(T[i-1]==1):
Ac2[i] += A[i-1]
for L in range(N-K+1):
R = L+K-1
sum1 = ... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
N, K = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
Ac1 = [0]*(N+1)
Ac2 = [0]*(N+1)
resp = 0
for i in range(1, N+1):
Ac1[i] = Ac1[i-1] + A[i-1]
Ac2[i] = Ac2[i-1]
if(T[i-1]==1):
Ac2[i] += A[i-1]
for L in range(N-K+1):
R = L+K-1
... | -1 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,694,673,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | a=int(input())
b=a/4.0
if int(b)-b==0:
print("YES")
else:
print("NO")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
a=int(input())
b=a/4.0
if int(b)-b==0:
print("YES")
else:
print("NO")
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 0 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,511,324,379 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 0 |
def sumOf(num):
return num + sum([int(char) for char in str(num)])
n = int(input())
l = []
for i in range(n - 9*len(str(n)), n+1):
if sumOf(i) == n:
l.append(i)
print(len(l))
for i in l:
print(i)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova th... | ```python
def sumOf(num):
return num + sum([int(char) for char in str(num)])
n = int(input())
l = []
for i in range(n - 9*len(str(n)), n+1):
if sumOf(i) == n:
l.append(i)
print(len(l))
for i in l:
print(i)
``` | -1 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,675,697,282 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | # LUOGU_RID: 101607150
from math import comb
a = [input() for _ in range(int(input()))]
print(sum(comb(x.count('C'), 2) for x in a) + sum(comb(x.count('C'), 2) for x in zip(*a)))
| Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
# LUOGU_RID: 101607150
from math import comb
a = [input() for _ in range(int(input()))]
print(sum(comb(x.count('C'), 2) for x in a) + sum(comb(x.count('C'), 2) for x in zip(*a)))
``` | 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,693,505,355 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | a=input()
s=len(a)
a=int(a,2)
b=int(input(),2)
c=a^b
c=bin(c).replace("0b","")
print("0"*(s-len(c))+c)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
s=len(a)
a=int(a,2)
b=int(input(),2)
c=a^b
c=bin(c).replace("0b","")
print("0"*(s-len(c))+c)
``` | 3.9885 |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,612,901,110 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 109 | 1,331,200 | x=int(input())
fibo=[1,1]
S="O"
for i in range(0,x):
fibo.append(fibo[-1]+fibo[-2])
for j in range(2,x+1):
if j in fibo:
S=S+'O'
else:
S=S+'o'
print(S) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
x=int(input())
fibo=[1,1]
S="O"
for i in range(0,x):
fibo.append(fibo[-1]+fibo[-2])
for j in range(2,x+1):
if j in fibo:
S=S+'O'
else:
S=S+'o'
print(S)
``` | 3 | |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,617,265,769 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n = int(input())
if n <= 5:
print(0, min(2,n))
elif n == 6:
print(0, 2)
else:
print(n//7, n//7 + min(n%7,2))
| Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
n = int(input())
if n <= 5:
print(0, min(2,n))
elif n == 6:
print(0, 2)
else:
print(n//7, n//7 + min(n%7,2))
``` | 0 | |
413 | A | Data Recovery | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer ... | The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures ... | If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). | [
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"2 1 1 3\n2\n"
] | [
"Correct\n",
"Correct\n",
"Incorrect\n"
] | In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3... | 500 | [
{
"input": "2 1 1 2\n1",
"output": "Correct"
},
{
"input": "3 1 1 3\n2",
"output": "Correct"
},
{
"input": "2 1 1 3\n2",
"output": "Incorrect"
},
{
"input": "3 1 1 5\n3",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 5",
"output": "Correct"
},
{
"input... | 1,492,102,553 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 5,529,600 | line = input()
n_steps, m_records, min_v, max_v = line.split()
n_steps, m_records, min_v, max_v = int(n_steps), int(m_records), int(min_v), int(max_v)
line = input()
a = [int(i) for i in line.split()]
low = False
high = False
for i in a:
if i == min_v:
low = True
if i == max_v:
high = True
if high == True ... | Title: Data Recovery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each ... | ```python
line = input()
n_steps, m_records, min_v, max_v = line.split()
n_steps, m_records, min_v, max_v = int(n_steps), int(m_records), int(min_v), int(max_v)
line = input()
a = [int(i) for i in line.split()]
low = False
high = False
for i in a:
if i == min_v:
low = True
if i == max_v:
high = True
if hig... | 0 | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,645,203,778 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 31 | 0 | l = ['<', '[', '{', '(']
r = ['>', ']', '}', ')']
s = input()
o = list()
count = 0
flag = True
for i in range(len(s)):
if s[i] in r and i == 0:
print("Impossible")
flag = False
break
elif s[i] in l:
o.append(s[i])
elif s[i] in r:
c = o.pop()
if l.index(c) != r... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
l = ['<', '[', '{', '(']
r = ['>', ']', '}', ')']
s = input()
o = list()
count = 0
flag = True
for i in range(len(s)):
if s[i] in r and i == 0:
print("Impossible")
flag = False
break
elif s[i] in l:
o.append(s[i])
elif s[i] in r:
c = o.pop()
if l.ind... | 0 | |
980 | E | The Number Games | PROGRAMMING | 2,200 | [
"data structures",
"greedy",
"trees"
] | null | null | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i... | The first line of input contains two integers $n$ and $k$ ($1 \leq k < n \leq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next $n-1$ lines each contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), that describe a road tha... | Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number. | [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n"
] | [
"1 3 4\n",
"1 3 4 5\n"
] | In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4. | 2,500 | [
{
"input": "6 3\n2 1\n2 6\n4 2\n5 6\n2 3",
"output": "1 3 4"
},
{
"input": "8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5",
"output": "1 3 4 5"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 1\n2 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 3\n1 2",
"output... | 1,526,394,929 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 78 | 7,168,000 | from collections import deque;
def getIntList():
return list(map(int, input().split()));
def getTransIntList(n):
first=getIntList();
m=len(first);
result=[[0]*n for _ in range(m)];
for i in range(m):
result[i][0]=first[i];
for j in range(1, n):
curr=getIntList();
... | Title: The Number Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$, each district has exact... | ```python
from collections import deque;
def getIntList():
return list(map(int, input().split()));
def getTransIntList(n):
first=getIntList();
m=len(first);
result=[[0]*n for _ in range(m)];
for i in range(m):
result[i][0]=first[i];
for j in range(1, n):
curr=getIntList... | 0 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,581,358,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | x,y,z = input().split()
x = int(x)
y = int(y)
z = int(z)
if ((x^y) >= 1):
print("0")
else:
print("1")
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
x,y,z = input().split()
x = int(x)
y = int(y)
z = int(z)
if ((x^y) >= 1):
print("0")
else:
print("1")
``` | 0 | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,675,047,702 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | def jhamela_check(l):
if len(l) != len(list(set(l))): jhamela = True
for i in l:
if i < 1 or i > 10: jhamela = True
return jhamela
r1, r2 = [int(i) for i in input().split()]
c1, c2 = [int(i) for i in input().split()]
d1, d2 = [int(i) for i in input().split()]
a = b = c = d = 0
a = min... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
def jhamela_check(l):
if len(l) != len(list(set(l))): jhamela = True
for i in l:
if i < 1 or i > 10: jhamela = True
return jhamela
r1, r2 = [int(i) for i in input().split()]
c1, c2 = [int(i) for i in input().split()]
d1, d2 = [int(i) for i in input().split()]
a = b = c = d = 0
... | -1 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,682,936,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | s = input()
cnt = max(int(c) for c in s)
ans = ["" for _ in range(cnt)]
for c in s:
for i in range(cnt):
x = "1" if i < int(c) else "0"
ans[i] += x
print(max(int(c) for c in s))
print(*ans) | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
s = input()
cnt = max(int(c) for c in s)
ans = ["" for _ in range(cnt)]
for c in s:
for i in range(cnt):
x = "1" if i < int(c) else "0"
ans[i] += x
print(max(int(c) for c in s))
print(*ans)
``` | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,672,931,276 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 122 | 0 | winner = ""
members = []
score = []
mx = -1001
for _ in range(int(input())):
name, point = [i for i in input().split()]
point = int(point)
if name not in members:
members.append(name)
score.append(point)
else:
score[members.index(name)] += point
if score.count(m... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
winner = ""
members = []
score = []
mx = -1001
for _ in range(int(input())):
name, point = [i for i in input().split()]
point = int(point)
if name not in members:
members.append(name)
score.append(point)
else:
score[members.index(name)] += point
if sco... | 0 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,674,205,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n,a,b=map(int,input().split())
x=0
x=min(n,a,b)
print(n-x) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
n,a,b=map(int,input().split())
x=0
x=min(n,a,b)
print(n-x)
``` | 0 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,681,806,148 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 0 | n = int(input())
s =tuple(map(int, list(input())))
pref = [None] * (n+1)
pref[0] = 0
for i in range(1, n+1):
pref[i] = pref[i-1] + s[i-1]
res = set()
res.add(0)
for i in range(n):
for j in range(i+1, n):
j += 1
if (j-i) / 2 == (pref[j] - pref[i]):
res.add(j-i)
print(max(res))
... | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n = int(input())
s =tuple(map(int, list(input())))
pref = [None] * (n+1)
pref[0] = 0
for i in range(1, n+1):
pref[i] = pref[i-1] + s[i-1]
res = set()
res.add(0)
for i in range(n):
for j in range(i+1, n):
j += 1
if (j-i) / 2 == (pref[j] - pref[i]):
res.add(j-i)
print(m... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,567,077,553 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | n = int(input())
a = map(int, input().split())
a = list(a)
chet = 0
neChet = 0
b = 0
c = 0
for i in range(n):
if a[i] % 2 == 0:
chet = chet + 1
b = a[i]
else:
neChet = neChet + 1
c = a[i]
if chet > neChet:
print(c)
else:
print(b)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
a = map(int, input().split())
a = list(a)
chet = 0
neChet = 0
b = 0
c = 0
for i in range(n):
if a[i] % 2 == 0:
chet = chet + 1
b = a[i]
else:
neChet = neChet + 1
c = a[i]
if chet > neChet:
print(c)
else:
print(b)
``` | 0 |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,532,201,849 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 0 | from math import sqrt,ceil
a,b = map(int,input().split())
e = a - b
if(e == 0) :
print("infinity")
else :
i = 1
t = e
ans = 0
while(True) :
if(e % i == 0):
t = e // i
if(t > b):
ans += 1
if(e // i <= b) :
break
i += 1
... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
from math import sqrt,ceil
a,b = map(int,input().split())
e = a - b
if(e == 0) :
print("infinity")
else :
i = 1
t = e
ans = 0
while(True) :
if(e % i == 0):
t = e // i
if(t > b):
ans += 1
if(e // i <= b) :
break
... | 0 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,569,736,147 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 186 | 2,150,400 | import sys
from collections import *
from math import *
import re
def sieve(n):
prime=[True for i in range(n+1)]
p=2
while p*p<=n:
if prime[p]==True:
for i in range(p*p,n+1,p):
prime[i]=False
p+=1
c=0
for i in range(2,n):
if prime[i]:... | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
import sys
from collections import *
from math import *
import re
def sieve(n):
prime=[True for i in range(n+1)]
p=2
while p*p<=n:
if prime[p]==True:
for i in range(p*p,n+1,p):
prime[i]=False
p+=1
c=0
for i in range(2,n):
if... | 0 | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,624,343,508 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 |
# import sys
# sys.stdin=open("input2.in",'r')
from sys import stdin,stdout
# stdin.readline
# def mp(): return list(map(int, stdin.readline().strip().split()))
# def it():return int(stdin.readline().strip())
stdin = open("input.txt", "r")
stdout = open("output.txt", "w")
def bs(l,x):
n = len(l)
s... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
# import sys
# sys.stdin=open("input2.in",'r')
from sys import stdin,stdout
# stdin.readline
# def mp(): return list(map(int, stdin.readline().strip().split()))
# def it():return int(stdin.readline().strip())
stdin = open("input.txt", "r")
stdout = open("output.txt", "w")
def bs(l,x):
n = ... | -1 | |
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,679,324,969 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | import math
a1 , a2 , a3 = map(int,input().split())
a = math.sqrt((a1*a3)//a2)
b = math.sqrt((a1*a2)//a3)
c = math.sqrt((a2*a3)//a1)
sum1 = 4*(a+b+c)
print(int(sum1)) | 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
import math
a1 , a2 , a3 = map(int,input().split())
a = math.sqrt((a1*a3)//a2)
b = math.sqrt((a1*a2)//a3)
c = math.sqrt((a2*a3)//a1)
sum1 = 4*(a+b+c)
print(int(sum1))
``` | 3 | |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,694,617,138 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 1,543 | 43,929,600 | s = input()
arr = [0] * len(s)
l, r = 0, len(s)-1
count = 1
for c in s:
if c == "l":
arr[r] = count
r -= 1
else:
arr[l] = count
l += 1
count += 1
for c in arr:
print(c)
| Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
s = input()
arr = [0] * len(s)
l, r = 0, len(s)-1
count = 1
for c in s:
if c == "l":
arr[r] = count
r -= 1
else:
arr[l] = count
l += 1
count += 1
for c in arr:
print(c)
``` | 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,639,725,343 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 0 | s=input()
l=0
u=0
for i in s:
if ord(i)>=65 and ord(i)<=90:
u+=1
else:
l+=1
ans=''
for i in s:
if u>l:
ans+=i.upper()
else:
ans+=i.lower()
print(ans)
| 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()
l=0
u=0
for i in s:
if ord(i)>=65 and ord(i)<=90:
u+=1
else:
l+=1
ans=''
for i in s:
if u>l:
ans+=i.upper()
else:
ans+=i.lower()
print(ans)
``` | 3.9695 |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,622,959,019 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n,m=map(int,input().split())
lsta=list(map(int,input().split()))
lstb=list(map(int,input().split()))
b=list(set(lstb))
cnt=0;c=0
if n>m:
print(m)
else:
for i in lsta:
if i in b:
cnt+=1
print(n-cnt) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
n,m=map(int,input().split())
lsta=list(map(int,input().split()))
lstb=list(map(int,input().split()))
b=list(set(lstb))
cnt=0;c=0
if n>m:
print(m)
else:
for i in lsta:
if i in b:
cnt+=1
print(n-cnt)
``` | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,620,112,097 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 154 | 0 |
import math
x = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse = True)
counter = 0
test = 0
for items in a :
if test == 0:
counter += pow(items,2)
test = 1
else:
test = 0
counter -= pow(items,2)
print(counter * math.pi)
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
x = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse = True)
counter = 0
test = 0
for items in a :
if test == 0:
counter += pow(items,2)
test = 1
else:
test = 0
counter -= pow(items,2)
print(counter * math.pi)
... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,696,505,434 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | in = int(input())
if n % 2 == 0 and not (n == 2):
print('YES')
else:
print('NO') | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
in = int(input())
if n % 2 == 0 and not (n == 2):
print('YES')
else:
print('NO')
``` | -1 |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,637,123,113 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | t=input()
n=len(t)
j=0
for i in range(int(n/2)) :
if(t[i]!=t[n-1]):
j+=1
else :
n-=1
i+=1
if (j>1 ):
print('NO')
elif (j==1):
print('YES')
elif(j==0 and n%2==1):
print('YES')
elif(j==0 and n%2==0):
print('NO') | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
t=input()
n=len(t)
j=0
for i in range(int(n/2)) :
if(t[i]!=t[n-1]):
j+=1
else :
n-=1
i+=1
if (j>1 ):
print('NO')
elif (j==1):
print('YES')
elif(j==0 and n%2==1):
print('YES')
elif(j==0 and n%2==0):
print('NO')
``` | 0 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,570,823,133 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | from sys import stdin
def isLucky(num):
ans = None
if num == "4" or num == "7": ans = True
else:
ans = True
for i in num:
if i != "4" and i != "7": ans = False; break
if ans:
nums = list(map(int, list(num)))
ans = sum(nums[:(len(nums)//2)]) == sum... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
from sys import stdin
def isLucky(num):
ans = None
if num == "4" or num == "7": ans = True
else:
ans = True
for i in num:
if i != "4" and i != "7": ans = False; break
if ans:
nums = list(map(int, list(num)))
ans = sum(nums[:(len(nums)//2... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,619,662,755 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 0 | n=int(input())
s=[int(x) for x in input().split()]
t=[]
for i in s:
if i%2==0:
t.append(1)
else:
t.append(0)
if t.count(1)==1:
print(t.index(1)+1)
else:
print(t.index(0)+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
s=[int(x) for x in input().split()]
t=[]
for i in s:
if i%2==0:
t.append(1)
else:
t.append(0)
if t.count(1)==1:
print(t.index(1)+1)
else:
print(t.index(0)+1)
``` | 3.9615 |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,633,583,234 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 154 | 7,065,600 | # import sys
# sys.stdin=open('Python\input.txt','r')
# sys.stdout=open('Python\output.txt','w')
n=int(input())
l=[i for i in range(1,n*n+1)]
m=n//2
for i in range(0,(n**2)//2,m):
# print(i)
print(*l[i:i+m],*l[(n**2)-i-m:(n**2)-i])
# print(sum(l[i:i+m]+l[(n**2)-i-m:(n**2)-i])) | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
# import sys
# sys.stdin=open('Python\input.txt','r')
# sys.stdout=open('Python\output.txt','w')
n=int(input())
l=[i for i in range(1,n*n+1)]
m=n//2
for i in range(0,(n**2)//2,m):
# print(i)
print(*l[i:i+m],*l[(n**2)-i-m:(n**2)-i])
# print(sum(l[i:i+m]+l[(n**2)-i-m:(n**2)-i]))
``` | 3 | |
936 | A | Save Energy! | PROGRAMMING | 1,700 | [
"binary search",
"implementation",
"math"
] | null | null | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. T... | The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018). | Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9.
Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if . | [
"3 2 6\n",
"4 2 20\n"
] | [
"6.5\n",
"20.0\n"
] | In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be coo... | 500 | [
{
"input": "3 2 6",
"output": "6.5"
},
{
"input": "4 2 20",
"output": "20.0"
},
{
"input": "8 10 9",
"output": "10.0"
},
{
"input": "43 50 140",
"output": "150.5"
},
{
"input": "251 79 76",
"output": "76.0"
},
{
"input": "892 67 1000",
"output": "1... | 1,525,184,066 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 93 | 7,065,600 | [k,d,t ] = input().split(' ')
k = float(k)
d = float(d)
t = float (t)
T = ((k-1)//d+1)*d #一个周期得时间
T1 = k + (T-k)*0.5#一个周期所能完成得
#print(T)
#print(T1)
ans = 0
ans = ans + t//T1*T
a = t-t//T1*T1
#print(a)
if a < k:
ans = ans + a
else :
ans = ans + k+(a-k)*2
print(ans)
| Title: Save Energy!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* mi... | ```python
[k,d,t ] = input().split(' ')
k = float(k)
d = float(d)
t = float (t)
T = ((k-1)//d+1)*d #一个周期得时间
T1 = k + (T-k)*0.5#一个周期所能完成得
#print(T)
#print(T1)
ans = 0
ans = ans + t//T1*T
a = t-t//T1*T1
#print(a)
if a < k:
ans = ans + a
else :
ans = ans + k+(a-k)*2
print(ans)
``` | 3 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,566,085,691 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 374 | 7,475,200 | n = int(input())
numbers = list(map(int, input().split()))
count = 0
sumP1 = sum(numbers[0:1])
sumP2 = sum(numbers[1:n])
if(sumP1 == sumP2):
count += 1
if(n > 2):
for i in range(1, n - 1, 1):
sumP1 += numbers[i]
sumP2 -= numbers[i]
if(sumP1 == sumP2):
count += 1
print(count) | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
numbers = list(map(int, input().split()))
count = 0
sumP1 = sum(numbers[0:1])
sumP2 = sum(numbers[1:n])
if(sumP1 == sumP2):
count += 1
if(n > 2):
for i in range(1, n - 1, 1):
sumP1 += numbers[i]
sumP2 -= numbers[i]
if(sumP1 == sumP2):
count += 1
print(count)
``` | 0 |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,691,411,352 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,764,800 | n=int(input())
n=n//2
even=n(n+1)
if(n&1):
odd= (n+1)*(n+1)
else:
odd=n*n
print(even-odd) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n=int(input())
n=n//2
even=n(n+1)
if(n&1):
odd= (n+1)*(n+1)
else:
odd=n*n
print(even-odd)
``` | -1 | |
633 | D | Fibonacci-ish | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"hashing",
"implementation",
"math"
] | null | null | Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=2<==<=*f**n*<=+<=1<=+<=*f**n* for all *n*<=≥<=0.
You are given some sequence of integers *a*1,<=*a... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the sequence *a**i*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=109). | Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement. | [
"3\n1 2 -1\n",
"5\n28 35 7 14 21\n"
] | [
"3\n",
"4\n"
] | In the first sample, if we rearrange elements of the sequence as - 1, 2, 1, the whole sequence *a*<sub class="lower-index">*i*</sub> would be Fibonacci-ish.
In the second sample, the optimal way to rearrange elements is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16f1f7e35511b29cb1396... | 1,750 | [
{
"input": "3\n1 2 -1",
"output": "3"
},
{
"input": "5\n28 35 7 14 21",
"output": "4"
},
{
"input": "11\n-9 -1 -10 9 7 -4 0 -8 -3 3 5",
"output": "5"
},
{
"input": "10\n-4 -8 -8 8 -9 0 -7 9 1 0",
"output": "4"
},
{
"input": "2\n2 2",
"output": "2"
},
{
... | 1,456,511,921 | 5,021 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 11 | 3,000 | 307,200 | n = int(input())
s = list(map(int, input().split()))
possibilities = set(s)
d = {}
for i in possibilities:
d[i] = 0
for i in range(n):
d[s[i]] += 1
maxlen = 0
for i in s:
for j in s:
if i != j or d[i] > 1:
seq1 = i
seq2 = j
lenprefix = 2
... | Title: Fibonacci-ish
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=... | ```python
n = int(input())
s = list(map(int, input().split()))
possibilities = set(s)
d = {}
for i in possibilities:
d[i] = 0
for i in range(n):
d[s[i]] += 1
maxlen = 0
for i in s:
for j in s:
if i != j or d[i] > 1:
seq1 = i
seq2 = j
lenprefix = 2
... | 0 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,544,361,919 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 1,060 | 10,752,000 | n = int(input())
a = []
count = 0
min = 1000000000
max = 0
for i in range(n):
temp = list(map(int,input().split()))
a.append(temp)
for i in range(0,n,1):
if a[i][0] < min:
min = a[i][0]
if a[i][1] > max:
max = a[i][1]
for j in range(0,n,1):
if a[j][0] == min and a[j][1]... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n = int(input())
a = []
count = 0
min = 1000000000
max = 0
for i in range(n):
temp = list(map(int,input().split()))
a.append(temp)
for i in range(0,n,1):
if a[i][0] < min:
min = a[i][0]
if a[i][1] > max:
max = a[i][1]
for j in range(0,n,1):
if a[j][0] == min a... | 3 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,683,489,249 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 0 | n, k = map(int, input().split())
powers = list(map(int, input().split()))
winner_idx = 0
wins = 0
loser_idx = -1 # initialize loser index to -1
while wins < k:
challenger_idx = (winner_idx + 1) % n
if powers[challenger_idx] > powers[winner_idx]:
winner_idx = challenger_idx
loser_... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
n, k = map(int, input().split())
powers = list(map(int, input().split()))
winner_idx = 0
wins = 0
loser_idx = -1 # initialize loser index to -1
while wins < k:
challenger_idx = (winner_idx + 1) % n
if powers[challenger_idx] > powers[winner_idx]:
winner_idx = challenger_idx
... | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,619,588,675 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = input()
if n == "heidi":
print("yes")
else:
print("no")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
n = input()
if n == "heidi":
print("yes")
else:
print("no")
``` | 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,695,904,152 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
letters = 0
word = ''
words = []
for i in range (n):
word = input()
words.append(word)
for word in words:
if len(word) > 10:
print(word[0] + str(len(word) - 2) + word[-1])
else:
print(word) | 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
n = int(input())
letters = 0
word = ''
words = []
for i in range (n):
word = input()
words.append(word)
for word in words:
if len(word) > 10:
print(word[0] + str(len(word) - 2) + word[-1])
else:
print(word)
``` | -1 |
631 | C | Report | PROGRAMMING | 1,700 | [
"data structures",
"sortings"
] | null | null | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lin... | Print *n* integers — the final report, which will be passed to Blake by manager number *m*. | [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
] | [
"2 1 3 ",
"2 4 1 3 "
] | In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the r... | 1,500 | [
{
"input": "3 1\n1 2 3\n2 2",
"output": "2 1 3 "
},
{
"input": "4 2\n1 2 4 3\n2 3\n1 2",
"output": "2 4 1 3 "
},
{
"input": "4 1\n4 3 2 1\n1 4",
"output": "1 2 3 4 "
},
{
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "5 4 3 2 1 "
},
{
"input": "6 2\n3 1 2 6 4 5\n1 6\n... | 1,585,326,702 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n, m = map(int,input().split())
l = list(map(int,input().split()))
for i in range(m):
a, b = map(int,input().split())
x = sorted(l[0:b])
if(a == 1):
l = x + l[b:]
else:
l = x[::-1] + l[b:]
print(l) | Title: Report
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that... | ```python
n, m = map(int,input().split())
l = list(map(int,input().split()))
for i in range(m):
a, b = map(int,input().split())
x = sorted(l[0:b])
if(a == 1):
l = x + l[b:]
else:
l = x[::-1] + l[b:]
print(l)
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,666,394,812 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | word1= input()
word2 = input()
count = 0
if len(word1) == len(word2):
for i in range(len(word1)):
if word1[i] == word2[len(word1)-i-1]:
count += 1
else:
print("NO")
if count == len(word1):
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
word1= input()
word2 = input()
count = 0
if len(word1) == len(word2):
for i in range(len(word1)):
if word1[i] == word2[len(word1)-i-1]:
count += 1
else:
print("NO")
if count == len(word1):
print("YES")
else:
print("NO")
``` | 0 |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,697,829,466 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 61 | 1,331,200 | N, a, b, c = map(int, input().split())
n = N
m = [a, b, c]
m.sort()
if m[-1] % m[-2]:
m[-1] = m[-2]
if m[-2] % m[-3]:
m[-2] = m[-3]
r = 0
while n > m[-2]:
n -= m[0]
r += 1
if n in m or n == 0:
print(r+1)
exit()
n = 0
else:
n = N
r = 0
while n > m[-1]:
... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
N, a, b, c = map(int, input().split())
n = N
m = [a, b, c]
m.sort()
if m[-1] % m[-2]:
m[-1] = m[-2]
if m[-2] % m[-3]:
m[-2] = m[-3]
r = 0
while n > m[-2]:
n -= m[0]
r += 1
if n in m or n == 0:
print(r+1)
exit()
n = 0
else:
n = N
r = 0
while n > m[... | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,678,289,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int((a+b+c)/3)
s = 0
if a > d:
s = s + (a-d)
else:
s = s + (d-a)
if b > d:
s = s + (b-d)
else:
s = s + (d-b)
if c > d:
s = s + (c-d)
else:
s = s + (d-c)
print(s)
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int((a+b+c)/3)
s = 0
if a > d:
s = s + (a-d)
else:
s = s + (d-a)
if b > d:
s = s + (b-d)
else:
s = s + (d-b)
if c > d:
s = s + (c-d)
else:
s = s + (d-c)
print(s)
``` | 0 | |
43 | B | Letter | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ... | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces o... | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"... | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of doggi... | 1,607,279,627 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 409,600 | import sys
from collections import Counter
alphabet = sys.stdin.readline().replace(" ", "")
target = sys.stdin.readline().replace(" ", "")
aletters = Counter(alphabet)
tletters = Counter(target)
if all(aletters[L] >= tletters[L] for L in target):
print("YES")
else:
print("NO") | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to... | ```python
import sys
from collections import Counter
alphabet = sys.stdin.readline().replace(" ", "")
target = sys.stdin.readline().replace(" ", "")
aletters = Counter(alphabet)
tletters = Counter(target)
if all(aletters[L] >= tletters[L] for L in target):
print("YES")
else:
print("NO")
``` | 3.937237 |
718 | A | Efim and Strange Grade | PROGRAMMING | 1,700 | [
"dp",
"implementation",
"math"
] | null | null | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | The first line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*t*<=≤<=109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least on... | Print the maximum grade that Efim can get in *t* seconds. Do not print trailing zeroes. | [
"6 1\n10.245\n",
"6 2\n10.245\n",
"3 100\n9.2\n"
] | [
"10.25\n",
"10.3\n",
"9.2\n"
] | In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | 500 | [
{
"input": "6 1\n10.245",
"output": "10.25"
},
{
"input": "6 2\n10.245",
"output": "10.3"
},
{
"input": "3 100\n9.2",
"output": "9.2"
},
{
"input": "12 5\n872.04488525",
"output": "872.1"
},
{
"input": "35 8\n984227318.2031144444444444494637612",
"output": "98... | 1,609,315,223 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 9,011,200 | n, t = map(int, input().split())
s = input()
pp, ap = s.split('.')
pp = int(pp)
for i, c in enumerate(map(int, ap)):
if c >= 5:
break
t -= 1
rnd = len(ap)
if c >= 5:
rnd = i-1
while t>0 and rnd >= 0 and int(ap[rnd])+1 >= 5:
rnd -= 1
t -= 1
if rnd == -1:
p... | Title: Efim and Strange Grade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Th... | ```python
n, t = map(int, input().split())
s = input()
pp, ap = s.split('.')
pp = int(pp)
for i, c in enumerate(map(int, ap)):
if c >= 5:
break
t -= 1
rnd = len(ap)
if c >= 5:
rnd = i-1
while t>0 and rnd >= 0 and int(ap[rnd])+1 >= 5:
rnd -= 1
t -= 1
if rnd == ... | 0 | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,616,566,283 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 280 | 13,312,000 | try:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = []
b.sort()
r = sum(a)
if (b[len(b)-1] + b[len(b)-2]) >= r:
print("YES")
else:
print("NO")
except:
pass | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
try:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = []
b.sort()
r = sum(a)
if (b[len(b)-1] + b[len(b)-2]) >= r:
print("YES")
else:
print("NO")
except:
pass
``` | 3 | |
690 | A2 | Collective Mindsets (medium) | PROGRAMMING | 2,300 | [] | null | null | Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The ... | The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). | Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive. | [
"1\n",
"3\n",
"99\n"
] | [
"0\n",
"1\n",
"49\n"
] | none | 0 | [
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "2"
},
{
"input": "6",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{... | 1,628,909,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 6,758,400 | n = int(input())
print(int(n / 2)) | Title: Collective Mindsets (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the small... | ```python
n = int(input())
print(int(n / 2))
``` | 0 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,639,716,860 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 77 | 0 | s = int(input())
c = 0
for i in range(1,s):
if s%i==0:
c = c+1
print(c) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
s = int(input())
c = 0
for i in range(1,s):
if s%i==0:
c = c+1
print(c)
``` | 3 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,621,843,008 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print('Hello')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#5\n",
"n = int(input())\n",
"a = list(input()... | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print('Hello')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#5\n",
"n = int(input())\n",
"a = li... | -1 | |
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti... | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal... | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$.... | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
... | 1,530,456,970 | 3,070 | Python 3 | OK | TESTS | 34 | 124 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
ans = 0
b = []
for i in range(n - 2):
if a[i] % 2:
r += 1
else:
l += 1
if l == r:
b.append(abs(a[i] - a[i + 1]))
b = sorted(b)
for i in b:
if i <= m:
ans += 1
m -= ... | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Gi... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
ans = 0
b = []
for i in range(n - 2):
if a[i] % 2:
r += 1
else:
l += 1
if l == r:
b.append(abs(a[i] - a[i + 1]))
b = sorted(b)
for i in b:
if i <= m:
ans += 1
... | 3 | |
928 | B | Chat | PROGRAMMING | 1,400 | [
"*special",
"dp"
] | null | null | There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*i*), where *a**i* denotes the *i*-th message link... | Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible. | [
"6 0\n0 1 1 2 3 2\n",
"10 1\n0 1 0 3 4 5 2 3 7 0\n",
"2 2\n0 1\n"
] | [
"1 2 2 3 3 3 \n",
"2 3 3 4 5 6 6 6 8 2 \n",
"2 2 \n"
] | Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6. | 1,250 | [
{
"input": "6 0\n0 1 1 2 3 2",
"output": "1 2 2 3 3 3 "
},
{
"input": "10 1\n0 1 0 3 4 5 2 3 7 0",
"output": "2 3 3 4 5 6 6 6 8 2 "
},
{
"input": "2 2\n0 1",
"output": "2 2 "
},
{
"input": "1 1\n0",
"output": "1 "
},
{
"input": "5 2\n0 1 2 3 1",
"output": "3 4... | 1,616,229,186 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 61 | 307,200 | n, k = map(int, input().split())
p = list(map(int, input().split()))
arr_d = [0 for _ in range(n)]
for i in range(len(p)):
l_space = k if i - k >= 0 else i
r_space = k if i + k < len(p) else abs(len(p) - i - 1)
arr_d[i] += l_space + r_space + 1
if p[i] != 0:
arr_d[i] += arr_d[p[i] - 1]
... | Title: Chat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More form... | ```python
n, k = map(int, input().split())
p = list(map(int, input().split()))
arr_d = [0 for _ in range(n)]
for i in range(len(p)):
l_space = k if i - k >= 0 else i
r_space = k if i + k < len(p) else abs(len(p) - i - 1)
arr_d[i] += l_space + r_space + 1
if p[i] != 0:
arr_d[i] += arr_d[p... | 0 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,596,007,018 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 312 | 21,504,000 | import sys
n = int(input())
l = sorted([int(x) for x in input().split()])
for i in range(n):
if l[i] != i+1:
print(i+1)
sys.exit()
print(n+1) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
import sys
n = int(input())
l = sorted([int(x) for x in input().split()])
for i in range(n):
if l[i] != i+1:
print(i+1)
sys.exit()
print(n+1)
``` | 3.881946 |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,529,599,773 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | s=set(input())
print(26*(len(s)+1)-1) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
s=set(input())
print(26*(len(s)+1)-1)
``` | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,590,910,951 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 202 | 2,150,400 | n,a,b=list(map(int,input().split()))
c=[]
for i in range(1,n+1):
if a//i>0 and b//(n-i)>0:
c.append(min(a//i,b//(n-i)))
print(min(c)) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n,a,b=list(map(int,input().split()))
c=[]
for i in range(1,n+1):
if a//i>0 and b//(n-i)>0:
c.append(min(a//i,b//(n-i)))
print(min(c))
``` | -1 | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,601,835,372 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 46,284,800 | # import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
n = int(input())
m = int(input())
big = 100000007
first = m % big
second = pow(2,n) % big
ans = first % second
print(ans) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
# import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
n = int(input())
m = int(input())
big = 100000007
first = m % big
second = pow(2,n) % big
ans = first % second
print(ans)
``` | 0 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,684,523,046 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a = input() + input()
b = input()
list(a).sort()
list(b).sort()
if a == b:
print('YES')
else:
print('NO') | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
a = input() + input()
b = input()
list(a).sort()
list(b).sort()
if a == b:
print('YES')
else:
print('NO')
``` | 0 | |
460 | D | Little Victor and Set | PROGRAMMING | 2,300 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers *S* that has the following properties:
- for all *x* the following inequality holds *l*<=≤<=*x*<=≤<=*r*; - 1<=≤<=|*S*|<=≤<=*k*; - lets denot... | The first line contains three space-separated integers *l*,<=*r*,<=*k* (1<=≤<=*l*<=≤<=*r*<=≤<=1012; 1<=≤<=*k*<=≤<=*min*(106,<=*r*<=-<=*l*<=+<=1)). | Print the minimum possible value of *f*(*S*). Then print the cardinality of set |*S*|. Then print the elements of the set in any order.
If there are multiple optimal sets, you can print any of them. | [
"8 15 3\n",
"8 30 7\n"
] | [
"1\n2\n10 11\n",
"0\n5\n14 9 28 11 16\n"
] | Operation <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b364f2e04c665b78b924ec10666327a4ef4635bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | 2,000 | [
{
"input": "8 15 3",
"output": "1\n2\n10 11"
},
{
"input": "8 30 7",
"output": "0\n5\n14 9 28 11 16"
},
{
"input": "1 1 1",
"output": "1\n1\n1 "
},
{
"input": "3 987654321502 1",
"output": "3\n1\n3"
},
{
"input": "15603259690 63210239992 2",
"output": "1\n2\n1... | 1,693,517,819 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | from sys import exit
l,r,k=[int(e) for e in input().split()]
def B(i):
return [int(e) for e in bin(i)[2:][::-1]]
def S(l,r,i):
b=B(i)
return {l+j for j in range(len(b)) if b[j]==1 and l+j<=r}
def xor(s):
y=0
for e in s:
y^=e
return y
if r-l+1<=4:
A=[S(l,r,i) for i in ran... | Title: Little Victor and Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers *S* that has the following properties:... | ```python
from sys import exit
l,r,k=[int(e) for e in input().split()]
def B(i):
return [int(e) for e in bin(i)[2:][::-1]]
def S(l,r,i):
b=B(i)
return {l+j for j in range(len(b)) if b[j]==1 and l+j<=r}
def xor(s):
y=0
for e in s:
y^=e
return y
if r-l+1<=4:
A=[S(l,r,i) fo... | 0 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,645,696,480 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 102,400 | from collections import Counter
n=int(input())
arr=map(int, input().split())
d=dict(Counter(arr))
# print(d)
d[0]=d.get(0,0)
d[5]=d.get(5,0)
if(d[0]==0):
print(-1)
else:
n=d[5]
while(5*n%9!=0):
n-=1
if(n==0):
print(0)
else:
print('5'*n + '0'*d[0])
| Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
from collections import Counter
n=int(input())
arr=map(int, input().split())
d=dict(Counter(arr))
# print(d)
d[0]=d.get(0,0)
d[5]=d.get(5,0)
if(d[0]==0):
print(-1)
else:
n=d[5]
while(5*n%9!=0):
n-=1
if(n==0):
print(0)
else:
print('5'*n + '0'*d[0])
``` | 3 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,665,032,760 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 5 23:42:17 2022
@author: lpf
"""
n,m=map(int,input().split())
lst=[int(x)for x in input().split()]
lst.append(m);lst.insert(0,0)
time=[lst[i+1]-lst[i]for i in range(0,len(lst)-1)]
answ=0
def answer(x):
y=0
for k in range(0,len(x),2):
y+=x[... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 5 23:42:17 2022
@author: lpf
"""
n,m=map(int,input().split())
lst=[int(x)for x in input().split()]
lst.append(m);lst.insert(0,0)
time=[lst[i+1]-lst[i]for i in range(0,len(lst)-1)]
answ=0
def answer(x):
y=0
for k in range(0,len(x),2):
... | 0 | |
440 | C | One-Based Arithmetic | PROGRAMMING | 1,800 | [
"brute force",
"dfs and similar",
"divide and conquer"
] | null | null | Prof. Vasechkin wants to represent positive integer *n* as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum. | The first line of the input contains integer *n* (1<=≤<=*n*<=<<=1015). | Print expected minimal number of digits 1. | [
"121\n"
] | [
"6\n"
] | none | 1,500 | [
{
"input": "121",
"output": "6"
},
{
"input": "10",
"output": "3"
},
{
"input": "72",
"output": "15"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input": "4",
"output": "4"
}... | 1,673,793,522 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 93 | 5,939,200 | def count_digits(n):
if n <= 3:
return n
rem = n % 11
if rem == 0:
return 3 * (n // 11)
if rem == 1:
return 3 * (n // 11) + 1 + count_digits(n % 10)
return 3 * (n // 11) + count_digits(n % 11)
def sod(n):
sum=0
while n>0:
d=n%10
... | Title: One-Based Arithmetic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Prof. Vasechkin wants to represent positive integer *n* as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the leas... | ```python
def count_digits(n):
if n <= 3:
return n
rem = n % 11
if rem == 0:
return 3 * (n // 11)
if rem == 1:
return 3 * (n // 11) + 1 + count_digits(n % 10)
return 3 * (n // 11) + count_digits(n % 11)
def sod(n):
sum=0
while n>0:
... | -1 | |
535 | A | Tavas and Nafas | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without... | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | 500 | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
... | 1,493,131,282 | 2,147,483,647 | Python 3 | OK | TESTS | 100 | 77 | 5,529,600 | word = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty... | Title: Tavas and Nafas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit... | ```python
word = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', ... | 3 | |
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXX... | 1,588,766,942 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 307,200 | # https://codeforces.com/contest/424/problem/A
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n = single_integer()
x_string = string()
x_count = 0
X_co... | Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to ... | ```python
# https://codeforces.com/contest/424/problem/A
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n = single_integer()
x_string = string()
x_count... | 0 | |
407 | B | Long Path | PROGRAMMING | 1,600 | [
"dp",
"implementation"
] | null | null | One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider roo... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of rooms. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*i*). Each *p**i* denotes the number of the room, that someone can reach, if he will use the second portal in the *i*-th room. | Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"2\n1 2\n",
"4\n1 1 2 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"20\n",
"62\n"
] | none | 1,000 | [
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "20"
},
{
"input": "5\n1 1 1 1 1",
"output": "62"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "154"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "3\n1 1 3",
"output": "8"... | 1,696,001,142 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | MOD = 1000000007
def solve(n, portals):
dp = [0] * (n + 2)
for i in range(2, n + 2):
dp[i] = (dp[portals[i - 2]] + 1) if (i - 2) % 2 == dp[i - 1] % 2 else dp[i - 1] + 1
return dp[n + 1] % MOD
# Ввод данных
n = int(input())
portals = list(map(int, input().split()))
# Решени... | Title: Long Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The ... | ```python
MOD = 1000000007
def solve(n, portals):
dp = [0] * (n + 2)
for i in range(2, n + 2):
dp[i] = (dp[portals[i - 2]] + 1) if (i - 2) % 2 == dp[i - 1] % 2 else dp[i - 1] + 1
return dp[n + 1] % MOD
# Ввод данных
n = int(input())
portals = list(map(int, input().split()))
... | 0 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,699,085,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a = 'NO'
for i in range(3):
b = input()
if ((i==0 or i==2) and (b.count('a')+b.count('e')+b.count('i')+b.count('o')+b.count('u'))==5) or ((i==1) and (b.count('a')+b.count('e')+b.count('i')+b.count('o')+b.count('u'))==7):
a = 'YES'
else:
a = 'NO'
break | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
a = 'NO'
for i in range(3):
b = input()
if ((i==0 or i==2) and (b.count('a')+b.count('e')+b.count('i')+b.count('o')+b.count('u'))==5) or ((i==1) and (b.count('a')+b.count('e')+b.count('i')+b.count('o')+b.count('u'))==7):
a = 'YES'
else:
a = 'NO'
break
``` | 0 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,688,822,988 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | a = int(input())
l = [[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
for i in range(a):
b = input().split()
for j in range(3):
l[i][j] = int(b[j])
count = 0
for i in range(3):
summ = 0
for j in range(a):
summ += l[j][i]
if summ == 0:
count += 1
if count... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
a = int(input())
l = [[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
for i in range(a):
b = input().split()
for j in range(3):
l[i][j] = int(b[j])
count = 0
for i in range(3):
summ = 0
for j in range(a):
summ += l[j][i]
if summ == 0:
count += 1
... | -1 |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,651,633,482 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
long long b = 0, c = 0, s = 0; string f; cin >> f;
for(auto u: f){
if(u == 'B') b++;
if(u == 'C') c++;
if(u == 'S') s++;
}
long long nb, ns, nc, pb, ps, pc; cin >> nb >> ns >> nc >> pb >> ps >> pc;
long long r; cin >... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
#include <bits/stdc++.h>
using namespace std;
int main(){
long long b = 0, c = 0, s = 0; string f; cin >> f;
for(auto u: f){
if(u == 'B') b++;
if(u == 'C') c++;
if(u == 'S') s++;
}
long long nb, ns, nc, pb, ps, pc; cin >> nb >> ns >> nc >> pb >> ps >> pc;
long lon... | -1 |
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.