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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | none | none | 0 | [
"none"
] | null | null | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence.
The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). | Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. | [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n"
] | [
"4\n",
"9\n"
] | In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.
In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. | 0 | [
{
"input": "4\n1 2 1 2",
"output": "4"
},
{
"input": "10\n1 1 2 2 2 1 1 2 2 1",
"output": "9"
},
{
"input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 ... | 1,518,615,219 | 5,319 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,632,000 | n = int(input())
ns = [int(x) for x in input().split()]
ns.append(6)
maxi = 0
lst = []
last = ns[0]
count = 0
for i in range(n + 1):
if last == ns[i]:
last = ns[i]
count += 1
else:
lst.append(count)
count = 1
last = ns[i]
maxi = 0
summa = sum(lst[:4])
otr = lst[:4]
if len... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding th... | ```python
n = int(input())
ns = [int(x) for x in input().split()]
ns.append(6)
maxi = 0
lst = []
last = ns[0]
count = 0
for i in range(n + 1):
if last == ns[i]:
last = ns[i]
count += 1
else:
lst.append(count)
count = 1
last = ns[i]
maxi = 0
summa = sum(lst[:4])
otr = lst[... | 0 | |
888 | E | Maximum Subsequence | PROGRAMMING | 1,800 | [
"bitmasks",
"divide and conquer",
"meet-in-the-middle"
] | null | null | You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty.
Print the maximum possibl... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=35, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum possible value of . | [
"4 4\n5 2 4 1\n",
"3 20\n199 41 299\n"
] | [
"3\n",
"19\n"
] | In the first example you can choose a sequence *b* = {1, 2}, so the sum <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c856546022c2feee13d02a4ec9cd1d361ab3a756.png" style="max-width: 100.0%;max-height: 100.0%;"/> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example... | 0 | [
{
"input": "4 4\n5 2 4 1",
"output": "3"
},
{
"input": "3 20\n199 41 299",
"output": "19"
},
{
"input": "5 10\n47 100 49 2 56",
"output": "9"
},
{
"input": "5 1000\n38361 75847 14913 11499 8297",
"output": "917"
},
{
"input": "10 10\n48 33 96 77 67 59 35 15 14 86"... | 1,637,929,023 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
input = sys.stdin.readline
def inlt():
return list(map(int,input().split()))
[n, m] = inlt()
a = inlt()
def powerset(s):
x = len(s)
for i in range(1 << x):
print [s[j] for j in range(x) if (i & (1 << j))]
max_value = 0
powerset_a = powerset(a)
for s in powerset_a:... | Title: Maximum Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*... | ```python
import sys
input = sys.stdin.readline
def inlt():
return list(map(int,input().split()))
[n, m] = inlt()
a = inlt()
def powerset(s):
x = len(s)
for i in range(1 << x):
print [s[j] for j in range(x) if (i & (1 << j))]
max_value = 0
powerset_a = powerset(a)
for s in p... | -1 | |
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,691,053,217 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = int(input())
teams = {}
for i in range(n) :
team = input()
if team not in teams.keys() :
teams[team] = 1
else :
teams[team] += 1
score = max(teams.values())
for i in teams.keys() :
if teams[i] == score :
print(i)
| 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
n = int(input())
teams = {}
for i in range(n) :
team = input()
if team not in teams.keys() :
teams[team] = 1
else :
teams[team] += 1
score = max(teams.values())
for i in teams.keys() :
if teams[i] == score :
print(i)
``` | 3.977 |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,696,763,990 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
cell = input().strip()
# Initialize a variable to count the number of changing bits
changes = 0
# Initialize a carry bit to handle the addition
carry = 1
# Iterate through the bits from LSB to MSB
for i in range(n - 1, -1, -1):
bit = int(cell[i])
# Calculate the sum of the ... | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
cell = input().strip()
# Initialize a variable to count the number of changing bits
changes = 0
# Initialize a carry bit to handle the addition
carry = 1
# Iterate through the bits from LSB to MSB
for i in range(n - 1, -1, -1):
bit = int(cell[i])
# Calculate the s... | 0 | |
802 | J | Send the Fool Further! (easy) | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d... | The first line of the input contains the number of friends *n* (3<=≤<=*n*<=≤<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≤<=*u*,<=*v*<=≤<=*n*<=-<=1, 1<=≤<=*c*<=≤<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling betwee... | Output a single integer – the maximum sum of costs. | [
"4\n0 1 4\n0 2 2\n2 3 3\n",
"6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n",
"11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n"
] | [
"5\n",
"105\n",
"5551\n"
] | In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). | 0 | [
{
"input": "4\n0 1 4\n0 2 2\n2 3 3",
"output": "5"
},
{
"input": "3\n1 0 5987\n2 0 8891",
"output": "8891"
},
{
"input": "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647",
"output": "15685"
},
{
"input": "11\n1 0 6646\n2 0 8816\n3 2 ... | 1,594,375,200 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 155 | 20,172,800 | n=int(input())
al=[[] for j in range(n)]
for i in range(n-1):
a,b,c=map(int,input().split())
al[a].append([b,c])
al[b].append([a,c])
mc=0
va=[0]*(n)
ca=[0]*(n)
def dfs(n,c):
va[n]=1
#print(c)
ca[n]=ca[n]+c
for e in al[n]:
#print(e... | Title: Send the Fool Further! (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the mess... | ```python
n=int(input())
al=[[] for j in range(n)]
for i in range(n-1):
a,b,c=map(int,input().split())
al[a].append([b,c])
al[b].append([a,c])
mc=0
va=[0]*(n)
ca=[0]*(n)
def dfs(n,c):
va[n]=1
#print(c)
ca[n]=ca[n]+c
for e in al[n]:
... | 3 | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,590,038,620 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 124 | 307,200 | n , k=map(int , input().split())
for i in range(1,n+1):
for j in range(1,n+1):
print(k if i == j else 0, end = ' ')
print()
| Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
n , k=map(int , input().split())
for i in range(1,n+1):
for j in range(1,n+1):
print(k if i == j else 0, end = ' ')
print()
``` | 3 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,675,770,559 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import numpy as np
n = int(input())
l = list(map(int,input().split()))
ans = np.zeros(int(sum(l))+2)
i = 1
for x in range(len(l)):
for j in range(i,i+l[x]):
ans[j] = int(x+1)
i = i+l[x]
t = int(input())
q = list(map(int,input().split()))
for i in q :
print(int(ans[i])) | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
import numpy as np
n = int(input())
l = list(map(int,input().split()))
ans = np.zeros(int(sum(l))+2)
i = 1
for x in range(len(l)):
for j in range(i,i+l[x]):
ans[j] = int(x+1)
i = i+l[x]
t = int(input())
q = list(map(int,input().split()))
for i in q :
print(int(ans[i... | -1 | |
350 | B | Resort | PROGRAMMING | 1,500 | [
"graphs"
] | null | null | Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of objects.
The second line contains *n* space-separated integers *type*1,<=*type*2,<=...,<=*type**n* — the types of the objects. If *type**i* equals zero, then the *i*-th object is the mountain. If *type**i* equals one, then the *i*-th object is the... | In the first line print *k* — the maximum possible path length for Valera. In the second line print *k* integers *v*1,<=*v*2,<=...,<=*v**k* — the path. If there are multiple solutions, you can print any of them. | [
"5\n0 0 0 0 1\n0 1 2 3 4\n",
"5\n0 0 1 0 1\n0 1 2 2 4\n",
"4\n1 0 0 0\n2 3 4 2\n"
] | [
"5\n1 2 3 4 5\n",
"2\n4 5\n",
"1\n1\n"
] | none | 1,000 | [
{
"input": "5\n0 0 0 0 1\n0 1 2 3 4",
"output": "5\n1 2 3 4 5"
},
{
"input": "5\n0 0 1 0 1\n0 1 2 2 4",
"output": "2\n4 5"
},
{
"input": "4\n1 0 0 0\n2 3 4 2",
"output": "1\n1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2",
"output": "2\n2 10"
},
{
... | 1,665,819,293 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 154 | 22,425,600 |
import sys
input = sys.stdin.readline
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
d = []
x = [0 for i in range(n+1)]
for i in b:
x[i] += 1
for i in range(1, n+1):
if a[i] == 1:
w = [i]
q = b[i]
while x[q] =... | Title: Resort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n*... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
d = []
x = [0 for i in range(n+1)]
for i in b:
x[i] += 1
for i in range(1, n+1):
if a[i] == 1:
w = [i]
q = b[i]
wh... | 0 | |
754 | A | Lesha and array splitting | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. | If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *... | [
"3\n1 2 -3\n",
"8\n9 -12 3 4 -4 -10 7 3\n",
"1\n0\n",
"4\n1 2 3 -5\n"
] | [
"YES\n2\n1 2\n3 3\n",
"YES\n2\n1 2\n3 8\n",
"NO\n",
"YES\n4\n1 1\n2 2\n3 3\n4 4\n"
] | none | 500 | [
{
"input": "3\n1 2 -3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "8\n9 -12 3 4 -4 -10 7 3",
"output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n1 2 3 -5",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
... | 1,640,880,567 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 61 | 0 | a=int(input())
b=list(map(int,input().split()))
s=0
l=[]
for i in b:
s+=i
if s!=0:
print("YES")
print("1")
print("1",len(b))
elif len(b)==b.count(0):
print("NO")
else:
for i in b:
if i!=0:
break
t=b.index(i)+1
print('YES')
print(2)
print("1"... | Title: Lesha and array splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that t... | ```python
a=int(input())
b=list(map(int,input().split()))
s=0
l=[]
for i in b:
s+=i
if s!=0:
print("YES")
print("1")
print("1",len(b))
elif len(b)==b.count(0):
print("NO")
else:
for i in b:
if i!=0:
break
t=b.index(i)+1
print('YES')
print(2)
... | 3 | |
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,663,229,323 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | M,N=map(int,input().split())
if M%2==1 and N%2==1:
n=((M-1)*N/2)+(N-1)/2
print(int(n))
else:
print(int(M*N/2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M,N=map(int,input().split())
if M%2==1 and N%2==1:
n=((M-1)*N/2)+(N-1)/2
print(int(n))
else:
print(int(M*N/2))
``` | 3.977 |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,584,681,185 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 171 | 0 | from collections import *
s=input()
ka=Counter(s)
print(min(ka['n']//3,ka['e']//3,ka['i']//1,ka['t']))
| Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
from collections import *
s=input()
ka=Counter(s)
print(min(ka['n']//3,ka['e']//3,ka['i']//1,ka['t']))
``` | 0 | |
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"out... | 1,655,400,227 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 93 | 1,740,800 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
z = n
c = 0
x = 0
while True:
new_w = []
n = len(w)
for i in range(n):
if w[i] <= c:
c += 1
else:
new_w.append(w[i])
if c == z:
break
x +=... | Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
z = n
c = 0
x = 0
while True:
new_w = []
n = len(w)
for i in range(n):
if w[i] <= c:
c += 1
else:
new_w.append(w[i])
if c == z:
break... | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,568,705,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 248 | 0 | n = int(input())
num = input()
a = []
def get_the_data(count, num, arr):
for i in range(0, len(num)):
if num[i] == ' ':
arr.append(int(num[count:i]))
count = i+1
elif i == len(num)-1:
arr.append(int(num[count:len(num)]))
return arr
arr = get_the_data(0, nu... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
num = input()
a = []
def get_the_data(count, num, arr):
for i in range(0, len(num)):
if num[i] == ' ':
arr.append(int(num[count:i]))
count = i+1
elif i == len(num)-1:
arr.append(int(num[count:len(num)]))
return arr
arr = get_the_... | 3 | |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,656,568,398 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 93 | 512,000 | fib=[1,1]
c=50
while c>0:
fib.append(fib[-1]+fib[-2])
c=c-1
#print(fib)
a=int(input())
d=''
for i in range(1,a+1):
if i in fib:
d+='O'
else:
d+='o'
print(d)
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
fib=[1,1]
c=50
while c>0:
fib.append(fib[-1]+fib[-2])
c=c-1
#print(fib)
a=int(input())
d=''
for i in range(1,a+1):
if i in fib:
d+='O'
else:
d+='o'
print(d)
``` | 3 | |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,557,772,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 154 | 307,200 | mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
bt,rt,st=1,1,1
n,m=f()
l=[sorted(il()) for _ in range(m)]
l.sort()
for i in range(m-1):
... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
bt,rt,st=1,1,1
n,m=f()
l=[sorted(il()) for _ in range(m)]
l.sort()
for i in range... | 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,666,850,100 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 436 | 10,137,600 | # LUOGU_RID: 91726065
n=int(input())
x=[0];h=[0];f=[[0,0,0]]#f[i][0]: 到第 i 棵树不倒最多;[i][1]:到第 i 棵树向左倒最多;f[i][2]:到第 i 棵树向右倒最多
for i in range(n):
x.append(0),h.append(0)
x[i+1],h[i+1]=input().split()
x[i+1]=int(x[i+1]);h[i+1]=int(h[i+1])
f.append([0,1,-1])
if x[2]-x[1]>h[1]:f[1][2]=1
for i in range(2,n):
f.... | 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
# LUOGU_RID: 91726065
n=int(input())
x=[0];h=[0];f=[[0,0,0]]#f[i][0]: 到第 i 棵树不倒最多;[i][1]:到第 i 棵树向左倒最多;f[i][2]:到第 i 棵树向右倒最多
for i in range(n):
x.append(0),h.append(0)
x[i+1],h[i+1]=input().split()
x[i+1]=int(x[i+1]);h[i+1]=int(h[i+1])
f.append([0,1,-1])
if x[2]-x[1]>h[1]:f[1][2]=1
for i in range(2,... | -1 | |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,693,643,604 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 46 | 0 | a=["Danil", "Olya", "Slava", "Ann","Nikita"]
n=input()
c=0
for i in a:
if i in n:c+=1
if(c==1):print("YES")
else:print("NO") | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
a=["Danil", "Olya", "Slava", "Ann","Nikita"]
n=input()
c=0
for i in a:
if i in n:c+=1
if(c==1):print("YES")
else:print("NO")
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,670,427,883 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | word=input()
low=0
high=0
for i in word:
if ord(i)>90:
low+=1
else:
high+=1
if high>low:
print(word.upper())
else:
print(word.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word=input()
low=0
high=0
for i in word:
if ord(i)>90:
low+=1
else:
high+=1
if high>low:
print(word.upper())
else:
print(word.lower())
``` | 3.977 |
606 | A | Magic Spheres | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,... | The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number o... | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what... | 500 | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0... | 1,484,677,292 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 5,324,800 | #Justin Hershberger
#Py3.5
import fileinput
def test():
pass
if __name__ == '__main__':
num_args = 2
for arg in range(num_args):
if arg == 0:
a,b,c = map(int, input().split())
else:
x,y,z = map(int, input().split())
# sum1 = a + b + c
# sum2 = x + y + z
#
# sum3 = (a - x) + (b - y)... | Title: Magic Spheres
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been see... | ```python
#Justin Hershberger
#Py3.5
import fileinput
def test():
pass
if __name__ == '__main__':
num_args = 2
for arg in range(num_args):
if arg == 0:
a,b,c = map(int, input().split())
else:
x,y,z = map(int, input().split())
# sum1 = a + b + c
# sum2 = x + y + z
#
# sum3 = (a - x)... | 0 | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,679,590,136 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 61 | 0 | square = []
possible = False
for _ in range(0,4):
inp = input()
inp =inp.replace('.','1')
inp =inp.replace('#','0')
square.append( list(map(lambda x:int(inp[x]),range(0,4))))
for a in range(0,3):
if possible :
break
for b in range(0,3):
if square[a][b]+square[a+1][b]+s... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
square = []
possible = False
for _ in range(0,4):
inp = input()
inp =inp.replace('.','1')
inp =inp.replace('#','0')
square.append( list(map(lambda x:int(inp[x]),range(0,4))))
for a in range(0,3):
if possible :
break
for b in range(0,3):
if square[a][b]+square... | 3 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,578,164,826 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 27 | 140 | 0 | arr = [input() for i in range(4)]
arr = sorted([[arr[i][:1], len(arr[i][2:])] for i in range(4)], key=lambda x: x[1])
if arr[0][1] * 2 <= arr[1][1]:
print(arr[0][0])
elif arr[3][1] >= arr[2][1]*2:
print(arr[3][0])
else:
print('C')
| Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
arr = [input() for i in range(4)]
arr = sorted([[arr[i][:1], len(arr[i][2:])] for i in range(4)], key=lambda x: x[1])
if arr[0][1] * 2 <= arr[1][1]:
print(arr[0][0])
elif arr[3][1] >= arr[2][1]*2:
print(arr[3][0])
else:
print('C')
``` | 0 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,698,083,291 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | s=input("")
l=s.split("+")
v=sorted(l)
q="+".join(v)
print(q) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s=input("")
l=s.split("+")
v=sorted(l)
q="+".join(v)
print(q)
``` | 3 | |
40 | A | Find Color | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"implementation",
"math"
] | A. Find Color | 2 | 256 | Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond... | The first and single line contains two integers *x* and *y* — the coordinates of the hole made in the clock by the ball. Each of the numbers *x* and *y* has an absolute value that does not exceed 1000. | Find the required color.
All the points between which and the origin of coordinates the distance is integral-value are painted black. | [
"-2 1\n",
"2 1\n",
"4 3\n"
] | [
"white\n",
"black\n",
"black\n"
] | none | 500 | [
{
"input": "-2 1",
"output": "white"
},
{
"input": "2 1",
"output": "black"
},
{
"input": "4 3",
"output": "black"
},
{
"input": "3 3",
"output": "black"
},
{
"input": "4 4",
"output": "white"
},
{
"input": "-4 4",
"output": "black"
},
{
"i... | 1,648,781,330 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | from math import hypot,floor
from sys import stdin
x, y = map(int,stdin.readline().split())
h = hypot(x,y)
print(h)
print(floor(h))
f_h = floor(h)
if (x>=0 and y>=0) or (x<0 and y<0):
if f_h == h or (f_h%2==0):
print('black')
else:
print('white')
print('DP')
else:
if... | Title: Find Color
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. Th... | ```python
from math import hypot,floor
from sys import stdin
x, y = map(int,stdin.readline().split())
h = hypot(x,y)
print(h)
print(floor(h))
f_h = floor(h)
if (x>=0 and y>=0) or (x<0 and y<0):
if f_h == h or (f_h%2==0):
print('black')
else:
print('white')
print('DP')
els... | 0 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,687,091,340 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | a = "a" + input()
k = 0
for i in range(len(a)-1):
b = ord(a[i])
c = ord(a[i+1])
s = abs(b-c)
if s > 13:
k += 26-s
else:
k += s
print(k) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
a = "a" + input()
k = 0
for i in range(len(a)-1):
b = ord(a[i])
c = ord(a[i+1])
s = abs(b-c)
if s > 13:
k += 26-s
else:
k += s
print(k)
``` | 3 | |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,677,672,444 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | n=int(input())
l1=list(map(int,input().split()))
l2=[]
f="yes"
for j in range(n-1):
if l1[j+1]-l1[j]==-1:
l2.append(j)
elif l1[j+1]<l1[j]:
f="no"
l2=[]
break
if len(l2)>1:
for i in range(len(l2)-1):
if l2[i+1]-l2[i]!=1:
f="no"
... | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
n=int(input())
l1=list(map(int,input().split()))
l2=[]
f="yes"
for j in range(n-1):
if l1[j+1]-l1[j]==-1:
l2.append(j)
elif l1[j+1]<l1[j]:
f="no"
l2=[]
break
if len(l2)>1:
for i in range(len(l2)-1):
if l2[i+1]-l2[i]!=1:
f="no"
... | 0 | |
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,682,432,834 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | from collections import deque
di=[-1,0,1,0]
dj=[0,-1,0,1]
n,m,k= list(map(int,input().split()))
nb=0
maze=[]
for i in range(n):
s=input()
l=[]
for s1 in s :
for j in s1:
l.append(j)
if j=='.' : nb+=1
maze.append(l)
seen=[[False]* m for _ in range(n)]
nb-=... | 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
from collections import deque
di=[-1,0,1,0]
dj=[0,-1,0,1]
n,m,k= list(map(int,input().split()))
nb=0
maze=[]
for i in range(n):
s=input()
l=[]
for s1 in s :
for j in s1:
l.append(j)
if j=='.' : nb+=1
maze.append(l)
seen=[[False]* m for _ in range(n... | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,627,716,723 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 218 | 8,192,000 | a = input()
b = input()
a = list(a)
b = list(b)
a.sort()
b.sort()
flag = False
genome = ''
for x in b:
genome += x
string = ''
for i in a:
string += i
if string == genome:
flag = True
break
if flag:
print("YES")
else:
print("NO")
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
a = input()
b = input()
a = list(a)
b = list(b)
a.sort()
b.sort()
flag = False
genome = ''
for x in b:
genome += x
string = ''
for i in a:
string += i
if string == genome:
flag = True
break
if flag:
print("YES")
else:
print("NO")
``` | 0 | |
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,677,860,804 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | n, m, a = map(int, input().split())
b = 0
if n <= 1 or m <= 1:
b -= 1
if n % a != 0:
b += n//a + 1
else:
b += n//a
if m % a != 0:
b += m//a + 1
else:
b += m//a
print(b)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
b = 0
if n <= 1 or m <= 1:
b -= 1
if n % a != 0:
b += n//a + 1
else:
b += n//a
if m % a != 0:
b += m//a + 1
else:
b += m//a
print(b)
``` | 0 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,672,642,687 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | a,b,c=map(int,input().split())
max1=max(a,b,c)
min1=min(a,b,c)
mid1=a+b+c-min1-max1
print(abs(mid1-min1)+abs(mid1-max1)) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
a,b,c=map(int,input().split())
max1=max(a,b,c)
min1=min(a,b,c)
mid1=a+b+c-min1-max1
print(abs(mid1-min1)+abs(mid1-max1))
``` | 3 | |
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,722,393 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | n,k=map(int,input().split())
num=n
m= 1000000007
arr=[1]*n
for _ in range(k-1):
for i in range(1,n+1):
for j in range(i+1,n+1):
if j%i==0:
arr[i-1]=(arr[i-1]%m+arr[j-1]%m)%m
print(sum(arr)%m)
| 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
n,k=map(int,input().split())
num=n
m= 1000000007
arr=[1]*n
for _ in range(k-1):
for i in range(1,n+1):
for j in range(i+1,n+1):
if j%i==0:
arr[i-1]=(arr[i-1]%m+arr[j-1]%m)%m
print(sum(arr)%m)
``` | 0 | |
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,691,307,321 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | def amazing_performances(points):
n = len(points)
if n <= 1:
return 0
best = worst = points[0]
amazing_count = 0
for i in range(1, n):
if points[i] > best:
best = points[i]
amazing_count += 1
elif points[i] < worst:
worst = p... | 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
def amazing_performances(points):
n = len(points)
if n <= 1:
return 0
best = worst = points[0]
amazing_count = 0
for i in range(1, n):
if points[i] > best:
best = points[i]
amazing_count += 1
elif points[i] < worst:
... | 3 | |
493 | D | Vasya and Chess | PROGRAMMING | 1,700 | [
"constructive algorithms",
"games",
"math"
] | null | null | Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell cont... | The input contains a single number *n* (2<=≤<=*n*<=≤<=109) — the size of the board. | On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If ther... | [
"2\n",
"3\n"
] | [
"white\n1 2\n",
"black\n"
] | In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for... | 1,500 | [
{
"input": "2",
"output": "white\n1 2"
},
{
"input": "3",
"output": "black"
},
{
"input": "4",
"output": "white\n1 2"
},
{
"input": "6",
"output": "white\n1 2"
},
{
"input": "10",
"output": "white\n1 2"
},
{
"input": "16",
"output": "white\n1 2"
... | 1,680,633,905 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 77 | 0 | print(["white\n1 2", "black"][int(input())%2]) | Title: Vasya and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. I... | ```python
print(["white\n1 2", "black"][int(input())%2])
``` | 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,687,284,408 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input())
lst = []
ai = input().split()
ai = list(map(int,ai))
lst.extend(ai)
lst.sort(reverse = True)
for z in range(len(lst)):
if (sum(lst[0:(z+1)])) > (sum(lst)-sum(lst[0:(z+1)])):
H = (z+1)
break
print(H) | 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
n = int(input())
lst = []
ai = input().split()
ai = list(map(int,ai))
lst.extend(ai)
lst.sort(reverse = True)
for z in range(len(lst)):
if (sum(lst[0:(z+1)])) > (sum(lst)-sum(lst[0:(z+1)])):
H = (z+1)
break
print(H)
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,435,882 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n=int(input())
count=0
for _ in range(n):
p,v,t=map(int,input().split())
if p+v+t>=2:
count+=1
print(count) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n=int(input())
count=0
for _ in range(n):
p,v,t=map(int,input().split())
if p+v+t>=2:
count+=1
print(count)
``` | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,621,607,283 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 1,028 | 7,884,800 | def sum(a):
c = 0
for el in a:
c+=int(el)
return str(c)
def main():
c = 0
a = input()
if int(a) < 9:
print(0)
return
while int(a)>9:
a = sum(a)
c+=1
print(c)
main()
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def sum(a):
c = 0
for el in a:
c+=int(el)
return str(c)
def main():
c = 0
a = input()
if int(a) < 9:
print(0)
return
while int(a)>9:
a = sum(a)
c+=1
print(c)
main()
``` | 3.728812 |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,695,282,928 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | s = input()
ko=list(map(int, s.split('+')))
ko.sort()
res= '+'.join(map(str, summands))
print(res)
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s = input()
ko=list(map(int, s.split('+')))
ko.sort()
res= '+'.join(map(str, summands))
print(res)
``` | -1 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,539,266,158 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n,d = map(int,input().split())
list1 = []
t = list(map(int,input().split()))
time = 0
jokes = 0
for i in range(len(t)):
if d - t[i] > 0:
d = d-t[i]
list1.append(0)
if d - 10 > 0:
d-=10
jokes+=2
else:
if d%5==0:
k = d//5
jokes+=k
if len(list1)... | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n,d = map(int,input().split())
list1 = []
t = list(map(int,input().split()))
time = 0
jokes = 0
for i in range(len(t)):
if d - t[i] > 0:
d = d-t[i]
list1.append(0)
if d - 10 > 0:
d-=10
jokes+=2
else:
if d%5==0:
k = d//5
jokes+=k
if ... | 0 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,691,076,140 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | input();l=list(map(int,input().split()));print(sum(l)/len(l))
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
input();l=list(map(int,input().split()));print(sum(l)/len(l))
``` | 3 | |
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,445,645,828 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | range=int(input())
rad=(input())
red=0.0
neg=5
for x in rad:
if x!=" ":
z=int(x)
if neg==0 or neg==5:
red=(red+((3.141592654)*(int(x)*int(x))))
if neg==5:
neg=0
else:
neg=1
else:
red=(red-((3.1415... | 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
range=int(input())
rad=(input())
red=0.0
neg=5
for x in rad:
if x!=" ":
z=int(x)
if neg==0 or neg==5:
red=(red+((3.141592654)*(int(x)*int(x))))
if neg==5:
neg=0
else:
neg=1
else:
red=(re... | 0 | |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,620,673,209 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,656,000 | N = input()
N = int(N)
n = int(N/2)
S = input()
S = str(S)
for i in range(0,n):
if S[i] == "R" and S[i+n] == "L":
print(S[i+n], S[i])
else:
print(S[i], S[i+n])
| Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
N = input()
N = int(N)
n = int(N/2)
S = input()
S = str(S)
for i in range(0,n):
if S[i] == "R" and S[i+n] == "L":
print(S[i+n], S[i])
else:
print(S[i], S[i+n])
``` | -1 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,678,121,020 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n=int(input(""))
posn=[0,0,0]
flag=0
if n>=1 and n<=100:
for i in range(n):
a,b,c=map(int,input().split())
if a<-100 or a>100 or b<-100 or b>100 or c<-100 or c>100:
flag=1
posn[0]+=a
posn[1]+=b
posn[2]+=c
for i in range(3):
if posn[i]!=0:
... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input(""))
posn=[0,0,0]
flag=0
if n>=1 and n<=100:
for i in range(n):
a,b,c=map(int,input().split())
if a<-100 or a>100 or b<-100 or b>100 or c<-100 or c>100:
flag=1
posn[0]+=a
posn[1]+=b
posn[2]+=c
for i in range(3):
if pos... | 3.977 |
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,508,125,374 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | list=[]
output=0
with open('input.txt', 'r') as f1:
content=f1.readlines()
content=[x.strip('\n') for x in content]
for i in range(len(content)):
if content[i][0:1]=='+':
list.append(content[i][1:])
elif content[i][0:1]=='-':
list.remove(content[i][1:])
elif ':' in content[i]:
index1=content[i].index(':')
... | 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
list=[]
output=0
with open('input.txt', 'r') as f1:
content=f1.readlines()
content=[x.strip('\n') for x in content]
for i in range(len(content)):
if content[i][0:1]=='+':
list.append(content[i][1:])
elif content[i][0:1]=='-':
list.remove(content[i][1:])
elif ':' in content[i]:
index1=content[i].in... | -1 |
723 | E | One-Way Reform | PROGRAMMING | 2,200 | [
"constructive algorithms",
"dfs and similar",
"flows",
"graphs",
"greedy"
] | null | null | There are *n* cities and *m* two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roa... | The first line contains a positive integer *t* (1<=≤<=*t*<=≤<=200) — the number of testsets in the input.
Each of the testsets is given in the following way. The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=200, 0<=≤<=*m*<=≤<=*n*·(*n*<=-<=1)<=/<=2) — the number of cities and the number of roads in Berla... | For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it.
In the next *m* lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there ... | [
"2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2\n"
] | [
"3\n1 3\n3 5\n5 4\n3 2\n2 1\n3\n2 4\n3 7\n"
] | none | 2,500 | [
{
"input": "2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2",
"output": "3\n1 3\n3 5\n5 4\n3 2\n2 1\n3\n2 4\n3 7"
},
{
"input": "4\n9 17\n3 6\n2 6\n6 9\n4 1\n2 8\n1 9\n7 9\n8 5\n1 7\n4 9\n6 7\n3 4\n9 3\n8 4\n2 1\n3 8\n2 7\n5 6\n2 5\n3 4\n1 3\n4 5\n5 3\n2 3\n12 8\n10 2\n9 2\n6 9\n10 6\n8 2\n4 10\n11 2... | 1,691,959,363 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691959363.175796")# 1691959363.1758132 | Title: One-Way Reform
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *m* two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itse... | ```python
print("_RANDOM_GUESS_1691959363.175796")# 1691959363.1758132
``` | 0 | |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl... | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "... | 1,678,971,287 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | s=["vaporeon8", "jolteon7", "flareon7", "espeon6", "umbreon7", "leafeon7", "glaceon7", "sylveon7"]
k={8:["vaporeon"],7:["jolteon","flareon","umbreon","leafeon","glaceon","sylveon"],6:["espeon"]}
n=int(input())
l=input()
if n==8:
print(k[8][0])
if n == 6 :
print(k[6][0])
m=dict()
if n ==7:
j=0
... | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight... | ```python
s=["vaporeon8", "jolteon7", "flareon7", "espeon6", "umbreon7", "leafeon7", "glaceon7", "sylveon7"]
k={8:["vaporeon"],7:["jolteon","flareon","umbreon","leafeon","glaceon","sylveon"],6:["espeon"]}
n=int(input())
l=input()
if n==8:
print(k[8][0])
if n == 6 :
print(k[6][0])
m=dict()
if n ==7:
... | 3 | |
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n... | 1,680,222,761 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 0 | n, x = map(int, input().split())
min_right = float('inf')
max_left = float('-inf')
for _ in range(n):
l, r = map(int, input().split())
min_right = min(min_right, max(l, r))
max_left = max(max_left, min(l, r))
if max_left > min_right:
print(-1)
else:
if x < max_left:
print(max_left... | Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. Bu... | ```python
n, x = map(int, input().split())
min_right = float('inf')
max_left = float('-inf')
for _ in range(n):
l, r = map(int, input().split())
min_right = min(min_right, max(l, r))
max_left = max(max_left, min(l, r))
if max_left > min_right:
print(-1)
else:
if x < max_left:
prin... | 3.969 |
260 | B | Ancient Prophesy | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"strings"
] | null | null | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha... | The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters. | In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique. | [
"777-444---21-12-2013-12-2013-12-2013---444-777\n"
] | [
"13-12-2013"
] | none | 1,000 | [
{
"input": "777-444---21-12-2013-12-2013-12-2013---444-777",
"output": "13-12-2013"
},
{
"input": "30-12-201429-15-208830-12-2014",
"output": "30-12-2014"
},
{
"input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013",
"output": "... | 1,629,542,479 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 280 | 30,412,800 | import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bi... | Title: Ancient Prophesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if th... | ```python
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right... | 3 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,611,203,054 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 0 | def is_prime(n):
if n in (2,3):
return True
elif n%2==0 or n%3==0:
return False
else:
i=5
while i*i<=n:
if n%i == 0 or n%(i+2)==0:
return False
i+=6
return True
n=int(input())
m=1
while True:
if not is_prime... | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
def is_prime(n):
if n in (2,3):
return True
elif n%2==0 or n%3==0:
return False
else:
i=5
while i*i<=n:
if n%i == 0 or n%(i+2)==0:
return False
i+=6
return True
n=int(input())
m=1
while True:
if no... | 0 | |
399 | B | Red and Blue Balls | PROGRAMMING | 0 | [] | null | null | User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.
- While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack.
The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of th... | Print the maximum number of operations ainta can repeatedly apply.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\nRBR\n",
"4\nRBBR\n",
"5\nRBBRR\n"
] | [
"2\n",
"6\n",
"6\n"
] | The first example is depicted below.
The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball.
The explanation how user ainta applies the second operation. He will not pop out red balls, he simply chang... | 1,000 | [
{
"input": "3\nRBR",
"output": "2"
},
{
"input": "4\nRBBR",
"output": "6"
},
{
"input": "5\nRBBRR",
"output": "6"
},
{
"input": "5\nRBRBR",
"output": "10"
},
{
"input": "10\nRRBRRBBRRR",
"output": "100"
},
{
"input": "10\nBRBRRRRRRR",
"output": "5"... | 1,583,743,813 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 500 | 3,481,600 | def remove_top_reds(stack):
if len(stack) < 1:
return stack
while len(stack) and stack[-1] == 'R':
stack = stack[:-1]
return stack
def change_top_blue(stack):
if len(stack) > 0 and stack[-1] == 'B':
stack[-1] = 'R'
return stack
def fill_with_blues(stack, size):
... | Title: Red and Blue Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.
- While the top ball inside the stack is red, pop the ball from the top of ... | ```python
def remove_top_reds(stack):
if len(stack) < 1:
return stack
while len(stack) and stack[-1] == 'R':
stack = stack[:-1]
return stack
def change_top_blue(stack):
if len(stack) > 0 and stack[-1] == 'B':
stack[-1] = 'R'
return stack
def fill_with_blues(stac... | 0 | |
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,696,959,359 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | # Read input
a = int(input())
b = int(input())
c = int(input())
# Initialize the maximum value to a*b*c (no operations)
max_value = a * b * c
# a*(b+c)
temp = a * (b + c)
if temp > max_value:
max_value = temp
temp = (a + b) * c
if temp > max_value:
max_value = temp
temp = a + b * c
if temp > m... | 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
# Read input
a = int(input())
b = int(input())
c = int(input())
# Initialize the maximum value to a*b*c (no operations)
max_value = a * b * c
# a*(b+c)
temp = a * (b + c)
if temp > max_value:
max_value = temp
temp = (a + b) * c
if temp > max_value:
max_value = temp
temp = a + b * c
i... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,601,393,425 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | n = int(input())
sx,sy,sz=0,0,0
for i in range(n):
x,y,z= [int(i) for i in input().split()]
sx= sx+x
sy= sy+y
sz= sz+z
if sx==0 and sy==0 and sz==0:
print("YES")
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
sx,sy,sz=0,0,0
for i in range(n):
x,y,z= [int(i) for i in input().split()]
sx= sx+x
sy= sy+y
sz= sz+z
if sx==0 and sy==0 and sz==0:
print("YES")
else:
print('NO')
``` | 3.9455 |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,681,442,921 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n=int(input())
l=list(map(int,input().split()))
test=False
for i in range(n-2):
for j in range(1,n-1):
for k in range(2,n):
if l[i]+1==l[j] and l[j+1]==l[k]:
test=True
break
if test:break
if test:break
if test:print('YES')
else: print('NO') | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n=int(input())
l=list(map(int,input().split()))
test=False
for i in range(n-2):
for j in range(1,n-1):
for k in range(2,n):
if l[i]+1==l[j] and l[j+1]==l[k]:
test=True
break
if test:break
if test:break
if test:print('YES')
else: p... | 0 | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,655,792,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n = int(input())
for i in range(n):
x = (n - i*7)/4
if x < 0:
print(-1)
break
elif x == int(x):
val = int(x)*'4' + i*'7'
print(int(val))
break | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
for i in range(n):
x = (n - i*7)/4
if x < 0:
print(-1)
break
elif x == int(x):
val = int(x)*'4' + i*'7'
print(int(val))
break
``` | 0 |
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ... | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000... | 1,454,609,643 | 4,142 | Python 3 | CHALLENGED | CHALLENGES | 8 | 61 | 0 | n=int(input())
L=list(map(int,input().split(" ")))
L.sort(reverse=True)
s=L[0]
p=L[0]
for i in range(1,len(L)):
c=L[i]
while c>=p:
c-=1
s+=c
p=c
print(s)
| Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than ... | ```python
n=int(input())
L=list(map(int,input().split(" ")))
L.sort(reverse=True)
s=L[0]
p=L[0]
for i in range(1,len(L)):
c=L[i]
while c>=p:
c-=1
s+=c
p=c
print(s)
``` | -1 | |
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,682,430,205 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 61 | 0 | import math
var = [0,0,0]
x = input()
var = x.split(" ")
n = var[0]
m = var[1]
a = var[2]
temp_1 = math.ceil(float(n)/float(a))
temp_2 = math.ceil(float(m)/float(a))
print(str(temp_1*temp_2))
| 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
import math
var = [0,0,0]
x = input()
var = x.split(" ")
n = var[0]
m = var[1]
a = var[2]
temp_1 = math.ceil(float(n)/float(a))
temp_2 = math.ceil(float(m)/float(a))
print(str(temp_1*temp_2))
``` | 3.9695 |
999 | E | Reachability from the Capital | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way. | The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_... | Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. | [
"9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n",
"5 4 5\n1 2\n2 3\n3 4\n4 1\n"
] | [
"3\n",
"1\n"
] | The first example is illustrated by the following:
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following:
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci... | 0 | [
{
"input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1",
"output": "3"
},
{
"input": "5 4 5\n1 2\n2 3\n3 4\n4 1",
"output": "1"
},
{
"input": "5000 0 2956",
"output": "4999"
},
{
"input": "2 0 2",
"output": "1"
},
{
"input": "2 1 1\n1 2",
"output": "0"... | 1,622,311,854 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 171 | 6,041,600 | from collections import deque
import heapq
import sys
input = sys.stdin.readline
def bfs1(s):
q = deque()
q.append(s)
visit[s] = 1
ok = set()
while q:
i = q.popleft()
ok.add(i)
for j in G[i]:
if not visit[j]:
q.append(j)
... | Title: Reachability from the Capital
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities r... | ```python
from collections import deque
import heapq
import sys
input = sys.stdin.readline
def bfs1(s):
q = deque()
q.append(s)
visit[s] = 1
ok = set()
while q:
i = q.popleft()
ok.add(i)
for j in G[i]:
if not visit[j]:
q.append(j)
... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,676,698,960 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | string_b=input()
low_b=0
up_b=0
for i in string_b:
if i.islower():
low_b+=1
else:
up_b+=1
if low_b>=up_b:
print(string_b.lower())
else:
print(string_b.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string_b=input()
low_b=0
up_b=0
for i in string_b:
if i.islower():
low_b+=1
else:
up_b+=1
if low_b>=up_b:
print(string_b.lower())
else:
print(string_b.upper())
``` | 3.969 |
660 | A | Co-prime Array | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values shoul... | [
"3\n2 7 28\n"
] | [
"1\n2 7 9 28\n"
] | none | 0 | [
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"... | 1,592,534,012 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 187 | 1,331,200 | import fractions
def coprimeArray(arr, n):
c = 0
for i in range(1, n):
if fractions.gcd(arr[i], arr[i-1]) != 1:
c = c+1
print(c)
print(arr[0], end=" ")
for i in range(1, n):
if fractions.gcd(arr[i], arr[i-1]) != 1:
print(1, end=" ")
print(arr[i], ... | Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
A... | ```python
import fractions
def coprimeArray(arr, n):
c = 0
for i in range(1, n):
if fractions.gcd(arr[i], arr[i-1]) != 1:
c = c+1
print(c)
print(arr[0], end=" ")
for i in range(1, n):
if fractions.gcd(arr[i], arr[i-1]) != 1:
print(1, end=" ")
prin... | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,681,092,097 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a = input()
a = str(a).replace('--','2')
a = str(a).replace('-.','1')
a = str(a).replace('.','0')
print(a)
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
a = input()
a = str(a).replace('--','2')
a = str(a).replace('-.','1')
a = str(a).replace('.','0')
print(a)
``` | 3.977 |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,692,955,235 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 92 | 0 | n = int(input())
k = int(input())
l = 7 - k
ok = True
for i in range(n):
a, b = map(int, input().split())
if a == k or a == l or b == k or b == l:
ok = False
break
if ok:
print('YES')
else:
print('NO') | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
n = int(input())
k = int(input())
l = 7 - k
ok = True
for i in range(n):
a, b = map(int, input().split())
if a == k or a == l or b == k or b == l:
ok = False
break
if ok:
print('YES')
else:
print('NO')
``` | 3 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,689,097,403 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 13 | 62 | 0 | length = int(input())
xcount = counter = 0
text = input()
for letter in text :
if letter == "x" :
xcount += 1
if xcount > 2 :
counter += 1
else :
xcount = 0
print(counter) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
length = int(input())
xcount = counter = 0
text = input()
for letter in text :
if letter == "x" :
xcount += 1
if xcount > 2 :
counter += 1
else :
xcount = 0
print(counter)
``` | 3 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,676,992,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 46 | 0 | #Task G - Сбалансированная подстрока
def create_prefix_arr(n, s): #в префиксном массиве прибавляем 1, если в массиве s встретили 1 и вычитаем 1 в обратно случае
pr = [0 for _ in range(n+1)]
pr[0] = 0 #для дальнейшего удобства первый элемент делаем нулевым
for i in range(n):
if s[i] == 0:
... | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
#Task G - Сбалансированная подстрока
def create_prefix_arr(n, s): #в префиксном массиве прибавляем 1, если в массиве s встретили 1 и вычитаем 1 в обратно случае
pr = [0 for _ in range(n+1)]
pr[0] = 0 #для дальнейшего удобства первый элемент делаем нулевым
for i in range(n):
if s[i] == 0:
... | 0 | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,453,390,412 | 2,011 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
int a, b;
int r = 0;
cin>>a>>b;
int k[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i=a;i < b+1; i++) {
int t = i;
while(t>9) {
r += k[t % 10];
t /= 10;
}
r += k[t % 10];
}
cout << r;
} | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
int a, b;
int r = 0;
cin>>a>>b;
int k[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i=a;i < b+1; i++) {
int t = i;
while(t>9) {
r += k[t % 10];
t /= 10;
}
r += k[t % 10];
}
cout << r;
}
``` | -1 | |
496 | C | Removing Columns | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
we obtain the table:
A table is called... | The first line contains two integers — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Next *n* lines contain *m* small English letters each — the characters of the table. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | [
"1 10\ncodeforces\n",
"4 4\ncase\ncare\ntest\ncode\n",
"5 4\ncode\nforc\nesco\ndefo\nrces\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample the table is already good.
In the second sample you may remove the first and third column.
In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).
Let strings *s* and *t* have equal length. Then, *s* is lexicographica... | 1,750 | [
{
"input": "1 10\ncodeforces",
"output": "0"
},
{
"input": "4 4\ncase\ncare\ntest\ncode",
"output": "2"
},
{
"input": "5 4\ncode\nforc\nesco\ndefo\nrces",
"output": "4"
},
{
"input": "2 2\nfb\nye",
"output": "0"
},
{
"input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrz... | 1,689,348,566 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689348566.139502")# 1689348566.1395268 | Title: Removing Columns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For e... | ```python
print("_RANDOM_GUESS_1689348566.139502")# 1689348566.1395268
``` | 0 | |
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,639,721,170 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 61 | 1,638,400 | import sys
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
n = int(f.readline())
key = f.readline().strip()
return n, key
def sol(n, key):
ph = key
t = []
for i in range(10):
dh = ph
... | 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
import sys
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
n = int(f.readline())
key = f.readline().strip()
return n, key
def sol(n, key):
ph = key
t = []
for i in range(10):
dh... | 3 | |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,560,868,298 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 278 | 102,400 | n,m=map(int,input().split())
d=[]
for i in range(n):
s=input()
s=list(s)
d.append(s)
minc=m
maxc=0
minr=n
maxr=0
for i in range(n):
if "*" in d[i]:
if i<minr:
minr=i
if i>maxr:
maxr=i
for j in range(m):
if d[i][j]=="*":
... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
n,m=map(int,input().split())
d=[]
for i in range(n):
s=input()
s=list(s)
d.append(s)
minc=m
maxc=0
minr=n
maxr=0
for i in range(n):
if "*" in d[i]:
if i<minr:
minr=i
if i>maxr:
maxr=i
for j in range(m):
if d[i][j]=="*... | 3.860237 |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,694,592,705 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | sentences = (['I hate', 'I love'] * 50)[:int(input())]
print(*sentences, sep=' that ', end=' it')
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
sentences = (['I hate', 'I love'] * 50)[:int(input())]
print(*sentences, sep=' that ', end=' it')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is... | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 0 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes... | 1,501,909,830 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 4,608,000 | def gameLegit(a, b):
prod = a * b
i = 1
cube = i**3
while cube < prod:
i += 1
cube = i**3
if cube == prod:
if a % i == 0 and b % i == 0:
return True
return False
n = int(input())
for i in range(0, n):
a, b = [int(x) for x in input().sp... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who ... | ```python
def gameLegit(a, b):
prod = a * b
i = 1
cube = i**3
while cube < prod:
i += 1
cube = i**3
if cube == prod:
if a % i == 0 and b % i == 0:
return True
return False
n = int(input())
for i in range(0, n):
a, b = [int(x) for x in ... | 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,636,789,527 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 61 | 4,300,800 | a=input()
b=input()
i=0
x=''
while i<len(a):
if a[i]!=b[i]:
x+='1'
else:
x+='0'
i+=1
print(x) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
i=0
x=''
while i<len(a):
if a[i]!=b[i]:
x+='1'
else:
x+='0'
i+=1
print(x)
``` | 3.976739 |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ... | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"ou... | 1,623,441,866 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 77 | 0 | t,s,x=map(int,input().split())
a=x-t
b=x-t-1
if(t==x):
print("YES")
else:
if(a>=s)or(b>=s):
if(a>=s)and(a%s==0):
print("YES")
elif((b%s==0)and(b>=s)):
print("YES")
else:
print("NO")
else:
... | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times... | ```python
t,s,x=map(int,input().split())
a=x-t
b=x-t-1
if(t==x):
print("YES")
else:
if(a>=s)or(b>=s):
if(a>=s)and(a%s==0):
print("YES")
elif((b%s==0)and(b>=s)):
print("YES")
else:
print("NO")
else:
... | 3 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,606,562,588 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 37 | 108 | 0 | def dfs(poc, duz):
if poc >= n-1:
return duz
if s[poc] == '0':
return -1
for i in range(d, 1, -1):
temp = dfs(poc+i, duz+1)
if temp >= 0:
return temp
return -1
n, d = map(int, input().split())
s = input()
print(dfs(0, 0))
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
def dfs(poc, duz):
if poc >= n-1:
return duz
if s[poc] == '0':
return -1
for i in range(d, 1, -1):
temp = dfs(poc+i, duz+1)
if temp >= 0:
return temp
return -1
n, d = map(int, input().split())
s = input()
print(dfs(0, 0))
... | 0 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,665,670,197 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 7,680,000 | n = int(input())
laptops = []
for _ in range(n):
laptops.append([int(x) for x in input().split()])
laptops.sort()
for i in range(len(laptops)):
for j in range(i+1, len(laptops)): # higher price
if laptops[j][1] < laptops[i][1]: # lower quality
print('Happy Alex')
exit()
print(... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n = int(input())
laptops = []
for _ in range(n):
laptops.append([int(x) for x in input().split()])
laptops.sort()
for i in range(len(laptops)):
for j in range(i+1, len(laptops)): # higher price
if laptops[j][1] < laptops[i][1]: # lower quality
print('Happy Alex')
exi... | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,659,326,097 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 77 | 3,379,200 | import sys
from collections import deque
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return deque(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s)
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write('\n'.join([str(... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
import sys
from collections import deque
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return deque(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s)
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write('\n'.... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,540,155,511 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | lines = int(input())
forces = [[int(f) for f in input().split(' ')] for n in range(lines)]
x = 0
y = 0
z = 0
for f in forces:
x += f[0]
y += f[1]
z += f[2]
if all([x == 0, y == 0, z == 0]):
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
lines = int(input())
forces = [[int(f) for f in input().split(' ')] for n in range(lines)]
x = 0
y = 0
z = 0
for f in forces:
x += f[0]
y += f[1]
z += f[2]
if all([x == 0, y == 0, z == 0]):
print('YES')
else:
print('NO')
``` | 3.938 |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,699,573,246 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def funzione():
nome=str(input(''))
male='IGNORE HIM!'
female='CHAT WITH HER!'
if len(nome)%2==0:
print(female)
else:
print(male) | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
def funzione():
nome=str(input(''))
male='IGNORE HIM!'
female='CHAT WITH HER!'
if len(nome)%2==0:
print(female)
else:
print(male)
``` | 0 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,589,863,270 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | s = str(input())
k = int(input())
l = list(map(int, input().split()))
numbers = []
for i in range(len(s)):
numbers.append(l[ord(s[i])-97])
high = max(numbers)
while k!=0:
numbers.append(high)
k=k-1
temp=1
ans= 0
for i in numbers:
ans = ans + temp*i
temp = temp+1
print(ans)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s = str(input())
k = int(input())
l = list(map(int, input().split()))
numbers = []
for i in range(len(s)):
numbers.append(l[ord(s[i])-97])
high = max(numbers)
while k!=0:
numbers.append(high)
k=k-1
temp=1
ans= 0
for i in numbers:
ans = ans + temp*i
temp = temp+1
print(ans)
... | 0 | |
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 ... | 1,605,261,616 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | '''Author- Akshit Monga'''
t=1
for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
a=b=c=0
ans=0
s=-1
temp=[]
for i in arr:
if i==s:
c+=1
else:
if len(temp)==3:
if temp[0] == temp[-1]:
... | Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo... | ```python
'''Author- Akshit Monga'''
t=1
for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
a=b=c=0
ans=0
s=-1
temp=[]
for i in arr:
if i==s:
c+=1
else:
if len(temp)==3:
if temp[0] == temp[-1]:
... | 0 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,592,330,415 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 249 | 13,312,000 | x=list(input())
l=len(x)
c=input()
lst=[0]*(l//2+1)
for i in input().split():
lst[int(i)-1]+=1
for i in range(1,(l//2+1)):
lst[i]+=lst[i-1]
for i in range(l//2):
if lst[i]%2==1:
x[i],x[l-i-1]=x[l-i-1],x[i]
print(''.join(x))
| Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
x=list(input())
l=len(x)
c=input()
lst=[0]*(l//2+1)
for i in input().split():
lst[int(i)-1]+=1
for i in range(1,(l//2+1)):
lst[i]+=lst[i-1]
for i in range(l//2):
if lst[i]%2==1:
x[i],x[l-i-1]=x[l-i-1],x[i]
print(''.join(x))
``` | 3 | |
963 | A | Alternating Sum | PROGRAMMING | 1,800 | [
"math",
"number theory"
] | null | null | You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative ... | The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$.
The second line contains a sequence of length $k$ consisting of characters '+' and '-'.
If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$.
Note that onl... | Output a single integer — value of given expression modulo $10^{9} + 9$. | [
"2 2 3 3\n+-+\n",
"4 1 5 1\n-\n"
] | [
"7\n",
"999999228\n"
] | In the first example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7
In the second example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$. | 500 | [
{
"input": "2 2 3 3\n+-+",
"output": "7"
},
{
"input": "4 1 5 1\n-",
"output": "999999228"
},
{
"input": "1 1 4 2\n-+",
"output": "3"
},
{
"input": "3 1 4 4\n+--+",
"output": "45"
},
{
"input": "5 1 1 6\n++---+",
"output": "0"
},
{
"input": "5 2 2 6\n+... | 1,537,848,957 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 |
def solution(n, a, b, ops):
sumNums = 0
cont = 0
for i in range(n + 1):
si = 1 if ops[cont] else -1
sumNums += si * (a ** (n - i)) * (b ** i)
if cont + 1 >= len(ops):
cont = 0
else:
cont += 1
base = (10 ** 9) + 9
print(sumNums % base)
if __name__ == '__main__':
n = int(input())
a = int(input())... | Title: Alternating Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other w... | ```python
def solution(n, a, b, ops):
sumNums = 0
cont = 0
for i in range(n + 1):
si = 1 if ops[cont] else -1
sumNums += si * (a ** (n - i)) * (b ** i)
if cont + 1 >= len(ops):
cont = 0
else:
cont += 1
base = (10 ** 9) + 9
print(sumNums % base)
if __name__ == '__main__':
n = int(input())
a = in... | -1 | |
631 | C | Report | PROGRAMMING | 1,700 | [
"data structures",
"sortings"
] | null | null | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lin... | Print *n* integers — the final report, which will be passed to Blake by manager number *m*. | [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
] | [
"2 1 3 ",
"2 4 1 3 "
] | In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the r... | 1,500 | [
{
"input": "3 1\n1 2 3\n2 2",
"output": "2 1 3 "
},
{
"input": "4 2\n1 2 4 3\n2 3\n1 2",
"output": "2 4 1 3 "
},
{
"input": "4 1\n4 3 2 1\n1 4",
"output": "1 2 3 4 "
},
{
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "5 4 3 2 1 "
},
{
"input": "6 2\n3 1 2 6 4 5\n1 6\n... | 1,458,758,869 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,608,000 | n, m = map(int, input('').split())
lst = list(map(int, input().split()))
managers = []
for i in range(m):
managers.append(list((map(int,input().split()))))
def sort(lst1, to, oneortwo):
k = lst1[:to]
if oneortwo == 1:
k.sort()
if oneortwo == 2:
k.sort(reverse = True)
l... | Title: Report
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that... | ```python
n, m = map(int, input('').split())
lst = list(map(int, input().split()))
managers = []
for i in range(m):
managers.append(list((map(int,input().split()))))
def sort(lst1, to, oneortwo):
k = lst1[:to]
if oneortwo == 1:
k.sort()
if oneortwo == 2:
k.sort(reverse = Tr... | 0 | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,520,178,966 | 1,266 | Python 3 | WRONG_ANSWER | TESTS | 19 | 62 | 5,632,000 | n, a, b = map(int, input().split());
cntb = 0;
cnt = 0;
f = 1;
while n > 1:
if not (((n // 2 >= a and n // 2 < b) or (n // 2 >= b and n // 2 < a))) and f:
cnt = cnt + 1;
n = n // 2;
a = a % n;
b = b % n;
cntb = cntb + 1;
else:
n = n // 2;
f = ... | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
n, a, b = map(int, input().split());
cntb = 0;
cnt = 0;
f = 1;
while n > 1:
if not (((n // 2 >= a and n // 2 < b) or (n // 2 >= b and n // 2 < a))) and f:
cnt = cnt + 1;
n = n // 2;
a = a % n;
b = b % n;
cntb = cntb + 1;
else:
n = n // 2;
... | 0 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,586,875,204 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | t = int(input())
d = []
c=0
for i in range(t):
s = [i for i in input().split()]
d.append((int(s[1]),int(s[2])))
for i in d:
if i[0]>=2400:
if i[0]-i[1]>0:
c+=1
if c > 0:
print("YES")
else:
print("NO") | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
t = int(input())
d = []
c=0
for i in range(t):
s = [i for i in input().split()]
d.append((int(s[1]),int(s[2])))
for i in d:
if i[0]>=2400:
if i[0]-i[1]>0:
c+=1
if c > 0:
print("YES")
else:
print("NO")
``` | 0 | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,667,774,205 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 87 | 77 | 2,252,800 | n,m=map(int,input().split())
t=list(map(int,input().split()))
b=list(map(int,input().split()))
t.sort()
b.sort()
ans=10000000000000000000
an=-10000000000000000000
for i in range(len(t)):
an=-10000000000000000000
for k in range(len(t)):
if i==k:
continue;
else:
... | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m=map(int,input().split())
t=list(map(int,input().split()))
b=list(map(int,input().split()))
t.sort()
b.sort()
ans=10000000000000000000
an=-10000000000000000000
for i in range(len(t)):
an=-10000000000000000000
for k in range(len(t)):
if i==k:
continue;
els... | 3 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,668,083,756 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 1,536,000 | k = int(input())
pr_ch = [19, 28, 37, 46, 55, 64, 73, 82, 91]
i = 109
sum = 0
while len(pr_ch) < k:
j = i
while j//10>0:
sum += j%10
j //= 10
if sum > 10: j = 0
sum += j
if sum == 10: pr_ch.append(i)
print(pr_ch[k-1]) | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
k = int(input())
pr_ch = [19, 28, 37, 46, 55, 64, 73, 82, 91]
i = 109
sum = 0
while len(pr_ch) < k:
j = i
while j//10>0:
sum += j%10
j //= 10
if sum > 10: j = 0
sum += j
if sum == 10: pr_ch.append(i)
print(pr_ch[k-1])
``` | 0 | |
70 | B | Text Messaging | PROGRAMMING | 1,600 | [
"expression parsing",
"greedy",
"strings"
] | B. Text Messaging | 1 | 256 | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing *n* characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not lik... | The first line contains an integer *n*, which is the size of one message (2<=≤<=*n*<=≤<=255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. | On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. | [
"25\nHello. I am a little walrus.\n",
"2\nHow are you?\n",
"19\nHello! Do you like fish? Why?\n"
] | [
"2\n",
"Impossible\n",
"3\n"
] | Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". | 1,000 | [
{
"input": "25\nHello. I am a little walrus.",
"output": "2"
},
{
"input": "2\nHow are you?",
"output": "Impossible"
},
{
"input": "19\nHello! Do you like fish? Why?",
"output": "3"
},
{
"input": "4\na. A.",
"output": "2"
},
{
"input": "191\nEvx vnxZtUSgtzH yDNXCs... | 1,690,496,541 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690496541.0089602")# 1690496541.0089831 | Title: Text Messaging
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing *n* characters (which... | ```python
print("_RANDOM_GUESS_1690496541.0089602")# 1690496541.0089831
``` | 0 |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,620,833,407 | 307 | Python 3 | OK | TESTS | 34 | 405 | 6,758,400 | r , d = map(int, input().split())
n = int(input())
k = 0
for i in range(n):
x, y, w = map(int, input().split())
l = (x**2 + y**2)**(1/2)
if l-w >= r-d and l+w <= r:
k += 1
print(k) | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
r , d = map(int, input().split())
n = int(input())
k = 0
for i in range(n):
x, y, w = map(int, input().split())
l = (x**2 + y**2)**(1/2)
if l-w >= r-d and l+w <= r:
k += 1
print(k)
``` | 3 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,585,205,453 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 155 | 0 | n,k =map(int,input().split())
a = list(map(int,input().split()))
t=0
for i in range(n-1):
t = max(t,a[i]-a[i+1]-k)
print(t) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
n,k =map(int,input().split())
a = list(map(int,input().split()))
t=0
for i in range(n-1):
t = max(t,a[i]-a[i+1]-k)
print(t)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,669,030,198 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | word = input()
upper = 0
for x in word:
if ord(x) < ord("a"):
upper += 1
if upper > (len(word) / 2):
print(word.upper())
else:
print(word.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
upper = 0
for x in word:
if ord(x) < ord("a"):
upper += 1
if upper > (len(word) / 2):
print(word.upper())
else:
print(word.lower())
``` | 3.969 |
0 | none | none | none | 0 | [
"none"
] | null | null | Есть *n*-подъездный дом, в каждом подъезде по *m* этажей, и на каждом этаже каждого подъезда ровно *k* квартир. Таким образом, в доме всего *n*·*m*·*k* квартир. Они пронумерованы естественным образом от 1 до *n*·*m*·*k*, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором ... | В первой строке входных данных следуют три числа *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — количество подъездов в доме, количество этажей в каждом подъезде и количество квартир на каждом этаже каждого подъезда соответственно.
Во второй строке входных данных записаны два числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=*n*·... | Выведите единственное целое число — минимальное время (в секундах), за которое Эдвард сможет добраться от своей квартиры до квартиры Наташи. | [
"4 10 5\n200 6\n",
"3 1 5\n7 2\n"
] | [
"39\n",
"15\n"
] | В первом тестовом примере Эдвард находится в 4 подъезде на 10 этаже, а Наташа находится в 1 подъезде на 2 этаже. Поэтому Эдварду выгодно сначала спуститься на лифте на первый этаж (на это он потратит 19 секунд, из которых 10 — на ожидание и 9 — на поездку на лифте), затем обойти дом против часовой стрелки до подъезда н... | 0 | [
{
"input": "4 10 5\n200 6",
"output": "39"
},
{
"input": "3 1 5\n7 2",
"output": "15"
},
{
"input": "100 100 100\n1 1000000",
"output": "124"
},
{
"input": "1000 1000 1000\n1 1000000000",
"output": "1024"
},
{
"input": "125 577 124\n7716799 6501425",
"output":... | 1,458,977,597 | 1,997 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 30 | 4,608,000 | n, m, k = map(int, input().split())
a, b = map(int, input().split())
podE = a // (m * k)
if a % (m * k) != 0:
podE += 1
podN = b // (m * k)
if b % (m * k) != 0:
podN += 1
etE = (a % (m * k)) // k
if (a % (m * k)) % k != 0:
etE += 1
etN = (b % (m * k)) // k
if (b % (m * k)) % k != 0:
etN += ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Есть *n*-подъездный дом, в каждом подъезде по *m* этажей, и на каждом этаже каждого подъезда ровно *k* квартир. Таким образом, в доме всего *n*·*m*·*k* квартир. Они пронумерованы естественным образом от 1 до *n*·*m*·*k*, то есть п... | ```python
n, m, k = map(int, input().split())
a, b = map(int, input().split())
podE = a // (m * k)
if a % (m * k) != 0:
podE += 1
podN = b // (m * k)
if b % (m * k) != 0:
podN += 1
etE = (a % (m * k)) // k
if (a % (m * k)) % k != 0:
etE += 1
etN = (b % (m * k)) // k
if (b % (m * k)) % k != 0:
... | 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,690,021,383 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | import math
num = input().split(' ')
n = int(num[0])
k = int(num[1])
print(math.floor(n*k/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
import math
num = input().split(' ')
n = int(num[0])
k = int(num[1])
print(math.floor(n*k/2))
``` | 3.9845 |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,504,015,643 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n,k=map(int,input().split())
a=[]
suma=0
for i in range(n):
a.append(list(input()))
for i in a:
suma+=2**i.count("1")+2**i.count("0")-2
for i in range(k):
b=[]
for j in a:
b.append(j[i])
suma+=2**b.count("1")+2**b.count("0")-2
print(suma-n*k+2) | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
n,k=map(int,input().split())
a=[]
suma=0
for i in range(n):
a.append(list(input()))
for i in a:
suma+=2**i.count("1")+2**i.count("0")-2
for i in range(k):
b=[]
for j in a:
b.append(j[i])
suma+=2**b.count("1")+2**b.count("0")-2
print(suma-n*k+2)
``` | 0 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,660,264,604 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 77 | 1,740,800 | a1, a2, a3, a4 = map(int, input().split())
calories = {}
calories["1"] = a1
calories["2"] = a2
calories["3"] = a3
calories["4"] = a4
total_calories = 0
s = input()
for c in s:
total_calories += calories[c]
print(total_calories)
| Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a1, a2, a3, a4 = map(int, input().split())
calories = {}
calories["1"] = a1
calories["2"] = a2
calories["3"] = a3
calories["4"] = a4
total_calories = 0
s = input()
for c in s:
total_calories += calories[c]
print(total_calories)
``` | 3 | |
797 | B | Odd sum | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequen... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | [
"4\n-2 2 -3 1\n",
"3\n2 -5 -3\n"
] | [
"3\n",
"-1\n"
] | In the first example sum of the second and the fourth elements is 3. | 0 | [
{
"input": "4\n-2 2 -3 1",
"output": "3"
},
{
"input": "3\n2 -5 -3",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046",
"ou... | 1,590,042,201 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 77 | 307,200 | n=int(input())
a=[int(x) for x in input().split()]
a.sort()
msum=0
i=n-1
while a[i]>0:
msum=msum+a[i]
i=i-1
if (msum%2)==0:
mnsum=msum
j=i+1
while (mnsum%2)==0:
mnsum=mnsum+a[i]
i=i-1
while (msum%2)==0:
msum=msum-a[j]
j=j+1
if msum>mnsum:
... | Title: Odd sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains... | ```python
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
msum=0
i=n-1
while a[i]>0:
msum=msum+a[i]
i=i-1
if (msum%2)==0:
mnsum=msum
j=i+1
while (mnsum%2)==0:
mnsum=mnsum+a[i]
i=i-1
while (msum%2)==0:
msum=msum-a[j]
j=j+1
if msum>m... | -1 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,650,368,243 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
answer= 1
if a[0]%2 == 0 and a[1]%2 == 0:
s = "odd"
else:
s = "even"
if s == "odd":
for i in range(n):
if a[i]%2:
answer = i+1
else:
for i in range(n):
if a[i]%2 == 0:
answer = i+1
print(a... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
a = list(map(int, input().split()))
answer= 1
if a[0]%2 == 0 and a[1]%2 == 0:
s = "odd"
else:
s = "even"
if s == "odd":
for i in range(n):
if a[i]%2:
answer = i+1
else:
for i in range(n):
if a[i]%2 == 0:
answer = i+1
... | 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,583,388,696 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 436 | 2,252,800 | # -*- coding: utf-8 -*-
"""
Created on Thu Mar 5 11:26:03 2020
@author: akprasad
5A. Chat Server's Outgoing Traffic
time limit per test: 1 second
memory limit per test: 64 megabytes
input: standard input
output: standard output
Polycarp is working on a new project called "Polychat".
Following modern tend... | 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
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 5 11:26:03 2020
@author: akprasad
5A. Chat Server's Outgoing Traffic
time limit per test: 1 second
memory limit per test: 64 megabytes
input: standard input
output: standard output
Polycarp is working on a new project called "Polychat".
Following m... | -1 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,644,427,247 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,048,000 | n, z = map(int, input().split())
sp=[]
for s in (n+1, z+1):
k=0
for i in range(2, int(s**0.5)+1):
if s%i==0:
k+=1
if k==0:
sp.append(s)
if len(sp)==1 and sp[0]==z:
print('YES')
if len(sp)!=1 and sp[-1]==z:
print('NO')
if len(sp)==0:
print('NO') | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n, z = map(int, input().split())
sp=[]
for s in (n+1, z+1):
k=0
for i in range(2, int(s**0.5)+1):
if s%i==0:
k+=1
if k==0:
sp.append(s)
if len(sp)==1 and sp[0]==z:
print('YES')
if len(sp)!=1 and sp[-1]==z:
print('NO')
if len(sp)==0:
print('NO')... | -1 |
19 | D | Points | PROGRAMMING | 2,800 | [
"data structures"
] | D. Points | 2 | 256 | Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types:
- add x y — on the sheet of paper Bob... | The first input line contains number *n* (1<=≤<=*n*<=≤<=2·105) — amount of requests. Then there follow *n* lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input... | For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*,<=*y*). If there are no points strictly above and to the right of point (*x*,<=*y*), output -1. | [
"7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n",
"13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n"
] | [
"1 1\n3 4\n1 1\n",
"7 7\n-1\n5 5\n"
] | none | 0 | [] | 1,669,653,503 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 4,505,600 | from bisect import insort_left as il, bisect_left as bl
M,d=10**9+2,[1,100,3000]
N=len(d)
k=M//d[-1]+1
for i in range(N):
d[i]=[d[i],k*d[-1]//d[i],[[[(0,0),(M,M)],[0,M],(0,0)] for _ in range(d[i])],set()]
def v():
for i in range(N-1,0,-1):
for k in d[i][3]:
l=d[i][2][k]
x,y=l[0]... | Title: Points
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is direc... | ```python
from bisect import insort_left as il, bisect_left as bl
M,d=10**9+2,[1,100,3000]
N=len(d)
k=M//d[-1]+1
for i in range(N):
d[i]=[d[i],k*d[-1]//d[i],[[[(0,0),(M,M)],[0,M],(0,0)] for _ in range(d[i])],set()]
def v():
for i in range(N-1,0,-1):
for k in d[i][3]:
l=d[i][2][k]
... | 0 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,696,337,739 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 122 | 0 | from math import sqrt as s
a,b,c = map(int,input().split())
s1 = s((a*c)/b)
s2 = s((a*b)/c)
s3 = s((b*c)/a)
print(int(4*(s1+s2+s3))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
from math import sqrt as s
a,b,c = map(int,input().split())
s1 = s((a*c)/b)
s2 = s((a*b)/c)
s3 = s((b*c)/a)
print(int(4*(s1+s2+s3)))
``` | 3 | |
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,681,835,142 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, m = map(int, input().split())
p = [input() for y in range(n)][::-1]
l = r = d = 0
i = j = -1
for y, t in enumerate(p):
if '1' in t:
if i == -1 and j == -1:
i, j = t.find('1'), t.rfind('1')
l, r = i, j
else:
prev_i, prev_j = i, j
i, j = t.find('1'),... | 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
n, m = map(int, input().split())
p = [input() for y in range(n)][::-1]
l = r = d = 0
i = j = -1
for y, t in enumerate(p):
if '1' in t:
if i == -1 and j == -1:
i, j = t.find('1'), t.rfind('1')
l, r = i, j
else:
prev_i, prev_j = i, j
i, j = t.... | 0 | |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ... | The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. | Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,521,824,589 | 1,689 | Python 3 | OK | TESTS | 56 | 109 | 7,270,400 | T = input()
D = {}
for i in T:
if i in D:
D[i]+=1
else:
D[i]=1
R = []
for i in D:
R.append(D[i])
if len(R) == 4:
print('YES')
elif len(R) == 3:
if max(R)>=2:
print('YES')
else:
print('NO')
elif len(R) == 2:
if min(R)>=2:
print('YES... | Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
T = input()
D = {}
for i in T:
if i in D:
D[i]+=1
else:
D[i]=1
R = []
for i in D:
R.append(D[i])
if len(R) == 4:
print('YES')
elif len(R) == 3:
if max(R)>=2:
print('YES')
else:
print('NO')
elif len(R) == 2:
if min(R)>=2:
... | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,672,240,319 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 154 | 2,048,000 | used={}
b=[]
mx=-1000000000000000000000000000000000000000000000
for i in range(int(input())):
s,n=input().split()
n=int(n)
if s in used:
used[s]+=n
else:
used[s]=n
b.append([s,used[s]])
for i in used:
if used[i]>mx:
mx=used[i]
for i,j in b:
if used[i]==... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
used={}
b=[]
mx=-1000000000000000000000000000000000000000000000
for i in range(int(input())):
s,n=input().split()
n=int(n)
if s in used:
used[s]+=n
else:
used[s]=n
b.append([s,used[s]])
for i in used:
if used[i]>mx:
mx=used[i]
for i,j in b:
if... | 3.907741 |
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.