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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,662,511,859 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | input()
nums = list(map(int, input().split()))
set_nums = sorted(set(nums))
ans = []
for num in set_nums:
count = nums.count(num)
if count == 1:
ans.append((num, 0))
continue
indexes = [nums.index(num)]
for _ in range(count - 1):
indexes.append(nums.index(num, indexes[... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
input()
nums = list(map(int, input().split()))
set_nums = sorted(set(nums))
ans = []
for num in set_nums:
count = nums.count(num)
if count == 1:
ans.append((num, 0))
continue
indexes = [nums.index(num)]
for _ in range(count - 1):
indexes.append(nums.index(num... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,541,394,245 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | a=input()
b=len(a)
n=0
for i in range(b):
c=a[i]
if n==0:
if c=='h':
n+=1
if n==1:
if c=='e':
n+=1
if n==2:
if c=='l':
n+=1
if n==3:
if c=='l':
n+=1
if n==4:
if c=='o':
n+=1
if... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a=input()
b=len(a)
n=0
for i in range(b):
c=a[i]
if n==0:
if c=='h':
n+=1
if n==1:
if c=='e':
n+=1
if n==2:
if c=='l':
n+=1
if n==3:
if c=='l':
n+=1
if n==4:
if c=='o':
... | 0 |
87 | A | Trains | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | A. Trains | 2 | 256 | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls ... | 500 | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 1,672,120,025 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | def ss(a,b):
if 2*a<b:
return 1
return 0
a,b = map(int,input().split())
if a<b:
if ss(a,b):
print("Dasha")
else:
print("Equal")
else:
if ss(b,a)==0:
print("Equal")
else:
print("Masha") | Title: Trains
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some... | ```python
def ss(a,b):
if 2*a<b:
return 1
return 0
a,b = map(int,input().split())
if a<b:
if ss(a,b):
print("Dasha")
else:
print("Equal")
else:
if ss(b,a)==0:
print("Equal")
else:
print("Masha")
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,589,970,789 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 307,200 | patern="hello"
def calc(str):
arr=[-1]
for i in str :
arr.append(-1)
for i in range(1,len(str)+1):
for j in range(0,i):
if arr[j]==-1:
if str[i-1]==patern[0]:
arr[i]=max(0,arr[i])
else :
arr[i]=max(-1,arr[i]... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
patern="hello"
def calc(str):
arr=[-1]
for i in str :
arr.append(-1)
for i in range(1,len(str)+1):
for j in range(0,i):
if arr[j]==-1:
if str[i-1]==patern[0]:
arr[i]=max(0,arr[i])
else :
arr[i]=max... | 3.937428 |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,628,946,907 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 6,758,400 | n = int(input())
s = input().split()
ans = 0
for i in range(1, n + 1) :
x = int(s[i - 1])
ans += (x - 1) * (i - 1) + x
print(ans) | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
n = int(input())
s = input().split()
ans = 0
for i in range(1, n + 1) :
x = int(s[i - 1])
ans += (x - 1) * (i - 1) + x
print(ans)
``` | 3.948911 |
0 | none | none | none | 0 | [
"none"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 0 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,409,066,639 | 5,039 | Python 3 | OK | TESTS | 36 | 451 | 20,172,800 | n = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
psum = [0]*n
psum[0] = num[0]
for i in range(1, n):
psum[i] = psum[i-1]+num[i]
print(sum(psum[1:])+psum[n-1])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and ... | ```python
n = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
psum = [0]*n
psum[0] = num[0]
for i in range(1, n):
psum[i] = psum[i-1]+num[i]
print(sum(psum[1:])+psum[n-1])
``` | 3 | |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,683,213,085 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
N,K,D = map(int, input().split())
dp = [0]*(N+1)
dp2 = [0]*(N+1)
dp[0] = 1
for i in range(N):
for j in range(1,K+1):
if i+j>N:break
if j<D:
dp[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
else:
dp2[... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N,K,D = map(int, input().split())
dp = [0]*(N+1)
dp2 = [0]*(N+1)
dp[0] = 1
for i in range(N):
for j in range(1,K+1):
if i+j>N:break
if j<D:
dp[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
else:
... | 0 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,633,958,796 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 23 | 78 | 6,758,400 | p,n=map(str, input().split())
x=p[0]
for i in range(1,len(p)):
if p[i]<=n[0]:
x=x+p[i]
else:
break
x=x+n[0]
print(x)
| Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
p,n=map(str, input().split())
x=p[0]
for i in range(1,len(p)):
if p[i]<=n[0]:
x=x+p[i]
else:
break
x=x+n[0]
print(x)
``` | 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,679,724,961 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | import math
n = int(input())
c = 0
for i in range(1, n+1):
if (n-i >= i):
if ((n-i) % i == 0):
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
import math
n = int(input())
c = 0
for i in range(1, n+1):
if (n-i >= i):
if ((n-i) % i == 0):
c += 1
print(c)
``` | 3 | |
622 | C | Not Equal on a Segment | PROGRAMMING | 1,700 | [
"data structures",
"implementation"
] | null | null | You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=... | Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number. | [
"6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n"
] | [
"2\n6\n-1\n4\n"
] | none | 0 | [
{
"input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2",
"output": "2\n6\n-1\n4"
},
{
"input": "1 1\n1\n1 1 1",
"output": "-1"
},
{
"input": "1 1\n2\n1 1 2",
"output": "-1"
},
{
"input": "1 1\n569888\n1 1 967368",
"output": "1"
},
{
"input": "10 10\n1 1 1 1 1 1 ... | 1,463,411,282 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 32,665,600 | i=input().split()
n,m=int(i[0]),int(i[1])
l=input().split()
for i in range(m):
j=input().split()
a,b,x=int(j[0]),int(j[1]),j[2]
if x==tuple(set(l[a-1:b]))[0] and len(set(l[a-1:b]))==1:
print(-1)
else:
for j in range(a-1,b)[::-1]:
if l[j]!=x:
print(j... | Title: Not Equal on a Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so ... | ```python
i=input().split()
n,m=int(i[0]),int(i[1])
l=input().split()
for i in range(m):
j=input().split()
a,b,x=int(j[0]),int(j[1]),j[2]
if x==tuple(set(l[a-1:b]))[0] and len(set(l[a-1:b]))==1:
print(-1)
else:
for j in range(a-1,b)[::-1]:
if l[j]!=x:
... | 0 | |
49 | B | Sum | PROGRAMMING | 1,500 | [
"math"
] | B. Sum | 2 | 256 | Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the... | The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands. | Print a single number — the length of the longest answer. | [
"78 87\n",
"1 1\n"
] | [
"3\n",
"2\n"
] | none | 1,000 | [
{
"input": "78 87",
"output": "3"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "9 7",
"output": "2"
},
{
"input": "11 11",
"output": "3"
},
{
"input": "43 21",
"output": "3"
},
{
"input": "84 89",
"output": "3"
},
{
"input": "12 34",
... | 1,563,395,235 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 248 | 0 | from math import log, floor
a, b = input().rstrip().split()
for i in reversed(range(1, 10)):
if str(i) in a+b:
print(floor(
log(int(a, i + 1) + int(b, i + 1), i + 1)
)+1)
break
| Title: Sum
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positiona... | ```python
from math import log, floor
a, b = input().rstrip().split()
for i in reversed(range(1, 10)):
if str(i) in a+b:
print(floor(
log(int(a, i + 1) + int(b, i + 1), i + 1)
)+1)
break
``` | 0 |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,624,119,056 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 154 | 0 | import math
n,x,y=map(int,input().split())
k=math.ceil(y*n/100)
if k>x:
print(k-x)
else:
print(0)
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
import math
n,x,y=map(int,input().split())
k=math.ceil(y*n/100)
if k>x:
print(k-x)
else:
print(0)
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,644,722,440 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 154 | 307,200 | def solve(k, s):
from collections import Counter
d = Counter(s)
for i in d:
if d[i]==k:
continue
else:
return -1
ans = ""
while k:
for i in d:
if d[i]>0:
ans+=i
d[i]-=1
k-=1
return ... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
def solve(k, s):
from collections import Counter
d = Counter(s)
for i in d:
if d[i]==k:
continue
else:
return -1
ans = ""
while k:
for i in d:
if d[i]>0:
ans+=i
d[i]-=1
k-=1
... | 0 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,696,744,820 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | mat = []
res = 0
for _ in range(5):
mat.append(list(map(int, input().split())))
for i in range(5):
for j in range(5):
if mat[i][j] == 1:
res = abs(3 - i) + abs(3 - j)
print(res)
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
mat = []
res = 0
for _ in range(5):
mat.append(list(map(int, input().split())))
for i in range(5):
for j in range(5):
if mat[i][j] == 1:
res = abs(3 - i) + abs(3 - j)
print(res)
``` | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,595,762,504 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 310 | 22,118,400 | n=input()
k=0
while (len(n)!=1):
s=0
for i in n:
s+=int(i)
n=str(s)
k+=1
print(k) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
n=input()
k=0
while (len(n)!=1):
s=0
for i in n:
s+=int(i)
n=str(s)
k+=1
print(k)
``` | 3.8827 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,656,357,161 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 61 | 4,300,800 | n,m,a = map(int, input().split())
if n % a > 0:
b = n//a + 1
else:
b = n//a
if m % a > 0:
c = m//a + 1
else:
c = m//a
print(b*c) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a = map(int, input().split())
if n % a > 0:
b = n//a + 1
else:
b = n//a
if m % a > 0:
c = m//a + 1
else:
c = m//a
print(b*c)
``` | 3.961489 |
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,667,227,294 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 78 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a = list(map(int, input().split()))
s = sum(a)
ans = "NO"
for i in range(6):
for j in range(i + 1, 6):
for k in range(j + 1, 6):
if 2 * (a[i] + a[j] + a[k]) == s:
ans = "YES"
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a = list(map(int, input().split()))
s = sum(a)
ans = "NO"
for i in range(6):
for j in range(i + 1, 6):
for k in range(j + 1, 6):
if 2 * (a[i] + a[j] + a[k]) == s:
ans = "YES"
pri... | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,396,364,715 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | qNumbers = int(input())
k = list(map(int, raw_input().split()))
minScnds = k[0] * 15
itms = list(map(int, raw_input().split()))
for i in range(k[0]):
minScnds += itms[i] * 5
for i in range(1, qNumbers):
scnds = k[i] * 15
itms = list(map(int, raw_input().split()))
for j in range(k[... | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
qNumbers = int(input())
k = list(map(int, raw_input().split()))
minScnds = k[0] * 15
itms = list(map(int, raw_input().split()))
for i in range(k[0]):
minScnds += itms[i] * 5
for i in range(1, qNumbers):
scnds = k[i] * 15
itms = list(map(int, raw_input().split()))
for j i... | -1 | |
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,589,006,908 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 6,656,000 | import sys
input = sys.stdin.readline
def insr():
return input()[:-1:]
def solve(a, b):
l = len(a)
res = ""
for c in range(l):
res += str(int(a[c]) ^ int(b[c]))
return res
if __name__ == '__main__':
a = insr()
b = insr()
print(solve(a,b)) | 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
import sys
input = sys.stdin.readline
def insr():
return input()[:-1:]
def solve(a, b):
l = len(a)
res = ""
for c in range(l):
res += str(int(a[c]) ^ int(b[c]))
return res
if __name__ == '__main__':
a = insr()
b = insr()
print(solve(a,b))
``` | 3.956602 |
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,696,316,571 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | a,b,c=map(int,input().split())
m=a+b+c
if((2*a)+(2*b)<m):
m=(2*a)+(2*b)
elif((2*a)+(2*c)<m):
m=(2*a)+(2*c)
elif((2*b)+(2*c)<m):
m=(2*c)+(2*b)
print(m) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a,b,c=map(int,input().split())
m=a+b+c
if((2*a)+(2*b)<m):
m=(2*a)+(2*b)
elif((2*a)+(2*c)<m):
m=(2*a)+(2*c)
elif((2*b)+(2*c)<m):
m=(2*c)+(2*b)
print(m)
``` | 3 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,670,699,769 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | import sys
from math import ceil
input = sys.stdin.readline
def nth(a, n, d):
return a + (n - 1) * d
a, b, c = [int(x) for x in input().split()]
ans = "NO"
low = a
high = b
mid = ceil((low + high) / 2)
while low < high:
res = nth(a, mid, c)
if res < b:
break
#print(res)
if res == b:
... | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
import sys
from math import ceil
input = sys.stdin.readline
def nth(a, n, d):
return a + (n - 1) * d
a, b, c = [int(x) for x in input().split()]
ans = "NO"
low = a
high = b
mid = ceil((low + high) / 2)
while low < high:
res = nth(a, mid, c)
if res < b:
break
#print(res)
if res ==... | 0 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,578,033,792 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | from math import ceil
r,x1,y1,x2,y2 = map(int, input().split())
dist = ((x2-x1)**2 + (y2-y1)**2)**(0.5)
ans = int(ceil(dist/(2*r)))
print(ans)
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
from math import ceil
r,x1,y1,x2,y2 = map(int, input().split())
dist = ((x2-x1)**2 + (y2-y1)**2)**(0.5)
ans = int(ceil(dist/(2*r)))
print(ans)
``` | 3 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,446,312,803 | 3,803 | Python 3 | OK | TESTS | 114 | 62 | 0 | def gcd(a, b):
if (b == 0):
return a
return gcd(b, a % b)
s = input()
s = s.split()
t = int(s[0])
w = int(s[1])
b = int(s[2])
g = gcd(w, b)
w = w // g
r = w * b
w = w * g
k = (t // r) + 1
ans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w, b) - 1)
ng = gcd(ans, t)
print(ans... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
def gcd(a, b):
if (b == 0):
return a
return gcd(b, a % b)
s = input()
s = s.split()
t = int(s[0])
w = int(s[1])
b = int(s[2])
g = gcd(w, b)
w = w // g
r = w * b
w = w * g
k = (t // r) + 1
ans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w, b) - 1)
ng = gcd(ans, t)
... | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,690,418,627 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 61 | 0 | k , r = input().split()
k,r=int(k),int(r)
n = 1
while True:
m = k*n
if(m-((m//10)*10) == r or m-((m//10)*10) == 0):
break
n += 1
print(n)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k , r = input().split()
k,r=int(k),int(r)
n = 1
while True:
m = k*n
if(m-((m//10)*10) == r or m-((m//10)*10) == 0):
break
n += 1
print(n)
``` | 3 | |
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output"... | 1,626,838,371 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 6,758,400 | [A,B] = map(int, input().split())
[x,y,z] = map(int, input().split())
yellow=x*2+y
blue=y+3*z
if yellow>=A:
ya=yellow-A
else:
ya=0
if blue>=B:
bl=blue-B
else:
bl=0
print (ya+bl) | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obta... | ```python
[A,B] = map(int, input().split())
[x,y,z] = map(int, input().split())
yellow=x*2+y
blue=y+3*z
if yellow>=A:
ya=yellow-A
else:
ya=0
if blue>=B:
bl=blue-B
else:
bl=0
print (ya+bl)
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,657,782,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 92 | 102,400 | import collections
n=int(input())
s=input()
t=''
d=collections.Counter(s)
k=list(d.keys())
v=list(d.values())
c=0
for i in range(len(v)):
if v[i]%n==0:
c+=1
else:
print(-1)
break
if c==len(v):
for i in range(len(k)):
t+=k[i]
print(t*n)
| Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
import collections
n=int(input())
s=input()
t=''
d=collections.Counter(s)
k=list(d.keys())
v=list(d.values())
c=0
for i in range(len(v)):
if v[i]%n==0:
c+=1
else:
print(-1)
break
if c==len(v):
for i in range(len(k)):
t+=k[i]
print(t*n)
``` | 0 | |
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result... | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"in... | 1,487,218,439 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 61 | 4,608,000 | val = lambda c : ord(c) - ord('a')
visited = [False]*(26)
c = 'abcdefghijklmnopqrtuvwxyz'
s = input()
ans = True
for x in s :
if visited[val(x)] : continue
i = 0
flag = True
while c[i] != x :
if not visited[i] :
flag = False
break
i += 1
visited[val(x)] = True
if not flag:
ans = Fals... | Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont... | ```python
val = lambda c : ord(c) - ord('a')
visited = [False]*(26)
c = 'abcdefghijklmnopqrtuvwxyz'
s = input()
ans = True
for x in s :
if visited[val(x)] : continue
i = 0
flag = True
while c[i] != x :
if not visited[i] :
flag = False
break
i += 1
visited[val(x)] = True
if not flag:
... | 0 | |
526 | B | Om Nom and Dark Park | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"implementation"
] | null | null | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so... | The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on th... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | [
"2\n1 2 3 4 5 6\n"
] | [
"5\n"
] | Picture for the sample test. Green color denotes the additional street lights. | 500 | [
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"... | 1,428,674,070 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | from operator import itemgetter
def prepare(a, n):
res = 0
for i in range(len(a) - 1):
a[i][1] = a[i//2 - 1][1] + a[i][0]
mx = max(a[2**n - 2:2**(n + 1) - 2], key=itemgetter(1))[1]
for i in range(2**n - 2, 2**(n + 1) - 2):
a[i][1] = mx - a[i][1]
for i in range(2**n ... | Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless a... | ```python
from operator import itemgetter
def prepare(a, n):
res = 0
for i in range(len(a) - 1):
a[i][1] = a[i//2 - 1][1] + a[i][0]
mx = max(a[2**n - 2:2**(n + 1) - 2], key=itemgetter(1))[1]
for i in range(2**n - 2, 2**(n + 1) - 2):
a[i][1] = mx - a[i][1]
for i in r... | 0 | |
14 | C | Four Segments | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr... | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
... | 1,691,593,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | # LUOGU_RID: 119974760
lines = []
for i in range(4):
x1, y1, x2, y2 = map(int, input().split())
x, y = abs(x1 - x2), abs(y1 - y2)
if y == 0:
lines.append(x)
else:
lines.append(-y)
li = list(set(lines))
if len(li) == 1:
print("YES")
elif len(li) != 2:
print("NO")
else:
if line... | Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creati... | ```python
# LUOGU_RID: 119974760
lines = []
for i in range(4):
x1, y1, x2, y2 = map(int, input().split())
x, y = abs(x1 - x2), abs(y1 - y2)
if y == 0:
lines.append(x)
else:
lines.append(-y)
li = list(set(lines))
if len(li) == 1:
print("YES")
elif len(li) != 2:
print("NO")
else:
... | 0 |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,671,901,300 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 102,400 | t=int(input())
l=[]
r=[]
for i in range(t):
l1,r1=list(map(int, input().split()))
l.append(l1)
r.append(r1)
l0=l.count(0)
l1=l.count(1)
r0=r.count(0)
r1=r.count(1)
print(min(l0,l1)+min(r0,r1)) | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
t=int(input())
l=[]
r=[]
for i in range(t):
l1,r1=list(map(int, input().split()))
l.append(l1)
r.append(r1)
l0=l.count(0)
l1=l.count(1)
r0=r.count(0)
r1=r.count(1)
print(min(l0,l1)+min(r0,r1))
``` | 3 | |
868 | D | Huge Strings | PROGRAMMING | 2,200 | [
"bitmasks",
"brute force",
"dp",
"implementation",
"strings"
] | null | null | You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concatenation *s**a**i**s**b**i* is saved into a new string *s**n*<=+<=*i* (the operations are numbered st... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of strings. The next *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=|*s**i*|<=≤<=100), one per line. The total length of strings is not greater than 100.
The next line contains single integer *m* (1<=≤<=*m*<=≤<=100) — the number o... | Print *m* lines, each should contain one integer — the answer to the question after the corresponding operation. | [
"5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n"
] | [
"1\n2\n0\n"
] | On the first operation, a new string "0110" is created. For *k* = 1 the two possible binary strings of length *k* are "0" and "1", they are substrings of the new string. For *k* = 2 and greater there exist strings of length *k* that do not appear in this string (for *k* = 2 such string is "00"). So the answer is 1.
On... | 1,500 | [
{
"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4",
"output": "1\n2\n0"
},
{
"input": "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7",
"output": "1\n1\n1\n2\n1\n2"
},
{
"input": "5\n111101000111100011100110000100\n000111001\n01101000\n000011010010001001100100000001010010011... | 1,570,803,378 | 7,878 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 20 | 810 | 268,390,400 | n = int(input())
data = []
for i in range(n):
data.append(input())
m = int(input())
for q in range(m):
u, v = map(int, input().split())
tmp = data[u-1] + data[v-1]
data.append(tmp)
for k in range(1, 100):
flag = True
for j in range(0, 2**k):
b = bin(j)[2:]
b = "0"*(k-len(b)) + b
if b not... | Title: Huge Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concaten... | ```python
n = int(input())
data = []
for i in range(n):
data.append(input())
m = int(input())
for q in range(m):
u, v = map(int, input().split())
tmp = data[u-1] + data[v-1]
data.append(tmp)
for k in range(1, 100):
flag = True
for j in range(0, 2**k):
b = bin(j)[2:]
b = "0"*(k-len(b)) + b
... | 0 | |
219 | D | Choosing Capital for Treeland | PROGRAMMING | 1,700 | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decid... | The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connect... | In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order. | [
"3\n2 1\n2 3\n",
"4\n1 4\n2 4\n3 4\n"
] | [
"0\n2 \n",
"2\n1 2 3 \n"
] | none | 2,000 | [
{
"input": "3\n2 1\n2 3",
"output": "0\n2 "
},
{
"input": "4\n1 4\n2 4\n3 4",
"output": "2\n1 2 3 "
},
{
"input": "2\n1 2",
"output": "0\n1 "
},
{
"input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7",
"output": "3\n4 6 8 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4... | 1,678,200,348 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 7 | 2,464 | 41,574,400 | def solve():
n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
v, w = list(map(int, input().split()))
g[v].append((w, 1))
g[w].append((v, -1))
rev1 = 0
def f(v, fa):
nonlocal rev1
for to, dir in g[v]:
if to != f... | Title: Choosing Capital for Treeland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the... | ```python
def solve():
n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
v, w = list(map(int, input().split()))
g[v].append((w, 1))
g[w].append((v, -1))
rev1 = 0
def f(v, fa):
nonlocal rev1
for to, dir in g[v]:
... | -1 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,674,999,581 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 187 | 8,396,800 | n = int(input())
n = str(n)
nn = n[::-1]
res = ''
res += n
res += nn
print(res) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
n = int(input())
n = str(n)
nn = n[::-1]
res = ''
res += n
res += nn
print(res)
``` | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,686,016,579 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | _ = input()
l_w = list(map(int, input().split()))
m = max(l_w)
t = 0
for w in l_w:
t += m - w
print(t) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
_ = input()
l_w = list(map(int, input().split()))
m = max(l_w)
t = 0
for w in l_w:
t += m - w
print(t)
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,691,142,648 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 |
n= int(input())
capacity=0
current=0
while(n):
a=int(input())
b=int(input())
current=current-a
current=current+b
if(current>capacity):
capacity=current
n-=1
print(capacity)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n= int(input())
capacity=0
current=0
while(n):
a=int(input())
b=int(input())
current=current-a
current=current+b
if(current>capacity):
capacity=current
n-=1
print(capacity)
``` | -1 | |
999 | F | Cards and Joy | PROGRAMMING | 2,000 | [
"dp"
] | null | null | There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning... | The first line of input contains two integers $n$ and $k$ ($1 \le n \le 500, 1 \le k \le 10$) — the number of players and the number of cards each player will get.
The second line contains $k \cdot n$ integers $c_1, c_2, \dots, c_{k \cdot n}$ ($1 \le c_i \le 10^5$) — the numbers written on the cards.
The third line c... | Print one integer — the maximum possible total joy levels of the players among all possible card distributions. | [
"4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n",
"3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n"
] | [
"21\n",
"0\n"
] | In the first example, one possible optimal card distribution is the following:
- Player $1$ gets cards with numbers $[1, 3, 8]$; - Player $2$ gets cards with numbers $[2, 2, 8]$; - Player $3$ gets cards with numbers $[2, 2, 8]$; - Player $4$ gets cards with numbers $[5, 5, 5]$.
Thus, the answer is $2 + 6 + 6 + 7 ... | 0 | [
{
"input": "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7",
"output": "21"
},
{
"input": "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3",
"output": "0"
},
{
"input": "1 1\n1\n2\n1",
"output": "0"
},
{
"input": "1 1\n1\n1\n1",
"output": "1"
},
{
"input": "1 1\n1\n1\n100000",... | 1,659,840,195 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 63,385,600 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
cards = list(map(int, input().split()))
favorites = list(map(int, input().split... | Title: Cards and Joy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i... | ```python
from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
cards = list(map(int, input().split()))
favorites = list(map(int, inp... | 0 | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,652,378,449 | 49 | Python 3 | OK | TESTS | 11 | 296 | 36,864,000 | d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a, b = map(int, input().split())
nums = str(list(range(a, b+1)))
r = 0
for i in range(len(d)):
r += d[i] * nums.count(str(i))
print(r) | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a, b = map(int, input().split())
nums = str(list(range(a, b+1)))
r = 0
for i in range(len(d)):
r += d[i] * nums.count(str(i))
print(r)
``` | 3 | |
374 | B | Inna and Nine | PROGRAMMING | 1,500 | [
"combinatorics",
"greedy"
] | null | null | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nin... | The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"369727\n",
"123456789987654321\n",
"1\n"
] | [
"2\n",
"1\n",
"1\n"
] | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | 1,000 | [
{
"input": "369727",
"output": "2"
},
{
"input": "123456789987654321",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "3636363636363454545454543636363636454545452727272727218181818181999111777",
"output": "1512"
},
{
"input": "1188",
"output": "1... | 1,655,011,389 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 655 | 11,264,000 | R=lambda:map(int,input().split())
import math as m
s=input()
a=[]
f=''
for i in range(1,len(s)):
if(int(s[i])+int(s[i-1])==9):
f+=s[i-1]
else:
f+=s[i-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(len(f))
... | Title: Inna and Nine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants... | ```python
R=lambda:map(int,input().split())
import math as m
s=input()
a=[]
f=''
for i in range(1,len(s)):
if(int(s[i])+int(s[i-1])==9):
f+=s[i-1]
else:
f+=s[i-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(l... | 3 | |
877 | C | Slava and tanks | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map. | In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them. | [
"2\n",
"3\n"
] | [
"3\n2 1 2 ",
"4\n2 1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "3\n2 1 2 "
},
{
"input": "3",
"output": "4\n2 1 3 2 "
},
{
"input": "4",
"output": "6\n2 4 1 3 2 4 "
},
{
"input": "6",
"output": "9\n2 4 6 1 3 5 2 4 6 "
},
{
"input": "10",
"output": "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 "
},
{
... | 1,614,024,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | mapSize = int(input())
subTargets = []
target = ''
for i in range(mapSize + 1):
if i > 1:
subTargets.append(i)
subTargets.sort(reverse = True)
subTargets.insert(0, 1)
subTargets.insert(0, 2)
for i in subTargets:
target += str(i) + ' '
print(len(subTargets))
print(target)
... | Title: Slava and tanks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there... | ```python
mapSize = int(input())
subTargets = []
target = ''
for i in range(mapSize + 1):
if i > 1:
subTargets.append(i)
subTargets.sort(reverse = True)
subTargets.insert(0, 1)
subTargets.insert(0, 2)
for i in subTargets:
target += str(i) + ' '
print(len(subTargets))
print(target)
... | 0 | |
645 | A | Amity Assessment | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the ... | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaran... | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | 500 | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC... | 1,458,371,654 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 5,120,000 | def main():
res = []
for _ in 0, 1:
a, b = input()
d, c = input()
res.append([x for x in (a, b, c, d) if x != 'X'])
a, b = res
print(("NO", "YES")[b[b.index(a[0]) - 1] == a[2]])
if __name__ == '__main__':
main()
| Title: Amity Assessment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one ... | ```python
def main():
res = []
for _ in 0, 1:
a, b = input()
d, c = input()
res.append([x for x in (a, b, c, d) if x != 'X'])
a, b = res
print(("NO", "YES")[b[b.index(a[0]) - 1] == a[2]])
if __name__ == '__main__':
main()
``` | 3 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,615,371,202 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 11,980,800 | n=int(input())
ls=[]
for _ in range(n):
s=int(input())
ls.append(s)
ls.sort()
cnt=0
mid=n//2-1
right=n-1
mated=0
for _ in range(n//2):
if ls[right]>=2*ls[mid] and mid>=0:
cnt+=1
mid-=1
right-=1
mated+=2
else:
mid-=1
print(cnt+n-mated)
| Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
n=int(input())
ls=[]
for _ in range(n):
s=int(input())
ls.append(s)
ls.sort()
cnt=0
mid=n//2-1
right=n-1
mated=0
for _ in range(n//2):
if ls[right]>=2*ls[mid] and mid>=0:
cnt+=1
mid-=1
right-=1
mated+=2
else:
mid-=1
print(cnt+n-mated)
... | 0 | |
22 | E | Scheme | PROGRAMMING | 2,300 | [
"dfs and similar",
"graphs",
"trees"
] | E. Scheme | 2 | 256 | To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem... | The first input line contains number *n* (2<=≤<=*n*<=≤<=105) — amount of BolgenOS community members. The second line contains *n* space-separated integer numbers *f**i* (1<=≤<=*f**i*<=≤<=*n*,<=*i*<=≠<=*f**i*) — index of a person, to whom calls a person with index *i*. | In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any. | [
"3\n3 3 2\n",
"7\n2 3 1 3 4 4 1\n"
] | [
"1\n3 1\n",
"3\n2 5\n2 6\n3 7\n"
] | none | 0 | [
{
"input": "3\n3 3 2",
"output": "1\n3 1"
},
{
"input": "7\n2 3 1 3 4 4 1",
"output": "3\n1 5\n1 6\n1 7"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "3\n2 3 1",
"output": "0"
},
{
"input": "4\n2 4 4 3",
"output": "1\n4 1"
},
{
"input": "5\n5 3 ... | 1,649,791,042 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 154 | 0 | N=int(input())
A=list(map(int,input().split()))
# UnionFind
Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
... | Title: Scheme
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first t... | ```python
N=int(input())
A=list(map(int,input().split()))
# UnionFind
Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
... | 0 |
976 | C | Nested Segments | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. | Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | [
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] | [
"2 1\n",
"-1 -1\n"
] | In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | 0 | [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n5000000... | 1,525,391,470 | 2,147,483,647 | PyPy 3 | OK | TESTS | 122 | 1,497 | 73,728,000 | from sys import stdin
n = int(input())
seg = []
inp = stdin.readlines()
for i in range(n):
l, r = map(int, inp[i].split())
seg.append([l, r, i + 1])
#seg.sort(key = lambda x: x[1], reverse = True)
seg.sort(key = lambda x: x[0])
if n == 1: print(-1, -1)
else:
ans = [-1, -1]
for i ... | Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment... | ```python
from sys import stdin
n = int(input())
seg = []
inp = stdin.readlines()
for i in range(n):
l, r = map(int, inp[i].split())
seg.append([l, r, i + 1])
#seg.sort(key = lambda x: x[1], reverse = True)
seg.sort(key = lambda x: x[0])
if n == 1: print(-1, -1)
else:
ans = [-1, -1]
... | 3 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,690,366,152 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 31 | 1,024,000 | n = int(input())
a = [int(x) for x in input().split()]
b = 0
c = []
for i in range(1, n):
if a[i]>=a[i-1]:
b+=1
c.append(b)
else:
b = 0
print(max(c)+1) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input())
a = [int(x) for x in input().split()]
b = 0
c = []
for i in range(1, n):
if a[i]>=a[i-1]:
b+=1
c.append(b)
else:
b = 0
print(max(c)+1)
``` | -1 | |
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,681,734,413 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | n = input()
l = input()
s = ""
for i in range(len(n)):
if n[i] != l[i]:
s += "1"
else:
s += "0"
print(s)
| 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
n = input()
l = input()
s = ""
for i in range(len(n)):
if n[i] != l[i]:
s += "1"
else:
s += "0"
print(s)
``` | 3.98075 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,595,074,227 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 140 | 20,172,800 | MAX = 100
def countSubsequence(s, n):
cntQ = 0
cntA = 0
result = 0
C=0
for i in range(n):
if (s[i] == 'Q'):
cntQ += 1
result += C
continue
if (s[i] == 'A'):
cntA += 1
C += cntQ
continue
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
MAX = 100
def countSubsequence(s, n):
cntQ = 0
cntA = 0
result = 0
C=0
for i in range(n):
if (s[i] == 'Q'):
cntQ += 1
result += C
continue
if (s[i] == 'A'):
cntA += 1
C += cntQ
c... | 3 | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,637,685,856 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 61 | 0 | # from dust i have come dust i will be
n=int(input())
s=input()
a=['a','e','i','o','u','y']
ch='#'
for i in range(n):
if s[i] not in a:
if ch!='#':
print(ch,end='')
ch='#'
print(s[i],end='')
else:
if ch=='#':
ch=s[i]
if ch!='#':
print(ch)
| Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
# from dust i have come dust i will be
n=int(input())
s=input()
a=['a','e','i','o','u','y']
ch='#'
for i in range(n):
if s[i] not in a:
if ch!='#':
print(ch,end='')
ch='#'
print(s[i],end='')
else:
if ch=='#':
ch=s[i]
if ch!='#':
pr... | 3 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,680,755,440 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 156 | 9,830,400 | n,m = map(int,input().split())
m1 = {}
m2 = {}
m3 = {}
for i in range(m):
s1,s2 = map(str,input().split())
m1[s1] = len(s1)
m2[s1] = [len(s2),s2]
l = list(map(str,input().split()))
for i in range(n):
if m2[l[i]][0]<m1[l[i]]:
print(m2[l[i]][1],end=" ")
else:
print(l[i],... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n,m = map(int,input().split())
m1 = {}
m2 = {}
m3 = {}
for i in range(m):
s1,s2 = map(str,input().split())
m1[s1] = len(s1)
m2[s1] = [len(s2),s2]
l = list(map(str,input().split()))
for i in range(n):
if m2[l[i]][0]<m1[l[i]]:
print(m2[l[i]][1],end=" ")
else:
p... | 3 | |
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,585,770,335 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | # IQ test: python
n = int(input())
lst = list(map(int, input().split()))
def find_flag(lst):
evens, odds = 0, 0
flag = ''
for i in range(3):
if lst[i] % 2 == 0:
evens += 1
else:
odds += 1
if i == 2:
if evens > odds:
flag = ... | 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
# IQ test: python
n = int(input())
lst = list(map(int, input().split()))
def find_flag(lst):
evens, odds = 0, 0
flag = ''
for i in range(3):
if lst[i] % 2 == 0:
evens += 1
else:
odds += 1
if i == 2:
if evens > odds:
... | 3.944928 |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,694,620,923 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 420 | 7,475,200 | n = int(input())
worms = [int(x) for x in input().split()]
m = int(input())
juicy = [int(x) for x in input().split()]
results = []
# 创建一个前缀和数组
for i in range(1, n):
worms[i] += worms[i-1]
for j in juicy:
# 特殊情况:果汁小于第一个蠕虫的值
if j <= worms[0]:
results.append(1)
continue
... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
n = int(input())
worms = [int(x) for x in input().split()]
m = int(input())
juicy = [int(x) for x in input().split()]
results = []
# 创建一个前缀和数组
for i in range(1, n):
worms[i] += worms[i-1]
for j in juicy:
# 特殊情况:果汁小于第一个蠕虫的值
if j <= worms[0]:
results.append(1)
continu... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,806,016 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
words=[]
for _ in range(n):
word=input().strip()
if len(word)>10:
abbreviation=word[0]+
str(len(word)-2)+word[-1]
words.append(abbreviation)
else:
words.append(word)
for abbreviation in words:
print(abbreviation)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input())
words=[]
for _ in range(n):
word=input().strip()
if len(word)>10:
abbreviation=word[0]+
str(len(word)-2)+word[-1]
words.append(abbreviation)
else:
words.append(word)
for abbreviation in words:
print(abbreviation)
``` | -1 |
23 | E | Tree | PROGRAMMING | 2,500 | [
"dp"
] | E. Tree | 2 | 256 | Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can... | The first input line contains integer number *n* (1<=≤<=*n*<=≤<=700) — amount of vertices in the tree. The following *n*<=-<=1 lines contain the description of the edges. Each line contains the pair of vertices' indexes, joined by an edge, *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). It's guaranteed that the graph d... | Output the only number — the maximum product of sizes of the connected components, that Bob can get after deleting some of the tree's edges. | [
"5\n1 2\n2 3\n3 4\n4 5\n",
"8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8\n",
"3\n1 2\n1 3\n"
] | [
"6",
"18",
"3"
] | none | 0 | [
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "6"
},
{
"input": "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8",
"output": "18"
},
{
"input": "3\n1 2\n1 3",
"output": "3"
},
{
"input": "5\n3 2\n1 5\n4 5\n5 3",
"output": "6"
},
{
"input": "5\n2 1\n3 4\n3 5\n5 2",
"outpu... | 1,383,440,936 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <cstring>
#define MAXN 701
using namespace std;
typedef long long ll;
vector<int> adj[MAXN];
ll DP[MAXN][4];
int order[MAXN];
int sz;
int pi[MAXN];
void dfs(int u, int p = -1) {
pi[u] = p;
int v;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (... | Title: Tree
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected compon... | ```python
#include <iostream>
#include <vector>
#include <cstring>
#define MAXN 701
using namespace std;
typedef long long ll;
vector<int> adj[MAXN];
ll DP[MAXN][4];
int order[MAXN];
int sz;
int pi[MAXN];
void dfs(int u, int p = -1) {
pi[u] = p;
int v;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i]... | -1 |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,518,644,636 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 5,632,000 | n, m = map(int,input().split())
t = list(map(int,input().split()))
b = list(map(int,input().split()))
larg = max(t)
t = t.remove(larg)
sec = max(t)
third = max(b)
bright = sec*third
print(bright)
| Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n, m = map(int,input().split())
t = list(map(int,input().split()))
b = list(map(int,input().split()))
larg = max(t)
t = t.remove(larg)
sec = max(t)
third = max(b)
bright = sec*third
print(bright)
``` | -1 | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,588,160,488 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | l = list(map(int, input().rstrip().split()))
a=[]
for i in range(l[0]):
a.append(list(map(int, input().rstrip().split())))
y=max((int(a[i][0]) for i in range(l[0])))
x=min(a[y])
print(a[y][x]) | Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
l = list(map(int, input().rstrip().split()))
a=[]
for i in range(l[0]):
a.append(list(map(int, input().rstrip().split())))
y=max((int(a[i][0]) for i in range(l[0])))
x=min(a[y])
print(a[y][x])
``` | -1 | |
207 | D2 | The Beaver's Problem - 3 | PROGRAMMING | 2,000 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are ... | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | 10 | [
{
"input": "7000\nTREASURY BALANCES AT FED FELL ON MARCH 27\nWASHINGTON, March 30 - Treasury balances at the Federal\nReserve fell on March 27 to 2.424 billion dlrs from 2.508\nbillion dlrs on the previous business day, the Treasury said in\nits latest budget statement.\nBalances in tax and loan note accounts f... | 1,673,006,155 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS2 | 0 | 15 | 0 | # LUOGU_RID: 98854447
n = int(input())
print(3 if n == 6 or n == 11 else 2 if n == 8 or n == 9 else 1) | Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subje... | ```python
# LUOGU_RID: 98854447
n = int(input())
print(3 if n == 6 or n == 11 else 2 if n == 8 or n == 9 else 1)
``` | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,685,649,824 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n=int(input())
for _ in range(n):
l=map(int, input().split())
counter=0
crimes=0
for i in l:
if counter==0 and i==-1:
crimes+=1
else:
counter=-1
if i==1:
counter+=1
print(crimes) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n=int(input())
for _ in range(n):
l=map(int, input().split())
counter=0
crimes=0
for i in l:
if counter==0 and i==-1:
crimes+=1
else:
counter=-1
if i==1:
counter+=1
print(crimes)
``` | -1 | |
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,635,748,855 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 19,763,200 | n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = [False]*(3001)
for i in range(n):
arr1[arr[i]] = True
for i in range(1,n+2):
if not arr1[i]:
print(i)
sys.exit() | 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
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = [False]*(3001)
for i in range(n):
arr1[arr[i]] = True
for i in range(1,n+2):
if not arr1[i]:
print(i)
sys.exit()
``` | -1 |
746 | D | Green and Black Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order ... | The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*. | If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be ... | [
"5 1 3 2\n",
"7 2 2 5\n",
"4 3 4 0\n"
] | [
"GBGBG\n",
"BBGBGBB",
"NO\n"
] | none | 2,000 | [
{
"input": "5 1 3 2",
"output": "GBGBG"
},
{
"input": "7 2 2 5",
"output": "BBGBBGB"
},
{
"input": "4 3 4 0",
"output": "NO"
},
{
"input": "2 2 0 2",
"output": "BB"
},
{
"input": "3 2 0 3",
"output": "NO"
},
{
"input": "1 1 0 1",
"output": "B"
},... | 1,690,269,178 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 2,764,800 | import sys
import random
from math import gcd, lcm, sqrt, isqrt, perm, comb, factorial
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, h... | Title: Green and Black Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like ... | ```python
import sys
import random
from math import gcd, lcm, sqrt, isqrt, perm, comb, factorial
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, ... | 0 | |
1,004 | B | Sonya and Exhibition | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul... | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ... | 1,000 | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 100... | 1,530,982,983 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 109 | 0 | def scanf(t=int):
return list(map(t, input().split()))
n, m = scanf()
s = '01' * (n//2) + '0' * (n % 2)
print(s) | Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the ... | ```python
def scanf(t=int):
return list(map(t, input().split()))
n, m = scanf()
s = '01' * (n//2) + '0' * (n % 2)
print(s)
``` | 3 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,693,677,736 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 62 | 0 | t = int(input())
mik , chri = 0,0
mikcount = 0
for _ in range(t):
nlist = list(map(int,input().split()))
if nlist[0] > nlist[1]:
mikcount +=1
if mikcount > t // 2 :
print("Mishka")
elif mikcount < t // 2 :
print("Chris")
else:
print("Friendship is magic!^^")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
t = int(input())
mik , chri = 0,0
mikcount = 0
for _ in range(t):
nlist = list(map(int,input().split()))
if nlist[0] > nlist[1]:
mikcount +=1
if mikcount > t // 2 :
print("Mishka")
elif mikcount < t // 2 :
print("Chris")
else:
print("Friendship is magic!^^")
``` | 0 | |
228 | D | Zigzag | PROGRAMMING | 2,100 | [
"data structures"
] | null | null | The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.
The Zigag's sequence with the... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — The number of elements in array *a*. The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of operations. Next ... | For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.
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 sp... | [
"5\n2 3 1 5 5\n4\n2 2 3 2\n2 1 5 3\n1 3 5\n2 1 5 3\n"
] | [
"5\n26\n38\n"
] | Explanation of the sample test:
- Result of the first operation is *Z*(2, 3, 2) = 3·1 + 1·2 = 5. - Result of the second operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 1·3 + 5·2 + 5·1 = 26. - After the third operation array *a* is equal to 2, 3, 5, 5, 5. - Result of the forth operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 5·3 +... | 2,000 | [] | 1,691,442,096 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1691442096.9175146")# 1691442096.9175315 | Title: Zigzag
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci s... | ```python
print("_RANDOM_GUESS_1691442096.9175146")# 1691442096.9175315
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,642,856,777 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 61 | 512,000 | i = list(input())
ofs = 0
lposes = []
for x in range(len(i)):
if i[x+ofs] not in ['h','e','l','o']:
del i[x+ofs]
ofs -= 1
if i[x+ofs] == 'l':
lposes.append(x+ofs)
for lp in lposes:
if len(i[:lp]) < 2:
continue
if 'e' in i[:lp+1] and 'l' in i[lp:]:
el = i[:lp-1];e=str(el).rfind('e')
l... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
i = list(input())
ofs = 0
lposes = []
for x in range(len(i)):
if i[x+ofs] not in ['h','e','l','o']:
del i[x+ofs]
ofs -= 1
if i[x+ofs] == 'l':
lposes.append(x+ofs)
for lp in lposes:
if len(i[:lp]) < 2:
continue
if 'e' in i[:lp+1] and 'l' in i[lp:]:
el = i[:lp-1];e=str(el).rfind... | 0 |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,544,236,279 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 0 | n = input()
a = 0
b = []
c = 0
for i in n:
a += 1
if i == "(":
b.append(1)
else:
b.append(-1)
while b[0] != 1:
del b[0]
c += 1
while b[-1] != -1:
del b[-1]
c += 1
print(len(n)-abs(sum(b))-c)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
n = input()
a = 0
b = []
c = 0
for i in n:
a += 1
if i == "(":
b.append(1)
else:
b.append(-1)
while b[0] != 1:
del b[0]
c += 1
while b[-1] != -1:
del b[-1]
c += 1
print(len(n)-abs(sum(b))-c)
``` | -1 |
630 | H | Benches | PROGRAMMING | 1,400 | [
"combinatorics",
"math"
] | null | null | The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possib... | The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths. | Output one integer — the number of ways to place the benches. | [
"5\n"
] | [
"120"
] | none | 0 | [
{
"input": "5",
"output": "120"
},
{
"input": "6",
"output": "4320"
},
{
"input": "7",
"output": "52920"
},
{
"input": "15",
"output": "1082161080"
},
{
"input": "17",
"output": "4594961280"
},
{
"input": "72",
"output": "23491596420472320"
},
... | 1,694,814,726 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 62 | 0 | ans = 1
n = int(input())
for i in range(5,0,-1):
ans*=n
n-=1
ans = (ans**2)//120
print(ans)
| Title: Benches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make... | ```python
ans = 1
n = int(input())
for i in range(5,0,-1):
ans*=n
n-=1
ans = (ans**2)//120
print(ans)
``` | 3 | |
761 | E | Dasha and Puzzle | PROGRAMMING | 2,000 | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.
The tree is a non-oriented connected graph without cycles. In particular, there always are *n*<=-<=1 edges in a tree with *n* vertices.
The puzzle ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=30) — the number of vertices in the tree.
Each of next *n*<=-<=1 lines contains two integers *u**i*, *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) that mean that the *i*-th edge of the tree connects vertices *u**i* and *v**i*.
It is guaranteed that the described gra... | If the puzzle doesn't have a solution then in the only line print "NO".
Otherwise, the first line should contain "YES". The next *n* lines should contain the pair of integers *x**i*, *y**i* (|*x**i*|,<=|*y**i*|<=≤<=1018) — the coordinates of the point which corresponds to the *i*-th vertex of the tree.
If there are s... | [
"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"6\n1 2\n2 3\n2 4\n2 5\n2 6\n",
"4\n1 2\n2 3\n3 4"
] | [
"YES\n0 0\n1 0\n0 1\n2 0\n1 -1\n-1 1\n0 2",
"NO\n",
"YES\n3 3\n4 3\n5 3\n6 3"
] | In the first sample one of the possible positions of tree is: <img class="tex-graphics" src="https://espresso.codeforces.com/360c9c903e5177970a5a3b2711f6718c2163ffd8.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 2,500 | [
{
"input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 1610612736\n536870912 1073741824\n1073741824 536870912\n1610612736 0"
},
{
"input": "6\n1 2\n2 3\n2 4\n2 5\n2 6",
"output": "NO"
},
{
"input": "4\n1 2\n2 3\n3 4",
"output": "YES\n0 0\n0 1... | 1,535,798,618 | 5,318 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 155 | 409,600 | n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
adj[u - 1].append(v - 1)
adj[v - 1].append(u - 1)
from collections import deque
def bfs(v):
vis = [i == v for i in range(n)]
paths = deque([[v]])
while paths:
p = paths.popleft()
... | Title: Dasha and Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.
The tree is a non-oriented connected graph wit... | ```python
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
adj[u - 1].append(v - 1)
adj[v - 1].append(u - 1)
from collections import deque
def bfs(v):
vis = [i == v for i in range(n)]
paths = deque([[v]])
while paths:
p = paths.popl... | 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,607,142,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | s=input()
p=input()
s=reversed(s)
if s==p:
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
s=input()
p=input()
s=reversed(s)
if s==p:
print("YES")
else:
print("NO")
``` | 0 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,590,923,676 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 310 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sun May 31 16:45:30 2020
@author: Mohit
"""
"""
Created on Sun May 31 16:25:54 2020
@author: Mohit
"""
x= input()
countl=0
countu=0
for i in x:
if(i.isupper()):
countu= countu+1
elif(i.islower()):
countl = countl+1
... | 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
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 16:45:30 2020
@author: Mohit
"""
"""
Created on Sun May 31 16:25:54 2020
@author: Mohit
"""
x= input()
countl=0
countu=0
for i in x:
if(i.isupper()):
countu= countu+1
elif(i.islower()):
countl = countl+... | 3.9225 |
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,507,885,908 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
s = input()
tab = [[0 for j in range(i, n)] for i in range(n)]
res = 0
for i in range(n):
for j in range(i+1, n):
tab[i][j-i] = tab[i][j-i-1]
tab[i][j-i] += 1 if s[j-1]=='0' else -1
if tab[i][j-i] == 0 and res < j-i:
res = j-i
| Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n = int(input())
s = input()
tab = [[0 for j in range(i, n)] for i in range(n)]
res = 0
for i in range(n):
for j in range(i+1, n):
tab[i][j-i] = tab[i][j-i-1]
tab[i][j-i] += 1 if s[j-1]=='0' else -1
if tab[i][j-i] == 0 and res < j-i:
res = j-i
``` | 0 | |
79 | A | Bus Game | PROGRAMMING | 1,200 | [
"greedy"
] | A. Bus Game | 2 | 256 | After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen ... | The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space. | If Ciel wins, print "Ciel". Otherwise, print "Hanako". | [
"2 2\n",
"3 22\n"
] | [
"Ciel\n",
"Hanako\n"
] | In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose. | 500 | [
{
"input": "2 2",
"output": "Ciel"
},
{
"input": "3 22",
"output": "Hanako"
},
{
"input": "0 22",
"output": "Ciel"
},
{
"input": "1000 1000",
"output": "Ciel"
},
{
"input": "0 0",
"output": "Hanako"
},
{
"input": "0 21",
"output": "Hanako"
},
{... | 1,621,782,438 | 2,147,483,647 | PyPy 3 | OK | TESTS | 99 | 280 | 2,867,200 | import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
# input = sys.stdin.readline
flush = lambda : sys.stdout.flush
comb = lambda x , y : (factorial(x) // factoria... | Title: Bus Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored ... | ```python
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
# input = sys.stdin.readline
flush = lambda : sys.stdout.flush
comb = lambda x , y : (factorial(x) /... | 3.924659 |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,417,314,707 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 156 | 0 | from itertools import*
s=map(int,input().split())
d=x=0
for a,b,c in combinations(s,3):
a,b,c=sorted([a,b,c]);d=max(d,a+b==c)
if a+b>c:x="TRIANGLE";break
else:x=["IMPOSSIBLE","SEGMENT"][d]
print(x)
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
from itertools import*
s=map(int,input().split())
d=x=0
for a,b,c in combinations(s,3):
a,b,c=sorted([a,b,c]);d=max(d,a+b==c)
if a+b>c:x="TRIANGLE";break
else:x=["IMPOSSIBLE","SEGMENT"][d]
print(x)
``` | 3.961 |
962 | C | Make a Square | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math"
] | null | null | You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently ... | The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes. | If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it. | [
"8314\n",
"625\n",
"333\n"
] | [
"2\n",
"0\n",
"-1\n"
] | In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the squa... | 0 | [
{
"input": "8314",
"output": "2"
},
{
"input": "625",
"output": "0"
},
{
"input": "333",
"output": "-1"
},
{
"input": "1881388645",
"output": "6"
},
{
"input": "1059472069",
"output": "3"
},
{
"input": "1354124829",
"output": "4"
},
{
"inpu... | 1,553,601,733 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 155 | 1,945,600 | sq=[0]*(50000)
for i in range(50000):
sq[i]=i*i
s=input()
for k in range(49999,0,-1):
t=str(sq[k])
if len(t)<=len(s):
j=0
i=0
while(j<len(s) and i<len(t)):
if t[i]==s[j]:
i+=1
j+=1
else:
j+=1
if i==len(t):
# print(t)
print(len(s)-len(t))
exit()
print("-1") | Title: Make a Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive intege... | ```python
sq=[0]*(50000)
for i in range(50000):
sq[i]=i*i
s=input()
for k in range(49999,0,-1):
t=str(sq[k])
if len(t)<=len(s):
j=0
i=0
while(j<len(s) and i<len(t)):
if t[i]==s[j]:
i+=1
j+=1
else:
j+=1
if i==len(t):
# print(t)
print(len(s)-len(t))
exit()
print("-... | 3 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,637,964,232 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 0 | nOfCities , x = map(int, input().split())
x -= 1
criminals = list(map(int, input().split()))
def criminalsFound(cities, criminals):
Counter = 0
for i in range(0, nOfCities):
if x - i >= 0 and x+i < nOfCities:
if criminals[x - i] == 1 and criminals[x + i] == 1:
Counter += 2
... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
nOfCities , x = map(int, input().split())
x -= 1
criminals = list(map(int, input().split()))
def criminalsFound(cities, criminals):
Counter = 0
for i in range(0, nOfCities):
if x - i >= 0 and x+i < nOfCities:
if criminals[x - i] == 1 and criminals[x + i] == 1:
Coun... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,693,642,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def room(v):
target = "room"
idx = 0
for ch in v:
if idx < len(target) and ch == target[idx]:
idx += 1
if idx == len(target):
return "YES"
return "NO"
v = input().strip()
result = room(v)
print(result)
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
def room(v):
target = "room"
idx = 0
for ch in v:
if idx < len(target) and ch == target[idx]:
idx += 1
if idx == len(target):
return "YES"
return "NO"
v = input().strip()
result = room(v)
print(result)
``` | 0 |
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,635,591,735 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 46 | 4,505,600 | A, B = input(), input()
keys,maps,mis = set(),[],False
for i in range(len(A)):
if A[i] != B[i] and [A[i],B[i]] not in maps and [B[i],A[i]] not in maps:
if A[i] not in keys and B[i] not in keys:
keys.add(A[i])
keys.add(B[i])
maps.append([A[i],B[i]])
else:
... | Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke... | ```python
A, B = input(), input()
keys,maps,mis = set(),[],False
for i in range(len(A)):
if A[i] != B[i] and [A[i],B[i]] not in maps and [B[i],A[i]] not in maps:
if A[i] not in keys and B[i] not in keys:
keys.add(A[i])
keys.add(B[i])
maps.append([A[i],B[i]])
else:... | 0 | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,688,104,572 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s=0
n = int(input())
for _ in range(n):
lst = list(map(int,input().split()))[:2]
if(lst[1]-lst[0]>=2):
s+=1
print(s) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
s=0
n = int(input())
for _ in range(n):
lst = list(map(int,input().split()))[:2]
if(lst[1]-lst[0]>=2):
s+=1
print(s)
``` | 3 | |
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibitio... | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ... | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\... | 1,699,348,299 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 1,263 | 22,016,000 | n = int(input())
elements = {}
elements = dict(elements)
for i in range(n):
a, b = map(int, input().split())
elements[a] = b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if elements.get(a):
elements[a] = max(elements[a], b)
else:
elements[a] = b
print(sum... | Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both... | ```python
n = int(input())
elements = {}
elements = dict(elements)
for i in range(n):
a, b = map(int, input().split())
elements[a] = b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if elements.get(a):
elements[a] = max(elements[a], b)
else:
elements[a] = b... | 3 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,662,576,439 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 218 | 19,353,600 | n, q = map(int, input().split())
a = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
pref, p = [0] * n, [0] * n
pref[0], p[0] = a[0], a[0]
for i in range(1, n):
pref[i], p[i] = pref[i - 1] + a[i], p[i - 1] + a[i]
ind, fl = -1, False
for i in range(q):
x = k[i]
l, r = ind, n... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
n, q = map(int, input().split())
a = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
pref, p = [0] * n, [0] * n
pref[0], p[0] = a[0], a[0]
for i in range(1, n):
pref[i], p[i] = pref[i - 1] + a[i], p[i - 1] + a[i]
ind, fl = -1, False
for i in range(q):
x = k[i]
l, ... | 0 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,586,794,595 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 102,400 | """
https://codeforces.com/problemset/problem/595/A
"""
args = [int(x) for x in input().split(" ")]
n = args[0]
m = args[1]
lightsOn = 0
for i in range(n):
floor = [int(x) for x in input().split(" ")]
for j in range(m):
if floor[2*j] == 1 or floor[2*j+1] == 1:
lightsOn += 1
... | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
"""
https://codeforces.com/problemset/problem/595/A
"""
args = [int(x) for x in input().split(" ")]
n = args[0]
m = args[1]
lightsOn = 0
for i in range(n):
floor = [int(x) for x in input().split(" ")]
for j in range(m):
if floor[2*j] == 1 or floor[2*j+1] == 1:
ligh... | 3 | |
315 | B | Sereja and Array | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. In... | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is i... | For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. | [
"10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n"
] | [
"2\n9\n11\n20\n30\n40\n39\n"
] | none | 1,000 | [
{
"input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9",
"output": "2\n9\n11\n20\n30\n40\n39"
},
{
"input": "1 3\n1\n1 1 2\n2 1\n3 1",
"output": "3"
},
{
"input": "1 1\n1\n3 1",
"output": "1"
},
{
"input": "6 6\n202714501 613423... | 1,662,578,686 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 218 | 18,534,400 | from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
arr=list(map(int,input().split()))
val = 0
for _ in range(m):
opt=list(map... | Title: Sereja and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*... | ```python
from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
arr=list(map(int,input().split()))
val = 0
for _ in range(m):
op... | 3 | |
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,592,676,144 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | #A.IQ Test
n = int(input())
a = list(map(int,input().split()))
t = 0
if a[0]%2==0:
t += 1
else:
t -= 1
if a[1]%2==0:
t += 1
else:
t -= 1
if a[2]%2==0:
t += 1
else:
t -= 1
if t>=1:
#all other numbers are even
for i in range(n):
if a[i]%2!=0:
print(i... | 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
#A.IQ Test
n = int(input())
a = list(map(int,input().split()))
t = 0
if a[0]%2==0:
t += 1
else:
t -= 1
if a[1]%2==0:
t += 1
else:
t -= 1
if a[2]%2==0:
t += 1
else:
t -= 1
if t>=1:
#all other numbers are even
for i in range(n):
if a[i]%2!=0:
... | 3.944928 |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,698,250,390 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 93 | 12,800,000 | n = int(input())
numArray = list(map(int, input().split()))
maxLenght = 1
currentLenght = 1
previousNum = numArray[0]
for i in range(1, n):
currentNum = numArray[i]
if currentNum > previousNum:
currentLenght += 1
else:
currentLenght = 1
maxLenght = max(maxL... | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
numArray = list(map(int, input().split()))
maxLenght = 1
currentLenght = 1
previousNum = numArray[0]
for i in range(1, n):
currentNum = numArray[i]
if currentNum > previousNum:
currentLenght += 1
else:
currentLenght = 1
maxLenght ... | 3 | |
931 | C | Laboratory Work | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are clo... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maxi... | In the first line print the minimum possible number of equal measurements.
In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Ki... | [
"6\n-1 1 1 0 0 -1\n",
"3\n100 100 101\n",
"7\n-10 -9 -10 -8 -10 -9 -9\n"
] | [
"2\n0 0 0 0 0 0 \n",
"3\n101 100 100 \n",
"5\n-10 -10 -9 -9 -9 -9 -9 \n"
] | In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make... | 1,750 | [
{
"input": "6\n-1 1 1 0 0 -1",
"output": "2\n0 0 0 0 0 0 "
},
{
"input": "3\n100 100 101",
"output": "3\n101 100 100 "
},
{
"input": "7\n-10 -9 -10 -8 -10 -9 -9",
"output": "5\n-10 -10 -9 -9 -9 -9 -9 "
},
{
"input": "60\n-8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -... | 1,520,182,380 | 4,680 | Python 3 | WRONG_ANSWER | PRETESTS | 10 | 295 | 12,697,600 | n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f... | Title: Laboratory Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and h... | ```python
n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-... | 0 | |
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,582,126,833 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n = int(input())
m = n * n
for i in range(1 , n+1):
print(i , end = ' ')
print(m - i + 1 )
| 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
n = int(input())
m = n * n
for i in range(1 , n+1):
print(i , end = ' ')
print(m - i + 1 )
``` | 0 | |
83 | A | Magical Array | PROGRAMMING | 1,300 | [
"math"
] | A. Magical Array | 2 | 256 | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutel... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | [
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] | [
"5\n",
"8\n"
] | Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | 500 | [
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output... | 1,660,325,995 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n = int(input())
li = list(map(int, input().split()))
e = li[0]
cnt = 1
total_cnt = n
for i in range(1, n):
if li[i] == e:
cnt += 1
else:
if cnt > 1:
total_cnt += ((cnt-1)*cnt)//2
e = li[i]
cnt = 1
print(total_cnt)
| Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a re... | ```python
n = int(input())
li = list(map(int, input().split()))
e = li[0]
cnt = 1
total_cnt = n
for i in range(1, n):
if li[i] == e:
cnt += 1
else:
if cnt > 1:
total_cnt += ((cnt-1)*cnt)//2
e = li[i]
cnt = 1
print(total_cnt)
``` | 0 |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,677,169,297 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
teams = []
c = 0
for i in range(n):
h, a = input().split()
h = int(h)
a = int(a)
teams.append([h, a])
for j in teams:
for i in teams:
if i != j:
if j[0] == i[1]:
c += 1
print(c) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n = int(input())
teams = []
c = 0
for i in range(n):
h, a = input().split()
h = int(h)
a = int(a)
teams.append([h, a])
for j in teams:
for i in teams:
if i != j:
if j[0] == i[1]:
c += 1
print(c)
``` | 3 | |
862 | C | Mahmoud and Ehab and the xor | PROGRAMMING | 1,900 | [
"constructive algorithms"
] | null | null | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to... | The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively. | If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. | [
"5 5\n",
"3 6\n"
] | [
"YES\n1 2 4 5 7",
"YES\n1 2 5"
] | You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-w... | 1,500 | [
{
"input": "5 5",
"output": "YES\n1 2 131072 131078 0 "
},
{
"input": "3 6",
"output": "YES\n131072 131078 0 "
},
{
"input": "3 0",
"output": "YES\n393216 131072 262144"
},
{
"input": "1 0",
"output": "YES\n0"
},
{
"input": "3 3",
"output": "YES\n131072 131075... | 1,518,852,900 | 4,800 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 10,547,200 | import random
import sys
n,k=input().split()
n=int(n)
k=int(k)
for tries in range(1000):
a=random.sample(range(100000),n-1)
x=0
for i in a:
x^=i
if k^x not in a:
print("YES")
for i in a:
print(i)
print(k^x)
sys.exit()
print("NO")
| Title: Mahmoud and Ehab and the xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to re... | ```python
import random
import sys
n,k=input().split()
n=int(n)
k=int(k)
for tries in range(1000):
a=random.sample(range(100000),n-1)
x=0
for i in a:
x^=i
if k^x not in a:
print("YES")
for i in a:
print(i)
print(k^x)
sys.exit()
print("N... | 0 | |
985 | C | Liebig's Barrels | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
... | The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. | [
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] | [
"7\n",
"20\n",
"2\n",
"0\n"
] | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | 0 | [
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194... | 1,542,578,861 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 296 | 11,468,800 | import configparser
import math
import sys
input = sys.stdin.readline
def can(arr, pos, left, k, dist):
# rightmost point 0 indexed
right_most = pos + left - 1
if abs(arr[right_most] - arr[0]) > dist:
return False
if len(arr) - right_most - 1 < ((k-1) * left):
return Fa... | Title: Liebig's Barrels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to ex... | ```python
import configparser
import math
import sys
input = sys.stdin.readline
def can(arr, pos, left, k, dist):
# rightmost point 0 indexed
right_most = pos + left - 1
if abs(arr[right_most] - arr[0]) > dist:
return False
if len(arr) - right_most - 1 < ((k-1) * left):
... | 0 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,652,950,476 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 30,924,800 | s=input()
m=int(input())
a=list(map(int,input().split()))
for i in a:
s=s[:i-1]+s[i-1:len(s)-(i-1)][::-1]+s[len(s)-(i-1):]
print(s)
| Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
s=input()
m=int(input())
a=list(map(int,input().split()))
for i in a:
s=s[:i-1]+s[i-1:len(s)-(i-1)][::-1]+s[len(s)-(i-1):]
print(s)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,678,350,004 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import sys
T= int(input())
for i in range(T):
a=input()
b=len(a)-2
if len(a)>10:
sys.stdout.write(a[0]+str(b)+a[len(a)-1])
print()
else:
print(a)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
import sys
T= int(input())
for i in range(T):
a=input()
b=len(a)-2
if len(a)>10:
sys.stdout.write(a[0]+str(b)+a[len(a)-1])
print()
else:
print(a)
``` | 3.977 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,698,628,573 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | n = int(input())
ps = list(map(int,input().split()))
idx = ps.index(max(ps))
nn = str(sorted(ps)[-2])
print(*[str(idx+1),nn]) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
n = int(input())
ps = list(map(int,input().split()))
idx = ps.index(max(ps))
nn = str(sorted(ps)[-2])
print(*[str(idx+1),nn])
``` | 3 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,621,379,422 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 7,270,400 | n, b, d = [int(i) for i in input().split()]
how_many = 0
storage = 0
a = [int(i) for i in input().split()]
for i in a:
if i <= b:
storage += i
if storage>d:
storage=0
how_many += 1
print(how_many) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = [int(i) for i in input().split()]
how_many = 0
storage = 0
a = [int(i) for i in input().split()]
for i in a:
if i <= b:
storage += i
if storage>d:
storage=0
how_many += 1
print(how_many)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s*... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*. | Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK". | [
"4\nVKVK\n",
"5\nBVVKV\n",
"7\nVVKEVKK\n",
"20\nVKVKVVVKVOVKVQKKKVVK\n",
"5\nLIMAK\n"
] | [
"3\n",
"2\n",
"3\n",
"8\n",
"0\n"
] | In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this str... | 0 | [] | 1,689,193,883 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689193883.046417")# 1689193883.046436 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possib... | ```python
print("_RANDOM_GUESS_1689193883.046417")# 1689193883.046436
``` | 0 | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,572,809,549 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 233 | 10,342,400 | #RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
from math import ceil
n, k = map(int,input().split())
a = list(map(int,input().split()))
day = 0
b1 = b2 = odd = 0
for i in range(n):
yy = ceil(a[i]/k)
if yy % 2 == 0:day+=(yy//2)
else:
odd+=1
day+=ceil(yy/2)
print(day-odd... | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
#RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
from math import ceil
n, k = map(int,input().split())
a = list(map(int,input().split()))
day = 0
b1 = b2 = odd = 0
for i in range(n):
yy = ceil(a[i]/k)
if yy % 2 == 0:day+=(yy//2)
else:
odd+=1
day+=ceil(yy/2)
pri... | 3 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,598,858,436 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 124 | 7,065,600 | #!/usr/bin/env python3
import random
def find_color(i, j):
if i == 0 and j == 0:
return random.choice(["B","W"])
elif i == len(board) - 1 and j == len(board[0]) - 1:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] =... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
#!/usr/bin/env python3
import random
def find_color(i, j):
if i == 0 and j == 0:
return random.choice(["B","W"])
elif i == len(board) - 1 and j == len(board[0]) - 1:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board... | -1 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,682,270,088 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 93 | 3,788,800 | n,t=map(int,input().split())
arr=list(map(int,input().split()))
curr=1
t-=1
while curr<t:
curr+=arr[curr]
if curr==t:
print("YES")
else:
print("NO")
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t=map(int,input().split())
arr=list(map(int,input().split()))
curr=1
t-=1
while curr<t:
curr+=arr[curr]
if curr==t:
print("YES")
else:
print("NO")
``` | 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,659,470,455 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 30 | 0 | s,w=input(),"heidi"
for x in s:
if(w[0]==x): w=w[1:]
print("YES" if len(w)==0 else "NO")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s,w=input(),"heidi"
for x in s:
if(w[0]==x): w=w[1:]
print("YES" if len(w)==0 else "NO")
``` | -1 | |
159 | B | Matchmaker | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"sortings"
] | null | null | Polycarpus has *n* markers and *m* marker caps. Each marker is described by two numbers: *x**i* is the color and *y**i* is the diameter. Correspondingly, each cap is described by two numbers: *a**j* is the color and *b**j* is the diameter. Cap (*a**j*,<=*b**j*) can close marker (*x**i*,<=*y**i*) only if their diameters... | The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of markers and the number of caps, correspondingly.
Next *n* lines describe the markers. The *i*-th line contains two space-separated integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the *i*-th mark... | Print two space-separated integers *u*,<=*v*, where *u* is the number of closed markers and *v* is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the nu... | [
"3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2\n",
"2 2\n1 2\n2 1\n3 4\n5 1\n"
] | [
"3 2\n",
"1 0\n"
] | In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers. | 1,000 | [
{
"input": "3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2",
"output": "3 2"
},
{
"input": "2 2\n1 2\n2 1\n3 4\n5 1",
"output": "1 0"
},
{
"input": "6 7\n2 1\n2 2\n2 1\n1 1\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n1 1\n1 2",
"output": "3 3"
},
{
"input": "6 7\n2 1\n1 1\n2 2\n1 2\n1 1\n1 2... | 1,653,304,042 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 3,000 | 10,444,800 | import sys
input = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
e = defaultdict(int)
for _ in range(n):
a, b = map(int, input().split())
d[b].append(a)
e[b] += 1
g = [list(map(int, input().split())) for _ in range(m)]
c, q =... | Title: Matchmaker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has *n* markers and *m* marker caps. Each marker is described by two numbers: *x**i* is the color and *y**i* is the diameter. Correspondingly, each cap is described by two numbers: *a**j* is the color and *b**j* i... | ```python
import sys
input = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
e = defaultdict(int)
for _ in range(n):
a, b = map(int, input().split())
d[b].append(a)
e[b] += 1
g = [list(map(int, input().split())) for _ in range(m)]... | 0 | |
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,662,750,602 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | def paresChocolate(matriz, n):
res = 0
for i in range(n):
count = 0
for j in range(n):
if matriz[i][j] == 'C':
count += 1
res += (count * (count - 1)) // 2
count = 0
for j in range(n):
if matriz[j][i] == 'C':
count +... | 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
def paresChocolate(matriz, n):
res = 0
for i in range(n):
count = 0
for j in range(n):
if matriz[i][j] == 'C':
count += 1
res += (count * (count - 1)) // 2
count = 0
for j in range(n):
if matriz[j][i] == 'C':
... | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,694,435,301 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n=int(input())
s=input()
t=0
for i in range(1,n):
if s[i] in s[i-1]:
t+=1
else:
continue
print(t) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n=int(input())
s=input()
t=0
for i in range(1,n):
if s[i] in s[i-1]:
t+=1
else:
continue
print(t)
``` | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,516,114,944 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 171 | 19,456,000 | def socks():
n = int(input())
arr = [False for _ in range(n + 1)]
pairs = list(map(int, input().split()))
count = 0
max_count = 0
for p in pairs:
if arr[p]:
count -= 1
else:
arr[p] = True
count += 1
max_count = max(count, max_count)
print(max_count)
if __nam... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
def socks():
n = int(input())
arr = [False for _ in range(n + 1)]
pairs = list(map(int, input().split()))
count = 0
max_count = 0
for p in pairs:
if arr[p]:
count -= 1
else:
arr[p] = True
count += 1
max_count = max(count, max_count)
print(max_count)
... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.