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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,696,614,524 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
a = 0
for x in range(1, n+1):
b = str(input())
if b == "++x" or b =="x++":
a += 1
else:
a -= 1
print(a) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n = int(input())
a = 0
for x in range(1, n+1):
b = str(input())
if b == "++x" or b =="x++":
a += 1
else:
a -= 1
print(a)
``` | 0 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,657,872,066 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | k = int(input())
str = input()
flag = True
elements = list(set(str))
counts = [str.count(e) for e in elements]
print(elements)
print(counts)
for i in range(len(elements)):
if counts[i] % k != 0:
print(-1)
flag = False
break
if flag:
kstring = ''
for i in range(len(elem... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k = int(input())
str = input()
flag = True
elements = list(set(str))
counts = [str.count(e) for e in elements]
print(elements)
print(counts)
for i in range(len(elements)):
if counts[i] % k != 0:
print(-1)
flag = False
break
if flag:
kstring = ''
for i in rang... | 0 | |
915 | D | Almost Acyclic Graph | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs"
] | null | null | You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.
Can you make this graph [acyclic](https://en.wikipedia.org/wiki/Directed_acy... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=500, 1<=≤<=*m*<=≤<=*min*(*n*(*n*<=-<=1),<=100000)) — the number of vertices and the number of edges, respectively.
Then *m* lines follow. Each line contains two integers *u* and *v* denoting a directed edge going from vertex *u* to vertex *v* (1<=≤<=*u*,<... | If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO. | [
"3 4\n1 2\n2 3\n3 2\n3 1\n",
"5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example you can remove edge <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the graph becomes acyclic.
In the second example you have to remove at least two edges (for example, <... | 0 | [
{
"input": "3 4\n1 2\n2 3\n3 2\n3 1",
"output": "YES"
},
{
"input": "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5",
"output": "NO"
},
{
"input": "2 2\n1 2\n2 1",
"output": "YES"
},
{
"input": "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2",
"output": "YES"
},
{
"input": "500 50\n39... | 1,633,165,482 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 21,299,200 | from collections import deque
def cycle_detectable_topological_sort(g, ind):
V = len(g)
order = []
depth = [-1]*V
for i in range(V):
if not ind[i]:
order.append(i)
depth[i] = 0
q = deque(order)
while q:
v = q.popleft()
cur_depth = dep... | Title: Almost Acyclic Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remo... | ```python
from collections import deque
def cycle_detectable_topological_sort(g, ind):
V = len(g)
order = []
depth = [-1]*V
for i in range(V):
if not ind[i]:
order.append(i)
depth[i] = 0
q = deque(order)
while q:
v = q.popleft()
cur_d... | 0 | |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,582,240,928 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | a=input()
b=input()
def check(arr,pos,word):
subset=""
# if (pos+len(word))<=len(arr):
if True:
for i in range(pos,pos+len(word)):
subset+=arr[i]
if subset==word:
return True
else:
return False
return False
count=0
for i in range(len(a)):
i... | Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
a=input()
b=input()
def check(arr,pos,word):
subset=""
# if (pos+len(word))<=len(arr):
if True:
for i in range(pos,pos+len(word)):
subset+=arr[i]
if subset==word:
return True
else:
return False
return False
count=0
for i in range(len(... | -1 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,637,437,525 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 62 | 0 | def main():
t = int(input())
l = [[1] * t for i in range(t)]
for j in range(1, t):
for i in range(1, t):
l[i][j] = l[i][j-1] + l[i-1][j]
a = l[t-1][t-1]
print(a)
if __name__ == '__main__':
main() | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
def main():
t = int(input())
l = [[1] * t for i in range(t)]
for j in range(1, t):
for i in range(1, t):
l[i][j] = l[i][j-1] + l[i-1][j]
a = l[t-1][t-1]
print(a)
if __name__ == '__main__':
main()
``` | 3 | |
691 | C | Exponential notation | PROGRAMMING | 1,800 | [
"implementation",
"strings"
] | null | null | You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it shou... | The only line contains the positive decimal number *x*. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. | Print the only line — the "simple exponential notation" of the given number *x*. | [
"16\n",
"01.23400\n",
".100\n",
"100.\n"
] | [
"1.6E1\n",
"1.234\n",
"1E-1\n",
"1E2\n"
] | none | 0 | [
{
"input": "16",
"output": "1.6E1"
},
{
"input": "01.23400",
"output": "1.234"
},
{
"input": ".100",
"output": "1E-1"
},
{
"input": "100.",
"output": "1E2"
},
{
"input": "9000",
"output": "9E3"
},
{
"input": "0.0012",
"output": "1.2E-3"
},
{
... | 1,516,813,796 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 312 | 10,752,000 | def f(q):
i = 0
while i < len(q) and q[i] == '0': i += 1
return q[i:]
def g(q):
i = len(q)
while i > 0 and q[i - 1] == '0': i -= 1
return q[:i]
a, b = (input() + '.').split('.')[:2]
a, b = f(a), g(b)
e = len(a) - 1
if not b: a = g(a)
if not a:
e = len(b) + 1
b = f(b)
e... | Title: Exponential notation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notatio... | ```python
def f(q):
i = 0
while i < len(q) and q[i] == '0': i += 1
return q[i:]
def g(q):
i = len(q)
while i > 0 and q[i - 1] == '0': i -= 1
return q[:i]
a, b = (input() + '.').split('.')[:2]
a, b = f(a), g(b)
e = len(a) - 1
if not b: a = g(a)
if not a:
e = len(b) + 1
b = f... | 3 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,697,046,128 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 16,384,000 | def sol(n,a):
c=a[-1]-a[0] # noqa: F841
M=a.count(a[0]);m=a.count(a[-1])
print(c,(M*m))
return
n=int(input())
s=sorted([int(x) for x in input().split()])
sol(n,s)
| Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
def sol(n,a):
c=a[-1]-a[0] # noqa: F841
M=a.count(a[0]);m=a.count(a[-1])
print(c,(M*m))
return
n=int(input())
s=sorted([int(x) for x in input().split()])
sol(n,s)
``` | 0 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,546,828,969 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 109 | 0 | n = int(input())
g = [None]*n
cnt = 0
for i in range(n):
g[i] = input()
for i in range(n):
c_cnt = 0
r_cnt = 0
for j in range(n):
if g[i][j] == 'C':
r_cnt += 1
if g[j][i] == 'C':
c_cnt += 1
cnt += (r_cnt * (r_cnt-1) // 2 if r_cnt > 1 else 0)
... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
n = int(input())
g = [None]*n
cnt = 0
for i in range(n):
g[i] = input()
for i in range(n):
c_cnt = 0
r_cnt = 0
for j in range(n):
if g[i][j] == 'C':
r_cnt += 1
if g[j][i] == 'C':
c_cnt += 1
cnt += (r_cnt * (r_cnt-1) // 2 if r_cnt > 1 e... | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,598,559,570 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n = int(input())
times = []
for _ in range(n):
times.append(_)
times_set = set(times)
print(len(times_set)) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
times = []
for _ in range(n):
times.append(_)
times_set = set(times)
print(len(times_set))
``` | 0 | |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,513,477,129 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 82,124,800 | n=int(input())
bb=list(map(int,input().split()))
if n==1 :
print(1)
else :
for i in range(n):
if i==0 :
if bb[1]>0 :
bb[0]=-1
else :
if bb[i]>=i :
for j in range(i):
bb[j]=-1
else :
... | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n=int(input())
bb=list(map(int,input().split()))
if n==1 :
print(1)
else :
for i in range(n):
if i==0 :
if bb[1]>0 :
bb[0]=-1
else :
if bb[i]>=i :
for j in range(i):
bb[j]=-1
else :
... | 0 | |
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he... | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 6... | 1,687,876,408 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 82 | 124 | 21,913,600 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N,a,b,c = map(int,input().split())
A = list(map(int,input().split()))
Z = [[A[-1],... | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N,a,b,c = map(int,input().split())
A = list(map(int,input().split()))
Z ... | 3 | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,604,424,431 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 216 | 307,200 | # calls = 0
cacheD = {}
cacheA = {}
def solve(vertice, passos):
# global calls
# calls += 1
if vertice == 'D':
if passos in cacheD:
return cacheD[passos]
if passos <= 1:
cacheD[passos] = 0
return cacheD[passos]
cacheD[passos] = 3 * solve('A', p... | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
# calls = 0
cacheD = {}
cacheA = {}
def solve(vertice, passos):
# global calls
# calls += 1
if vertice == 'D':
if passos in cacheD:
return cacheD[passos]
if passos <= 1:
cacheD[passos] = 0
return cacheD[passos]
cacheD[passos] = 3 * so... | 0 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,493,232,394 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | i = 0
fail = 0
z = []
while i < len(x):
if x[i] == y[i]:
z.append(x[i])
elif x[i] < y[i] and x[i] == 'a':
print('-1')
break
else:
z.append('z')
i += 1
print(''.join(z)) | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
i = 0
fail = 0
z = []
while i < len(x):
if x[i] == y[i]:
z.append(x[i])
elif x[i] < y[i] and x[i] == 'a':
print('-1')
break
else:
z.append('z')
i += 1
print(''.join(z))
``` | -1 | |
888 | D | Almost Identity Permutations | PROGRAMMING | 1,600 | [
"combinatorics",
"dp",
"math"
] | null | null | A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity ... | The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4). | Print the number of almost identity permutations for given *n* and *k*. | [
"4 1\n",
"4 2\n",
"5 3\n",
"5 4\n"
] | [
"1\n",
"7\n",
"31\n",
"76\n"
] | none | 0 | [
{
"input": "4 1",
"output": "1"
},
{
"input": "4 2",
"output": "7"
},
{
"input": "5 3",
"output": "31"
},
{
"input": "5 4",
"output": "76"
},
{
"input": "200 1",
"output": "1"
},
{
"input": "200 2",
"output": "19901"
},
{
"input": "200 3",
... | 1,626,336,682 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 22,220,800 | import math
from math import comb
def countDer(n):
# Base Case
if n == 1 or n == 2:
return n-1;
# Variables for storing prevoius values
a = 0
b = 1
# using above recursive formula
for i in range(3, n + 1):
cur = (i-1)*(a+b)
a = b
... | Title: Almost Identity Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*... | ```python
import math
from math import comb
def countDer(n):
# Base Case
if n == 1 or n == 2:
return n-1;
# Variables for storing prevoius values
a = 0
b = 1
# using above recursive formula
for i in range(3, n + 1):
cur = (i-1)*(a+b)
... | -1 | |
597 | C | Subsequences | PROGRAMMING | 1,900 | [
"data structures",
"dp"
] | null | null | For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018. | First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements in increasing subsequences.
Next *n* lines contains one integer *a**i* (1<=≤<=*a**i*<=≤<=*n*) each — elements of sequence. All values *a**i* are different. | Print one integer — the answer to the problem. | [
"5 2\n1\n2\n3\n5\n4\n"
] | [
"7\n"
] | none | 1,500 | [
{
"input": "5 2\n1\n2\n3\n5\n4",
"output": "7"
},
{
"input": "1 0\n1",
"output": "1"
},
{
"input": "2 1\n1\n2",
"output": "1"
},
{
"input": "2 1\n2\n1",
"output": "0"
},
{
"input": "3 2\n1\n2\n3",
"output": "1"
},
{
"input": "3 1\n1\n3\n2",
"output... | 1,676,914,269 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,000 | 5,529,600 | #https://codeforces.com/contest/597/problem/C
from collections import defaultdict
import sys
class Fenwick:
def __init__(self, size):
self.tree = [0] * size
def update(self, ind, num):
current = ind
while current < len(self.tree):
self.tree[current] += num
cur... | Title: Subsequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input Specification:
First line contain t... | ```python
#https://codeforces.com/contest/597/problem/C
from collections import defaultdict
import sys
class Fenwick:
def __init__(self, size):
self.tree = [0] * size
def update(self, ind, num):
current = ind
while current < len(self.tree):
self.tree[current] += num
... | 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,603,279,927 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 307,200 | n=int(input(''))
l=[]
m=x=y=0
while n>0:
a,b,c = input('').split()
a=int(a)
b=int(b)
c=int(c)
l.append(a)
l.append(b)
l.append(c)
n=n-1
for i in l[0::3]:
m=m+i
for j in l[1::3]:
x=x+j
for k in l[2::3]:
y=y+k
if(m==0 and x==0 and y==0):
print('YES')
els... | 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(''))
l=[]
m=x=y=0
while n>0:
a,b,c = input('').split()
a=int(a)
b=int(b)
c=int(c)
l.append(a)
l.append(b)
l.append(c)
n=n-1
for i in l[0::3]:
m=m+i
for j in l[1::3]:
x=x+j
for k in l[2::3]:
y=y+k
if(m==0 and x==0 and y==0):
print('... | 3.944928 |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,658,420,541 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 124 | 17,920,000 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
last = b.pop()
second_last = b.pop()
capacity = last + second_last
summ = 0
for i in range(0, n):
summ += a[i]
if summ > capacity:
print("NO")
else:
print("YES")
| Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
last = b.pop()
second_last = b.pop()
capacity = last + second_last
summ = 0
for i in range(0, n):
summ += a[i]
if summ > capacity:
print("NO")
else:
print("YES")
``` | 3 | |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,588,710,719 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 108 | 0 | k=int(input())
a=''.join([input()for _ in[0]*4])
print('YNEOS'[max((a.count(str(x))for x in range(10)),default=0)>2*k::2]) | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
k=int(input())
a=''.join([input()for _ in[0]*4])
print('YNEOS'[max((a.count(str(x))for x in range(10)),default=0)>2*k::2])
``` | 3 | |
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,594,216,711 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 93 | 6,656,000 | n = int(input())
yesOrNo = "NO"
for i in range(n):
name, rateBef, rateAft = [str(i) for i in input().split()]
if int(rateBef) >= 2500 and int(rateAft) > int(rateBef):
yesOrNo = "YES"
print(yesOrNo) | 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
n = int(input())
yesOrNo = "NO"
for i in range(n):
name, rateBef, rateAft = [str(i) for i in input().split()]
if int(rateBef) >= 2500 and int(rateAft) > int(rateBef):
yesOrNo = "YES"
print(yesOrNo)
``` | 0 | |
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,575,487,499 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 0 | import numpy as np
n, k = [int(i) for i in input().split()]
a = np.zeros((n, n), dtype=int)
np.fill_diagonal(a, k)
for elem in a:
print(*elem) | 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
import numpy as np
n, k = [int(i) for i in input().split()]
a = np.zeros((n, n), dtype=int)
np.fill_diagonal(a, k)
for elem in a:
print(*elem)
``` | -1 | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,518,862,755 | 435 | Python 3 | OK | TESTS | 49 | 62 | 6,348,800 | nn = int(input())
txt = input()
txt = list(txt)
arr = ['a','e','i','o','u','y']
bol = [True]*len(txt)
#print(bol)
#print(txt)
for i in range(1,len(txt)):
if(txt[i] in arr and txt[i-1] in arr):
bol[i] = False
for i in range(len(bol)):
if(bol[i]==True):
print(txt[i],sep='',end='') | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
nn = int(input())
txt = input()
txt = list(txt)
arr = ['a','e','i','o','u','y']
bol = [True]*len(txt)
#print(bol)
#print(txt)
for i in range(1,len(txt)):
if(txt[i] in arr and txt[i-1] in arr):
bol[i] = False
for i in range(len(bol)):
if(bol[i]==True):
print(txt[i],sep='',en... | 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,697,125,023 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 92 | 102,400 | def func(n):
sum = 0
while n > 0:
sum += n % 10
n //= 10
return sum
def main():
s = input()
if len(s) != 1:
sum = 0
for i in range(len(s)):
sum += int(s[i])
cnt = 1
while sum >= 10:
ans = sum
sum... | 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 func(n):
sum = 0
while n > 0:
sum += n % 10
n //= 10
return sum
def main():
s = input()
if len(s) != 1:
sum = 0
for i in range(len(s)):
sum += int(s[i])
cnt = 1
while sum >= 10:
ans = sum
... | 3.976816 |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,662,289,346 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def solution():
n = int(input())
sizes = map(int, input().split())
sizes = list(sizes)
maxi = -float('inf')
mini = -maxi
for e in sizes:
if e > maxi:
maxi = e
if e < mini:
mini = e
d = {}
count = 0
for i in range(len(sizes)):
if sizes... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
def solution():
n = int(input())
sizes = map(int, input().split())
sizes = list(sizes)
maxi = -float('inf')
mini = -maxi
for e in sizes:
if e > maxi:
maxi = e
if e < mini:
mini = e
d = {}
count = 0
for i in range(len(sizes)):
... | 0 | |
289 | A | Polo the Penguin and Segments | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 uni... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*... | In a single line print a single integer — the answer to the problem. | [
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 ... | 1,616,089,040 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 498 | 0 | n, k = input().split()
n=int(n)
k=int(k)
seg = 0
for i in range(n):
l, r = input().split()
l=int(l)
r=int(r)
seg+=((r - l) + 1)
#print(seg)
q=(k - (seg % k)) % k
print(q)
| Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]... | ```python
n, k = input().split()
n=int(n)
k=int(k)
seg = 0
for i in range(n):
l, r = input().split()
l=int(l)
r=int(r)
seg+=((r - l) + 1)
#print(seg)
q=(k - (seg % k)) % k
print(q)
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,687,188,622 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def weights(w):
if w % 2 == 0:
return True
else:
return False
try:
w = int(input("Enter a number: "))
print(weights(w))
except ValueError:
print("Invalid input. Please enter a valid integer.")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def weights(w):
if w % 2 == 0:
return True
else:
return False
try:
w = int(input("Enter a number: "))
print(weights(w))
except ValueError:
print("Invalid input. Please enter a valid integer.")
``` | 0 |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,524,509,109 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 93 | 7,065,600 | s = input();
if s.startswith('a') and s.endswith('c') and (list(s).count('c') == list(s).count('a') or list(s).count('c') == list(s).count('b')) and sorted(list(s)) == list(s) and 'a' in s and 'b' in s:
print('YES');
else:
print('NO');
| Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s = input();
if s.startswith('a') and s.endswith('c') and (list(s).count('c') == list(s).count('a') or list(s).count('c') == list(s).count('b')) and sorted(list(s)) == list(s) and 'a' in s and 'b' in s:
print('YES');
else:
print('NO');
``` | 3 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,685,644,533 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | v1=int(input())
if v1%2==0:
print(v1//2,v1//2)
else:
w=2
print(v1-w,w) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
v1=int(input())
if v1%2==0:
print(v1//2,v1//2)
else:
w=2
print(v1-w,w)
``` | 0 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,449,918,169 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | vowel=['a','o','y','e','u','i']
s=input()
l=len(s)
a=list(s)
for i in range(l):
if ord(a[i])>=65 and ord(a[i])<=90:
a[i]=chr(ord(a[i])+32)
s=''.join(a)
for i in s:
if i not in vowel:
print('.',end='')
print(i,end='')
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
vowel=['a','o','y','e','u','i']
s=input()
l=len(s)
a=list(s)
for i in range(l):
if ord(a[i])>=65 and ord(a[i])<=90:
a[i]=chr(ord(a[i])+32)
s=''.join(a)
for i in s:
if i not in vowel:
print('.',end='')
print(i,end='')
``` | 0 | |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,689,831,209 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n, m, k = map(int, input().split())
m -= n
ans = 1
s = 1
mini, maxi = min(k-1, n-k), max(k-1, n-k)
for i in range(maxi+1):
if m < s:
break
else:
m -= s
ans += 1
s += 2 if i < mini else 1
ans += m//n
print(ans)
| Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
n, m, k = map(int, input().split())
m -= n
ans = 1
s = 1
mini, maxi = min(k-1, n-k), max(k-1, n-k)
for i in range(maxi+1):
if m < s:
break
else:
m -= s
ans += 1
s += 2 if i < mini else 1
ans += m//n
print(ans)
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,688,466,038 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n=int(input())
mc=0
cc=0
for i in range(n):
a,b=map(int,input().split())
cc-=a
cc+=b
mc=max(mc,cc)
print(mc)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n=int(input())
mc=0
cc=0
for i in range(n):
a,b=map(int,input().split())
cc-=a
cc+=b
mc=max(mc,cc)
print(mc)
``` | 3 | |
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make... | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
}... | 1,637,139,685 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 171 | 2,252,800 | s = input()
n = len(s)
a = s.count('a')
b = s.count('b')
ans = max(n - a, n - b)
pref = [0] * (n + 1)
for i in range(1, n + 1):
pref[i] = int(s[i - 1] == 'b') + pref[i - 1]
for i in range(1, n + 1):
for j in range(i, n + 1):
cnt_a = j - i + 1 - (pref[j] - pref[i - 1])
cnt_b_left = pre... | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ... | ```python
s = input()
n = len(s)
a = s.count('a')
b = s.count('b')
ans = max(n - a, n - b)
pref = [0] * (n + 1)
for i in range(1, n + 1):
pref[i] = int(s[i - 1] == 'b') + pref[i - 1]
for i in range(1, n + 1):
for j in range(i, n + 1):
cnt_a = j - i + 1 - (pref[j] - pref[i - 1])
cnt_b_... | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,671,014,918 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 62 | 0 | a,b = map(int,input().split())
f,d,s = (0,0,0)
for x in range(1,7):
if abs(a-x) < abs(b-x):
f += 1
elif abs(b-x) < abs(a-x):
s += 1
else:
d += 1
print(f,d,s) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b = map(int,input().split())
f,d,s = (0,0,0)
for x in range(1,7):
if abs(a-x) < abs(b-x):
f += 1
elif abs(b-x) < abs(a-x):
s += 1
else:
d += 1
print(f,d,s)
``` | 3 | |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,678,481,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 62 | 0 | n = int(input())
arr = [int(x) for x in input().split()]
pages = 0
day = 0
while pages < n:
for i in arr:
day += 1
pages += i
if pages >= n:
break
print(day%7) | Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
pages = 0
day = 0
while pages < n:
for i in arr:
day += 1
pages += i
if pages >= n:
break
print(day%7)
``` | 0 | |
414 | A | Mashmokh and Numbers | PROGRAMMING | 1,500 | [
"constructive algorithms",
"number theory"
] | null | null | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108). | If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | [
"5 2\n",
"5 3",
"7 2\n"
] | [
"1 2 3 4 5\n",
"2 4 3 7 1",
"-1\n"
] | *gcd*(*x*, *y*) is greatest common divisor of *x* and *y*. | 500 | [
{
"input": "5 2",
"output": "1 2 3 4 5"
},
{
"input": "5 3",
"output": "2 4 5 6 7"
},
{
"input": "7 2",
"output": "-1"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input"... | 1,602,911,840 | 2,147,483,647 | PyPy 3 | OK | TESTS | 84 | 233 | 8,192,000 | import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
if k<n//2 or (n==1 and k!=0):
print(-1)
else:
if n==1:
print(1)
else:
x=r=k-(n-2)//2
while r<=x+n:
r+=x
an=[r,x]
for i in range(2,n):
an.append(an[1]+i-1)
print(*an) | Title: Mashmokh and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. ... | ```python
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
if k<n//2 or (n==1 and k!=0):
print(-1)
else:
if n==1:
print(1)
else:
x=r=k-(n-2)//2
while r<=x+n:
r+=x
an=[r,x]
for i in range(2,n):
an.append(an[1]+i-1)
print(*an)
``` | 3 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,597,228,411 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 155 | 22,528,000 | t=int(input())
s=(t//2)*'8'+(t%2)*'4'
if(len(s)<=10**18):
print(s)
else:
print(-1) | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
t=int(input())
s=(t//2)*'8'+(t%2)*'4'
if(len(s)<=10**18):
print(s)
else:
print(-1)
``` | 0 | |
207 | D4 | The Beaver's Problem - 3 | PROGRAMMING | 2,100 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are ... | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | 10 | [
{
"input": "19000\nGROUP OF FIVE MEETING ENDS\nWASHINGTON, April 8 - A meeting of finance ministers and\ncentral bankers of the Group of Five ended after nearly three\nand a half hours.\nWest German Finance Minister Gerhard Stoltenberg and\nBritish Chancellor of the Exchequer Nigel Lawson declined to\ncomment o... | 1,673,005,726 | 2,147,483,647 | Python 3 | OK | TESTS4 | 5 | 31 | 0 | # LUOGU_RID: 98853484
print(1)# dx | Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subje... | ```python
# LUOGU_RID: 98853484
print(1)# dx
``` | 3 | |
371 | D | Vessels | PROGRAMMING | 1,800 | [
"data structures",
"dsu",
"implementation",
"trees"
] | null | null | There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the w... | The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The t... | For each query, print on a single line the number of liters of water in the corresponding vessel. | [
"2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n",
"3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n"
] | [
"4\n5\n8\n",
"7\n10\n5\n"
] | none | 2,000 | [
{
"input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2",
"output": "4\n5\n8"
},
{
"input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3",
"output": "7\n10\n5"
},
{
"input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n... | 1,662,537,200 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import sys
input=sys.stdin.readline
if __name__=='__main__':
n=int(input())
maxvol=list(map(int,input().split()))
maxvol.append(float('inf'))
nxt=list(range(n+1))
vol=[0]*n
def addwater(i,water):
if i>=n or water==0:
return
vol[i]+=water
if vol[i... | Title: Vessels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a*... | ```python
import sys
input=sys.stdin.readline
if __name__=='__main__':
n=int(input())
maxvol=list(map(int,input().split()))
maxvol.append(float('inf'))
nxt=list(range(n+1))
vol=[0]*n
def addwater(i,water):
if i>=n or water==0:
return
vol[i]+=water
... | 0 | |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,658,514,629 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | na, nb = input().split(' ')
n, k = input().split(' ')
n1, k1 = 0, 0
array1 = input().split(' ')
array2 = input().split(' ')
array1 = list(map(int, array1))
array2 = list(map(int, array2))
for i in range(int(na)):
if array1[i] < array2[0]:
n1+=1
print('YES' if n1>=int(n) else 'NO')
... | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
na, nb = input().split(' ')
n, k = input().split(' ')
n1, k1 = 0, 0
array1 = input().split(' ')
array2 = input().split(' ')
array1 = list(map(int, array1))
array2 = list(map(int, array2))
for i in range(int(na)):
if array1[i] < array2[0]:
n1+=1
print('YES' if n1>=int(n) e... | 0 | |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,684,363,297 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 102,400 | p = int(input())
co=0
ok=1
for i in range(1, p - 1):
for j in range(1, p - 2):
po = (i ** j)
if(po - 1)%p == 0:
ok = 0
po = i ** (p - 1)
if(po-1)%p == 0 and ok == 1:
co+=1
ok = 1
print(co)
| Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
p = int(input())
co=0
ok=1
for i in range(1, p - 1):
for j in range(1, p - 2):
po = (i ** j)
if(po - 1)%p == 0:
ok = 0
po = i ** (p - 1)
if(po-1)%p == 0 and ok == 1:
co+=1
ok = 1
print(co)
``` | 0 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,678,532,543 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 12 | 233 | 268,390,400 | from math import log2
n = int(input())
a = {'s':"Sheldon", 'l':"Leonard", 'p':"Penny", 'r':"Rajesh", 'h':"Howard"}
d = log2((n-1)/5+1)
n -= 5*(2**(int(d))-1)
b=''
b +='s'*(2**int(d))
b +='l'*(2**int(d))
b +='p'*(2**int(d))
b +='r'*(2**int(d))
b +='h'*(2**int(d))
print(a[b[n-1]])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
from math import log2
n = int(input())
a = {'s':"Sheldon", 'l':"Leonard", 'p':"Penny", 'r':"Rajesh", 'h':"Howard"}
d = log2((n-1)/5+1)
n -= 5*(2**(int(d))-1)
b=''
b +='s'*(2**int(d))
b +='l'*(2**int(d))
b +='p'*(2**int(d))
b +='r'*(2**int(d))
b +='h'*(2**int(d))
print(a[b[n-1]])
``` | 0 |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkg... | 1,573,063,323 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 109 | 0 | a = 'xXAHIMmoOTuUVvWwYyn'
d = {'LJ', 'bd', 'pq'}
s = input()
n = len(s)
res = True
for i in range(n):
x, y = s[i], s[n - i - 1]
if x == y and x in a: continue
if x + y in d or y + x in d:
continue
print("NIE")
exit()
print("TAK")
| Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h... | ```python
a = 'xXAHIMmoOTuUVvWwYyn'
d = {'LJ', 'bd', 'pq'}
s = input()
n = len(s)
res = True
for i in range(n):
x, y = s[i], s[n - i - 1]
if x == y and x in a: continue
if x + y in d or y + x in d:
continue
print("NIE")
exit()
print("TAK")
``` | 0 | |
799 | B | T-shirt buying | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts.
The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt.
The following line contains sequence of integers *a*1,<... | Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1. | [
"5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n",
"2\n1000000000 1\n1 1\n1 2\n2\n2 1\n"
] | [
"200 400 300 500 911 -1 \n",
"1 1000000000 \n"
] | none | 1,000 | [
{
"input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1",
"output": "200 400 300 500 911 -1 "
},
{
"input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1",
"output": "1 1000000000 "
},
{
"input": "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 8... | 1,681,457,713 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 3,000 | 24,576,000 |
n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = int(input())
buyer = list(map(int, input().split()))
ans = []
s1 = set()
s2 = set()
s3 = set()
for i in range(n):
if a[i] == 1 or b[i] == 1:
s1.add(p[i])
if a[i] == 2 or b... | Title: T-shirt buying
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt a... | ```python
n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = int(input())
buyer = list(map(int, input().split()))
ans = []
s1 = set()
s2 = set()
s3 = set()
for i in range(n):
if a[i] == 1 or b[i] == 1:
s1.add(p[i])
if a[i]... | 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,665,989,358 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 0 | a=input()
b=input()
for i in range(len(a)):
if a[i]!=b[i]:print(end='1')
else:print(end='0') | 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()
for i in range(len(a)):
if a[i]!=b[i]:print(end='1')
else:print(end='0')
``` | 3.9845 |
837 | E | Vasya's Function | PROGRAMMING | 2,100 | [
"binary search",
"implementation",
"math"
] | null | null | Vasya is studying number theory. He has denoted a function *f*(*a*,<=*b*) such that:
- *f*(*a*,<=0)<==<=0; - *f*(*a*,<=*b*)<==<=1<=+<=*f*(*a*,<=*b*<=-<=*gcd*(*a*,<=*b*)), where *gcd*(*a*,<=*b*) is the greatest common divisor of *a* and *b*.
Vasya has two numbers *x* and *y*, and he wants to calculate *f*(*x*,<=*y*)... | The first line contains two integer numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=1012). | Print *f*(*x*,<=*y*). | [
"3 5\n",
"6 3\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "3 5",
"output": "3"
},
{
"input": "6 3",
"output": "1"
},
{
"input": "1000000009 1000000008",
"output": "1000000008"
},
{
"input": "1000000007 1000000006",
"output": "1000000006"
},
{
"input": "2000000018 2000000017",
"output": "1000000009"
},
... | 1,501,781,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 5,734,400 | import sys
from decimal import Decimal
import math
def primes_till(n): # Sieve of Eratosthenes
p = [True] * n
for i in range(2, n):
if p[i]:
j = i * i
while j < n:
p[j] = False
j += i
res = []
for i in range(2, n):
... | Title: Vasya's Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is studying number theory. He has denoted a function *f*(*a*,<=*b*) such that:
- *f*(*a*,<=0)<==<=0; - *f*(*a*,<=*b*)<==<=1<=+<=*f*(*a*,<=*b*<=-<=*gcd*(*a*,<=*b*)), where *gcd*(*a*,<=*b*) is the greatest commo... | ```python
import sys
from decimal import Decimal
import math
def primes_till(n): # Sieve of Eratosthenes
p = [True] * n
for i in range(2, n):
if p[i]:
j = i * i
while j < n:
p[j] = False
j += i
res = []
for i in range(2, n)... | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,668,591,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 140 | 5,836,800 | n = input()
l = input().split()
l2 = l.copy()
l2.sort()
d1 = {0:0}
d2 = {0:0}
s = 0
s1 = 0
i = 1
for v1, v2 in zip(l, l2):
s += int(v1)
s1 += int(v2)
d1[i] = (s)
d2[i] = (s1)
i += 1
for _ in range(int(input())):
ty, st, ed = list(map(int, input().split()))
if ty == 1:
... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = input()
l = input().split()
l2 = l.copy()
l2.sort()
d1 = {0:0}
d2 = {0:0}
s = 0
s1 = 0
i = 1
for v1, v2 in zip(l, l2):
s += int(v1)
s1 += int(v2)
d1[i] = (s)
d2[i] = (s1)
i += 1
for _ in range(int(input())):
ty, st, ed = list(map(int, input().split()))
if... | 0 | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,609,257,116 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 13,926,400 | n, s, t = map(int, input().split())
v = [*range(1, n+1)]
p = list(map(lambda x : int(x) - 1, input().split()))
num_moves = 0
s , t = s-1, t
if t == v[s]:
print(0)
exit(0)
while True:
v = [v[i] for i in p]
num_moves += 1
if t == v[s]:
break
# print(v)
if s + 1 == v[s]:
print(-... | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n, s, t = map(int, input().split())
v = [*range(1, n+1)]
p = list(map(lambda x : int(x) - 1, input().split()))
num_moves = 0
s , t = s-1, t
if t == v[s]:
print(0)
exit(0)
while True:
v = [v[i] for i in p]
num_moves += 1
if t == v[s]:
break
# print(v)
if s + 1 == v[s]:
... | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,676,612,625 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n=int(input())
m=0
c=0
for i in range(n):
nn=[int(x) for x in input().split()]
if nn[0]>nn[1]:
m+=1
elif nn[1]>nn[0]:
c+=1
if m>c:
print("Mishka")
elif c>m:
print("Chris")
else:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n=int(input())
m=0
c=0
for i in range(n):
nn=[int(x) for x in input().split()]
if nn[0]>nn[1]:
m+=1
elif nn[1]>nn[0]:
c+=1
if m>c:
print("Mishka")
elif c>m:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 | |
207 | D2 | The Beaver's Problem - 3 | PROGRAMMING | 2,000 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are ... | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | 10 | [
{
"input": "7000\nTREASURY BALANCES AT FED FELL ON MARCH 27\nWASHINGTON, March 30 - Treasury balances at the Federal\nReserve fell on March 27 to 2.424 billion dlrs from 2.508\nbillion dlrs on the previous business day, the Treasury said in\nits latest budget statement.\nBalances in tax and loan note accounts f... | 1,668,661,288 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS2 | 0 | 46 | 0 | # LUOGU_RID: 94322221
a=int(input())
if(a==8 or a==9):print('2')
elif(a==6 or a==11):print('3')
else:print('1') | Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subje... | ```python
# LUOGU_RID: 94322221
a=int(input())
if(a==8 or a==9):print('2')
elif(a==6 or a==11):print('3')
else:print('1')
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).
Let's define *dist*(*v*,<=*u*) as the ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the integers written in the vertices.
The next (*n*<=-<=1) lines contain two integers each. The *i*-th of these lines contains integers *p**i* and *w**i* (1<=≤<=*... | Print *n* integers — the *i*-th of these numbers should be equal to the number of vertices that the *i*-th vertex controls. | [
"5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6\n",
"5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1\n"
] | [
"1 0 1 0 0\n",
"4 3 2 1 0\n"
] | In the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5). | 0 | [
{
"input": "5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6",
"output": "1 0 1 0 0"
},
{
"input": "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1",
"output": "4 3 2 1 0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 1\n1 1",
"output": "1 0"
},
{
"input": "10\n40 77 65 14 86 16 2 51 ... | 1,479,925,890 | 6,990 | Python 3 | RUNTIME_ERROR | PRETESTS | 4 | 46 | 0 | def main():
n=int(input())
nodes=list(map(int,input().split()))
controlling=[0]*n
parent={0:[]}
tree={}
for i in range(1,n):
p,edge=list(map(int,input().split()))
p-=1
parent[i]=parent[p]+[p]
tree[(p,i)]=edge
pList=parent[i]+[i]
weight=... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree ... | ```python
def main():
n=int(input())
nodes=list(map(int,input().split()))
controlling=[0]*n
parent={0:[]}
tree={}
for i in range(1,n):
p,edge=list(map(int,input().split()))
p-=1
parent[i]=parent[p]+[p]
tree[(p,i)]=edge
pList=parent[i]+[i]
... | -1 | |
316 | A2 | Special Task | PROGRAMMING | 1,400 | [
"math"
] | null | null | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get th... | The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
- 1<=≤<=|*s*|<=≤<=5.
The input limits for s... | Print the number of codes that match the given hint. | [
"AJ\n",
"1?AA\n"
] | [
"81\n",
"100\n"
] | none | 70 | [
{
"input": "AJ",
"output": "81"
},
{
"input": "1?AA",
"output": "100"
},
{
"input": "?",
"output": "9"
},
{
"input": "7",
"output": "1"
},
{
"input": "A",
"output": "9"
},
{
"input": "BBB?",
"output": "90"
},
{
"input": "BC??",
"output"... | 1,436,146,643 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS2 | 2 | 372 | 819,200 | from collections import Counter as c
f=lambda a,b:a*f(a-1,b-1)if b else 1
a=input()
b='ABCDEFGHIJ'
d=c(i for i in a if i in b)
e=10-(a[0]in b)
print(e*f(9,len(d.items())-1),end='')
for i in a:
if i=='?':print('0',end='') | Title: Special Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expen... | ```python
from collections import Counter as c
f=lambda a,b:a*f(a-1,b-1)if b else 1
a=input()
b='ABCDEFGHIJ'
d=c(i for i in a if i in b)
e=10-(a[0]in b)
print(e*f(9,len(d.items())-1),end='')
for i in a:
if i=='?':print('0',end='')
``` | -1 | |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 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.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,699,706,322 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
s=str(n)
g=0
for ele in s:
if ele in "47":
g+=1
if g==len(s):print("yes")
else:print("no")
| Title: Nearly Lucky Number
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())
s=str(n)
g=0
for ele in s:
if ele in "47":
g+=1
if g==len(s):print("yes")
else:print("no")
``` | 0 |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,622,205,724 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 0 | def f(r,c):
if r==1 or c==1:
return 1
return f(r-1,c) + f(r,c-1)
n=int(input())
print(f(n,n)) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
def f(r,c):
if r==1 or c==1:
return 1
return f(r-1,c) + f(r,c-1)
n=int(input())
print(f(n,n))
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,642,846,002 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 248 | 3,788,800 | from fractions import Fraction
l=list(map(int,input().split()))
print(Fraction(min(l)/max(l)))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
l=list(map(int,input().split()))
print(Fraction(min(l)/max(l)))
``` | 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,653,287,589 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n,m,a = map(int,input().split())
area_rect = n * m
area_square = a * a
print(area_rect / area_square) | 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())
area_rect = n * m
area_square = a * a
print(area_rect / area_square)
``` | 0 |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,656,652,776 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | n = int(input())
s = '1'
for i in range(2, n + 1):
s += str(i)
print(s[n - 1]) | Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
n = int(input())
s = '1'
for i in range(2, n + 1):
s += str(i)
print(s[n - 1])
``` | 3 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,664,986,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | input();a=list(map(int,input().split()));n=0;m=[]
for x in a:
n,N,y,s=2,1,0,[]
while x!=0:
y=int((x/N)%n);s.append(y);x-=N*y;N*=n
while len(s)!=2:
s.append(0)
m.append(s)
def ck(a):
f=[]
for i in a:
if i==0:
f.append(1)
else:
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
input();a=list(map(int,input().split()));n=0;m=[]
for x in a:
n,N,y,s=2,1,0,[]
while x!=0:
y=int((x/N)%n);s.append(y);x-=N*y;N*=n
while len(s)!=2:
s.append(0)
m.append(s)
def ck(a):
f=[]
for i in a:
if i==0:
f.append(1)
else:
... | 0 | |
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,617,818,273 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 77 | 268,390,400 | import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
eps = 1e-10
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn ... | 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
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
eps = 1e-10
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstr... | 0 | |
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we ... | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000... | 1,595,440,390 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 6,656,000 | n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
if a == b:
print("YES")
else:
changes = 0
flag = True
for i in range(n):
if a[i]!=b[i]:
changes += 1
if changes > 2:
flag = False
break
if changes==2 and fl... | Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to c... | ```python
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
if a == b:
print("YES")
else:
changes = 0
flag = True
for i in range(n):
if a[i]!=b[i]:
changes += 1
if changes > 2:
flag = False
break
if changes... | 0 | |
923 | C | Perfect Security | PROGRAMMING | 1,800 | [
"data structures",
"greedy",
"strings",
"trees"
] | null | null | Alice has a very important message *M* consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key *K* of the length equal to the message's length. Alice computes the bitwise xor of each element of t... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=300000), the length of the message.
The second line contains *N* integers *A*1,<=*A*2,<=...,<=*A**N* (0<=≤<=*A**i*<=<<=230) representing the encrypted message.
The third line contains *N* integers *P*1,<=*P*2,<=...,<=*P**N* (0<=≤<=*P**i*<=<<=230) repr... | Output a single line with *N* integers, the lexicographically smallest possible message *O*. Note that all its elements should be non-negative. | [
"3\n8 4 13\n17 2 7\n",
"5\n12 7 87 22 11\n18 39 9 12 16\n",
"10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667\n"
] | [
"10 3 28\n",
"0 14 69 6 44\n",
"128965467 243912600 4281110 112029883 223689619 76924724 429589 119397893 613490433 362863284\n"
] | In the first case, the solution is (10, 3, 28), since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a896b30a69636d1bfbfa981eae10650f5fee843c.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e383e4333ea37c465... | 1,500 | [
{
"input": "3\n8 4 13\n17 2 7",
"output": "10 3 28"
},
{
"input": "5\n12 7 87 22 11\n18 39 9 12 16",
"output": "0 14 69 6 44"
},
{
"input": "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529... | 1,520,737,863 | 63 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 3,500 | 161,996,800 | __author__ = 'RaldenProg'
n = int(input())
list_a = [_ for _ in map(int, input().split())]
list_p = [_ for _ in map(int, input().split())]
list_x = [0] * n
list_r = []
import itertools
A = itertools.permutations(range(1, n+1))
for x in A:
list_x = []
for i in range(n):
xor = list_a[i] ^ lis... | Title: Perfect Security
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice has a very important message *M* consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random ke... | ```python
__author__ = 'RaldenProg'
n = int(input())
list_a = [_ for _ in map(int, input().split())]
list_p = [_ for _ in map(int, input().split())]
list_x = [0] * n
list_r = []
import itertools
A = itertools.permutations(range(1, n+1))
for x in A:
list_x = []
for i in range(n):
xor = list_... | 0 | |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,583,918,157 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 202 | 10,854,400 | import collections
def findsubsegment(l, nums):
freq_map = collections.Counter(nums)
beauty = max(freq_map.items(), key = lambda x: x[1])[1]
keys = {}
if beauty == 1:
print("1 1")
return
for key, val in freq_map.items():
if val == beauty:
keys[key] = [l, -1]
... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
import collections
def findsubsegment(l, nums):
freq_map = collections.Counter(nums)
beauty = max(freq_map.items(), key = lambda x: x[1])[1]
keys = {}
if beauty == 1:
print("1 1")
return
for key, val in freq_map.items():
if val == beauty:
keys[key] = [l... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,657,595,220 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
m = int(input())
a = int(input())
print((2*n*m)//(a*a)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n = int(input())
m = int(input())
a = int(input())
print((2*n*m)//(a*a))
``` | -1 |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,648,335,513 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 0 | a, b = input().split()
a = int(a)
b = int(b)
s = 0
while a != b:
s += 1
if a > b:
a -= b
else:
b -= a
print(str(s+1)) | Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
a, b = input().split()
a = int(a)
b = int(b)
s = 0
while a != b:
s += 1
if a > b:
a -= b
else:
b -= a
print(str(s+1))
``` | 0 | |
990 | E | Post Lamps | PROGRAMMING | 2,100 | [
"brute force",
"greedy"
] | null | null | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are bloc... | The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2,... | Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1. | [
"6 2 3\n1 3\n1 2 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"5 1 5\n0\n3 3 3 3 3\n",
"7 4 3\n2 4 5 6\n3 14 15\n"
] | [
"6\n",
"1000\n",
"-1\n",
"-1\n"
] | none | 0 | [
{
"input": "6 2 3\n1 3\n1 2 3",
"output": "6"
},
{
"input": "4 3 4\n1 2 3\n1 10 100 1000",
"output": "1000"
},
{
"input": "5 1 5\n0\n3 3 3 3 3",
"output": "-1"
},
{
"input": "7 4 3\n2 4 5 6\n3 14 15",
"output": "-1"
},
{
"input": "1 0 1\n\n1000000",
"output": ... | 1,676,468,728 | 5,428 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 15 | 748 | 122,675,200 | import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#################################... | Title: Post Lamps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they corres... | ```python
import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################... | -1 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,676,391,502 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | x, n = map(int,input().split())
i = 1
j = 1
if x * x % n == 0:
while i * i <= n:
if n % i == 0:
j += 1
i += 1
print(j)
else:
print(0) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
x, n = map(int,input().split())
i = 1
j = 1
if x * x % n == 0:
while i * i <= n:
if n % i == 0:
j += 1
i += 1
print(j)
else:
print(0)
``` | 0 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,598,026,462 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,963,200 | s=list(input())
full={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
avi=set(s)
flag=0
if '?' not in s and len(avi)==26:
print(s)
elif '?' not in s and len(avi)<26:
print(-1)
else:
avi.remove('?')
c=full-avi
count=0
D=set()
ind=0
di... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
s=list(input())
full={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
avi=set(s)
flag=0
if '?' not in s and len(avi)==26:
print(s)
elif '?' not in s and len(avi)<26:
print(-1)
else:
avi.remove('?')
c=full-avi
count=0
D=set()
i... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,695,083,246 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 93 | 13,619,200 | n = int(input())
a = list(map(int, input().split()))
count = [0] * 100001
for num in a:
count[num] += 1
dp = [0] * 100001
dp[0] = 0
dp[1] = count[1]
for i in range(2, 100001):
dp[i] = max(dp[i - 1], dp[i - 2] + i * count[i])
print(dp[100000])
| Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
a = list(map(int, input().split()))
count = [0] * 100001
for num in a:
count[num] += 1
dp = [0] * 100001
dp[0] = 0
dp[1] = count[1]
for i in range(2, 100001):
dp[i] = max(dp[i - 1], dp[i - 2] + i * count[i])
print(dp[100000])
``` | 3 | |
415 | B | Mashmokh and Tokens | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation",
"math"
] | null | null | Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest o... | The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). | Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. | [
"5 1 4\n12 6 11 9 1\n",
"3 1 2\n1 2 3\n",
"1 1 1\n1\n"
] | [
"0 2 3 1 1 ",
"1 0 1 ",
"0 "
] | none | 1,000 | [
{
"input": "5 1 4\n12 6 11 9 1",
"output": "0 2 3 1 1 "
},
{
"input": "3 1 2\n1 2 3",
"output": "1 0 1 "
},
{
"input": "1 1 1\n1",
"output": "0 "
},
{
"input": "1 1 1000000000\n1000000000",
"output": "0 "
},
{
"input": "1 1 1000000000\n999999999",
"output": "9... | 1,665,258,313 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 156 | 15,052,800 | n,a,b = map(int,input().split())
arr = list(map(int,input().split()))
if a>b : print(*([0]*n))
else :
for x in arr :print(((x*a)%b)//a,end = ' ')
| Title: Mashmokh and Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each... | ```python
n,a,b = map(int,input().split())
arr = list(map(int,input().split()))
if a>b : print(*([0]*n))
else :
for x in arr :print(((x*a)%b)//a,end = ' ')
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,656,256,667 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 92 | 17,715,200 | import math
def soluton(n,m,p):
print(math.ceil(n/p)*math.ceil(m/p))
n,m,p=map(int,input().split())
soluton(n,m,p) | 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
def soluton(n,m,p):
print(math.ceil(n/p)*math.ceil(m/p))
n,m,p=map(int,input().split())
soluton(n,m,p)
``` | 3.921003 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,663,808,514 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n=int(input())
f=list(map(int,input().split()))
c=0
s=sum(f)
for i in range(1,6):
if s%(n+1)!=0:
s+=1
c+=1
else:
s+=1
print(c) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
f=list(map(int,input().split()))
c=0
s=sum(f)
for i in range(1,6):
if s%(n+1)!=0:
s+=1
c+=1
else:
s+=1
print(c)
``` | 3 | |
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,689,002,105 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
for i in range(n):
print ('I hate that', end=' ') if (i % 2) == 0 else print ('I love it', end=' ')
print()
| 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
n = int(input())
for i in range(n):
print ('I hate that', end=' ') if (i % 2) == 0 else print ('I love it', end=' ')
print()
``` | 0 | |
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test,... | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12... | 1,606,932,397 | 5,797 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 0 | import math
t,q,s=map(int,input().split())
count=1
while(pow(q,count)<t/s):
count=count+1
print(count)
| Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the... | ```python
import math
t,q,s=map(int,input().split())
count=1
while(pow(q,count)<t/s):
count=count+1
print(count)
``` | 0 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,600,263,941 | 941 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 124 | 3,072,000 | import sys
n, k = map(int, input().split())
matrix = [[0]*n for _ in range(n)]
i1, j1, i2, j2 = 0, 0, 0, 0
for _ in range(n*2-1):
if k < i2-i1+1:
break
for d in range(i2-i1+1):
matrix[i2-d][j2+d] = 1
k -= 1
if j1 == n-1:
i1 += 1
else:
j1 += 1
... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
import sys
n, k = map(int, input().split())
matrix = [[0]*n for _ in range(n)]
i1, j1, i2, j2 = 0, 0, 0, 0
for _ in range(n*2-1):
if k < i2-i1+1:
break
for d in range(i2-i1+1):
matrix[i2-d][j2+d] = 1
k -= 1
if j1 == n-1:
i1 += 1
else:
... | 0 | |
922 | C | Cave Painting | PROGRAMMING | 1,600 | [
"brute force",
"number theory"
] | null | null | Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wan... | The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). | Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper). | [
"4 4\n",
"5 3\n"
] | [
"No\n",
"Yes\n"
] | In the first sample remainders modulo 1 and 4 coincide. | 1,250 | [
{
"input": "4 4",
"output": "No"
},
{
"input": "5 3",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "744 18",
"output": "No"
},
{
"input": "47879 10",
"output": "Yes"
},
{
"input": "1000000000000000000 1000000000000000000",
"ou... | 1,687,980,095 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 70 | 77 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N,M = map(int,input().split())
if M==1 :exit(print("Yes"))
if N==1:
if M<=2:
... | Title: Cave Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N,M = map(int,input().split())
if M==1 :exit(print("Yes"))
if N==1:
... | 0 | |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,669,183,152 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 122 | 0 | n,a,b = list(map(int, input ().split()))
s = set(range(1,n+1))
sa = set(range(a+1,n+1))
sb = set(range(n-b,n+1))
print(len(sa.intersection(sb))) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
n,a,b = list(map(int, input ().split()))
s = set(range(1,n+1))
sa = set(range(a+1,n+1))
sb = set(range(n-b,n+1))
print(len(sa.intersection(sb)))
``` | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,689,057,134 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s = input()
alphabets = [0]*26
for i in range(1, len(s) - 1):
ind = 97 - ord(s[i])
alphabets[ind] = 1
return sum(alphabets)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
alphabets = [0]*26
for i in range(1, len(s) - 1):
ind = 97 - ord(s[i])
alphabets[ind] = 1
return sum(alphabets)
``` | -1 | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,683,219,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 61 | 109 | 13,721,600 | n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
b=[a[0]]
for i in range(1,n):
if a[i]>=sum(b):
ans+=1
b.append(a[i])
print(ans) | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
b=[a[0]]
for i in range(1,n):
if a[i]>=sum(b):
ans+=1
b.append(a[i])
print(ans)
``` | 3 | |
900 | C | Remove Extra One | PROGRAMMING | 1,700 | [
"brute force",
"data structures",
"math"
] | null | null | You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible.
We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a**i* is a record if for every integer *j* (1<=≤<=*j*<=<<=*i*) the following holds: *a**j*<=<<=*a*... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=105) — the length of the permutation.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation. All the integers are distinct. | Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one. | [
"1\n1\n",
"5\n5 1 2 3 4\n"
] | [
"1\n",
"5\n"
] | In the first example the only element can be removed. | 1,500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n5 1 2 3 4",
"output": "5"
},
{
"input": "5\n4 3 5 1 2",
"output": "1"
},
{
"input": "9\n9 5 8 6 3 2 4 1 7",
"output": "9"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 6 7 4 2 5 3",
"... | 1,513,104,708 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 5,529,600 | cases = sys.stdin.readline()
my_list = [int(a) for a in sys.stdin.readline().split(" ")]
#my_list = [4, 5, 3, 2, 1]
max_val_a = my_list[0]
max_val_b = 0
my_counts = dict()
for x in my_list:
my_counts[x] = 0
my_counts[max_val_a] = -1
for x in my_list:
#print(my_counts)
if(x > max_val_a):
my_counts[x] = my_... | Title: Remove Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible.
We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a*... | ```python
cases = sys.stdin.readline()
my_list = [int(a) for a in sys.stdin.readline().split(" ")]
#my_list = [4, 5, 3, 2, 1]
max_val_a = my_list[0]
max_val_b = 0
my_counts = dict()
for x in my_list:
my_counts[x] = 0
my_counts[max_val_a] = -1
for x in my_list:
#print(my_counts)
if(x > max_val_a):
my_count... | -1 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,642,045,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | values = [int(val) for val in input().split()]
a = values[0]
b = values[1]
n = values[2]
def gcd(x, y):
i = 0
z = 0
if x == 0:
return y
else:
while y > 0:
z = max(x, y) - min(x, y)
x = min(x, y)
y = z
i += 1
return x
i = 0
while n... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
values = [int(val) for val in input().split()]
a = values[0]
b = values[1]
n = values[2]
def gcd(x, y):
i = 0
z = 0
if x == 0:
return y
else:
while y > 0:
z = max(x, y) - min(x, y)
x = min(x, y)
y = z
i += 1
return x
i =... | 0 | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,651,965,400 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 512,000 | n=int(input())
r=list(input())
C=0
R=0
h=0
l=[]
for i in range(len(r)):
if r[i]=="R" and h<1:
R+=i
R+=1
h+=1
for i in range(len(r)):
if r[i]=="R":
R+=1
C+=1
K=R-C
L=R+1
for j in r:
if j=="L":
L-=1
while L<=0:
... | Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n=int(input())
r=list(input())
C=0
R=0
h=0
l=[]
for i in range(len(r)):
if r[i]=="R" and h<1:
R+=i
R+=1
h+=1
for i in range(len(r)):
if r[i]=="R":
R+=1
C+=1
K=R-C
L=R+1
for j in r:
if j=="L":
L-=1
while L<=0... | 0 | |
771 | A | Bear and Friendship Condition | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that... | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ... | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 250 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
... | 1,654,957,921 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 20,684,800 |
n, m = input().split(' ')
n, m = int(n), int(m)
pairs = []
friends = {}
for i in range(m):
pair = input().split()
pair_f = max(pair[0], pair[1])
pair_s = min(pair[0], pair[1])
if pair_f in friends.keys():
friends[pair_f].append(pair_s)
else:
friends[pair_f] = [pair_s]
... | Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through... | ```python
n, m = input().split(' ')
n, m = int(n), int(m)
pairs = []
friends = {}
for i in range(m):
pair = input().split()
pair_f = max(pair[0], pair[1])
pair_s = min(pair[0], pair[1])
if pair_f in friends.keys():
friends[pair_f].append(pair_s)
else:
friends[pair_f] =... | 0 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,663,556,668 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 234 | 38,195,200 | from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
f,f1,f2=Counter(arr),Counter(arr1),Counter(arr2)
for k in f.keys():
if f[k]!=f1[k]:
print(k)
break
for k in f1.keys():
if f1[k]!=f2... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
f,f1,f2=Counter(arr),Counter(arr1),Counter(arr2)
for k in f.keys():
if f[k]!=f1[k]:
print(k)
break
for k in f1.keys():
if... | 3 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,609,580,681 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 307,200 | def Diff(li1, li2,x):
li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
if len(li_dif)==n*n:
return x
else:
return 0
n=int(input())
for x in range(n*n):
if x==0:
a=list(map(int,input().split()))
print(1,end=' ')
b=a
else:
a =... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
def Diff(li1, li2,x):
li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
if len(li_dif)==n*n:
return x
else:
return 0
n=int(input())
for x in range(n*n):
if x==0:
a=list(map(int,input().split()))
print(1,end=' ')
b=a
else:
... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,482,958,359 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 4,608,000 | s=input()
b=True
a=s.find('h')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('e')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('l')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('l')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('o')
if a==-1:
b=False
else:
s=s[a+1... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
b=True
a=s.find('h')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('e')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('l')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('l')
if a==-1:
b=False
else:
s=s[a+1:]
a=s.find('o')
if a==-1:
b=False
else:
... | 3.960417 |
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we ... | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000... | 1,468,129,071 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 156 | 7,987,200 | # your code goes here
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
diff = 0
for i in range(n):
if a[i] != b[i]: diff += 1
if diff <= 2:
print("YES")
else:
print("NO")
| Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to c... | ```python
# your code goes here
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
diff = 0
for i in range(n):
if a[i] != b[i]: diff += 1
if diff <= 2:
print("YES")
else:
print("NO")
``` | 3 | |
394 | A | Counting Sticks | PROGRAMMING | 0 | [
"brute force",
"implementation"
] | null | null | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add... | The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. | If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print... | [
"||+|=|||||\n",
"|||||+||=||\n",
"|+|=||||||\n",
"||||+||=||||||\n"
] | [
"|||+|=||||\n",
"Impossible\n",
"Impossible\n",
"||||+||=||||||\n"
] | In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth s... | 500 | [
{
"input": "||+|=|||||",
"output": "|||+|=||||"
},
{
"input": "|||||+||=||",
"output": "Impossible"
},
{
"input": "|+|=||||||",
"output": "Impossible"
},
{
"input": "||||+||=||||||",
"output": "||||+||=||||||"
},
{
"input": "||||||||||||+|||||||||||=||||||||||||||... | 1,567,754,218 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | a, b =input().split('+')
c,d = b.split('=')
if (len(a)+len(c))==len(d):
print(a+"+"+c+"="+d)
elif len(d)!=1 and (len(a)+len(c)+1)==len(d)-1:
print(a+"+"+c+"|"+"="+d[:-1])
elif len(c)!=1 and (len(a)+len(c)-1)==len(d)+1:
print(a+"+"+c[:-1]+"="+d)
elif len(a)!=1 and (len(a)-1+len(c))==len(d)+1:
... | Title: Counting Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our te... | ```python
a, b =input().split('+')
c,d = b.split('=')
if (len(a)+len(c))==len(d):
print(a+"+"+c+"="+d)
elif len(d)!=1 and (len(a)+len(c)+1)==len(d)-1:
print(a+"+"+c+"|"+"="+d[:-1])
elif len(c)!=1 and (len(a)+len(c)-1)==len(d)+1:
print(a+"+"+c[:-1]+"="+d)
elif len(a)!=1 and (len(a)-1+len(c))==len(d... | 0 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,518,701,698 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 37 | 62 | 5,632,000 | def generate_num(loops):
if loops not in range(1,1000000) : return -1
num = ""
while loops != 0:
if loops >= 2:
num += str(8)
loops -= 2
elif loops >= 1:
num += str(9)
loops -= 1
return num
loops = generate_num(int(input())... | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
def generate_num(loops):
if loops not in range(1,1000000) : return -1
num = ""
while loops != 0:
if loops >= 2:
num += str(8)
loops -= 2
elif loops >= 1:
num += str(9)
loops -= 1
return num
loops = generate_num(in... | 0 | |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,485,874,065 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 4,608,000 | n=int(input())
t=1
a=[]
while n>=t:
a.append(t)
n-=t
t=t+1
a[-1]+=n
print(len(a))
for i in range(len(a)):
print(a[i],end=' ')
| Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n=int(input())
t=1
a=[]
while n>=t:
a.append(t)
n-=t
t=t+1
a[-1]+=n
print(len(a))
for i in range(len(a)):
print(a[i],end=' ')
``` | 3 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,444,381,701 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | def p(x):
if '8' in x:
return True
n=str(input())
for i in range(1,17):
if(p(str(int(n)+i))==True):
print(i)
break
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
def p(x):
if '8' in x:
return True
n=str(input())
for i in range(1,17):
if(p(str(int(n)+i))==True):
print(i)
break
``` | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,603,116,027 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 372 | 0 | n = int(input())
lst = list(map(int, input().split()))
summ = sum(lst)
res = 0
if summ % 2 == 0:
for i in lst:
if i % 2 == 0:
res += 1
else:
for i in lst:
if i % 2 != 0:
res += 1
print(res) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
lst = list(map(int, input().split()))
summ = sum(lst)
res = 0
if summ % 2 == 0:
for i in lst:
if i % 2 == 0:
res += 1
else:
for i in lst:
if i % 2 != 0:
res += 1
print(res)
``` | 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,592,216,176 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 248 | 0 | st = input()
a=[]
b=[]
count=0
c=[]
for i in range(len(st)):
c.append(st[i])
for i in range(len(st)-1):
if c[i] == '-' and c[i+1] == '.':
b.append(1)
c[i] = 0
c[i+1] = 0
i=i+1
elif c[i] =='-' and c[i+1] =='-':
b.append(2)
c[i] = 0
c... | 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
st = input()
a=[]
b=[]
count=0
c=[]
for i in range(len(st)):
c.append(st[i])
for i in range(len(st)-1):
if c[i] == '-' and c[i+1] == '.':
b.append(1)
c[i] = 0
c[i+1] = 0
i=i+1
elif c[i] =='-' and c[i+1] =='-':
b.append(2)
c[i] = 0
... | 0 |
181 | B | Number of Triplets | PROGRAMMING | 1,300 | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are diff... | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 ... | 1,672,177,128 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,318,400 | n = int(input())
points = []
for i in range(n):#data input
xy = list(map(int, input().split()))
couple = (xy[0],xy[1])
points.append(couple)
class TrieNode:
def __init__(self):
self.children = {}
self.count = 0
def insert(root, point):
node = root
for coord in po... | Title: Number of Triplets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points ar... | ```python
n = int(input())
points = []
for i in range(n):#data input
xy = list(map(int, input().split()))
couple = (xy[0],xy[1])
points.append(couple)
class TrieNode:
def __init__(self):
self.children = {}
self.count = 0
def insert(root, point):
node = root
for c... | 0 | |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,666,370,305 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 499 | 11,468,800 | first_string = input()
second_string = input()
info ={
"F_S_L" : len(first_string) ,
"S_S_L" : len(second_string)
}
arr = []
counter = 0
if info["F_S_L"] == info["S_S_L"] :
for i in range(0 , info["S_S_L"]) :
counter += abs(int(second_string[i]) - int(first_string[i]) )
else :
for i ... | Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
first_string = input()
second_string = input()
info ={
"F_S_L" : len(first_string) ,
"S_S_L" : len(second_string)
}
arr = []
counter = 0
if info["F_S_L"] == info["S_S_L"] :
for i in range(0 , info["S_S_L"]) :
counter += abs(int(second_string[i]) - int(first_string[i]) )
else :
... | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,596,820,228 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 156 | 20,172,800 |
def f(n):
if n%2>0:
return 0
n = n//2
return (n-1)//2
n = int(input())
print(f(n))
| Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
def f(n):
if n%2>0:
return 0
n = n//2
return (n-1)//2
n = int(input())
print(f(n))
``` | 3 | |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,694,904,302 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 77 | 7,372,800 | n, alvo = map(int,input().split())
lista = []
def func(val):
if val > alvo:
return False
if val == alvo:
lista.append(val)
return True
if func(10*val + 1) or func(2*val):
lista.append(val)
return True
return False
if func(n):
print(f'YES\n{len(lista)... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
n, alvo = map(int,input().split())
lista = []
def func(val):
if val > alvo:
return False
if val == alvo:
lista.append(val)
return True
if func(10*val + 1) or func(2*val):
lista.append(val)
return True
return False
if func(n):
print(f'YES\n{... | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,524,890,934 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 218 | 20,582,400 | n = int(input())
a = list(map(int, input().split()))
s = []
tmp = 0
for i in range(n):
tmp += a[i]
s.append(tmp)
half = s[n - 1] / 2
for i in range(n):
if s[i] >= half:
print(i + 1)
exit()
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
n = int(input())
a = list(map(int, input().split()))
s = []
tmp = 0
for i in range(n):
tmp += a[i]
s.append(tmp)
half = s[n - 1] / 2
for i in range(n):
if s[i] >= half:
print(i + 1)
exit()
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,593,593,168 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | n = int(input())
d = []
def base(num,base):
s = []
while num>0:
s.append(str(num%base))
num//=base
return sum(int(i) for i in "".join(s)[::-1])
for i in range(2,n):
d.append(base(n,i))
print("{}/{}".format(sum(d),len(d)))
| Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
n = int(input())
d = []
def base(num,base):
s = []
while num>0:
s.append(str(num%base))
num//=base
return sum(int(i) for i in "".join(s)[::-1])
for i in range(2,n):
d.append(base(n,i))
print("{}/{}".format(sum(d),len(d)))
``` | 0 |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,641,921,700 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 716,800 | n1 = input().split()
list1 = []
for i in n1:
list1.append(int(i))
n = list1[0]
k = list1[1]
sasha_count = 0
other_count = 0
b1 = False
while b1==False:
if n < k:
break
n -= k
sasha_count+=1
if n < k:
break
n -= k
other_count+=1
if sasha_count>other_coun... | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n1 = input().split()
list1 = []
for i in n1:
list1.append(int(i))
n = list1[0]
k = list1[1]
sasha_count = 0
other_count = 0
b1 = False
while b1==False:
if n < k:
break
n -= k
sasha_count+=1
if n < k:
break
n -= k
other_count+=1
if sasha_count>... | 0 | |
382 | C | Arithmetic Progression | PROGRAMMING | 1,700 | [
"implementation",
"sortings"
] | null | null | Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills:
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108. | If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)... | [
"3\n4 1 7\n",
"1\n10\n",
"4\n1 3 5 9\n",
"4\n4 3 4 5\n",
"2\n2 4\n"
] | [
"2\n-2 10\n",
"-1\n",
"1\n7\n",
"0\n",
"3\n0 3 6\n"
] | none | 1,500 | [
{
"input": "3\n4 1 7",
"output": "2\n-2 10"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "4\n1 3 5 9",
"output": "1\n7"
},
{
"input": "4\n4 3 4 5",
"output": "0"
},
{
"input": "2\n2 4",
"output": "3\n0 3 6"
},
{
"input": "4\n1 3 4 5",
"outpu... | 1,529,750,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt=0
if n==1:
print(-1)
exit()
if n==2:
if(a[1]==a[0]):
print(1)
print(a[0])
exit()
if((a[1]+a[0])/2==(a[1]+a[0])//2):
print(3)
print(2*a[1]-a[0],2*a[0]-a[1],(a[0]+a[1])//2)
exit()
print(2)
print(2*a[1]-a[0],2*a[0]-a[1])
d=min(a[1]-a[0],a[2]-a[... | Title: Arithmetic Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition ... | ```python
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt=0
if n==1:
print(-1)
exit()
if n==2:
if(a[1]==a[0]):
print(1)
print(a[0])
exit()
if((a[1]+a[0])/2==(a[1]+a[0])//2):
print(3)
print(2*a[1]-a[0],2*a[0]-a[1],(a[0]+a[1])//2)
exit()
print(2)
print(2*a[1]-a[0],2*a[0]-a[1])
d=min(a[1]-a[... | 0 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,603,418,617 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 26 | 218 | 307,200 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(m):
x,y=map(int,input().split())
if (x-1)==0:
right_birds=a[x-1]-y
a[x-1]=0
a[x]=a[x]+right_birds
elif x==n:
left_birds=y-1
a[x-1]=0
a[x-2]=a[x-2]+left_birds
el... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(m):
x,y=map(int,input().split())
if (x-1)==0:
right_birds=a[x-1]-y
a[x-1]=0
a[x]=a[x]+right_birds
elif x==n:
left_birds=y-1
a[x-1]=0
a[x-2]=a[x-2]+left_birds
... | -1 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,684,750,519 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 1,762 | 20,787,200 | n=int(input())
cost=list(map(int,input().split()))
inc_cost=list(cost)
inc_cost.sort()
costps=[0]*len(cost)
inc_costps=[0]*len(cost)
for i in range(len(cost)):
if i==0:
costps[i]+=cost[i]
else:
costps[i]+=costps[i-1]+cost[i]
for i in range(len(cost)):
if i==0:
inc_c... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n=int(input())
cost=list(map(int,input().split()))
inc_cost=list(cost)
inc_cost.sort()
costps=[0]*len(cost)
inc_costps=[0]*len(cost)
for i in range(len(cost)):
if i==0:
costps[i]+=cost[i]
else:
costps[i]+=costps[i-1]+cost[i]
for i in range(len(cost)):
if i==0:
... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.