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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,582,029,317 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 124 | 921,600 | import queue
from collections import defaultdict, deque
import sys
def diaxtra(n, starting, ending, graph, cost, distance):
q = queue.PriorityQueue()
distance[starting] = 0
q.put((distance[starting], starting))
parent = {}
while(not q.empty()):
now_dis, now_node = q.get()
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
import queue
from collections import defaultdict, deque
import sys
def diaxtra(n, starting, ending, graph, cost, distance):
q = queue.PriorityQueue()
distance[starting] = 0
q.put((distance[starting], starting))
parent = {}
while(not q.empty()):
now_dis, now_node = q.... | -1 |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,503,341,293 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
a=list(map(int,input().split()))
m=0'''67'''
for i in range(2*n,n-1,-1):
for j in range(i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print('NO' if a[n]==a[n-1] else 'YES')
| Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
n=int(input())
a=list(map(int,input().split()))
m=0'''67'''
for i in range(2*n,n-1,-1):
for j in range(i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print('NO' if a[n]==a[n-1] else 'YES')
``` | -1 | |
220 | B | Little Elephant and Array | PROGRAMMING | 1,800 | [
"constructive algorithms",
"data structures"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 1,000 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,562,160,439 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 4 | 795 | 268,390,400 | n,q=map(int,input().split())
l=[int(i) for i in input().split()]
from math import sqrt as S
m=int(2*S(n))
pre=[[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,m):
pre[i][j]=pre[i-1][j]+(l[i-1]==j)
for i in range(q):
left,right=map(int,input().split())
c... | Title: Little Elephant and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant... | ```python
n,q=map(int,input().split())
l=[int(i) for i in input().split()]
from math import sqrt as S
m=int(2*S(n))
pre=[[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,m):
pre[i][j]=pre[i-1][j]+(l[i-1]==j)
for i in range(q):
left,right=map(int,input().split... | 0 | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,577,913,484 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 436 | 2,150,400 | fin = open('input.txt', 'r')
fout = open('output.txt', 'w')
n = int(fin.readline())
l = list(map(int, fin.readline()))
idx = []
for i, j in enumerate(l):
if j == 1:
idx.append(i)
diff = idx[1] - idx[0]
flag = True
for i in range(1, len(idx)-1):
if idx[i+1] - idx[i] != diff:
flag = Fa... | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
fin = open('input.txt', 'r')
fout = open('output.txt', 'w')
n = int(fin.readline())
l = list(map(int, fin.readline()))
idx = []
for i, j in enumerate(l):
if j == 1:
idx.append(i)
diff = idx[1] - idx[0]
flag = True
for i in range(1, len(idx)-1):
if idx[i+1] - idx[i] != diff:
... | -1 |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,588,105,782 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
mod = 10**9 + 7
n, k = map(int, input().split())
count = [1]*(n+1)
for i in range(k-1):
new = [0]*(n+1)
for j in range(1, n+1):
t = count[j]
for k in range(j, n+1, j):
new[k] = (new[k]+t)%mod
count = new
print(sum(count)%mod... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
mod = 10**9 + 7
n, k = map(int, input().split())
count = [1]*(n+1)
for i in range(k-1):
new = [0]*(n+1)
for j in range(1, n+1):
t = count[j]
for k in range(j, n+1, j):
new[k] = (new[k]+t)%mod
count = new
print(sum(... | 0 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,662,734,482 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n = int(input())
dig = False
others = False
chr_d = ''
char_other = ''
st= input()
if (st[0]==st[n-1]):
chr_d = st[0]
else:
dig = True
if(n>3):
for i in set(range(n))-set((1,n-1)):
if(st[i]==st[i+2]):
char_other = st[i]
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
dig = False
others = False
chr_d = ''
char_other = ''
st= input()
if (st[0]==st[n-1]):
chr_d = st[0]
else:
dig = True
if(n>3):
for i in set(range(n))-set((1,n-1)):
if(st[i]==st[i+2]):
char_other = st[i]
... | 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,685,529,552 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | def abbreviate_words(words):
"""
Abbreviates long words in a list of words.
Args:
words: A list of words.
Returns:
A list of abbreviated words.
"""
# Create a dictionary that maps from a word to its abbreviation.
abbreviations = {}
for word in words:
if len(word) > 10:
abbreviations... | 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
def abbreviate_words(words):
"""
Abbreviates long words in a list of words.
Args:
words: A list of words.
Returns:
A list of abbreviated words.
"""
# Create a dictionary that maps from a word to its abbreviation.
abbreviations = {}
for word in words:
if len(word) > 10:
abb... | 3.977 |
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,690,010,723 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | d1,d2,d3=map(int,input().split())
print(min(d1+d3+d2,2*d1+2*d2)) | 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
d1,d2,d3=map(int,input().split())
print(min(d1+d3+d2,2*d1+2*d2))
``` | 0 | |
366 | A | Dima and Guards | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for... | In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to t... | [
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] | [
"1 5 5\n",
"3 4 6\n",
"-1\n"
] | Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fo... | 500 | [
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 10... | 1,675,609,654 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | # LUOGU_RID: 101541280
(n, ), *a = [[*(map(int, s.split()))] for s in open(0)]
for i, (a, b, c, d) in enumerate(a):
if min(a, b) + min(c, d) <= n:
exit(print(i + 1, min(a, b), n - min(a, b)))
print(-1)
| Title: Dima and Guards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardpost... | ```python
# LUOGU_RID: 101541280
(n, ), *a = [[*(map(int, s.split()))] for s in open(0)]
for i, (a, b, c, d) in enumerate(a):
if min(a, b) + min(c, d) <= n:
exit(print(i + 1, min(a, b), n - min(a, b)))
print(-1)
``` | 3 | |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,658,240,926 | 166 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_ = min(a)
b_ = min(b)
print(min(10*a_ + b_, 10*b_ + a_)) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_ = min(a)
b_ = min(b)
print(min(10*a_ + b_, 10*b_ + a_))
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,567,271,569 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n = int(input())
a = list(map(int, input().split()))
t = 1
k = len(a)
while t < k:
if t%2 != 0:
a.remove(max(a))
elif t%2 == 0:
a.remove(min(a))
t = t+1
print(a[0])
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n = int(input())
a = list(map(int, input().split()))
t = 1
k = len(a)
while t < k:
if t%2 != 0:
a.remove(max(a))
elif t%2 == 0:
a.remove(min(a))
t = t+1
print(a[0])
``` | 3 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,620,349,997 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 6,656,000 | # e - 1
line=input().split()
boys=int(line[0])
girls=int(line[1])
length=min(girls,boys)
for i in range(length):
print("BG",end="")
for i in range(boys-length):
print("B",end="")
for i in range(girls-length):
print("G",end="")
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
# e - 1
line=input().split()
boys=int(line[0])
girls=int(line[1])
length=min(girls,boys)
for i in range(length):
print("BG",end="")
for i in range(boys-length):
print("B",end="")
for i in range(girls-length):
print("G",end="")
``` | -1 | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,675,777,957 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 0 | n = int(input())
steps = input()
for i in range(n):
if steps[i] != "." :
start = steps[i]
key = i
break
for x in range(key,n):
if steps[x] == "L":
end = x
break
elif steps[x] == "." :
end = x+1
break
print(key+1,end)
| Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n = int(input())
steps = input()
for i in range(n):
if steps[i] != "." :
start = steps[i]
key = i
break
for x in range(key,n):
if steps[x] == "L":
end = x
break
elif steps[x] == "." :
end = x+1
break
print(key+1,end)
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,689,625,004 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 62 | 0 | n1, n2 = map(int, input().split())
n1w = 0
d = 0
n2w = 0
for n in range(6):
i = n+1
if abs(i - n1) < abs(i - n2):
n1w += 1
elif abs(i - n2) < abs(i - n1):
n2w += 1
else:
d += 1
print(n1w, d, n2w) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
n1, n2 = map(int, input().split())
n1w = 0
d = 0
n2w = 0
for n in range(6):
i = n+1
if abs(i - n1) < abs(i - n2):
n1w += 1
elif abs(i - n2) < abs(i - n1):
n2w += 1
else:
d += 1
print(n1w, d, n2w)
``` | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,677,121,083 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 22,732,800 | import re
a=input();a1=len(a)
b=input();b1=len(b)
j = 0
if len(a) > len(b):
while re.search(b,a) is None:
b=b[j:]
j+=1
y = re.search(b,a)
try: print(len(a) - len(b)+ (b1-len(b)) if y.end()==len(a) else a1+b1)
except: print(a1-b1)
else:
while re.search(a,b) is None:
... | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
import re
a=input();a1=len(a)
b=input();b1=len(b)
j = 0
if len(a) > len(b):
while re.search(b,a) is None:
b=b[j:]
j+=1
y = re.search(b,a)
try: print(len(a) - len(b)+ (b1-len(b)) if y.end()==len(a) else a1+b1)
except: print(a1-b1)
else:
while re.search(a,b) i... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,621,960,030 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 184 | 0 | a,b=map(int,input().split())
r=int(a*b)
print(int(r/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a,b=map(int,input().split())
r=int(a*b)
print(int(r/2))
``` | 3.954 |
735 | C | Tennis Championship | PROGRAMMING | 1,600 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are st... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't p... | 1,750 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output"... | 1,624,892,928 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def msi(): return map(str,input().split())
def li(): return list(mi())
n=ii()
ans=0
p,q=2,1
while p<=n:
p,q=p+q,p
ans+=1
| Title: Tennis Championship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very firs... | ```python
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def msi(): return map(str,input().split())
def li(): return list(mi())
n=ii()
ans=0
p,q=2,1
while p<=n:
p,q=p+q,p
ans+=1
``` | 0 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,678,845,348 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | x = int(input())
# We can represent x in binary and count the number of 1s in it
# This will give us the number of bacteria we need to add to get x
count = 0
while x > 0:
if x % 2 == 1:
count += 1
x //= 2
print(count)
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
x = int(input())
# We can represent x in binary and count the number of 1s in it
# This will give us the number of bacteria we need to add to get x
count = 0
while x > 0:
if x % 2 == 1:
count += 1
x //= 2
print(count)
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,691,384,172 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | from math import *
n = int(input())
k = floor(log(n/5+1, 2))
r = (n-5*(2**k-1))/(2**k)
print(["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"][ceil(r)-1]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
from math import *
n = int(input())
k = floor(log(n/5+1, 2))
r = (n-5*(2**k-1))/(2**k)
print(["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"][ceil(r)-1])
``` | 3.969 |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,614,421,335 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 156 | 0 | def largestPalinSub(s):
res = ""
mx = s[0]
# Find the largest character
for i in range(1, len(s)):
mx = max(mx, s[i])
# Append all occurrences of largest
# character to the resultant string
for i in range(0, len(s)):
if s[i] == mx:
... | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
def largestPalinSub(s):
res = ""
mx = s[0]
# Find the largest character
for i in range(1, len(s)):
mx = max(mx, s[i])
# Append all occurrences of largest
# character to the resultant string
for i in range(0, len(s)):
if s[i] ==... | 3 | |
181 | B | Number of Triplets | PROGRAMMING | 1,300 | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are diff... | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 ... | 1,622,058,922 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 16 | 652 | 4,608,000 | n = int(input())
ans = 0
l = []
d = {}
for i in range(n):
x,y = map(int,input().split())
if x in d:
d[x].append(y)
else:
d[x] = [y]
l.append([x,y])
for i in range(n-2):
for j in range(i+1,n):
if (l[i][0]+l[j][0])%2==0 and (l[i][1]+l[j][1])%2==0:
if (... | Title: Number of Triplets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points ar... | ```python
n = int(input())
ans = 0
l = []
d = {}
for i in range(n):
x,y = map(int,input().split())
if x in d:
d[x].append(y)
else:
d[x] = [y]
l.append([x,y])
for i in range(n-2):
for j in range(i+1,n):
if (l[i][0]+l[j][0])%2==0 and (l[i][1]+l[j][1])%2==0:
... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,616,035,785 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 2,252,800 | from itertools import combinations as comb
n,weight=int(input()),list(map(int,input().split()))
weight=sorted(weight)
'''weight=weight[:-2]
marked_indexes=[]
for i in range(len(weight)-1):
if weight[i]==weight[i+1]:
if i not in marked_indexes and i+1 not in marked_indexes:
marked_indexes.append(... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
from itertools import combinations as comb
n,weight=int(input()),list(map(int,input().split()))
weight=sorted(weight)
'''weight=weight[:-2]
marked_indexes=[]
for i in range(len(weight)-1):
if weight[i]==weight[i+1]:
if i not in marked_indexes and i+1 not in marked_indexes:
marked_index... | -1 | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,693,055,578 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 140 | 819,200 | import sys
input = lambda: sys.stdin.readline()
I = lambda: int(input())
M = lambda: map(int, input().strip().split())
L = lambda: list(map(int, input().strip().split()))
S = lambda: input().strip()
n = S()
count = n.count('4') + n.count('8') + n.count('0')
for i in range(len(n)-1):
if int(n[i:i+2]) % ... | Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
import sys
input = lambda: sys.stdin.readline()
I = lambda: int(input())
M = lambda: map(int, input().strip().split())
L = lambda: list(map(int, input().strip().split()))
S = lambda: input().strip()
n = S()
count = n.count('4') + n.count('8') + n.count('0')
for i in range(len(n)-1):
if int(n[... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,674,068,608 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | b=list(map(int,input().split()))
z=b.copy()
c=0
a= min(b[0:2])
x=max(b[0:2])
if b[0]*b[1]==b[2]*b[2]:
c+=1
elif b[0]!=b[1]:
while x>0:
c+=1
a-=b[2]
x-=b[2]
while a>0:
c+=1
x-=b[2]
else:
while b[1]>0:
c+=1
b[1]-=b[2]
while b[0]>0:
c+=1
... | 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
b=list(map(int,input().split()))
z=b.copy()
c=0
a= min(b[0:2])
x=max(b[0:2])
if b[0]*b[1]==b[2]*b[2]:
c+=1
elif b[0]!=b[1]:
while x>0:
c+=1
a-=b[2]
x-=b[2]
while a>0:
c+=1
x-=b[2]
else:
while b[1]>0:
c+=1
b[1]-=b[2]
while b[0]>0:
c+... | 0 |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,578,484,685 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | import sys
traffic =0
n=0
for x in sys.stdin:
if(x[0] =='+'):
n +=1
elif(x[0] =='-'):
n -=1
else:
message= x.split(':')[1]
traffic +=n*len(message)
print(traffic) | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
import sys
traffic =0
n=0
for x in sys.stdin:
if(x[0] =='+'):
n +=1
elif(x[0] =='-'):
n -=1
else:
message= x.split(':')[1]
traffic +=n*len(message)
print(traffic)
``` | 0 |
997 | A | Convert to Ones | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for examp... | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consist... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1... | 500 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
... | 1,530,454,232 | 332 | Python 3 | OK | TESTS | 115 | 233 | 1,024,000 | n, x, y = [int(x) for x in input().split()]
xs = input().strip()
from itertools import groupby
count = sum(1 for g, _ in groupby(xs) if g == '0')
ans = count * y
for i in range(count):
ans = min(ans, i * x + (count - i) * y)
print(ans)
| Title: Convert to Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can a... | ```python
n, x, y = [int(x) for x in input().split()]
xs = input().strip()
from itertools import groupby
count = sum(1 for g, _ in groupby(xs) if g == '0')
ans = count * y
for i in range(count):
ans = min(ans, i * x + (count - i) * y)
print(ans)
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,660,948,589 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | def football():
goals = []
for i in range(int(input())):
goals.append(input())
sorted_goals = list(sorted(goals))
teams = [sorted_goals[0], sorted_goals[-1]]
if teams[0] == teams[1]:
print(teams[0])
else:
scores = [0, 0]
for item in sorted_goals:
... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
def football():
goals = []
for i in range(int(input())):
goals.append(input())
sorted_goals = list(sorted(goals))
teams = [sorted_goals[0], sorted_goals[-1]]
if teams[0] == teams[1]:
print(teams[0])
else:
scores = [0, 0]
for item in sorted_goal... | 3.969 |
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly ... | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus t... | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"out... | 1,606,713,823 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 109 | 0 | n=int(input())
lst = list(map(int, input().strip().split(' ')))
if lst[-1]==15:
print('DOWN')
elif lst[-1]==0:
print('UP')
elif n==1:
print('-1')
else:
if lst[-1]<lst[-2]:
print('DOWN')
else:
print('UP') | Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the momen... | ```python
n=int(input())
lst = list(map(int, input().strip().split(' ')))
if lst[-1]==15:
print('DOWN')
elif lst[-1]==0:
print('UP')
elif n==1:
print('-1')
else:
if lst[-1]<lst[-2]:
print('DOWN')
else:
print('UP')
``` | 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,621,259,575 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | a,b = list(map(int,input().split()))
arr= list(map(int,input().split()))
b = b-1
al = []
for i in range(a):
al.append(abs(b-i))
al.append(i)
dt = {}
for i in set(al):
dt[i]= 0
for i in al:
dt[i]+=arr[i]
print(sum(1 for i,v in dt.items() if v>1)) | 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
a,b = list(map(int,input().split()))
arr= list(map(int,input().split()))
b = b-1
al = []
for i in range(a):
al.append(abs(b-i))
al.append(i)
dt = {}
for i in set(al):
dt[i]= 0
for i in al:
dt[i]+=arr[i]
print(sum(1 for i,v in dt.items() if v>1))
``` | 0 | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,550,392,705 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | n=int(input())
arr1=[int(input()) for _ in range(n)]
arr2=set(arr1)
if len(arr2)==2 and arr1.count(arr2[0])==arr1.count(arr2[1]):
print('YES')
print(*arr2)
print('NO')
| Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
n=int(input())
arr1=[int(input()) for _ in range(n)]
arr2=set(arr1)
if len(arr2)==2 and arr1.count(arr2[0])==arr1.count(arr2[1]):
print('YES')
print(*arr2)
print('NO')
``` | -1 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,664,033,661 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 92 | 0 | c = int(input())
cou = 0
p = [0 for i in range(3005)]
for i in range(2,1005):
if p[i] == 0:
for j in range(2*i,3005,i):
p[j] += 1
for i in range(1,c+1):
if p[i] == 2:
cou += 1
print (cou) | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
c = int(input())
cou = 0
p = [0 for i in range(3005)]
for i in range(2,1005):
if p[i] == 0:
for j in range(2*i,3005,i):
p[j] += 1
for i in range(1,c+1):
if p[i] == 2:
cou += 1
print (cou)
``` | 0 |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,673,782,170 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | n = int(input())
count = (3**(n-1)) % ((10**6) + 3)
if n > 0:
print(count)
else:
print(0) | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
n = int(input())
count = (3**(n-1)) % ((10**6) + 3)
if n > 0:
print(count)
else:
print(0)
``` | 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,680,283,201 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s=input()
t=input()
x=''
for i in range(len(t)-1,-1,-1):
x+=t[i]
if s==x:
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()
t=input()
x=''
for i in range(len(t)-1,-1,-1):
x+=t[i]
if s==x:
print('YES')
else:
print('NO')
``` | 3.977 |
665 | D | Simple Subset | PROGRAMMING | 1,800 | [
"constructive algorithms",
"greedy",
"number theory"
] | null | null | A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You wan... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. | On the first line print integer *m* — the maximum possible size of simple subset of *a*.
On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in an... | [
"2\n2 3\n",
"2\n2 2\n",
"3\n2 1 1\n",
"2\n83 14\n"
] | [
"2\n3 2\n",
"1\n2\n",
"3\n1 1 2\n",
"2\n14 83\n"
] | none | 0 | [
{
"input": "2\n2 3",
"output": "2\n3 2"
},
{
"input": "2\n2 2",
"output": "1\n2"
},
{
"input": "3\n2 1 1",
"output": "3\n1 1 2"
},
{
"input": "2\n83 14",
"output": "2\n14 83"
},
{
"input": "10\n10 10 1 2 3 3 1 2 1 5",
"output": "4\n1 1 10 1"
},
{
"inpu... | 1,606,212,310 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 202 | 9,318,400 | #besme taala
#ya_hossein
q = (1000000 + 1)*[0]
prime = (1000000 + 1)*[0]
for i in range(2 ,int(1e6 + 1)):
for j in range(2*i,int(1e6 + 1), i):
prime[j] = 1
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
q[a[i]] += 1
if q[1] >= 2:
print(q[1] + q[2])
... | Title: Simple Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an arra... | ```python
#besme taala
#ya_hossein
q = (1000000 + 1)*[0]
prime = (1000000 + 1)*[0]
for i in range(2 ,int(1e6 + 1)):
for j in range(2*i,int(1e6 + 1), i):
prime[j] = 1
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
q[a[i]] += 1
if q[1] >= 2:
print(q[1] + q... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,642,791,639 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | kare=input()
kenar1=int(kare[0])
kenar2=int(kare[-1])
alan=kenar1*kenar2
print(int(alan/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
kare=input()
kenar1=int(kare[0])
kenar2=int(kare[-1])
alan=kenar1*kenar2
print(int(alan/2))
``` | 0 |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,679,857,251 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | n = int(input())
values = list(map(int, input().split(' ')))
prefix_sum = []
sum = 0
for i in range(n):
sum += values[i]
prefix_sum.append(sum)
theset = set(prefix_sum)
print(n - len(theset))
| Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
values = list(map(int, input().split(' ')))
prefix_sum = []
sum = 0
for i in range(n):
sum += values[i]
prefix_sum.append(sum)
theset = set(prefix_sum)
print(n - len(theset))
``` | 0 |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,692,327,942 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 139 | 16,588,800 | import sys
input = sys.stdin.readline
MOD=10**9+7
if __name__ == '__main__':
n=int(input())
arr=list()
for _ in range(n):
arr.append(list(map(int, input().split())))
if n<=2:
print(n)
exit()
left=True
res=2
for i in range(1,n-1):
if left... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
import sys
input = sys.stdin.readline
MOD=10**9+7
if __name__ == '__main__':
n=int(input())
arr=list()
for _ in range(n):
arr.append(list(map(int, input().split())))
if n<=2:
print(n)
exit()
left=True
res=2
for i in range(1,n-1):
... | 0 | |
445 | B | DZY Loves Chemistry | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ... | The first line contains two space-separated integers *n* and *m* .
Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=<<=*y**i*<=≤<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once i... | Print a single integer — the maximum possible danger. | [
"1 0\n",
"2 1\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first sample, there's only one way to pour, and the danger won't increase.
In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.
In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that... | 1,000 | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "3 2\n1 2\n2 3",
"output": "4"
},
{
"input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7",
"output": "512"
},
{
"input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12... | 1,665,423,451 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 307,200 | import timeit
numbers = list(map(int , input().split()))
info = []
hash_table = {}
# start = timeit.default_timer()
for i in range(0 , numbers[0]) :
x = {
"name" : i+1 ,
"react" : []
}
info.append(x)
hash_table[i+1] = len(info) - 1
for i in range(0 , numbers[1] ) :
... | Title: DZY Loves Chemistry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order... | ```python
import timeit
numbers = list(map(int , input().split()))
info = []
hash_table = {}
# start = timeit.default_timer()
for i in range(0 , numbers[0]) :
x = {
"name" : i+1 ,
"react" : []
}
info.append(x)
hash_table[i+1] = len(info) - 1
for i in range(0 , numbe... | 0 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,683,023,918 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
dp = [[False] * (sum_a + 1) for _ in range(n + 1)]
dp[0][0] = True
for i in range(1, n + 1):
for j in range(sum_a + 1):
dp[i][j] = dp[i - 1][j]
if j >= a[i - 1]:
dp[i][j] |= dp[i - 1][j - a[i - 1]]
max_diff = 0
for j ... | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
dp = [[False] * (sum_a + 1) for _ in range(n + 1)]
dp[0][0] = True
for i in range(1, n + 1):
for j in range(sum_a + 1):
dp[i][j] = dp[i - 1][j]
if j >= a[i - 1]:
dp[i][j] |= dp[i - 1][j - a[i - 1]]
max_diff ... | -1 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,665,315,567 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 3 | 124 | 0 | #I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collections import ... | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
#I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collectio... | 3 | |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,628,534,955 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 6,963,200 | n, m, k = map(int, input().split())
lista = [["#"]*(m+2)] + [["#"] + list(input()) + ["#"] for _ in range(n)] + [["#"]*(m+2)]
pontos = sum(l.count(".") for l in lista)
st = [(x, y) for i in range(n+2) for j in range(m+2) if lista[x][y] == "."][:1]
a = 0
while a < pontos - k:
x, y = st.pop()
if list... | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
n, m, k = map(int, input().split())
lista = [["#"]*(m+2)] + [["#"] + list(input()) + ["#"] for _ in range(n)] + [["#"]*(m+2)]
pontos = sum(l.count(".") for l in lista)
st = [(x, y) for i in range(n+2) for j in range(m+2) if lista[x][y] == "."][:1]
a = 0
while a < pontos - k:
x, y = st.pop()
... | -1 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,616,931,639 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 216 | 1,945,600 | n = int(input())
arr = list(map(int, input().split()))
water = [0] * n
# Search Right
for i in range(n):
temp = 1
for j in range(i, n-1):
l = arr[j]
r = arr[j+1]
if l >= r:
temp +=1
else: break;
water[i] += temp
# Search Left
for i in range(n-1,-1,... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
n = int(input())
arr = list(map(int, input().split()))
water = [0] * n
# Search Right
for i in range(n):
temp = 1
for j in range(i, n-1):
l = arr[j]
r = arr[j+1]
if l >= r:
temp +=1
else: break;
water[i] += temp
# Search Left
for i in ran... | 3.942376 |
148 | D | Bag of mice | PROGRAMMING | 1,800 | [
"dp",
"games",
"math",
"probabilities"
] | null | null | The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc... | The only line of input data contains two integers *w* and *b* (0<=≤<=*w*,<=*b*<=≤<=1000). | Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. | [
"1 3\n",
"5 5\n"
] | [
"0.500000000\n",
"0.658730159\n"
] | Let's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one... | 1,000 | [
{
"input": "1 3",
"output": "0.500000000"
},
{
"input": "5 5",
"output": "0.658730159"
},
{
"input": "100 100",
"output": "0.666295063"
},
{
"input": "100 1",
"output": "0.990099010"
},
{
"input": "1 100",
"output": "0.336633663"
},
{
"input": "67 420"... | 1,695,298,017 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 154 | 614,400 | from functools import cache
w, b = map(int, input().split())
@cache
def f(w, b):
if w==0:
return 0
elif b==0:
return 1
else:
a = w/(w+b)
fix = b/(w+b)
b -= 1
if b==0:
c = 0
else:
c = (b/(w+b))*f(w,b-1)
... | Title: Bag of mice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed ear... | ```python
from functools import cache
w, b = map(int, input().split())
@cache
def f(w, b):
if w==0:
return 0
elif b==0:
return 1
else:
a = w/(w+b)
fix = b/(w+b)
b -= 1
if b==0:
c = 0
else:
c = (b/(w+b))*f(w,b-1... | 0 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,690,538,217 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | from itertools import product
n = int(input())
luck = []
def generate_lucky(l:int) -> list:
ns = list(product("47", repeat=l))
return list(map(lambda x:int("".join(x)),ns))
for i in range(1, 4):
l = generate_lucky(i)
for x in l:
luck.append(x)
for x in luck:
if n%x ==0:
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
from itertools import product
n = int(input())
luck = []
def generate_lucky(l:int) -> list:
ns = list(product("47", repeat=l))
return list(map(lambda x:int("".join(x)),ns))
for i in range(1, 4):
l = generate_lucky(i)
for x in l:
luck.append(x)
for x in luck:
if n... | 3 | |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,536,329,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 |
a, b, c = map(int, input().split())
good = False
template = [True if i % a == 0 else False for i in range(3 * max([a, b, c]))]
A = template[:]
i = 0
while i * b + 1 < len(A):
A[i * b + 1] = True
i += 1
i = 0
while i < len(A):
if not A[i]:
break
break
i += 1
j = 0
while j * c + i < len... | Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
a, b, c = map(int, input().split())
good = False
template = [True if i % a == 0 else False for i in range(3 * max([a, b, c]))]
A = template[:]
i = 0
while i * b + 1 < len(A):
A[i * b + 1] = True
i += 1
i = 0
while i < len(A):
if not A[i]:
break
break
i += 1
j = 0
while j * c... | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,545,833,411 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 218 | 0 | input()
a = sorted(set(map(int, input().split())))
if len(a) == 1:
print("NO")
else:
print(a[1])
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
input()
a = sorted(set(map(int, input().split())))
if len(a) == 1:
print("NO")
else:
print(a[1])
``` | 3.9455 |
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,526,931,723 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 202 | 8,192,000 | from bisect import bisect_right
def bad():
print(0)
exit()
n, k, l_ = map(int, input().split())
a = sorted(list(map(int, input().split())))
if n == 1:
print(min(a))
exit()
if a[1] - a[0] > l_:
bad()
b = bisect_right(a, a[0] + l_)
if b < n:
bad()
to_sum = [0]
if... | 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
from bisect import bisect_right
def bad():
print(0)
exit()
n, k, l_ = map(int, input().split())
a = sorted(list(map(int, input().split())))
if n == 1:
print(min(a))
exit()
if a[1] - a[0] > l_:
bad()
b = bisect_right(a, a[0] + l_)
if b < n:
bad()
to_sum =... | 0 | |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,555,259,807 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 171 | 1,024,000 | MAX = 5
matriz = []
for i in range(MAX):
linha = []
for j in range(MAX):
linha.append(0)
matriz.append(linha)
def imprimir_matriz(mat):
for l in mat:
for ind, el in enumerate(l):
if ind == len(l) - 1:
print(el)
else:
... | Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
MAX = 5
matriz = []
for i in range(MAX):
linha = []
for j in range(MAX):
linha.append(0)
matriz.append(linha)
def imprimir_matriz(mat):
for l in mat:
for ind, el in enumerate(l):
if ind == len(l) - 1:
print(el)
else:
... | -1 | |
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,665,680,394 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 5,017,600 | from re import match
print("YES" if match(r"[^\s]*h[^\s]*e[^\s]*l[^\s]*l[^\s]*o[^\s]*",input()) else "NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
from re import match
print("YES" if match(r"[^\s]*h[^\s]*e[^\s]*l[^\s]*l[^\s]*o[^\s]*",input()) else "NO")
``` | 3.959654 |
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,679,846,920 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,m,k = map(int,input().split())
a = min(n,m,k)
print(a) | 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,k = map(int,input().split())
a = min(n,m,k)
print(a)
``` | 0 |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,608,880,984 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 218 | 307,200 | #from collections import Counter
import math
pi = math.pi
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
i = 0
area = 0
while i<len(arr):
if i+1<len(arr):
area += pi*(arr[i]**2-arr[i+1]**2)
else:
area += pi*(arr[i]**2)
i +... | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
#from collections import Counter
import math
pi = math.pi
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
i = 0
area = 0
while i<len(arr):
if i+1<len(arr):
area += pi*(arr[i]**2-arr[i+1]**2)
else:
area += pi*(arr[i]**2)
... | 3 | |
76 | E | Points | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | E. Points | 1 | 256 | You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. | The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide. | The only line of output should contain the required sum of squares of distances between all pairs of points. | [
"4\n1 1\n-1 -1\n1 -1\n-1 1\n"
] | [
"32\n"
] | none | 0 | [
{
"input": "4\n1 1\n-1 -1\n1 -1\n-1 1",
"output": "32"
},
{
"input": "1\n6 3",
"output": "0"
},
{
"input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1... | 1,670,662,014 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 528 | 5,017,600 | from heapq import heapify, heappop, heappush, nlargest
from collections import Counter, defaultdict
from sys import stdin, stdout
from math import ceil, floor, sqrt
from functools import reduce,lru_cache
# n,m = map(int,stdin.readline().split())
# stdout.write(str(arr[x-y]-arr[x])+'\n')
# reps = int(stdin.readli... | Title: Points
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
Input Specification:
The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000)... | ```python
from heapq import heapify, heappop, heappush, nlargest
from collections import Counter, defaultdict
from sys import stdin, stdout
from math import ceil, floor, sqrt
from functools import reduce,lru_cache
# n,m = map(int,stdin.readline().split())
# stdout.write(str(arr[x-y]-arr[x])+'\n')
# reps = int(st... | 3.726654 |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,697,361,482 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 77 | 0 | i=[]
ans=[]
for _ in range(3):
i.append(int(input()))
ans.append(i[0]*i[1]*i[2])
ans.append(i[0] + i[1] + i[2])
ans.append(i[0]*(i[1] + i[2]))
ans.append((i[0]+i[1]) * i[2])
print(max(ans))
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
i=[]
ans=[]
for _ in range(3):
i.append(int(input()))
ans.append(i[0]*i[1]*i[2])
ans.append(i[0] + i[1] + i[2])
ans.append(i[0]*(i[1] + i[2]))
ans.append((i[0]+i[1]) * i[2])
print(max(ans))
``` | 3 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,586,720,933 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | n,m,k=map(int,input().split())
l=list(map(int,input().split()))
ind=1
flag=0
for i in range(k):
u,v=map(int,input().split())
if flag==0:
if v in l:
ind=v
flag=1
else:
ind=v
print(ind)
| Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
ind=1
flag=0
for i in range(k):
u,v=map(int,input().split())
if flag==0:
if v in l:
ind=v
flag=1
else:
ind=v
print(ind)
``` | 0 | |
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. | Print single integer — the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a... | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23... | 1,485,196,840 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 10,854,400 | def main():
QWE = 'river'
INF = 10 ** 18 + 9
EPS = 10 ** -10
import sys, math, re
#fi = open('input.txt', 'r')
#fo = open('output.txt', 'w+')
#fi = open(QWE +".in", "r")
#fo = open(QWE + ".out", "w+")
#n, m, k = map(int, input().split(' ', 2))
n = int(input())
... | Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr... | ```python
def main():
QWE = 'river'
INF = 10 ** 18 + 9
EPS = 10 ** -10
import sys, math, re
#fi = open('input.txt', 'r')
#fo = open('output.txt', 'w+')
#fi = open(QWE +".in", "r")
#fo = open(QWE + ".out", "w+")
#n, m, k = map(int, input().split(' ', 2))
n = int(inpu... | 0 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,660,925,756 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 55 | 77 | 0 | num = int(input())
people = []
s = set()
for i in range(num):
person = input()
if person in s:
print("YES")
else:
print("NO")
s.add(person)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
num = int(input())
people = []
s = set()
for i in range(num):
person = input()
if person in s:
print("YES")
else:
print("NO")
s.add(person)
``` | 3 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,441,499,798 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | numdig = int(input())
innum = int(input())
import math
length = numdig
digits = []
def shift(l, n):
return l[n:] + l[:n]
for x in range (0,length):
digits.append( int( innum%(math.pow(10, x+1))/(math.pow(10,x))) )
innum = innum - (innum%(math.pow(10, x+1)))
bestshort = 0
bestdigits = dig... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
numdig = int(input())
innum = int(input())
import math
length = numdig
digits = []
def shift(l, n):
return l[n:] + l[:n]
for x in range (0,length):
digits.append( int( innum%(math.pow(10, x+1))/(math.pow(10,x))) )
innum = innum - (innum%(math.pow(10, x+1)))
bestshort = 0
bestdi... | 0 | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,620,840,726 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 93 | 6,963,200 | n=list(map(int,input().split()))
count=0
m=[]
for i in range(n[0]):
x=list(map(int,input().split()))
m.append(x)
# print(m)
f=len(m)-i-1
for i in range(n[0]):
f=len(m)-i-1
if i==0:
count+=(n[1]-m[f][0])
if i!=0:
count+=(m[f+1][0]-m[f][0])
if (count)<m[f][1]:
... | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n=list(map(int,input().split()))
count=0
m=[]
for i in range(n[0]):
x=list(map(int,input().split()))
m.append(x)
# print(m)
f=len(m)-i-1
for i in range(n[0]):
f=len(m)-i-1
if i==0:
count+=(n[1]-m[f][0])
if i!=0:
count+=(m[f+1][0]-m[f][0])
if (count)<... | 3 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,954,934 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | '''程文奇 2100015898'''
n=int(input())
coinlist=list(map(int,input().split()))
myvalue=0
totalvalue=sum(coinlist)
for i in range(n):
myvalue+=coinlist[i]
if myvalue>(totalvalue/2) :
print(i+1)
break | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
'''程文奇 2100015898'''
n=int(input())
coinlist=list(map(int,input().split()))
myvalue=0
totalvalue=sum(coinlist)
for i in range(n):
myvalue+=coinlist[i]
if myvalue>(totalvalue/2) :
print(i+1)
break
``` | 0 | |
812 | B | Sagheer, the Hausmeister | PROGRAMMING | 1,600 | [
"bitmasks",
"brute force",
"dp"
] | null | null | Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of *n* floors with stairs at the left and the right sid... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively.
The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then ... | Print a single integer — the minimum total time needed to turn off all the lights. | [
"2 2\n0010\n0100\n",
"3 4\n001000\n000010\n000010\n",
"4 3\n01110\n01110\n01110\n01110\n"
] | [
"5\n",
"12\n",
"18\n"
] | In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.
In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th... | 1,000 | [
{
"input": "2 2\n0010\n0100",
"output": "5"
},
{
"input": "3 4\n001000\n000010\n000010",
"output": "12"
},
{
"input": "4 3\n01110\n01110\n01110\n01110",
"output": "18"
},
{
"input": "3 2\n0000\n0100\n0100",
"output": "4"
},
{
"input": "1 89\n0000000000000000000000... | 1,626,889,258 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 108 | 20,172,800 | import sys
import io, os
import math
gcd = math.gcd
sqrt = math.sqrt
ceil = math.ceil
# arr=list(map(int, input().split()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def strinp(testcases):
k = 5
if (testcases == -1 or testcases == 1):
k = 1
f = str(input())
f = f[... | Title: Sagheer, the Hausmeister
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goe... | ```python
import sys
import io, os
import math
gcd = math.gcd
sqrt = math.sqrt
ceil = math.ceil
# arr=list(map(int, input().split()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def strinp(testcases):
k = 5
if (testcases == -1 or testcases == 1):
k = 1
f = str(input())
... | 0 | |
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,531,725,920 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | line1 = str(input())
line2 = str(input())
nline = ""
for a in range(len(line2)):
if line1[a] == line2[a]:
nline += "0"
else:
nline += "1"
print(nline) | 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
line1 = str(input())
line2 = str(input())
nline = ""
for a in range(len(line2)):
if line1[a] == line2[a]:
nline += "0"
else:
nline += "1"
print(nline)
``` | 3.969 |
356 | B | Xenia and Hamming | PROGRAMMING | 1,900 | [
"implementation",
"math"
] | null | null | Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance.
The Hamming distance between two strings *s*<==<=*s*1*s*2... *s**n* and *t*<==<=*t*1*t*2... *t**n* of equal length *n* is value . Record [*s**i*<=≠<=*t**i*] is the Iverson notation and represents the following: if *s**i*<=≠<... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1012). The second line contains a non-empty string *x*. The third line contains a non-empty string *y*. Both strings consist of at most 106 lowercase English letters.
It is guaranteed that strings *a* and *b* that you obtain from the input have the ... | Print a single integer — the required Hamming distance.
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. | [
"100 10\na\naaaaaaaaaa\n",
"1 1\nabacaba\nabzczzz\n",
"2 3\nrzr\naz\n"
] | [
"0\n",
"4\n",
"5\n"
] | In the first test case string *a* is the same as string *b* and equals 100 letters a. As both strings are equal, the Hamming distance between them is zero.
In the second test case strings *a* and *b* differ in their 3-rd, 5-th, 6-th and 7-th characters. Thus, the Hamming distance equals 4.
In the third test case stri... | 1,000 | [] | 1,573,994,038 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 13,619,200 | e=[]
s=input()
e=s.split()
n=int(e[0])
m=int(e[1])
x=str(input())
y=str(input())
a=''
b=''
count=0
for i in range(n):
a=a+x
for j in range(m):
b=b+y
for q in range(len(a)):
if(a[q]!=b[q]):
count=count+1
print(count)
| Title: Xenia and Hamming
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance.
The Hamming distance between two strings *s*<==<=*s*1*s*2... *s**n* and *t*<==<=*t*1*t*2... *t**n* of equal length *n* is... | ```python
e=[]
s=input()
e=s.split()
n=int(e[0])
m=int(e[1])
x=str(input())
y=str(input())
a=''
b=''
count=0
for i in range(n):
a=a+x
for j in range(m):
b=b+y
for q in range(len(a)):
if(a[q]!=b[q]):
count=count+1
print(count)
``` | 0 | |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,663,323,014 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 61 | 0 | n,m=map(int,input().split());print(n if n==m else 2) | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
n,m=map(int,input().split());print(n if n==m else 2)
``` | 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,702,533 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 5 | 77 | 2,867,200 | import sys, math
input = sys.stdin.readline
a, b, c = [int(x) for x in input().split()]
if (c == 0 and a == b) or (((b - a) / c) >= 0 and ((b - a) / c) == (b - a) // c):
print("YES")
else:
print("NO") | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
import sys, math
input = sys.stdin.readline
a, b, c = [int(x) for x in input().split()]
if (c == 0 and a == b) or (((b - a) / c) >= 0 and ((b - a) / c) == (b - a) // c):
print("YES")
else:
print("NO")
``` | -1 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,594,811,933 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 6,656,000 | n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
c=min(k,a[i],8)
if i!=n-1:
a[i+1]+=a[i]-c
k-=c
if k==0:
print(i+1)
break
else:
print("-1")
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
c=min(k,a[i],8)
if i!=n-1:
a[i+1]+=a[i]-c
k-=c
if k==0:
print(i+1)
break
else:
print("-1")
``` | 3 | |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,538,550,110 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | n = int(input())
k = int(input())
A = int(input())
B = int(input())
res1 = A*n
res2 = 0
x = n
while x != 1:
res2 += A*(x%k) + B
x -= (x % k)
x = x // k
print(res1, res2)
print(res1 if res1 < res2 else res2); | Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
n = int(input())
k = int(input())
A = int(input())
B = int(input())
res1 = A*n
res2 = 0
x = n
while x != 1:
res2 += A*(x%k) + B
x -= (x % k)
x = x // k
print(res1, res2)
print(res1 if res1 < res2 else res2);
``` | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,696,788,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | for t in range(int(input())):
X = 0
n = input()
print(X) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
for t in range(int(input())):
X = 0
n = input()
print(X)
``` | 0 | |
837 | B | Flag of Berland | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. ... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | 0 | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"out... | 1,687,220,992 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 17 | 77 | 2,969,600 | import sys
input = lambda: sys.stdin.readline().rstrip()
N,M = map(int, input().split())
S = []
for _ in range(N):
S.append(input())
INF = float('inf')
A = [[INF,INF,-1,-1],[INF,INF,-1,-1],[INF,INF,-1,-1]]
for i in range(N):
for j in range(M):
if S[i][j]=='R':
A[0][0] = min(A[... | Title: Flag of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N,M = map(int, input().split())
S = []
for _ in range(N):
S.append(input())
INF = float('inf')
A = [[INF,INF,-1,-1],[INF,INF,-1,-1],[INF,INF,-1,-1]]
for i in range(N):
for j in range(M):
if S[i][j]=='R':
A[0][0... | 0 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,660,057,960 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | n = int(input())
data = list(map(int, input().split()))
intial_diff = 99999999999999999999999999
solders = [1, 2]
for i in range(len(data)):
for j in range(len(data)):
if i != j and abs(data[i] - data[j]) < intial_diff and (abs(i-j) == 1 or (i==0 and j==len(data)-1) or (i==len(data)-1 and j==0)):... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n = int(input())
data = list(map(int, input().split()))
intial_diff = 99999999999999999999999999
solders = [1, 2]
for i in range(len(data)):
for j in range(len(data)):
if i != j and abs(data[i] - data[j]) < intial_diff and (abs(i-j) == 1 or (i==0 and j==len(data)-1) or (i==len(data)-1 a... | 3.977 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,693,987,080 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 |
n = int(input())
points = list(map(int, input().split()))
amazing_count = 0
best_score = worst_score = points[0]
for j in range(1, n):
if points[j] > best_score:
amazing_count += 1
best_score = points[j]
elif points[j] < worst_score:
amazing_count += 1
worst_s... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
points = list(map(int, input().split()))
amazing_count = 0
best_score = worst_score = points[0]
for j in range(1, n):
if points[j] > best_score:
amazing_count += 1
best_score = points[j]
elif points[j] < worst_score:
amazing_count += 1
... | 3 | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,531,395,038 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | import math
a,b=input().split()
a,b=[int(a),int(b)]
c=1
l=min(a+10,b)
while a!=l:
c=(c*a)%10
a+=1
print(c) | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
import math
a,b=input().split()
a,b=[int(a),int(b)]
c=1
l=min(a+10,b)
while a!=l:
c=(c*a)%10
a+=1
print(c)
``` | 0 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,592,651,758 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 280 | 1,536,000 | n=int(input())
points=[list(map(int, input().split()))+[False] for i in range(n)]
def visit(points,point):
point[2]=True
x,y=point[0],point[1]
for point in points:
if not point[2] and (point[0] == x or point[1] == y):
visit(points,point)
c=-1
for point in points:
if not p... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n=int(input())
points=[list(map(int, input().split()))+[False] for i in range(n)]
def visit(points,point):
point[2]=True
x,y=point[0],point[1]
for point in points:
if not point[2] and (point[0] == x or point[1] == y):
visit(points,point)
c=-1
for point in points:
... | 3 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,678,696,589 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 684 | 8,396,800 | n=int(input())
mina,maxb=map(int,input().split())
x=[[mina,maxb]]
for i in range(n-1):
a,b=map(int,input().split())
mina=min(a,mina)
maxb=max(b,maxb)
x.append([a,b])
f=True
for i in range(n):
if x[i][0]==mina and x[i][1]==maxb:
print(i+1)
f=False
break
if f:
... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n=int(input())
mina,maxb=map(int,input().split())
x=[[mina,maxb]]
for i in range(n-1):
a,b=map(int,input().split())
mina=min(a,mina)
maxb=max(b,maxb)
x.append([a,b])
f=True
for i in range(n):
if x[i][0]==mina and x[i][1]==maxb:
print(i+1)
f=False
break
... | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,116,963 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | import sys
import math
input = sys.stdin.readline
a, b = int(input().split())
if a == b:
sys.stdout.write("1")
exit()
n = math.ceil(math.log(b / a) / math.log(3 / 2))
if math.log(a, 2) == math.log(b, 3):
n += 1
sys.stdout.write(f"{n}")
| Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
import sys
import math
input = sys.stdin.readline
a, b = int(input().split())
if a == b:
sys.stdout.write("1")
exit()
n = math.ceil(math.log(b / a) / math.log(3 / 2))
if math.log(a, 2) == math.log(b, 3):
n += 1
sys.stdout.write(f"{n}")
``` | -1 | |
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso alrea... | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707... | 1,461,948,534 | 834 | PyPy 3 | WRONG_ANSWER | PRETESTS | 2 | 93 | 23,142,400 | n = int(input())
s = [int(i) for i in input().split()]
a = max(s)
b = min(s)
c = sum(s)
print(a-(c-a-b))
| Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, ... | ```python
n = int(input())
s = [int(i) for i in input().split()]
a = max(s)
b = min(s)
c = sum(s)
print(a-(c-a-b))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name *w* and the collection of forbidden substrings *s*1,<=*s*2,<=...,<=*s**n*. All those strings consist of uppercase and low... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of forbidden substrings in the collection. Next *n* lines contain these substrings. The next line contains string *w*. All those *n*<=+<=1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not e... | Output the only line — Petya's resulting string with the maximum number of letters *letter*. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line *a* is lexicographically ... | [
"3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt\n",
"4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na\n",
"2\naCa\ncba\nabAcaba\nc\n"
] | [
"PetrLovtTttttNumtttt\n",
"petrsmatchwin\n",
"abCacba\n"
] | none | 0 | [] | 1,690,493,195 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1690493195.802798")# 1690493195.802835 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name *w* and the collection of forbi... | ```python
print("_RANDOM_GUESS_1690493195.802798")# 1690493195.802835
``` | 0 | |
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ... | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100... | 1,664,136,374 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 77 | 1,126,400 | s, e = [int(i) for i in input().split(" ")]
# def get_closest_lucky(num):
# if num == 0:
# return ""
# curr = num % 10
# if curr <= 4:
# to_add = "4"
# elif 4 < curr <= 7:
# to_add = "7"
# elif curr < 10:
# to_add = "44"
# return get_closest_lucky(num // 10) + ... | Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *... | ```python
s, e = [int(i) for i in input().split(" ")]
# def get_closest_lucky(num):
# if num == 0:
# return ""
# curr = num % 10
# if curr <= 4:
# to_add = "4"
# elif 4 < curr <= 7:
# to_add = "7"
# elif curr < 10:
# to_add = "44"
# return get_closest_lucky(num... | 0 | |
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,567,874,568 | 168 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 0 | l = [int(i) for i in input().split()]
s = str(input())
n = l[0]
k = l[1]
i = 0
#find initial position
while i < n:
if s[i] =="G":
break;
i+=1
right = s[i:n:k]
left = s[::-1]
left = left[n-i-1:n:k]
if ('T' in right and '#' not in right) or ('T' in left and '#' not in left):
print(... | Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
l = [int(i) for i in input().split()]
s = str(input())
n = l[0]
k = l[1]
i = 0
#find initial position
while i < n:
if s[i] =="G":
break;
i+=1
right = s[i:n:k]
left = s[::-1]
left = left[n-i-1:n:k]
if ('T' in right and '#' not in right) or ('T' in left and '#' not in left):
... | 0 | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,506,245,483 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | s = input()
vowels = {'a', 'e', 'i', 'u', 'o'}
def will_divide(x):
for l in x:
if l in vowels:
return False
if len(set(x)) == 1:
return False
return True
space_positions = []
space_positions_set = set()
i = 2
while i < len(s):
if not space_positions_set.intersection({i-... | Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (... | ```python
s = input()
vowels = {'a', 'e', 'i', 'u', 'o'}
def will_divide(x):
for l in x:
if l in vowels:
return False
if len(set(x)) == 1:
return False
return True
space_positions = []
space_positions_set = set()
i = 2
while i < len(s):
if not space_positions_set.inters... | 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,557,078,384 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 0 | n,m=map(int,input().split())
x=0
for i in range(n):
a=list(map(int,input().split()))
for j in range(len(a)-1):
if j%2==0:
if a[j]==1 or a[j+1]==1:
x+=1
print(x) | 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
n,m=map(int,input().split())
x=0
for i in range(n):
a=list(map(int,input().split()))
for j in range(len(a)-1):
if j%2==0:
if a[j]==1 or a[j+1]==1:
x+=1
print(x)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,660,657,777 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | x,y,a=list(map(int,input().split()))
n=x//a
m=y//a
if(x%a!=0):
n+=1
if(y%a!=0):
m+=1
print(n*m) | 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
x,y,a=list(map(int,input().split()))
n=x//a
m=y//a
if(x%a!=0):
n+=1
if(y%a!=0):
m+=1
print(n*m)
``` | 3.977 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,694,149,087 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | a=input()
b=['A','E','I','O','U','Y','y','a','e','i','o','u','.']
for i in a:
if i in b:
a=a.replace(i,"")
x=''
for i in a:
x+='.'+i
print(x.lower()) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
a=input()
b=['A','E','I','O','U','Y','y','a','e','i','o','u','.']
for i in a:
if i in b:
a=a.replace(i,"")
x=''
for i in a:
x+='.'+i
print(x.lower())
``` | 3 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,541,777,740 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 280 | 0 | n = int(input())
ans = 0
for i in range(35):
num = i * (i+1) // 2
if num == n:
ans = 1
break
print("YES" * ans + "NO" * ( 1 - ans))
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input())
ans = 0
for i in range(35):
num = i * (i+1) // 2
if num == n:
ans = 1
break
print("YES" * ans + "NO" * ( 1 - ans))
``` | 3.93 |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,650,626,059 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 0 | r = int(input())
if r%2 == 1:
print (r//2)
else:
print(r//2-1)
| Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
r = int(input())
if r%2 == 1:
print (r//2)
else:
print(r//2-1)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) meaning that value should be equal to *q**i*.
Your task is to find any inte... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=105) — the number of elements in the array and the number of limits.
Each of the next *m* lines contains three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 0<=≤<=*q**i*<=<<=230) describing the *i*-th limit. | If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a*[*i*]<=<<=230) decribing the interesting array. If there are multiple answers, print any of them.
If the interesting array doesn't exist, print "NO... | [
"3 1\n1 3 3\n",
"3 2\n1 3 3\n1 3 2\n"
] | [
"YES\n3 3 3\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1\n1 3 3",
"output": "YES\n3 3 3"
},
{
"input": "3 2\n1 3 3\n1 3 2",
"output": "NO"
},
{
"input": "3 2\n1 2 536870912\n2 3 536870911",
"output": "YES\n536870912 1073741823 536870911"
},
{
"input": "1 1\n1 1 10",
"output": "YES\n10"
},
{
"input": "1 2... | 1,642,201,452 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 109 | 12,595,200 | class SegmentTreeSum:
def __init__(self, k):
self.n = 2**k
self.load = [0] * (2*self.n)
self.val = [0] * (2*self.n)
def _propagate(self, v, a, b):
l = v*2
r = v*2+1
self.load[l] += self.load[v]
self.load[r] += self.load[v]
self.val[v] +... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**... | ```python
class SegmentTreeSum:
def __init__(self, k):
self.n = 2**k
self.load = [0] * (2*self.n)
self.val = [0] * (2*self.n)
def _propagate(self, v, a, b):
l = v*2
r = v*2+1
self.load[l] += self.load[v]
self.load[r] += self.load[v]
sel... | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,426,273,685 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 409,600 | from collections import Counter
n = int(input())
l = []
for i in range(n):
l.append(input())
l_counter = Counter(l)
l_counter_1 = dict((v,k) for k, v in l_counter.items())
print(l_counter_1[max(l_counter_1)])
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
from collections import Counter
n = int(input())
l = []
for i in range(n):
l.append(input())
l_counter = Counter(l)
l_counter_1 = dict((v,k) for k, v in l_counter.items())
print(l_counter_1[max(l_counter_1)])
``` | 3.968237 |
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,596,106,477 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 6,758,400 | a=int(input())
if a%2==0:print("1"*(a//2))
else:
print("7"+"1"*((a-3)//2)) | Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 o... | ```python
a=int(input())
if a%2==0:print("1"*(a//2))
else:
print("7"+"1"*((a-3)//2))
``` | 3 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,655,634,280 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 62 | 8,806,400 | n = int(input());a = [*map(int, input().split())];print(max(0, n-(a.count(min(a)) + a.count(max(a)))))
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n = int(input());a = [*map(int, input().split())];print(max(0, n-(a.count(min(a)) + a.count(max(a)))))
``` | 3 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,592,997,242 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | n=int(input())
a=list(map(int,input().split()))
s=list(set(a))
if len(s)==n:
print(1)
else:
print(2) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n=int(input())
a=list(map(int,input().split()))
s=list(set(a))
if len(s)==n:
print(1)
else:
print(2)
``` | 0 | |
226 | A | Flying Saucer Segments | PROGRAMMING | 1,400 | [
"math"
] | null | null | An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the... | The first line contains two space-separated integers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly. | Print a single number — the answer to the problem modulo *m*. | [
"1 10\n",
"3 8\n"
] | [
"2\n",
"2\n"
] | In the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.
To briefly describe the movements in the second sample we will use value <img align="middle" class="tex-formula" src="https://espresso.cod... | 500 | [
{
"input": "1 10",
"output": "2"
},
{
"input": "3 8",
"output": "2"
},
{
"input": "8 12",
"output": "8"
},
{
"input": "4 84",
"output": "80"
},
{
"input": "9 95",
"output": "17"
},
{
"input": "331358794 820674098",
"output": "2619146"
},
{
... | 1,689,342,742 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | print("_RANDOM_GUESS_1689342742.045868")# 1689342742.0459 | Title: Flying Saucer Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, c... | ```python
print("_RANDOM_GUESS_1689342742.045868")# 1689342742.0459
``` | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,625,163,177 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 233 | 17,408,000 | arr_size = int(input())
arr = [int(x) for x in input().split()]
max_sum = 0
best_first = 0
first_sum = 0
third_sum = 0
first_cursor = 0
last_cursor = arr_size-1
while last_cursor >= first_cursor:
if first_sum > third_sum:
third_sum += arr[last_cursor]
last_cursor -= 1
elif third_sum > first_... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
arr_size = int(input())
arr = [int(x) for x in input().split()]
max_sum = 0
best_first = 0
first_sum = 0
third_sum = 0
first_cursor = 0
last_cursor = arr_size-1
while last_cursor >= first_cursor:
if first_sum > third_sum:
third_sum += arr[last_cursor]
last_cursor -= 1
elif third_su... | 0 | |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,626,304,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 154 | 6,758,400 | a,b=map(int,input().split())
c=sorted(list(map(int,input().split())))
s=0
for x,y in zip(c,c[1:]):
if (y-x)<=b:
s=s+1
print(2*s)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
a,b=map(int,input().split())
c=sorted(list(map(int,input().split())))
s=0
for x,y in zip(c,c[1:]):
if (y-x)<=b:
s=s+1
print(2*s)
``` | 0 |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,598,017,578 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 310 | 25,190,400 | from sys import stdin, stdout
def fin(): return stdin.readline().strip()
def fout(x): stdout.write(str(x) + '\n')
stk = []
for i in fin():
if stk and stk[-1] == i: stk.pop()
else: stk.append(i)
if not stk: fout('Yes')
else: print('No') | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
from sys import stdin, stdout
def fin(): return stdin.readline().strip()
def fout(x): stdout.write(str(x) + '\n')
stk = []
for i in fin():
if stk and stk[-1] == i: stk.pop()
else: stk.append(i)
if not stk: fout('Yes')
else: print('No')
``` | 3 | |
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" ... | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
... | 1,686,042,203 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import math
def binary_search(l,num,left,right):
if(left<=right):
mid=left+(right-left)//2
if(num<l[mid]):
return binary_search(l,num,left,mid-1)
elif(num>l[mid]):
return binary_search(l,num,mid+1,right)
else:
return mid
else:
retu... | Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*... | ```python
import math
def binary_search(l,num,left,right):
if(left<=right):
mid=left+(right-left)//2
if(num<l[mid]):
return binary_search(l,num,left,mid-1)
elif(num>l[mid]):
return binary_search(l,num,mid+1,right)
else:
return mid
else:
... | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,675,833,790 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | y, k, n = list(map(int, input().split()))
x = 0
li = []
while x + y < n:
if (x + y) % k == 0:
li.append(x)
x += 1
if li:
print(*li)
else:
print(-1)
| Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y, k, n = list(map(int, input().split()))
x = 0
li = []
while x + y < n:
if (x + y) % k == 0:
li.append(x)
x += 1
if li:
print(*li)
else:
print(-1)
``` | 0 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,654,306,105 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 468 | 10,649,600 | # 2022-06-04T08:16:23Z
"""
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ ... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
# 2022-06-04T08:16:23Z
"""
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low... | 3.863164 |
630 | F | Selection of Personnel | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the... | The only line of the input contains one integer *n* (7<=≤<=*n*<=≤<=777) — the number of potential employees that sent resumes. | Output one integer — the number of different variants of group composition. | [
"7\n"
] | [
"29"
] | none | 0 | [
{
"input": "7",
"output": "29"
},
{
"input": "8",
"output": "92"
},
{
"input": "9",
"output": "246"
},
{
"input": "10",
"output": "582"
},
{
"input": "321",
"output": "66715035255088"
},
{
"input": "624",
"output": "7147161340917624"
},
{
"... | 1,694,340,992 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 77 | 1,536,000 | from math import factorial
a = int(input())
s = ((factorial(a)//(factorial(5)*factorial(a-5)))+(factorial(a)//(factorial(6)*factorial(a-6)))+(factorial(a)//(factorial(7)*factorial(a-7))))
print(s)
| Title: Selection of Personnel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR ... | ```python
from math import factorial
a = int(input())
s = ((factorial(a)//(factorial(5)*factorial(a-5)))+(factorial(a)//(factorial(6)*factorial(a-6)))+(factorial(a)//(factorial(7)*factorial(a-7))))
print(s)
``` | 3 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,627,129,695 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 6,963,200 | n = int(input())
l=list(map(int , input().split()))
m = 10e9
f = 0
e = 0
for i in range(n - 1):
s = abs(l[i+1] - l[i])
if s < m:
f = i+1
e = i + 2
m = s
s = abs(l[-1] - l[0])
if s < m:
f = 1
e = n
print(f , e) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n = int(input())
l=list(map(int , input().split()))
m = 10e9
f = 0
e = 0
for i in range(n - 1):
s = abs(l[i+1] - l[i])
if s < m:
f = i+1
e = i + 2
m = s
s = abs(l[-1] - l[0])
if s < m:
f = 1
e = n
print(f , e)
``` | 3.95603 |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,671,031,228 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 |
n=int(input())
a=list(map(int,input().split()))
b=a.count(0)
if (b>1) or (n==1 and a==[0]):
print("NO")
else:
print("YES") | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
n=int(input())
a=list(map(int,input().split()))
b=a.count(0)
if (b>1) or (n==1 and a==[0]):
print("NO")
else:
print("YES")
``` | 0 | |
464 | B | Restore Cube | PROGRAMMING | 2,000 | [
"brute force",
"geometry"
] | null | null | Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — c... | Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value. | If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the *i*-th output line must be a permutation of the numbers in *i*-th input line. The numbers should represent the vertices of a cube w... | [
"0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1\n",
"0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n"
] | [
"YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1\n",
"NO\n"
] | none | 1,500 | [
{
"input": "0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1",
"output": "YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1"
},
{
"input": "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "NO"
},
{
"input": "0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1... | 1,698,264,925 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n,m,a,b=map(int,input().split())
print(min(n*a,-n//m*-b,n//m*b+n%m*a))
| Title: Restore Cube
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate ... | ```python
n,m,a,b=map(int,input().split())
print(min(n*a,-n//m*-b,n//m*b+n%m*a))
``` | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.