contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 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
sequencelengths 0
7
| demo-output
sequencelengths 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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,682,620,865 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
if(n%2!=0):
print(n-((n+1)//2),(n+1)//2)
else:
print(((n//2)-1),n-((n//2)-1))
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
n = int(input())
if(n%2!=0):
print(n-((n+1)//2),(n+1)//2)
else:
print(((n//2)-1),n-((n//2)-1))
``` | 0 |
|
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874",
"output": "11 9 8 2 2 1 5 5 0 0 1"
},
{
"input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897",
"output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11"
},
{
"input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9",
"output": "1 1 2 2 3 3 4 4 5"
},
{
"input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1",
"output": "1"
},
{
"input": "5 1\n1 3 3 3 5\n3",
"output": "4"
},
{
"input": "4 5\n1 1 1 4\n1 5 5 4 3",
"output": "3 4 4 4 3"
},
{
"input": "5 4\n0 5 5 5 6\n5 1 6 3",
"output": "4 1 5 1"
},
{
"input": "1 3\n0\n-1 0 1",
"output": "0 1 1"
},
{
"input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1",
"output": "96"
},
{
"input": "7 1\n1 2 3 4 5 6 7\n1",
"output": "1"
},
{
"input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "7 13 7 13 7 13 7 13 7 13 7 13 7"
},
{
"input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1",
"output": "3 3 3 3 3 3 3 3"
},
{
"input": "1 1\n-11111\n-5938",
"output": "1"
},
{
"input": "1 1\n1\n400000009",
"output": "1"
},
{
"input": "1 1\n1\n300000009",
"output": "1"
},
{
"input": "1 1\n1\n200000009",
"output": "1"
},
{
"input": "1 1\n1\n200000003",
"output": "1"
}
] | 1,680,121,995 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | size = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
# arr1.sort()
# result = ""
# for i in range(size[1]):
# quantity = 0
# start = 0
# end = size[0]
# mid = (start + end) // 2
# if (start + end) / 2 > mid // 2: mid = mid + 1
# while start < end:
# # If arr2[i] is greater, ignore left half
# if arr1[mid] <= arr2[i]:
# print(mid, start, end)
# quantity += 1
# mid -= 1
# start += 1
# # If arr2[i] is smaller, ignore right half
# elif arr1[mid] > arr2[i]:
# mid -= 1
# end -= 1
# # means arr2[i] is present at mid
# else:
# quantity += 1
# if i != size[1]-1: result += str(quantity) + " "
# else: result += str(quantity)
# print("\n")
# print(result)
arr1.sort(reverse=True)
i = 0
j = 0
count = 0
result = ""
while i != len(arr2) and arr2[i] <= arr1[j]:
if j == len(arr1)-1: break
if arr2[i] < arr1[j]:
count += 1
j += 1
if arr2[i] >= arr1[j]:
i += 1
j = 0
result += str(len(arr1) - count) + " "
count = 0
if result == "": result = 0
print(result)
# 5 2 2 1 1
# 1 1 3 4 5
| Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Output Specification:
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
Demo Input:
['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n']
Demo Output:
['3 2 1 4\n', '4 2 4 2 5\n']
Note:
none | ```python
size = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
# arr1.sort()
# result = ""
# for i in range(size[1]):
# quantity = 0
# start = 0
# end = size[0]
# mid = (start + end) // 2
# if (start + end) / 2 > mid // 2: mid = mid + 1
# while start < end:
# # If arr2[i] is greater, ignore left half
# if arr1[mid] <= arr2[i]:
# print(mid, start, end)
# quantity += 1
# mid -= 1
# start += 1
# # If arr2[i] is smaller, ignore right half
# elif arr1[mid] > arr2[i]:
# mid -= 1
# end -= 1
# # means arr2[i] is present at mid
# else:
# quantity += 1
# if i != size[1]-1: result += str(quantity) + " "
# else: result += str(quantity)
# print("\n")
# print(result)
arr1.sort(reverse=True)
i = 0
j = 0
count = 0
result = ""
while i != len(arr2) and arr2[i] <= arr1[j]:
if j == len(arr1)-1: break
if arr2[i] < arr1[j]:
count += 1
j += 1
if arr2[i] >= arr1[j]:
i += 1
j = 0
result += str(len(arr1) - count) + " "
count = 0
if result == "": result = 0
print(result)
# 5 2 2 1 1
# 1 1 3 4 5
``` | 0 |
|
117 | C | Cycle | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs"
] | null | null | A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes *u* and *v* (*u*<=≠<=*v*) exists either an edge going from *u* to *v*, or an edge from *v* to *u*.
You are given a tournament consisting of *n* vertexes. Your task is to find there a cycle of length three. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5000). Next *n* lines contain the adjacency matrix *A* of the graph (without spaces). *A**i*,<=*j*<==<=1 if the graph has an edge going from vertex *i* to vertex *j*, otherwise *A**i*,<=*j*<==<=0. *A**i*,<=*j* stands for the *j*-th character in the *i*-th line.
It is guaranteed that the given graph is a tournament, that is, *A**i*,<=*i*<==<=0,<=*A**i*,<=*j*<=≠<=*A**j*,<=*i* (1<=≤<=*i*,<=*j*<=≤<=*n*,<=*i*<=≠<=*j*). | Print three distinct vertexes of the graph *a*1, *a*2, *a*3 (1<=≤<=*a**i*<=≤<=*n*), such that *A**a*1,<=*a*2<==<=*A**a*2,<=*a*3<==<=*A**a*3,<=*a*1<==<=1, or "-1", if a cycle whose length equals three does not exist.
If there are several solutions, print any of them. | [
"5\n00100\n10000\n01001\n11101\n11000\n",
"5\n01111\n00000\n01000\n01100\n01110\n"
] | [
"1 3 2 ",
"-1\n"
] | none | 1,500 | [
{
"input": "5\n00100\n10000\n01001\n11101\n11000",
"output": "1 3 2 "
},
{
"input": "5\n01111\n00000\n01000\n01100\n01110",
"output": "-1"
},
{
"input": "5\n01000\n00101\n10010\n11001\n10100",
"output": "1 2 3 "
},
{
"input": "5\n00110\n10110\n00011\n00000\n11010",
"output": "1 3 5 "
},
{
"input": "10\n0011000010\n1011001101\n0000101100\n0010101010\n1100000100\n1111101100\n1000100000\n1001001011\n0110111001\n1011111000",
"output": "1 3 5 "
},
{
"input": "10\n0111001000\n0011111000\n0000110110\n0010101110\n1000011001\n1001000010\n0010010101\n1100110000\n1100101100\n1111010110",
"output": "1 3 5 "
},
{
"input": "10\n0101111011\n0001111111\n1100011110\n0010011000\n0011000110\n0000101011\n0000100000\n1001011011\n0001001000\n0011101010",
"output": "1 4 3 "
},
{
"input": "10\n0000010011\n1001001111\n1100001110\n1010010011\n1111011000\n0110000001\n1001010100\n1001110000\n0000111101\n0010101100",
"output": "1 6 2 "
},
{
"input": "10\n0000000000\n1001100111\n1101101111\n1000000011\n1001000111\n1111101111\n1101100111\n1001000011\n1000000001\n1000000000",
"output": "-1"
},
{
"input": "1\n0",
"output": "-1"
},
{
"input": "2\n00\n10",
"output": "-1"
},
{
"input": "3\n001\n100\n010",
"output": "1 3 2 "
},
{
"input": "3\n010\n001\n100",
"output": "1 2 3 "
},
{
"input": "2\n01\n00",
"output": "-1"
},
{
"input": "3\n011\n000\n010",
"output": "-1"
},
{
"input": "4\n0000\n1010\n1001\n1100",
"output": "2 3 4 "
},
{
"input": "5\n01111\n00111\n00010\n00001\n00100",
"output": "3 4 5 "
}
] | 1,686,498,624 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 2,182 | 239,206,400 | n = int(input())
g = []
for i in range(n):
g += [list(map(int, input()))]
vis = [0]*n
dis = [0]*n
par = [-1]*n
def dfs(u, x, d=0):
st = [(u, x, d)]
while st:
u, x, d = st.pop()
vis[u] = x
dis[u] = d
for v in range(n):
if g[u][v]:
if vis[v] == x:
if dis[u] - dis[v] == 2:
return [v+1, par[u]+1, u+1]
elif vis[v] == 0:
par[v] = u
st += [(v, x, d+1)]
return []
x = 1
for u in range(n):
if not vis[u]:
ans = dfs(u, x)
if ans:
print(*ans)
break
x += 1
else:
print(-1) | Title: Cycle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes *u* and *v* (*u*<=≠<=*v*) exists either an edge going from *u* to *v*, or an edge from *v* to *u*.
You are given a tournament consisting of *n* vertexes. Your task is to find there a cycle of length three.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=5000). Next *n* lines contain the adjacency matrix *A* of the graph (without spaces). *A**i*,<=*j*<==<=1 if the graph has an edge going from vertex *i* to vertex *j*, otherwise *A**i*,<=*j*<==<=0. *A**i*,<=*j* stands for the *j*-th character in the *i*-th line.
It is guaranteed that the given graph is a tournament, that is, *A**i*,<=*i*<==<=0,<=*A**i*,<=*j*<=≠<=*A**j*,<=*i* (1<=≤<=*i*,<=*j*<=≤<=*n*,<=*i*<=≠<=*j*).
Output Specification:
Print three distinct vertexes of the graph *a*1, *a*2, *a*3 (1<=≤<=*a**i*<=≤<=*n*), such that *A**a*1,<=*a*2<==<=*A**a*2,<=*a*3<==<=*A**a*3,<=*a*1<==<=1, or "-1", if a cycle whose length equals three does not exist.
If there are several solutions, print any of them.
Demo Input:
['5\n00100\n10000\n01001\n11101\n11000\n', '5\n01111\n00000\n01000\n01100\n01110\n']
Demo Output:
['1 3 2 ', '-1\n']
Note:
none | ```python
n = int(input())
g = []
for i in range(n):
g += [list(map(int, input()))]
vis = [0]*n
dis = [0]*n
par = [-1]*n
def dfs(u, x, d=0):
st = [(u, x, d)]
while st:
u, x, d = st.pop()
vis[u] = x
dis[u] = d
for v in range(n):
if g[u][v]:
if vis[v] == x:
if dis[u] - dis[v] == 2:
return [v+1, par[u]+1, u+1]
elif vis[v] == 0:
par[v] = u
st += [(v, x, d+1)]
return []
x = 1
for u in range(n):
if not vis[u]:
ans = dfs(u, x)
if ans:
print(*ans)
break
x += 1
else:
print(-1)
``` | 0 |
|
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output": "12"
},
{
"input": "4 5\n5 2 6 4\n8 9 1 3 7",
"output": "12"
},
{
"input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1",
"output": "1"
},
{
"input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6",
"output": "1"
},
{
"input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n8\n9",
"output": "89"
},
{
"input": "1 1\n9\n8",
"output": "89"
},
{
"input": "1 1\n1\n2",
"output": "12"
},
{
"input": "1 1\n2\n1",
"output": "12"
},
{
"input": "1 1\n9\n9",
"output": "9"
},
{
"input": "1 1\n1\n1",
"output": "1"
},
{
"input": "4 5\n3 2 4 5\n1 6 5 9 8",
"output": "5"
},
{
"input": "3 2\n4 5 6\n1 5",
"output": "5"
},
{
"input": "5 4\n1 3 5 6 7\n2 4 3 9",
"output": "3"
},
{
"input": "5 5\n1 3 5 7 9\n2 4 6 8 9",
"output": "9"
},
{
"input": "2 2\n1 8\n2 8",
"output": "8"
},
{
"input": "5 5\n5 6 7 8 9\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6",
"output": "2"
},
{
"input": "2 2\n1 5\n2 5",
"output": "5"
},
{
"input": "4 4\n1 3 5 8\n2 4 6 8",
"output": "8"
},
{
"input": "3 3\n1 5 3\n2 5 7",
"output": "5"
},
{
"input": "3 3\n3 6 8\n2 6 9",
"output": "6"
},
{
"input": "2 2\n1 4\n2 4",
"output": "4"
},
{
"input": "5 3\n3 4 5 6 7\n1 5 9",
"output": "5"
},
{
"input": "4 4\n1 2 3 4\n2 5 6 7",
"output": "2"
},
{
"input": "5 5\n1 2 3 4 5\n9 2 1 7 5",
"output": "1"
},
{
"input": "2 2\n1 3\n2 3",
"output": "3"
},
{
"input": "3 3\n3 2 1\n3 2 1",
"output": "1"
},
{
"input": "3 3\n1 3 5\n2 3 6",
"output": "3"
},
{
"input": "3 3\n5 6 7\n5 6 7",
"output": "5"
},
{
"input": "1 2\n5\n2 5",
"output": "5"
},
{
"input": "3 3\n2 4 9\n7 8 9",
"output": "9"
},
{
"input": "3 3\n1 2 4\n3 4 5",
"output": "4"
},
{
"input": "3 2\n1 4 9\n2 4",
"output": "4"
},
{
"input": "3 3\n3 5 6\n1 5 9",
"output": "5"
},
{
"input": "3 2\n1 2 4\n3 4",
"output": "4"
},
{
"input": "2 4\n8 9\n1 2 3 9",
"output": "9"
},
{
"input": "1 2\n9\n8 9",
"output": "9"
},
{
"input": "3 2\n1 2 4\n4 2",
"output": "2"
},
{
"input": "2 3\n4 5\n1 3 5",
"output": "5"
},
{
"input": "3 2\n1 2 3\n2 3",
"output": "2"
},
{
"input": "4 3\n1 3 5 9\n2 8 9",
"output": "9"
},
{
"input": "2 2\n1 9\n9 2",
"output": "9"
}
] | 1,653,703,690 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort()
c = [a[0],b[0]]
c.sort()
if a[0] == b[0]:
print(c[0])
else:
print(str(c[0])+str(c[1])) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Output Specification:
Print the smallest pretty integer.
Demo Input:
['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n']
Demo Output:
['25\n', '1\n']
Note:
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | ```python
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort()
c = [a[0],b[0]]
c.sort()
if a[0] == b[0]:
print(c[0])
else:
print(str(c[0])+str(c[1]))
``` | 0 |
|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,680,256,589 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 46 | 0 | n = int(input())
welfare = [int(x) for x in input().split()]
maxi = max(welfare)
total = 0
for item in welfare:
if item < maxi:
total += (maxi - item)
print(total)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | ```python
n = int(input())
welfare = [int(x) for x in input().split()]
maxi = max(welfare)
total = 0
for item in welfare:
if item < maxi:
total += (maxi - item)
print(total)
``` | 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 is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. | 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": "919067153",
"output": "5"
},
{
"input": "690422411",
"output": "7"
},
{
"input": "-408490162",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-6",
"output": "14"
},
{
"input": "-4",
"output": "12"
},
{
"input": "-2",
"output": "10"
},
{
"input": "0",
"output": "8"
},
{
"input": "2",
"output": "6"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "2"
},
{
"input": "8",
"output": "10"
},
{
"input": "1000000000",
"output": "8"
},
{
"input": "-1000000000",
"output": "2"
},
{
"input": "88888",
"output": "1"
},
{
"input": "89",
"output": "9"
},
{
"input": "-80000000",
"output": "2"
},
{
"input": "-8888",
"output": "1"
},
{
"input": "-17",
"output": "9"
},
{
"input": "78",
"output": "2"
},
{
"input": "-19",
"output": "1"
},
{
"input": "-999999998",
"output": "9"
},
{
"input": "-999999997",
"output": "8"
},
{
"input": "999999997",
"output": "1"
},
{
"input": "811111111",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-5",
"output": "13"
},
{
"input": "-7",
"output": "15"
},
{
"input": "1000000000",
"output": "8"
}
] | 1,586,091,172 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | a=int(input())
a=str(a)
if '8' in a and int(a)>=0:
b=int(a)-8
elif int(a[-1])>8:
b=int(a[-1])-8
else:
if '8' in a:
b=abs((int(a)%8))
if b==0:
b=1
else:
b-=8
else:
b=8-int(a)
print(b)
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
Input Specification:
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Output Specification:
Print the minimum *b* in a line.
Demo Input:
['179\n', '-1\n', '18\n']
Demo Output:
['1\n', '9\n', '10\n']
Note:
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. | ```python
a=int(input())
a=str(a)
if '8' in a and int(a)>=0:
b=int(a)-8
elif int(a[-1])>8:
b=int(a[-1])-8
else:
if '8' in a:
b=abs((int(a)%8))
if b==0:
b=1
else:
b-=8
else:
b=8-int(a)
print(b)
``` | 0 |
|
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 1,589,661,704 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 6,656,000 | ar=input()
br=input()
cr=input()
a = list(ar)
b = list(br)
c = list(cr)
def symmetry(a,b,c):
for i in range(3):
if(a[i]!=c[2-i] or b[i]!=b[2-i]):
return 'NO'
return 'YES'
print(symmetry(a,b,c)) | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input Specification:
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Output Specification:
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
Demo Input:
['XX.\n...\n.XX\n', 'X.X\nX..\n...\n']
Demo Output:
['YES\n', 'NO\n']
Note:
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | ```python
ar=input()
br=input()
cr=input()
a = list(ar)
b = list(br)
c = list(cr)
def symmetry(a,b,c):
for i in range(3):
if(a[i]!=c[2-i] or b[i]!=b[2-i]):
return 'NO'
return 'YES'
print(symmetry(a,b,c))
``` | 3.925602 |
216 | A | Tiling with Hexagons | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has *a*, *b*, *c*, *a*, *b* and *c* adjacent tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for *a*<==<=2, *b*<==<=3 and *c*<==<=4.
According to the legend, as the King of Berland obtained the values *a*, *b* and *c*, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same? | The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000). | Print a single number — the total number of tiles on the hall floor. | [
"2 3 4\n"
] | [
"18"
] | none | 500 | [
{
"input": "2 3 4",
"output": "18"
},
{
"input": "2 2 2",
"output": "7"
},
{
"input": "7 8 13",
"output": "224"
},
{
"input": "14 7 75",
"output": "1578"
},
{
"input": "201 108 304",
"output": "115032"
},
{
"input": "999 998 996",
"output": "2983022"
},
{
"input": "2 2 3",
"output": "10"
},
{
"input": "2 3 2",
"output": "10"
},
{
"input": "3 2 2",
"output": "10"
},
{
"input": "2 3 3",
"output": "14"
},
{
"input": "3 2 3",
"output": "14"
},
{
"input": "3 3 2",
"output": "14"
},
{
"input": "3 3 3",
"output": "19"
},
{
"input": "4 5 3",
"output": "36"
},
{
"input": "2 2 856",
"output": "2569"
},
{
"input": "2 986 2",
"output": "2959"
},
{
"input": "985 2 2",
"output": "2956"
},
{
"input": "2 958 983",
"output": "943654"
},
{
"input": "992 2 912",
"output": "906607"
},
{
"input": "789 894 2",
"output": "707048"
},
{
"input": "1000 1000 1000",
"output": "2997001"
},
{
"input": "384 458 284",
"output": "413875"
},
{
"input": "709 14 290",
"output": "218584"
},
{
"input": "485 117 521",
"output": "369265"
},
{
"input": "849 333 102",
"output": "401998"
},
{
"input": "998 999 1000",
"output": "2991006"
},
{
"input": "2 2 1000",
"output": "3001"
},
{
"input": "2 1000 2",
"output": "3001"
},
{
"input": "1000 2 2",
"output": "3001"
},
{
"input": "1000 2 1000",
"output": "1001999"
},
{
"input": "865 291 383",
"output": "692925"
},
{
"input": "41 49 28",
"output": "4412"
},
{
"input": "34 86 90",
"output": "13515"
},
{
"input": "39 23 56",
"output": "4252"
},
{
"input": "14 99 81",
"output": "10346"
},
{
"input": "48 38 193",
"output": "18144"
},
{
"input": "395 85 22",
"output": "43634"
},
{
"input": "38 291 89",
"output": "39922"
},
{
"input": "7 23 595",
"output": "17387"
},
{
"input": "948 48 3",
"output": "47494"
}
] | 1,614,628,994 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | a,b,c=map(int,input().split())
print(b*c+(a-1)*(c+b-1)) | Title: Tiling with Hexagons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has *a*, *b*, *c*, *a*, *b* and *c* adjacent tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for *a*<==<=2, *b*<==<=3 and *c*<==<=4.
According to the legend, as the King of Berland obtained the values *a*, *b* and *c*, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?
Input Specification:
The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000).
Output Specification:
Print a single number — the total number of tiles on the hall floor.
Demo Input:
['2 3 4\n']
Demo Output:
['18']
Note:
none | ```python
a,b,c=map(int,input().split())
print(b*c+(a-1)*(c+b-1))
``` | 3 |
|
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n1",
"output": "NO"
},
{
"input": "1 10 100\n100 10 1\n20",
"output": "NO"
},
{
"input": "1 1 1\n0 0 0\n1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1\n1",
"output": "YES"
},
{
"input": "5 5 5\n0 0 0\n2",
"output": "NO"
},
{
"input": "0 0 0\n10 10 10\n2",
"output": "NO"
},
{
"input": "21 61 39\n63 58 69\n44",
"output": "YES"
},
{
"input": "18 95 4\n7 1 75\n46",
"output": "YES"
},
{
"input": "64 27 81\n72 35 23\n48",
"output": "YES"
},
{
"input": "6 6 6\n11 11 11\n7",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n3",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n4",
"output": "YES"
},
{
"input": "99 99 99\n99 99 99\n89",
"output": "NO"
},
{
"input": "5 0 0\n15 0 0\n2",
"output": "NO"
},
{
"input": "10 10 10\n0 0 0\n1",
"output": "NO"
},
{
"input": "1 1 1\n1 1 1\n15",
"output": "YES"
},
{
"input": "2 3 5\n2 3 5\n2",
"output": "NO"
},
{
"input": "2 2 2\n3 3 5\n3",
"output": "NO"
},
{
"input": "1 2 2\n2 4 4\n1",
"output": "NO"
},
{
"input": "1 2 3\n1 5 5\n2",
"output": "NO"
}
] | 1,646,127,377 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a1,a2,a3,b1,b2,b3,n,x;
cin>>a1>>a2>>a3;
cin>>b1>>b2>>b3;
cin>>n;
if(n==1 && (a1>0||a2>0||a3>0)&&(b1>0||b2>0||b3>0))
{
cout<<"NO"<<endl;
}
else
{
for(int x=1;x<=(n-1);x++)
{
if(x*5+(n-x)*10>=(a1+a2+a3+b1+b2+b3))
{
cout<<"YES"<<endl;
return 0;
}
else
{
cout<<"NO"<<endl;
return 0;
}
}
}
return 0;
}
| Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
Input Specification:
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
Output Specification:
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
Demo Input:
['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1,a2,a3,b1,b2,b3,n,x;
cin>>a1>>a2>>a3;
cin>>b1>>b2>>b3;
cin>>n;
if(n==1 && (a1>0||a2>0||a3>0)&&(b1>0||b2>0||b3>0))
{
cout<<"NO"<<endl;
}
else
{
for(int x=1;x<=(n-1);x++)
{
if(x*5+(n-x)*10>=(a1+a2+a3+b1+b2+b3))
{
cout<<"YES"<<endl;
return 0;
}
else
{
cout<<"NO"<<endl;
return 0;
}
}
}
return 0;
}
``` | -1 |
|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "14"
},
{
"input": "5 5\n3 2 1 0 0",
"output": "3"
},
{
"input": "8 6\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 7\n10 9 8 7 7 7 5 5",
"output": "8"
},
{
"input": "8 4\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 3\n10 9 8 7 7 7 5 5",
"output": "3"
},
{
"input": "8 1\n10 9 8 7 7 7 5 5",
"output": "1"
},
{
"input": "8 2\n10 9 8 7 7 7 5 5",
"output": "2"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "26"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "11 5\n100 99 98 97 96 95 94 93 92 91 90",
"output": "5"
},
{
"input": "10 4\n100 81 70 69 64 43 34 29 15 3",
"output": "4"
},
{
"input": "11 6\n87 71 62 52 46 46 43 35 32 25 12",
"output": "6"
},
{
"input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2",
"output": "12"
},
{
"input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2",
"output": "3"
},
{
"input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5",
"output": "12"
},
{
"input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1",
"output": "9"
},
{
"input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0",
"output": "29"
},
{
"input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4",
"output": "34"
},
{
"input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4",
"output": "44"
},
{
"input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3",
"output": "13"
},
{
"input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3",
"output": "30"
},
{
"input": "2 1\n10 10",
"output": "2"
},
{
"input": "2 2\n10 10",
"output": "2"
},
{
"input": "2 2\n10 0",
"output": "1"
},
{
"input": "2 2\n10 1",
"output": "2"
},
{
"input": "2 1\n10 0",
"output": "1"
},
{
"input": "2 1\n10 2",
"output": "1"
},
{
"input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10 1\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 2\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 3\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 4\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 5\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 6\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 7\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 8\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 9\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 10\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
}
] | 1,696,586,963 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n,k=map(int,input().split())
count=0
for i in range(1,n+1):
a=int(input())
if(a>k):
count+=1
print(count)
| Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output Specification:
Output the number of participants who advance to the next round.
Demo Input:
['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n']
Demo Output:
['6\n', '0\n']
Note:
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | ```python
n,k=map(int,input().split())
count=0
for i in range(1,n+1):
a=int(input())
if(a>k):
count+=1
print(count)
``` | -1 |
|
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "83"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "74"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "52"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 1,619,170,689 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 184 | 0 | n = int(input())
arr = list(map(int, input().split()))
i = 0
cm = 1
while i < n:
cc = -1
curr = arr[i]
j = i
k = i
while j > 0:
if curr >= arr[j]:
cc += 1
else:
break
curr = arr[j]
j -= 1
curr = arr[i]
while k < n:
if curr >= arr[k]:
cc += 1
else:
break
curr = arr[k]
k += 1
i += 1
if cc > cm:
cm = cc
print(cm)
| Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output Specification:
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Demo Input:
['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
none | ```python
n = int(input())
arr = list(map(int, input().split()))
i = 0
cm = 1
while i < n:
cc = -1
curr = arr[i]
j = i
k = i
while j > 0:
if curr >= arr[j]:
cc += 1
else:
break
curr = arr[j]
j -= 1
curr = arr[i]
while k < n:
if curr >= arr[k]:
cc += 1
else:
break
curr = arr[k]
k += 1
i += 1
if cc > cm:
cm = cc
print(cm)
``` | 0 |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,692,803,119 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(n):
for j in range(n):
if a[i]<a[j] and b[i]>b[j]:
print('Happy Alex')
exit()
print('Poor Alex') | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(n):
for j in range(n):
if a[i]<a[j] and b[i]>b[j]:
print('Happy Alex')
exit()
print('Poor Alex')
``` | -1 |
|
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string. | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss",
"output": "1"
},
{
"input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs",
"output": "2"
},
{
"input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi",
"output": "2"
},
{
"input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn",
"output": "1"
},
{
"input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti",
"output": "2"
},
{
"input": "rmeetriiitijmrenmeiijt",
"output": "0"
},
{
"input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne",
"output": "1"
},
{
"input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer",
"output": "2"
},
{
"input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim",
"output": "2"
},
{
"input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm",
"output": "3"
},
{
"input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn",
"output": "3"
},
{
"input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni",
"output": "1"
},
{
"input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm",
"output": "2"
},
{
"input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet",
"output": "3"
},
{
"input": "jrjshtjstteh",
"output": "0"
},
{
"input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn",
"output": "2"
},
{
"input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn",
"output": "2"
},
{
"input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei",
"output": "1"
},
{
"input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin",
"output": "2"
},
{
"input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin",
"output": "1"
},
{
"input": "rnsrsmretjiitrjthhritniijhjmm",
"output": "0"
},
{
"input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj",
"output": "3"
},
{
"input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni",
"output": "0"
},
{
"input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis",
"output": "2"
},
{
"input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh",
"output": "3"
},
{
"input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei",
"output": "3"
},
{
"input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs",
"output": "1"
},
{
"input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj",
"output": "1"
},
{
"input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj",
"output": "2"
},
{
"input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii",
"output": "1"
},
{
"input": "iihienhirmnihh",
"output": "0"
},
{
"input": "ismtthhshjmhisssnmnhe",
"output": "0"
},
{
"input": "rhsmnrmhejshinnjrtmtsssijimimethnm",
"output": "0"
},
{
"input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj",
"output": "3"
},
{
"input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes",
"output": "2"
},
{
"input": "ssrmjmjeeetrnimemrhimes",
"output": "0"
},
{
"input": "n",
"output": "0"
},
{
"input": "ni",
"output": "0"
},
{
"input": "nine",
"output": "0"
},
{
"input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen",
"output": "13"
},
{
"input": "ninetee",
"output": "0"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd",
"output": "0"
},
{
"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch",
"output": "0"
},
{
"input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq",
"output": "0"
},
{
"input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz",
"output": "13"
},
{
"input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee",
"output": "3"
},
{
"input": "ttttiiiieeeeeeeeeeeennnnnnnnn",
"output": "4"
},
{
"input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn",
"output": "3"
},
{
"input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt",
"output": "4"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn",
"output": "3"
},
{
"input": "nineeen",
"output": "0"
},
{
"input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii",
"output": "0"
},
{
"input": "nineteenieteenieteenieteenieteenieteenieteen",
"output": "4"
},
{
"input": "nineteenineteenineteenineteenineteen",
"output": "5"
}
] | 1,580,661,778 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | import sys
inputString = input()
letters = ["n", "i", "e", "t"]
count = [0, 0, 0, 0]
for elem in inputString:
number = 0
for i in letters:
if i == elem:
count[number] += 1
number += 1
count[0] = round((count[0]-1)/2)
count[0] = round(count[2]/3)
output = min(count)
print(output) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string.
Input Specification:
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Output Specification:
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
Demo Input:
['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n']
Demo Output:
['2', '2', '2']
Note:
none | ```python
import sys
inputString = input()
letters = ["n", "i", "e", "t"]
count = [0, 0, 0, 0]
for elem in inputString:
number = 0
for i in letters:
if i == elem:
count[number] += 1
number += 1
count[0] = round((count[0]-1)/2)
count[0] = round(count[2]/3)
output = min(count)
print(output)
``` | 0 |
|
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,699,277,186 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,496 | 5,324,800 | s = input()
L = [0]
num = 0
for i in range(1,len(s)):
if s[i] == s[i - 1]:
num += 1
L.append(num)
m = int(input())
for _ in range(m):
i,j = map(int,input().split())
print(L[j - 1] - L[i - 1]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none | ```python
s = input()
L = [0]
num = 0
for i in range(1,len(s)):
if s[i] == s[i - 1]:
num += 1
L.append(num)
m = int(input())
for _ in range(m):
i,j = map(int,input().split())
print(L[j - 1] - L[i - 1])
``` | 3 |
|
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 could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. | 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 can't sort the array in more than one swap operation, so the answer is "NO". | 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",
"output": "YES"
},
{
"input": "10\n1 2 9 4 5 6 7 8 3 10",
"output": "YES"
},
{
"input": "4\n2 2 2 1",
"output": "YES"
},
{
"input": "10\n1 2 4 4 4 5 5 7 7 10",
"output": "YES"
},
{
"input": "10\n4 5 11 12 13 14 16 16 16 18",
"output": "YES"
},
{
"input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321",
"output": "YES"
},
{
"input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644",
"output": "YES"
},
{
"input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5",
"output": "NO"
},
{
"input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472",
"output": "NO"
},
{
"input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503",
"output": "NO"
},
{
"input": "4\n5 12 12 6",
"output": "YES"
},
{
"input": "5\n1 3 3 3 2",
"output": "YES"
},
{
"input": "4\n2 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "4\n1000000000 1 1000000000 1",
"output": "YES"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 1",
"output": "YES"
},
{
"input": "6\n1 2 3 4 5 3",
"output": "NO"
},
{
"input": "9\n3 3 3 2 2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n4 1 2 3",
"output": "NO"
},
{
"input": "6\n3 4 5 6 7 2",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "4\n3 2 1 1",
"output": "NO"
},
{
"input": "4\n4 5 1 1",
"output": "NO"
},
{
"input": "6\n1 6 2 4 3 5",
"output": "NO"
},
{
"input": "5\n1 4 5 2 3",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n1 4 3 2 1",
"output": "NO"
},
{
"input": "5\n1 4 2 2 3",
"output": "NO"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "5\n5 1 2 3 4",
"output": "NO"
},
{
"input": "5\n3 3 3 2 2",
"output": "NO"
},
{
"input": "5\n100 5 6 10 7",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "NO"
},
{
"input": "5\n4 4 1 1 1",
"output": "NO"
},
{
"input": "5\n1 2 5 3 4",
"output": "NO"
},
{
"input": "4\n3 4 1 2",
"output": "NO"
},
{
"input": "4\n2 4 1 5",
"output": "NO"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 5 4 4 4",
"output": "YES"
},
{
"input": "7\n3 2 1 2 3 5 4",
"output": "NO"
},
{
"input": "5\n1 1 3 2 2",
"output": "YES"
},
{
"input": "9\n1 8 7 7 7 7 7 8 3",
"output": "YES"
},
{
"input": "5\n1 3 2 3 3",
"output": "YES"
},
{
"input": "10\n4 4 4 4 10 4 4 4 4 4",
"output": "YES"
},
{
"input": "8\n3 6 6 6 6 6 4 9",
"output": "YES"
},
{
"input": "4\n4 4 3 3",
"output": "NO"
},
{
"input": "4\n3 2 2 4",
"output": "YES"
},
{
"input": "5\n2 2 1 3 3",
"output": "YES"
},
{
"input": "5\n1 2 7 3 5",
"output": "NO"
},
{
"input": "5\n2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n1 4 3 6 2 5",
"output": "NO"
},
{
"input": "5\n3 3 1 5 4",
"output": "NO"
},
{
"input": "4\n1 2 1 2",
"output": "YES"
},
{
"input": "6\n4 5 3 4 2 6",
"output": "NO"
},
{
"input": "11\n1 2 3 4 5 1 2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n6 1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n4 1 1 1 1",
"output": "YES"
},
{
"input": "9\n1 2 3 5 4 6 7 8 9",
"output": "YES"
},
{
"input": "6\n6 1 2 3 4 2",
"output": "NO"
},
{
"input": "6\n2 2 2 2 3 2",
"output": "YES"
},
{
"input": "3\n2 1 1",
"output": "YES"
},
{
"input": "5\n1 2 1 1 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 2",
"output": "YES"
},
{
"input": "8\n5 5 5 5 5 5 1 1",
"output": "NO"
}
] | 1,590,601,387 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 2,150,400 | n=int(input())
a=list(map(int,input().split(" ")))
c=0
f=0
for i in range(0,n-1,1):
x=min(a)
s=a.index(x)
if a[0]!=x:
c+=1
temp=a[0]
a[0]=a[s]
a[s]=temp
a.pop(0)
if c>1:
print("NO")
f=1
break
if f==0:
print("YES")
| 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 call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
Input Specification:
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.
Output Specification:
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.
Demo Input:
['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
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 can't sort the array in more than one swap operation, so the answer is "NO". | ```python
n=int(input())
a=list(map(int,input().split(" ")))
c=0
f=0
for i in range(0,n-1,1):
x=min(a)
s=a.index(x)
if a[0]!=x:
c+=1
temp=a[0]
a[0]=a[s]
a[s]=temp
a.pop(0)
if c>1:
print("NO")
f=1
break
if f==0:
print("YES")
``` | 0 |
|
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 unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | 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",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,600,346,965 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | w,y=map(int,input().split())
if w>y:
x=w
else:
x=y
x=(x/6)-(1/6)
print(1-x) | 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 Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
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 Specification:
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».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
w,y=map(int,input().split())
if w>y:
x=w
else:
x=y
x=(x/6)-(1/6)
print(1-x)
``` | 0 |
358 | B | Dima and Text Messages | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3*word*1<3*word*2<3 ... *word**n*<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | [
"3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n"
] | [
"yes\n",
"no\n"
] | Please note that Dima got a good old kick in the pants for the second sample from the statement. | 1,000 | [
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3",
"output": "yes"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3",
"output": "yes"
},
{
"input": "4\na\nb\nc\nd\n<3a<3b<3c<3d",
"output": "no"
},
{
"input": "4\na\nb\nc\nd\na<3b<3c<3d<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<3you<3",
"output": "yes"
},
{
"input": "1\na\na",
"output": "no"
},
{
"input": "1\na\n<3a<3b",
"output": "yes"
},
{
"input": "1\naa\n<3a<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww",
"output": "yes"
},
{
"input": "3\ni\nlove\nyou\n<3ilove<23you<3",
"output": "no"
},
{
"input": "2\na\ni\n<3ai<3",
"output": "no"
}
] | 1,699,266,393 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 701 | 10,035,200 | words = []
for _ in range(int(input())):
words.append(input())
encoded = input()
msg = '<3' + '<3'.join(words)+'<3'
i = 0
for c in encoded:
if msg[i] == c:
i += 1
if i == len(msg):
break
print('yes' if i == len(msg) else 'no')
| Title: Dima and Text Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3*word*1<3*word*2<3 ... *word**n*<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
Output Specification:
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
Demo Input:
['3\ni\nlove\nyou\n<3i<3love<23you<3\n', '7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n']
Demo Output:
['yes\n', 'no\n']
Note:
Please note that Dima got a good old kick in the pants for the second sample from the statement. | ```python
words = []
for _ in range(int(input())):
words.append(input())
encoded = input()
msg = '<3' + '<3'.join(words)+'<3'
i = 0
for c in encoded:
if msg[i] == c:
i += 1
if i == len(msg):
break
print('yes' if i == len(msg) else 'no')
``` | 3 |
|
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"output": "1"
},
{
"input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156",
"output": "-1"
},
{
"input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173",
"output": "1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n1000000",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
}
] | 1,565,133,916 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 139 | 0 | n = int(input())
nums = [int(s) for s in input().split()]
if 1 in nums:
print(-1)
else:
print(1)
| Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes.
Output Specification:
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1.
Demo Input:
['5\n1 2 3 4 5\n']
Demo Output:
['-1\n']
Note:
none | ```python
n = int(input())
nums = [int(s) for s in input().split()]
if 1 in nums:
print(-1)
else:
print(1)
``` | 3 |
|
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 remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | 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"
},
{
"input": "9",
"output": "12870"
},
{
"input": "10",
"output": "48620"
},
{
"input": "8",
"output": "3432"
}
] | 1,656,418,195 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
if n == 1:
print(1)
else:
lst = [[1]*n]
for i in range(1,n):
new = []
for j in range(n):
if j == 0:
new.append(1)
else:
new.append(lst[i-1][j] + new[j-1])
lst.append(new)
print(lst[n-1][n-1]) | 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 table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
n = int(input())
if n == 1:
print(1)
else:
lst = [[1]*n]
for i in range(1,n):
new = []
for j in range(n):
if j == 0:
new.append(1)
else:
new.append(lst[i-1][j] + new[j-1])
lst.append(new)
print(lst[n-1][n-1])
``` | 3 |
|
707 | C | Pythagorean Triples | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same? | The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle. | Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. | [
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] | [
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] | Illustration for the first sample. | 1,500 | [
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14",
"output": "48 50"
},
{
"input": "22",
"output": "120 122"
},
{
"input": "23",
"output": "264 265"
},
{
"input": "246",
"output": "15128 15130"
},
{
"input": "902",
"output": "203400 203402"
},
{
"input": "1000000000",
"output": "1250000000 750000000"
},
{
"input": "1998",
"output": "998000 998002"
},
{
"input": "2222222",
"output": "1234567654320 1234567654322"
},
{
"input": "2222226",
"output": "1234572098768 1234572098770"
},
{
"input": "1111110",
"output": "308641358024 308641358026"
},
{
"input": "9999998",
"output": "24999990000000 24999990000002"
},
{
"input": "1024",
"output": "1280 768"
},
{
"input": "8388608",
"output": "10485760 6291456"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "492",
"output": "615 369"
},
{
"input": "493824",
"output": "617280 370368"
},
{
"input": "493804",
"output": "617255 370353"
},
{
"input": "493800",
"output": "617250 370350"
},
{
"input": "2048",
"output": "2560 1536"
},
{
"input": "8388612",
"output": "10485765 6291459"
},
{
"input": "44",
"output": "55 33"
},
{
"input": "444",
"output": "555 333"
},
{
"input": "4444",
"output": "5555 3333"
},
{
"input": "44444",
"output": "55555 33333"
},
{
"input": "444444",
"output": "555555 333333"
},
{
"input": "4444444",
"output": "5555555 3333333"
},
{
"input": "100000000",
"output": "125000000 75000000"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "4 5"
},
{
"input": "5",
"output": "12 13"
},
{
"input": "7",
"output": "24 25"
},
{
"input": "9",
"output": "40 41"
},
{
"input": "11",
"output": "60 61"
},
{
"input": "13",
"output": "84 85"
},
{
"input": "15",
"output": "112 113"
},
{
"input": "19",
"output": "180 181"
},
{
"input": "111",
"output": "6160 6161"
},
{
"input": "113",
"output": "6384 6385"
},
{
"input": "115",
"output": "6612 6613"
},
{
"input": "117",
"output": "6844 6845"
},
{
"input": "119",
"output": "7080 7081"
},
{
"input": "111111",
"output": "6172827160 6172827161"
},
{
"input": "111113",
"output": "6173049384 6173049385"
},
{
"input": "111115",
"output": "6173271612 6173271613"
},
{
"input": "111117",
"output": "6173493844 6173493845"
},
{
"input": "111119",
"output": "6173716080 6173716081"
},
{
"input": "9999993",
"output": "49999930000024 49999930000025"
},
{
"input": "9999979",
"output": "49999790000220 49999790000221"
},
{
"input": "9999990",
"output": "24999950000024 24999950000026"
},
{
"input": "9999991",
"output": "49999910000040 49999910000041"
},
{
"input": "9999992",
"output": "12499990 7499994"
},
{
"input": "9999973",
"output": "49999730000364 49999730000365"
},
{
"input": "9999994",
"output": "24999970000008 24999970000010"
},
{
"input": "9999995",
"output": "49999950000012 49999950000013"
},
{
"input": "9999996",
"output": "12499995 7499997"
},
{
"input": "9999997",
"output": "49999970000004 49999970000005"
},
{
"input": "9999978",
"output": "24999890000120 24999890000122"
},
{
"input": "99999993",
"output": "4999999300000024 4999999300000025"
},
{
"input": "99999979",
"output": "4999997900000220 4999997900000221"
},
{
"input": "99999990",
"output": "2499999500000024 2499999500000026"
},
{
"input": "99999991",
"output": "4999999100000040 4999999100000041"
},
{
"input": "99999992",
"output": "124999990 74999994"
},
{
"input": "99999973",
"output": "4999997300000364 4999997300000365"
},
{
"input": "99999994",
"output": "2499999700000008 2499999700000010"
},
{
"input": "99999995",
"output": "4999999500000012 4999999500000013"
},
{
"input": "99999996",
"output": "124999995 74999997"
},
{
"input": "99999997",
"output": "4999999700000004 4999999700000005"
},
{
"input": "99999978",
"output": "2499998900000120 2499998900000122"
},
{
"input": "987654323",
"output": "487730530870294164 487730530870294165"
},
{
"input": "2",
"output": "-1"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "64",
"output": "80 48"
},
{
"input": "999999999",
"output": "499999999000000000 499999999000000001"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "999999937",
"output": "499999937000001984 499999937000001985"
},
{
"input": "999999998",
"output": "249999999000000000 249999999000000002"
},
{
"input": "433494437",
"output": "93958713454973484 93958713454973485"
},
{
"input": "484916147",
"output": "117571834810662804 117571834810662805"
},
{
"input": "999999929",
"output": "499999929000002520 499999929000002521"
},
{
"input": "982451653",
"output": "482605625241216204 482605625241216205"
},
{
"input": "2048",
"output": "2560 1536"
}
] | 1,676,959,079 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 90 | 62 | 0 | a=int(input())
if a==1 or a==2 :
print(-1)
else:
if a % 2 == 1:
b = (a*a-1)//2
c = b+1
print(b, c)
else:
b = (a*a)//4-1
c = b+2
print(b, c)
| Title: Pythagorean Triples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
Input Specification:
The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle.
Output Specification:
Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them.
Demo Input:
['3\n', '6\n', '1\n', '17\n', '67\n']
Demo Output:
['4 5', '8 10', '-1', '144 145', '2244 2245']
Note:
Illustration for the first sample. | ```python
a=int(input())
if a==1 or a==2 :
print(-1)
else:
if a % 2 == 1:
b = (a*a-1)//2
c = b+1
print(b, c)
else:
b = (a*a)//4-1
c = b+2
print(b, c)
``` | 3 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,645,187,164 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 592 | 0 | n, m = map(int, input().split())
result = 0
for i in range(0,n+1):
for j in range(0, m + 1):
if i!=0 or j!=0:
if i*i+j==n and i+j*j==m:
result+=1
print(result) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
n, m = map(int, input().split())
result = 0
for i in range(0,n+1):
for j in range(0, m + 1):
if i!=0 or j!=0:
if i*i+j==n and i+j*j==m:
result+=1
print(result)
``` | 3 |
|
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,623,740,730 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 77 | 102,400 | n,m=map(int,input().split())
d={}
for i in range(n+m):
k,l=map(str,input().split())
k1=l
l=l.rstrip(";")
if d.get(l)==None:
d[l]=k
else:
print(k,l+";","#"+d[l])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none | ```python
n,m=map(int,input().split())
d={}
for i in range(n+m):
k,l=map(str,input().split())
k1=l
l=l.rstrip(";")
if d.get(l)==None:
d[l]=k
else:
print(k,l+";","#"+d[l])
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,645,812,564 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
dominopiling=input()
dominopiling_2=dominopiling.split()
M=int(dominopiling_2[0])
N=int(dominopiling_2[1])
numer=math.floor(M*N/2)
print(numer) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
import math
dominopiling=input()
dominopiling_2=dominopiling.split()
M=int(dominopiling_2[0])
N=int(dominopiling_2[1])
numer=math.floor(M*N/2)
print(numer)
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"input": "100 99 98 100",
"output": "-1"
},
{
"input": "100 40 30 40",
"output": "-1"
},
{
"input": "100 50 19 25",
"output": "100\n51\n25"
},
{
"input": "100 50 19 30",
"output": "100\n61\n30"
},
{
"input": "49 48 25 49",
"output": "-1"
},
{
"input": "48 47 23 46",
"output": "94\n93\n46"
},
{
"input": "37 23 16 20",
"output": "42\n41\n20"
},
{
"input": "98 2 1 1",
"output": "98\n3\n1"
},
{
"input": "99 22 13 14",
"output": "99\n29\n14"
},
{
"input": "97 95 3 2",
"output": "97\n95\n3"
},
{
"input": "27 3 2 3",
"output": "-1"
},
{
"input": "13 7 6 2",
"output": "-1"
},
{
"input": "19 17 11 6",
"output": "19\n17\n11"
},
{
"input": "15 6 4 5",
"output": "15\n11\n5"
},
{
"input": "21 3 1 3",
"output": "-1"
},
{
"input": "100 99 98 97",
"output": "196\n195\n98"
},
{
"input": "99 32 13 5",
"output": "-1"
},
{
"input": "5 4 3 1",
"output": "-1"
},
{
"input": "50 20 4 8",
"output": "50\n20\n8"
},
{
"input": "60 30 10 1",
"output": "-1"
},
{
"input": "100 50 10 1",
"output": "-1"
},
{
"input": "40 30 20 10",
"output": "40\n30\n20"
},
{
"input": "50 49 5 10",
"output": "50\n49\n10"
},
{
"input": "99 98 50 97",
"output": "196\n195\n97"
},
{
"input": "50 30 10 5",
"output": "50\n30\n10"
},
{
"input": "4 3 2 1",
"output": "4\n3\n2"
},
{
"input": "100 50 3 1",
"output": "-1"
}
] | 1,514,038,609 | 709 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,529,600 | Fa, Ma, Ka, ma = map(int, input().split())
F = max(Fa, ma)
M = max(Ma, ma)
K = max(Ma, ma)
flag = (Fa > Ma) and (ma < Ma) and (ma < Ka * 2)
if flag:
print(Fa*2, min(Fa-1, Ma*2), max(Ka, ma))
else:
print(-1)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input Specification:
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3.
Output Specification:
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Demo Input:
['50 30 10 10\n', '100 50 10 21\n']
Demo Output:
['50\n30\n10\n', '-1\n']
Note:
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | ```python
Fa, Ma, Ka, ma = map(int, input().split())
F = max(Fa, ma)
M = max(Ma, ma)
K = max(Ma, ma)
flag = (Fa > Ma) and (ma < Ma) and (ma < Ka * 2)
if flag:
print(Fa*2, min(Fa-1, Ma*2), max(Ka, ma))
else:
print(-1)
``` | 0 |
|
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5. | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903",
"output": "13"
},
{
"input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94",
"output": "3"
},
{
"input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190",
"output": "31"
},
{
"input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997",
"output": "0"
},
{
"input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176",
"output": "412"
},
{
"input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886",
"output": "938"
},
{
"input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993",
"output": "937"
},
{
"input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7",
"output": "0"
},
{
"input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19",
"output": "12"
},
{
"input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "0"
},
{
"input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17",
"output": "31"
},
{
"input": "2 2\n1000 4",
"output": "996"
},
{
"input": "2 3\n4 502 1000",
"output": "498"
},
{
"input": "3 3\n4 1000 4",
"output": "996"
}
] | 1,682,874,341 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | L1 = [int(x) for x in input().split(" ")]
L2=[int(x) for x in input().split(" ")]
num=L1[1]-L1[0]+1
#print(num)
L4=[]
for i in range (0,num):
ctr=0
L3=[]
for j in range(0,L1[0]):
if ctr<5:
ctr=ctr+1
L3.append(L2[j+i])
else:
break
L4.append(L3)
L5=[]
for i in L4:
for j in i:
num=max(i)-min(i)
L5.append(num)
print(min(L5)) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
Input Specification:
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Output Specification:
Print a single integer — the least possible difference the teacher can obtain.
Demo Input:
['4 6\n10 12 10 7 5 22\n']
Demo Output:
['5\n']
Note:
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5. | ```python
L1 = [int(x) for x in input().split(" ")]
L2=[int(x) for x in input().split(" ")]
num=L1[1]-L1[0]+1
#print(num)
L4=[]
for i in range (0,num):
ctr=0
L3=[]
for j in range(0,L1[0]):
if ctr<5:
ctr=ctr+1
L3.append(L2[j+i])
else:
break
L4.append(L3)
L5=[]
for i in L4:
for j in i:
num=max(i)-min(i)
L5.append(num)
print(min(L5))
``` | 0 |
|
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 wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | 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, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 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",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,618,209,425 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 154 | 0 | n = int(input())
l = [int(x) for x in input().split(" ")]
flag = 1
count = 0
if(sum(l)%2==0):
flag = 0
for i in l:
if(flag == 0 and i%2 == 0):
count +=1
elif(flag == 1 and i%2!=0):
count+=1
print(count)
| 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 want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
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.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['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']
Demo Output:
['1\n', '8\n', '1\n']
Note:
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, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n = int(input())
l = [int(x) for x in input().split(" ")]
flag = 1
count = 0
if(sum(l)%2==0):
flag = 0
for i in l:
if(flag == 0 and i%2 == 0):
count +=1
elif(flag == 1 and i%2!=0):
count+=1
print(count)
``` | 3 |
|
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 from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game. | 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*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | 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"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 1,673,287,841 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a, b, n = map(int, input().split())
while n > 0:
if n < max(a, b):
break
n -= max(a, b)
if n < min(a, b):
n -= min(a, b)
if n < 0:
print("1")
else:
print("0") | 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* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
Input Specification:
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.
Output Specification:
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Demo Input:
['3 5 9\n', '1 1 100\n']
Demo Output:
['0', '1']
Note:
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*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | ```python
a, b, n = map(int, input().split())
while n > 0:
if n < max(a, b):
break
n -= max(a, b)
if n < min(a, b):
n -= min(a, b)
if n < 0:
print("1")
else:
print("0")
``` | 0 |
|
598 | C | Nearest vectors | PROGRAMMING | 2,300 | [
"geometry",
"sortings"
] | null | null | You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π. | First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors.
The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=><=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions). | Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. | [
"4\n-1 0\n0 -1\n1 0\n1 1\n",
"6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n"
] | [
"3 4\n",
"6 5"
] | none | 0 | [
{
"input": "4\n-1 0\n0 -1\n1 0\n1 1",
"output": "3 4"
},
{
"input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6",
"output": "5 6"
},
{
"input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7",
"output": "1 3"
},
{
"input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2",
"output": "13 16"
},
{
"input": "2\n351 -4175\n-328 -657",
"output": "2 1"
},
{
"input": "3\n620 -1189\n8101 -2770\n3347 3473",
"output": "1 2"
},
{
"input": "4\n-7061 -5800\n-3471 -9470\n-7639 2529\n5657 -6522",
"output": "1 2"
},
{
"input": "5\n-7519 -3395\n-32 -257\n-4827 -1889\n9545 -7037\n2767 583",
"output": "3 1"
},
{
"input": "6\n-5120 -3251\n8269 -7984\n841 3396\n3136 -7551\n-1280 -3013\n-3263 -3278",
"output": "1 6"
},
{
"input": "7\n-2722 6597\n-3303 200\n6508 -1021\n-1107 -1042\n6875 7616\n-3047 6749\n662 -1979",
"output": "1 6"
},
{
"input": "8\n-36 749\n5126 943\n1165 533\n-1647 -5725\n5031 6532\n5956 8447\n2297 -2284\n1986 6937",
"output": "5 6"
},
{
"input": "9\n-391 -1706\n995 -5756\n-5013 -154\n1121 3160\n-7111 8303\n-7303 -2414\n-7791 -935\n7576 -9361\n1072 203",
"output": "3 7"
},
{
"input": "10\n-9920 -5477\n9691 -3200\n754 885\n-1895 1768\n-941 1588\n6293 -2631\n-2288 9129\n4067 696\n-6754 9869\n-5747 701",
"output": "5 9"
},
{
"input": "2\n1 0\n-1 0",
"output": "1 2"
},
{
"input": "2\n0 1\n0 -1",
"output": "1 2"
},
{
"input": "2\n2131 -3249\n-2131 3249",
"output": "2 1"
},
{
"input": "3\n-5 1\n-5 -1\n5 0",
"output": "1 2"
},
{
"input": "3\n-100 1\n-100 -1\n0 100",
"output": "1 2"
},
{
"input": "3\n1 10\n10 1\n10 -1",
"output": "3 2"
},
{
"input": "3\n3 0\n0 3\n1 -3",
"output": "3 1"
},
{
"input": "3\n1 1\n-1 0\n1 -1",
"output": "3 1"
},
{
"input": "3\n-1 0\n10 -1\n1 0",
"output": "2 3"
},
{
"input": "4\n1 10\n10 1\n-2 -2\n10 -1",
"output": "4 2"
},
{
"input": "3\n-6 0\n6 1\n6 -1",
"output": "3 2"
},
{
"input": "3\n114 1\n-514 0\n114 -1",
"output": "3 1"
},
{
"input": "4\n-1 0\n0 -1\n-1 1\n1 0",
"output": "3 1"
},
{
"input": "4\n2 1\n2 -1\n-1 1\n-1 -1",
"output": "2 1"
},
{
"input": "3\n3 1\n3 -1\n0 3",
"output": "2 1"
},
{
"input": "3\n1 1\n9000 1\n9000 -1",
"output": "3 2"
},
{
"input": "3\n1 0\n-1 1\n-1 -1",
"output": "2 3"
},
{
"input": "6\n1 1\n-1 -1\n0 20\n100 1\n-100 0\n100 -1",
"output": "6 4"
},
{
"input": "4\n1 0\n0 1\n-1 0\n-13 -1",
"output": "3 4"
},
{
"input": "3\n1 0\n-1 0\n1 -1",
"output": "3 1"
},
{
"input": "3\n100 1\n-100 0\n100 -1",
"output": "3 1"
},
{
"input": "3\n-100 1\n100 0\n-100 -1",
"output": "1 3"
},
{
"input": "3\n1 100\n0 -100\n-1 100",
"output": "1 3"
},
{
"input": "11\n-7945 386\n7504 -576\n-6020 -8277\n930 9737\n1682 474\n-8279 1197\n2790 2607\n-5514 -9601\n-3159 5939\n-1806 4207\n-9073 -2138",
"output": "10 9"
},
{
"input": "3\n1 0\n10000 -1\n1 1",
"output": "2 1"
},
{
"input": "4\n-7125 -1643\n-1235 4071\n-75 -8717\n2553 9278",
"output": "4 2"
},
{
"input": "5\n-6 0\n6 1\n6 -1\n0 6\n0 -6",
"output": "3 2"
},
{
"input": "4\n5 5\n5 -5\n-555 1\n-555 -1",
"output": "3 4"
},
{
"input": "4\n1 1\n-1 1\n-1 -1\n2 -1",
"output": "4 1"
},
{
"input": "4\n-1 -100\n1 -100\n-100 -100\n100 -100",
"output": "1 2"
},
{
"input": "3\n1 0\n1 -1\n-4 -6",
"output": "2 1"
},
{
"input": "4\n-1 -100\n1 -100\n100 -100\n-100 -100",
"output": "1 2"
},
{
"input": "4\n-1 0\n0 -2\n-3 3\n4 0",
"output": "3 1"
},
{
"input": "4\n-2 0\n0 -3\n-5 5\n4 0",
"output": "3 1"
},
{
"input": "3\n1 -100\n0 100\n-1 -100",
"output": "3 1"
},
{
"input": "5\n10000 2\n10000 -1\n10000 -5\n10000 -9\n10000 -13",
"output": "2 1"
},
{
"input": "8\n-9580 8545\n-9379 -1139\n5824 -391\n-8722 2765\n-1357 -5547\n-7700 217\n9323 -7008\n957 -8356",
"output": "6 2"
},
{
"input": "4\n5 5\n5 -5\n-500 1\n-500 -1",
"output": "3 4"
},
{
"input": "3\n30 1\n30 -1\n0 30",
"output": "2 1"
},
{
"input": "4\n3966 -1107\n8007 -5457\n-7753 4945\n-2209 -4221",
"output": "2 1"
},
{
"input": "4\n1 9999\n0 1\n10000 0\n10000 -1",
"output": "4 3"
},
{
"input": "3\n10000 1\n10000 -1\n-10000 0",
"output": "2 1"
},
{
"input": "13\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n13 14\n12 13",
"output": "12 13"
},
{
"input": "4\n2 1\n2 -1\n0 1\n-1 0",
"output": "2 1"
},
{
"input": "4\n10 3\n10 -3\n-500 1\n-500 -1",
"output": "3 4"
},
{
"input": "4\n1 10000\n-1 1\n10000 0\n10000 -1",
"output": "4 3"
},
{
"input": "3\n0 1\n1 0\n1 -1",
"output": "3 2"
},
{
"input": "3\n1 0\n0 1\n1 -1",
"output": "3 1"
},
{
"input": "4\n1 1\n-1 1\n1 -2\n-1 -2",
"output": "4 3"
},
{
"input": "4\n0 -1\n-1 0\n-1 1\n1 0",
"output": "3 2"
},
{
"input": "3\n-100 1\n-100 -1\n1 1",
"output": "1 2"
},
{
"input": "3\n-3 1\n-3 -1\n2 -3",
"output": "1 2"
},
{
"input": "3\n1 -1\n1 0\n0 1",
"output": "1 2"
},
{
"input": "5\n-5 1\n0 5\n4 1\n0 -4\n-5 -1",
"output": "1 5"
},
{
"input": "4\n1 10000\n0 1\n10000 0\n9999 -1",
"output": "1 2"
},
{
"input": "4\n2 3\n2 -3\n-3 2\n-3 -2",
"output": "3 4"
},
{
"input": "3\n1 -3\n1 0\n0 1",
"output": "1 2"
},
{
"input": "3\n1 0\n-1 0\n-1 -1",
"output": "2 3"
},
{
"input": "4\n-2 1\n-2 -1\n1 1\n1 -1",
"output": "1 2"
},
{
"input": "3\n1 -1\n-1 1\n-1 -2",
"output": "3 1"
},
{
"input": "3\n1 0\n-1 -1\n1 -1",
"output": "3 1"
},
{
"input": "3\n5 5\n-5 0\n5 -5",
"output": "3 1"
},
{
"input": "4\n1 -2\n1 0\n-1 0\n10 -1",
"output": "4 2"
},
{
"input": "3\n-1000 1\n-1000 -1\n1000 0",
"output": "1 2"
},
{
"input": "6\n1 1\n1 -1\n-1 1\n-1 -1\n1 -10000\n-1 -10000",
"output": "6 5"
},
{
"input": "3\n1 1\n-1 0\n0 -1",
"output": "2 3"
},
{
"input": "4\n5000 1\n5000 -1\n-2 -1\n2 -1",
"output": "2 1"
},
{
"input": "3\n1 0\n-1 1\n-1 -5",
"output": "3 1"
},
{
"input": "3\n-5374 1323\n-4463 -8462\n6118 -7918",
"output": "2 3"
},
{
"input": "4\n-6427 -6285\n-5386 -5267\n-3898 7239\n-3905 7252",
"output": "4 3"
},
{
"input": "10\n-7 -3\n-2 8\n9 -9\n0 1\n4 5\n5 3\n-3 0\n10 2\n4 -1\n2 -10",
"output": "4 2"
},
{
"input": "4\n9999 1\n9999 -1\n-9998 1\n-10000 -1",
"output": "2 1"
},
{
"input": "4\n10000 9999\n9999 9998\n9998 9997\n9997 9996",
"output": "2 1"
},
{
"input": "4\n-6285 -6427\n-5267 -5386\n7239 -3898\n7252 -3905",
"output": "3 4"
},
{
"input": "4\n-6427 6285\n-5386 5267\n3898 -7239\n3905 -7252",
"output": "4 3"
},
{
"input": "4\n-6427 -6285\n-5386 -5267\n-3898 -7239\n-3905 -7252",
"output": "3 4"
},
{
"input": "3\n0 1\n-1 -1\n1 -1",
"output": "2 3"
},
{
"input": "4\n10000 1\n9998 -1\n-9999 1\n-9999 -1",
"output": "3 4"
},
{
"input": "3\n100 0\n100 2\n100 -1",
"output": "3 1"
},
{
"input": "3\n-1 1\n-1 -1\n1 0",
"output": "1 2"
},
{
"input": "4\n9844 9986\n181 9967\n-9812 -9925\n-194 -9900",
"output": "1 2"
},
{
"input": "4\n9800 9981\n61 9899\n-9926 -9932\n-149 -9926",
"output": "3 4"
},
{
"input": "4\n-9901 9900\n-10000 9899\n9899 9801\n9899 9900",
"output": "3 4"
},
{
"input": "4\n9934 9989\n199 9949\n-9917 -9974\n-197 -9901",
"output": "3 4"
},
{
"input": "3\n-1 1\n1 0\n-1 -1",
"output": "1 3"
},
{
"input": "3\n1 1\n-10 -10\n-10 -9",
"output": "3 2"
},
{
"input": "3\n1 0\n10000 -1\n-1 0",
"output": "2 1"
},
{
"input": "4\n9999 1\n9999 -1\n-10000 1\n-10000 -1",
"output": "3 4"
},
{
"input": "3\n-5 1\n-5 -1\n1 0",
"output": "1 2"
},
{
"input": "3\n1 0\n10000 1\n-1 0",
"output": "1 2"
},
{
"input": "4\n-9990 9995\n9994 -9991\n-9999 -9992\n9993 9992",
"output": "2 4"
},
{
"input": "8\n1 0\n1 1\n0 1\n-1 1\n-1 0\n-1 -1\n0 -1\n1 -2",
"output": "7 8"
},
{
"input": "3\n-9930 9932\n9909 -9909\n-9932 -9931",
"output": "3 2"
},
{
"input": "4\n9876 9977\n127 9938\n-9820 -9934\n-120 -9921",
"output": "3 4"
},
{
"input": "3\n10000 -1\n-1 0\n0 -1",
"output": "3 1"
},
{
"input": "4\n6427 -6285\n5386 -5267\n3898 7239\n3905 7252",
"output": "3 4"
},
{
"input": "4\n9811 9970\n155 9994\n-9826 -9977\n-159 -9986",
"output": "1 2"
},
{
"input": "4\n9851 9917\n74 9921\n-9855 -9916\n-77 -9984",
"output": "1 2"
},
{
"input": "4\n9826 9977\n159 9986\n-9811 -9970\n-155 -9994",
"output": "3 4"
},
{
"input": "4\n9849 9986\n148 9980\n-9800 -9999\n-116 -9927",
"output": "3 4"
},
{
"input": "4\n9822 9967\n111 9905\n-9943 -9986\n-163 -9953",
"output": "1 2"
},
{
"input": "4\n9959 9995\n113 9940\n-9965 -9931\n-148 -9945",
"output": "1 2"
},
{
"input": "4\n9851 9972\n153 9983\n-9866 -9926\n-183 -9946",
"output": "1 2"
},
{
"input": "4\n9816 -9979\n127 -9940\n-9876 9915\n-190 9978",
"output": "2 1"
},
{
"input": "4\n9887 -9917\n138 -9977\n-9826 9995\n-68 9971",
"output": "2 1"
},
{
"input": "4\n9936 -9965\n135 -9949\n-9928 9980\n-123 9908",
"output": "2 1"
},
{
"input": "4\n9981 -9985\n191 -9956\n-9893 9937\n-171 9962",
"output": "2 1"
},
{
"input": "4\n-9811 9970\n-155 9994\n9826 -9977\n159 -9986",
"output": "2 1"
},
{
"input": "4\n9808 9899\n179 9966\n-9870 -9961\n-179 -9950",
"output": "3 4"
},
{
"input": "4\n9815 -9936\n168 -9937\n-9896 9995\n-180 9969",
"output": "2 1"
},
{
"input": "4\n1 1\n1 -1\n-100 1\n-100 -1",
"output": "3 4"
},
{
"input": "4\n9965 114\n87 9916\n-9957 -106\n-95 -9929",
"output": "3 4"
},
{
"input": "4\n9895 -9949\n188 -9978\n-9810 9935\n-151 9914",
"output": "2 1"
},
{
"input": "4\n-9957 106\n-95 9929\n9965 -114\n87 -9916",
"output": "2 1"
},
{
"input": "4\n-9862 9980\n-174 9917\n9845 -9967\n173 -9980",
"output": "2 1"
},
{
"input": "4\n9944 9926\n9927 9935\n-9961 -9929\n-9997 -9991",
"output": "3 4"
},
{
"input": "4\n9917 9909\n196 9925\n-9971 -9991\n-183 -9977",
"output": "3 4"
}
] | 1,665,380,727 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 163 | 779 | 41,369,600 | from sys import stdin
input=lambda :stdin.readline()[:-1]
def compare(a,b):
# 比較関数 (a<=b)
# 偏角ソート
ax, ay = a[:2]
bx, by = b[:2]
if ay < 0:
return by >= 0 or ax * by - ay * bx > 0
if ay == 0:
return ax >= 0 and (by > 0 or (by == 0 and bx < 0))
return by >= 0 and (ax * by - ay * bx) > 0
def merge(l, r):
new = []
ln = 0
rn = 0
while ln < len(l) and rn < len(r):
if compare(l[ln],r[rn]):
new.append(l[ln])
ln += 1
else:
new.append(r[rn])
rn += 1
for i in range(ln, len(l)):
new.append(l[i])
for i in range(rn, len(r)):
new.append(r[i])
return new
def MergeSort(l):
if len(l) == 0:
return []
if len(l) == 1:
return l
else:
a = l[:len(l)//2]
b = l[len(l)//2:]
return merge(MergeSort(a), MergeSort(b))
n=int(input())
xy=[]
for i in range(n):
x,y=map(int,input().split())
xy.append((x,y,i))
xy=MergeSort(xy)
def cos(i,j):
xi,yi=xy[i][:2]
xj,yj=xy[j][:2]
den=(xi*xi+yi*yi)*(xj*xj+yj*yj)
num=xi*xj+yi*yj
if num>=0:
return 1,num**2,den
else:
return -1,num**2,den
def comp(sgn1,num1,den1,sgn2,num2,den2):
# return 1>=2
if sgn1>sgn2:
return True
if sgn1<sgn2:
return False
if sgn1==1:
return num1*den2>=den1*num2
else:
return num1*den2<=den1*num2
sgn,num,den=-1,1,1
for i in range(n):
j=(i+1)%n
sgn1,num1,den1=cos(i,j)
if comp(sgn1,num1,den1,sgn,num,den):
ans1=xy[i][2]
ans2=xy[j][2]
sgn,num,den=sgn1,num1,den1
print(ans1+1,ans2+1) | Title: Nearest vectors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input Specification:
First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors.
The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=><=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output Specification:
Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Demo Input:
['4\n-1 0\n0 -1\n1 0\n1 1\n', '6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n']
Demo Output:
['3 4\n', '6 5']
Note:
none | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
def compare(a,b):
# 比較関数 (a<=b)
# 偏角ソート
ax, ay = a[:2]
bx, by = b[:2]
if ay < 0:
return by >= 0 or ax * by - ay * bx > 0
if ay == 0:
return ax >= 0 and (by > 0 or (by == 0 and bx < 0))
return by >= 0 and (ax * by - ay * bx) > 0
def merge(l, r):
new = []
ln = 0
rn = 0
while ln < len(l) and rn < len(r):
if compare(l[ln],r[rn]):
new.append(l[ln])
ln += 1
else:
new.append(r[rn])
rn += 1
for i in range(ln, len(l)):
new.append(l[i])
for i in range(rn, len(r)):
new.append(r[i])
return new
def MergeSort(l):
if len(l) == 0:
return []
if len(l) == 1:
return l
else:
a = l[:len(l)//2]
b = l[len(l)//2:]
return merge(MergeSort(a), MergeSort(b))
n=int(input())
xy=[]
for i in range(n):
x,y=map(int,input().split())
xy.append((x,y,i))
xy=MergeSort(xy)
def cos(i,j):
xi,yi=xy[i][:2]
xj,yj=xy[j][:2]
den=(xi*xi+yi*yi)*(xj*xj+yj*yj)
num=xi*xj+yi*yj
if num>=0:
return 1,num**2,den
else:
return -1,num**2,den
def comp(sgn1,num1,den1,sgn2,num2,den2):
# return 1>=2
if sgn1>sgn2:
return True
if sgn1<sgn2:
return False
if sgn1==1:
return num1*den2>=den1*num2
else:
return num1*den2<=den1*num2
sgn,num,den=-1,1,1
for i in range(n):
j=(i+1)%n
sgn1,num1,den1=cos(i,j)
if comp(sgn1,num1,den1,sgn,num,den):
ans1=xy[i][2]
ans2=xy[j][2]
sgn,num,den=sgn1,num1,den1
print(ans1+1,ans2+1)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,685,071,060 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | def main():
outputs = []
n = int(input())
for _ in range(n):
x = input()
outputs.append(shorten(x))
for output in outputs:
print(output)
def shorten(n):
if len(n) > 10:
result = n[0] + str(len(n)-2) + n[len(n)-1]
return result
else:
return n
main()
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
def main():
outputs = []
n = int(input())
for _ in range(n):
x = input()
outputs.append(shorten(x))
for output in outputs:
print(output)
def shorten(n):
if len(n) > 10:
result = n[0] + str(len(n)-2) + n[len(n)-1]
return result
else:
return n
main()
``` | 3.977 |
999 | F | Cards and Joy | PROGRAMMING | 2,000 | [
"dp"
] | null | null | There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning will be explained below.
The players have to distribute all the cards in such a way that each of them will hold exactly $k$ cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals $h_t$ if the player holds $t$ cards containing his favorite number. If a player gets no cards with his favorite number (i.e., $t=0$), his joy level is $0$.
Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence $h_1, \dots, h_k$ is the same for all the players. | The first line of input contains two integers $n$ and $k$ ($1 \le n \le 500, 1 \le k \le 10$) — the number of players and the number of cards each player will get.
The second line contains $k \cdot n$ integers $c_1, c_2, \dots, c_{k \cdot n}$ ($1 \le c_i \le 10^5$) — the numbers written on the cards.
The third line contains $n$ integers $f_1, f_2, \dots, f_n$ ($1 \le f_j \le 10^5$) — the favorite numbers of the players.
The fourth line contains $k$ integers $h_1, h_2, \dots, h_k$ ($1 \le h_t \le 10^5$), where $h_t$ is the joy level of a player if he gets exactly $t$ cards with his favorite number written on them. It is guaranteed that the condition $h_{t - 1} < h_t$ holds for each $t \in [2..k]$. | Print one integer — the maximum possible total joy levels of the players among all possible card distributions. | [
"4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n",
"3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n"
] | [
"21\n",
"0\n"
] | In the first example, one possible optimal card distribution is the following:
- Player $1$ gets cards with numbers $[1, 3, 8]$; - Player $2$ gets cards with numbers $[2, 2, 8]$; - Player $3$ gets cards with numbers $[2, 2, 8]$; - Player $4$ gets cards with numbers $[5, 5, 5]$.
Thus, the answer is $2 + 6 + 6 + 7 = 21$.
In the second example, no player can get a card with his favorite number. Thus, the answer is $0$. | 0 | [
{
"input": "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7",
"output": "21"
},
{
"input": "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3",
"output": "0"
},
{
"input": "1 1\n1\n2\n1",
"output": "0"
},
{
"input": "1 1\n1\n1\n1",
"output": "1"
},
{
"input": "1 1\n1\n1\n100000",
"output": "100000"
},
{
"input": "50 1\n52 96 99 37 143 148 10 140 131 29 82 134 56 73 121 57 98 101 134 4 103 10 86 70 4 98 102 35 149 47 136 87 4 127 142 105 78 10 123 75 67 149 81 78 34 79 62 12 43 115\n31 132 59 75 4 135 138 33 33 60 135 5 30 127 61 74 102 131 11 16 74 4 101 74 70 45 29 12 137 59 24 52 25 122 64 147 92 77 23 6 19 76 26 55 126 130 4 148 86 3\n94393",
"output": "1321502"
},
{
"input": "50 1\n995 1815 941 1716 725 1098 747 627 1728 1007 34 1001 679 1742 22 1495 1299 1696 507 631 1971 775 1052 1665 1035 203 1564 1329 1592 1295 983 177 734 1442 172 943 33 486 1078 946 947 592 1524 563 396 1541 1670 326 543 79\n176 214 1601 1758 1468 972 628 1524 1506 425 746 309 387 1761 1002 625 496 1638 1855 1115 47 1813 1258 289 891 518 1247 1782 788 1449 1174 183 899 1728 366 1270 1641 327 1839 1093 223 1005 1214 1866 1432 1715 25 1240 1234 324\n52314",
"output": "104628"
}
] | 1,693,299,591 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 74 | 233 | 15,155,200 | # https://codeforces.com/contest/999
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, k = map(int, input().split()) # 1 <= n <= 500, 1 <= k <= 10
c = list(map(int, input().split())) # 1 <= c[i] <= 10**5
f = list(map(int, input().split())) # 1 <= f[i] <= 10**5
h = [0] + list(map(int, input().split())) # 1 <= h[i] <= 10**5, h[i] < h[i+1]
cnt_c = [0] * (10 ** 5 + 1)
for x in c:
cnt_c[x] += 1
cnt_f = [0] * (10 ** 5 + 1)
for x in f:
cnt_f[x] += 1
ans = 0
for num in range(10 ** 5 + 1):
# nobody has num as their favourite number or there are no cards with num on it: no joy
if cnt_f[num] == 0 or cnt_c[num] == 0:
continue
# there are k cards with num on it for everybody who has num as their favourite number: max joy
if cnt_c[num] >= k * cnt_f[num]:
ans += cnt_f[num] * h[k]
continue
# dp[i][j]: maximum joy of distributing j cards with number num across i players
dp = [[0] * (min(k * i, cnt_c[num]) + 1) for i in range(cnt_f[num] + 1)]
for i in range(cnt_f[num]):
for j in range(min(k * i, cnt_c[num]) + 1):
for kk in range(k + 1):
if j + kk <= cnt_c[num]:
dp[i + 1][j + kk] = max(dp[i + 1][j + kk], dp[i][j] + h[kk])
ans += dp[cnt_f[num]][cnt_c[num]]
print(ans)
| Title: Cards and Joy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning will be explained below.
The players have to distribute all the cards in such a way that each of them will hold exactly $k$ cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals $h_t$ if the player holds $t$ cards containing his favorite number. If a player gets no cards with his favorite number (i.e., $t=0$), his joy level is $0$.
Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence $h_1, \dots, h_k$ is the same for all the players.
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \le n \le 500, 1 \le k \le 10$) — the number of players and the number of cards each player will get.
The second line contains $k \cdot n$ integers $c_1, c_2, \dots, c_{k \cdot n}$ ($1 \le c_i \le 10^5$) — the numbers written on the cards.
The third line contains $n$ integers $f_1, f_2, \dots, f_n$ ($1 \le f_j \le 10^5$) — the favorite numbers of the players.
The fourth line contains $k$ integers $h_1, h_2, \dots, h_k$ ($1 \le h_t \le 10^5$), where $h_t$ is the joy level of a player if he gets exactly $t$ cards with his favorite number written on them. It is guaranteed that the condition $h_{t - 1} < h_t$ holds for each $t \in [2..k]$.
Output Specification:
Print one integer — the maximum possible total joy levels of the players among all possible card distributions.
Demo Input:
['4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n', '3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n']
Demo Output:
['21\n', '0\n']
Note:
In the first example, one possible optimal card distribution is the following:
- Player $1$ gets cards with numbers $[1, 3, 8]$; - Player $2$ gets cards with numbers $[2, 2, 8]$; - Player $3$ gets cards with numbers $[2, 2, 8]$; - Player $4$ gets cards with numbers $[5, 5, 5]$.
Thus, the answer is $2 + 6 + 6 + 7 = 21$.
In the second example, no player can get a card with his favorite number. Thus, the answer is $0$. | ```python
# https://codeforces.com/contest/999
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, k = map(int, input().split()) # 1 <= n <= 500, 1 <= k <= 10
c = list(map(int, input().split())) # 1 <= c[i] <= 10**5
f = list(map(int, input().split())) # 1 <= f[i] <= 10**5
h = [0] + list(map(int, input().split())) # 1 <= h[i] <= 10**5, h[i] < h[i+1]
cnt_c = [0] * (10 ** 5 + 1)
for x in c:
cnt_c[x] += 1
cnt_f = [0] * (10 ** 5 + 1)
for x in f:
cnt_f[x] += 1
ans = 0
for num in range(10 ** 5 + 1):
# nobody has num as their favourite number or there are no cards with num on it: no joy
if cnt_f[num] == 0 or cnt_c[num] == 0:
continue
# there are k cards with num on it for everybody who has num as their favourite number: max joy
if cnt_c[num] >= k * cnt_f[num]:
ans += cnt_f[num] * h[k]
continue
# dp[i][j]: maximum joy of distributing j cards with number num across i players
dp = [[0] * (min(k * i, cnt_c[num]) + 1) for i in range(cnt_f[num] + 1)]
for i in range(cnt_f[num]):
for j in range(min(k * i, cnt_c[num]) + 1):
for kk in range(k + 1):
if j + kk <= cnt_c[num]:
dp[i + 1][j + kk] = max(dp[i + 1][j + kk], dp[i][j] + h[kk])
ans += dp[cnt_f[num]][cnt_c[num]]
print(ans)
``` | 3 |
|
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions).
Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 1 100000 100001",
"output": "NO"
},
{
"input": "25 10000 200 10000 5",
"output": "YES"
},
{
"input": "1 100000 10 100000 50000",
"output": "NO"
},
{
"input": "91939 94921 10197 89487 1",
"output": "NO"
},
{
"input": "30518 58228 74071 77671 1",
"output": "NO"
},
{
"input": "46646 79126 78816 91164 5",
"output": "NO"
},
{
"input": "30070 83417 92074 99337 2",
"output": "NO"
},
{
"input": "13494 17544 96820 99660 6",
"output": "NO"
},
{
"input": "96918 97018 10077 86510 9",
"output": "YES"
},
{
"input": "13046 45594 14823 52475 1",
"output": "YES"
},
{
"input": "29174 40572 95377 97669 4",
"output": "NO"
},
{
"input": "79894 92433 8634 86398 4",
"output": "YES"
},
{
"input": "96022 98362 13380 94100 6",
"output": "YES"
},
{
"input": "79446 95675 93934 96272 3",
"output": "NO"
},
{
"input": "5440 46549 61481 99500 10",
"output": "NO"
},
{
"input": "21569 53580 74739 87749 3",
"output": "NO"
},
{
"input": "72289 78297 79484 98991 7",
"output": "NO"
},
{
"input": "88417 96645 92742 98450 5",
"output": "NO"
},
{
"input": "71841 96625 73295 77648 8",
"output": "NO"
},
{
"input": "87969 99230 78041 94736 4",
"output": "NO"
},
{
"input": "4 4 1 2 3",
"output": "NO"
},
{
"input": "150 150 1 2 100",
"output": "NO"
},
{
"input": "99 100 1 100 50",
"output": "YES"
},
{
"input": "7 7 3 6 2",
"output": "NO"
},
{
"input": "10 10 1 10 1",
"output": "YES"
},
{
"input": "36 36 5 7 6",
"output": "YES"
},
{
"input": "73 96 1 51 51",
"output": "NO"
},
{
"input": "3 3 1 3 2",
"output": "NO"
},
{
"input": "10000000 10000000 1 100000 10000000",
"output": "YES"
},
{
"input": "9222174 9829060 9418763 9955619 9092468",
"output": "NO"
},
{
"input": "70 70 1 2 50",
"output": "NO"
},
{
"input": "100 200 1 20 5",
"output": "YES"
},
{
"input": "1 200000 65536 65536 65537",
"output": "NO"
},
{
"input": "15 15 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "10 10 2 5 4",
"output": "NO"
},
{
"input": "67 69 7 7 9",
"output": "NO"
},
{
"input": "100000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "9 12 1 2 7",
"output": "NO"
},
{
"input": "5426234 6375745 2636512 8492816 4409404",
"output": "NO"
},
{
"input": "6134912 6134912 10000000 10000000 999869",
"output": "NO"
},
{
"input": "3 3 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 10 10000000 100000",
"output": "YES"
},
{
"input": "4 4 1 100 2",
"output": "YES"
},
{
"input": "8 13 1 4 7",
"output": "NO"
},
{
"input": "10 10 100000 10000000 10000000",
"output": "NO"
},
{
"input": "5 6 1 4 2",
"output": "YES"
},
{
"input": "1002 1003 1 2 1000",
"output": "NO"
},
{
"input": "4 5 1 2 2",
"output": "YES"
},
{
"input": "5 6 1 5 1",
"output": "YES"
},
{
"input": "15 21 2 4 7",
"output": "YES"
},
{
"input": "4 5 3 7 1",
"output": "YES"
},
{
"input": "15 15 3 4 4",
"output": "NO"
},
{
"input": "3 6 1 2 2",
"output": "YES"
},
{
"input": "2 10 3 6 3",
"output": "YES"
},
{
"input": "1 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "8 13 1 2 7",
"output": "NO"
},
{
"input": "98112 98112 100000 100000 128850",
"output": "NO"
},
{
"input": "2 2 1 2 1",
"output": "YES"
},
{
"input": "8 8 3 4 2",
"output": "YES"
},
{
"input": "60 60 2 3 25",
"output": "NO"
},
{
"input": "16 17 2 5 5",
"output": "NO"
},
{
"input": "2 4 1 3 1",
"output": "YES"
},
{
"input": "4 5 1 2 3",
"output": "NO"
},
{
"input": "10 10 3 4 3",
"output": "NO"
},
{
"input": "10 10000000 999999 10000000 300",
"output": "NO"
},
{
"input": "100 120 9 11 10",
"output": "YES"
},
{
"input": "8 20 1 3 4",
"output": "YES"
},
{
"input": "10 14 2 3 4",
"output": "YES"
},
{
"input": "2000 2001 1 3 1000",
"output": "YES"
},
{
"input": "12 13 2 3 5",
"output": "NO"
},
{
"input": "7 7 2 3 3",
"output": "NO"
},
{
"input": "5 8 1 10000000 4",
"output": "YES"
},
{
"input": "5 5 1 1 4",
"output": "NO"
},
{
"input": "5 5 1 6 2",
"output": "NO"
},
{
"input": "200 300 4000381 4000382 4000381",
"output": "NO"
},
{
"input": "11 17 2 5 2",
"output": "NO"
},
{
"input": "9999999 10000000 1 10000000 999997",
"output": "NO"
},
{
"input": "7 8 2 3 3",
"output": "NO"
},
{
"input": "7 7 3 3 2",
"output": "NO"
},
{
"input": "15 15 2 3 7",
"output": "NO"
},
{
"input": "65408 65408 859 859 10000000",
"output": "NO"
},
{
"input": "1000000 10000000 1 100000 1",
"output": "NO"
},
{
"input": "6 12 2 3 2",
"output": "YES"
},
{
"input": "7 8 1 3 3",
"output": "NO"
},
{
"input": "4 4 1 2 2",
"output": "YES"
},
{
"input": "2 3 1 2 2",
"output": "YES"
},
{
"input": "11 14 2 3 5",
"output": "NO"
},
{
"input": "7 7 1 10 3",
"output": "NO"
},
{
"input": "49 50 1 2 27",
"output": "NO"
},
{
"input": "1 10000000 1 10000000 123456",
"output": "YES"
},
{
"input": "100000 10000000 100 10000000 100000",
"output": "YES"
},
{
"input": "17 19 2 3 8",
"output": "NO"
},
{
"input": "4 6 3 9 1",
"output": "YES"
},
{
"input": "19 20 6 7 3",
"output": "NO"
},
{
"input": "5000000 10000000 1 4999999 1",
"output": "NO"
}
] | 1,610,522,194 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 1,331,200 | ins = input().split()
l = int(ins[0])
r = int(ins[1])
x = int(ins[2])
y = int(ins[3])
k = int(ins[4])
found=False;
for i in range(l, r+1):
for j in range(x, y+1):
if(i/j==k):
found=True
break
if(found==True):
print("YES")
else:
print("NO")
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions).
Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
Input Specification:
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Output Specification:
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register.
Demo Input:
['1 10 1 10 1\n', '1 5 6 10 1\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
ins = input().split()
l = int(ins[0])
r = int(ins[1])
x = int(ins[2])
y = int(ins[3])
k = int(ins[4])
found=False;
for i in range(l, r+1):
for j in range(x, y+1):
if(i/j==k):
found=True
break
if(found==True):
print("YES")
else:
print("NO")
``` | 0 |
|
296 | B | Yaroslav and Two Strings | PROGRAMMING | 2,000 | [
"combinatorics",
"dp"
] | null | null | Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents the *j*-th digit of string *w*.
A string's template is a string that consists of digits and question marks ("?").
Yaroslav has two string templates, each of them has length *n*. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.
Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109<=+<=7). | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format. | In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7). | [
"2\n90\n09\n",
"2\n11\n55\n",
"5\n?????\n?????\n"
] | [
"1\n",
"0\n",
"993531194\n"
] | The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | 1,500 | [
{
"input": "2\n90\n09",
"output": "1"
},
{
"input": "2\n11\n55",
"output": "0"
},
{
"input": "5\n?????\n?????",
"output": "993531194"
},
{
"input": "10\n104?3?1??3\n?1755?1??7",
"output": "91015750"
},
{
"input": "10\n6276405116\n6787?352?9",
"output": "46"
},
{
"input": "10\n0844033584\n0031021311",
"output": "0"
},
{
"input": "10\n???0?19?01\n957461????",
"output": "983368000"
},
{
"input": "10\n8703870339\n994987934?",
"output": "9"
},
{
"input": "10\n?8?528?91?\n45??06???1",
"output": "980398000"
},
{
"input": "10\n8030456630\n83406?6890",
"output": "5"
},
{
"input": "1\n?\n?",
"output": "0"
},
{
"input": "2\n12\n?9",
"output": "1"
},
{
"input": "3\n??1\n?12",
"output": "890"
},
{
"input": "3\n?12\n??1",
"output": "890"
},
{
"input": "5\n??15?\n?32??",
"output": "939500"
},
{
"input": "5\n??25?\n?32??",
"output": "812550"
},
{
"input": "5\n??55?\n?32??",
"output": "872950"
},
{
"input": "5\n?32??\n??55?",
"output": "872950"
}
] | 1,568,529,698 | 998 | PyPy 3 | WRONG_ANSWER | TESTS | 35 | 342 | 3,174,400 | #!/usr/bin/python3
def build(n, s, t):
ans = 1
for i in range(n):
if s[i] == '?' and t[i] == '?':
ans = (55 * ans) % (10 ** 9 + 7)
elif s[i] == '?':
ans = ((ord(t[i]) - ord('0') + 1) * ans) % (10 ** 9 + 7)
elif t[i] == '?':
ans = ((ord('9') - ord(s[i]) + 1) * ans) % (10 ** 9 + 7)
return ans
n = int(input())
s = input()
t = input()
sltt = True
tlts = True
qm = 0
cqm = 0
for i in range(n):
if t[i] == '?':
qm += 1
if s[i] == '?':
qm += 1
if t[i] == '?' or s[i] == '?':
cqm += 1
continue
if ord(s[i]) < ord(t[i]):
tlts = False
if ord(t[i]) < ord(s[i]):
sltt = False
if not sltt and not tlts:
print(pow(10, qm, 10 ** 9 + 7))
elif sltt and tlts:
print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t) - build(n, t, s) + pow(10, cqm, 10 ** 9 + 7)) % (10 ** 9 + 7))
elif sltt:
print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t)) % (10 ** 9 + 7))
else:
print((pow(10, qm, 10 ** 9 + 7) - build(n, t, s)) % (10 ** 9 + 7))
| Title: Yaroslav and Two Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents the *j*-th digit of string *w*.
A string's template is a string that consists of digits and question marks ("?").
Yaroslav has two string templates, each of them has length *n*. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.
Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109<=+<=7).
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format.
Output Specification:
In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7).
Demo Input:
['2\n90\n09\n', '2\n11\n55\n', '5\n?????\n?????\n']
Demo Output:
['1\n', '0\n', '993531194\n']
Note:
The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | ```python
#!/usr/bin/python3
def build(n, s, t):
ans = 1
for i in range(n):
if s[i] == '?' and t[i] == '?':
ans = (55 * ans) % (10 ** 9 + 7)
elif s[i] == '?':
ans = ((ord(t[i]) - ord('0') + 1) * ans) % (10 ** 9 + 7)
elif t[i] == '?':
ans = ((ord('9') - ord(s[i]) + 1) * ans) % (10 ** 9 + 7)
return ans
n = int(input())
s = input()
t = input()
sltt = True
tlts = True
qm = 0
cqm = 0
for i in range(n):
if t[i] == '?':
qm += 1
if s[i] == '?':
qm += 1
if t[i] == '?' or s[i] == '?':
cqm += 1
continue
if ord(s[i]) < ord(t[i]):
tlts = False
if ord(t[i]) < ord(s[i]):
sltt = False
if not sltt and not tlts:
print(pow(10, qm, 10 ** 9 + 7))
elif sltt and tlts:
print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t) - build(n, t, s) + pow(10, cqm, 10 ** 9 + 7)) % (10 ** 9 + 7))
elif sltt:
print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t)) % (10 ** 9 + 7))
else:
print((pow(10, qm, 10 ** 9 + 7) - build(n, t, s)) % (10 ** 9 + 7))
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,664,490,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | m,n = input("enter a value of m and n for domino separeted with space").split()
print((int(m)*int(n))//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m,n = input("enter a value of m and n for domino separeted with space").split()
print((int(m)*int(n))//2)
``` | 0 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,543,345,218 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | p=input()
w=[]
x = input()
y=x.split()
z=[int(i) for i in y ]
for i in (z) :
if i%2 == 1 :
w.append(1)
else:
w.append(0)
#print(w)
s=sum(w)
for t in range(len(w)-1) :
if (w[t]) != (w[t+1]) and w[t]>w[t+1] and s==1:
print(t+1)
break
elif (w[t]) != (w[t+1]) and w[t]<w[t+1] and s>1:
print(t+1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
p=input()
w=[]
x = input()
y=x.split()
z=[int(i) for i in y ]
for i in (z) :
if i%2 == 1 :
w.append(1)
else:
w.append(0)
#print(w)
s=sum(w)
for t in range(len(w)-1) :
if (w[t]) != (w[t+1]) and w[t]>w[t+1] and s==1:
print(t+1)
break
elif (w[t]) != (w[t+1]) and w[t]<w[t+1] and s>1:
print(t+1)
``` | 0 |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him! | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output": "97969 30664297 9597924961 "
},
{
"input": "5482 100347128000 342",
"output": "116964 40001688 13680577296 "
},
{
"input": "3680 37745933600 10",
"output": "10000 100000 1000000 10000000 100000000 1000000000 10000000000 "
},
{
"input": "17098 191120104800 43",
"output": "79507 3418801 147008443 6321363049 "
},
{
"input": "10462 418807699200 2",
"output": "16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 "
},
{
"input": "30061 641846400000 3",
"output": "59049 177147 531441 1594323 4782969 14348907 43046721 129140163 387420489 1162261467 3486784401 10460353203 31381059609 94143178827 282429536481 "
},
{
"input": "1 1000000000000000000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 2251799813685248 4503599627370496 900719925474099..."
},
{
"input": "32 2498039712000 4",
"output": "64 256 1024 4096 16384 65536 262144 1048576 4194304 16777216 67108864 268435456 1073741824 4294967296 17179869184 68719476736 274877906944 1099511627776 "
},
{
"input": "1 2576683920000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 "
},
{
"input": "5 25 5",
"output": "5 25 "
},
{
"input": "1 90 90",
"output": "1 90 "
},
{
"input": "95 2200128528000 68",
"output": "4624 314432 21381376 1453933568 98867482624 "
},
{
"input": "64 426314644000 53",
"output": "2809 148877 7890481 418195493 22164361129 "
},
{
"input": "198765 198765 198765",
"output": "198765 "
},
{
"input": "42 2845016496000 12",
"output": "144 1728 20736 248832 2985984 35831808 429981696 5159780352 61917364224 743008370688 "
},
{
"input": "6 6 3",
"output": "-1"
},
{
"input": "1 10 11",
"output": "1 "
},
{
"input": "2 10 11",
"output": "-1"
},
{
"input": "87 160 41",
"output": "-1"
},
{
"input": "237171123124584251 923523399718980912 7150",
"output": "-1"
},
{
"input": "101021572000739548 453766043506276015 8898",
"output": "-1"
},
{
"input": "366070689449360724 928290634811046396 8230",
"output": "-1"
},
{
"input": "438133886369772308 942612870269666780 7193",
"output": "-1"
},
{
"input": "10 10 10",
"output": "10 "
},
{
"input": "16 16 256",
"output": "-1"
},
{
"input": "1 1000000000000000000 1000000000",
"output": "1 1000000000 1000000000000000000 "
},
{
"input": "1000000000000000000 1000000000000000000 1000000000",
"output": "1000000000000000000 "
},
{
"input": "1000000000 1000000000000000000 1000000000",
"output": "1000000000 1000000000000000000 "
},
{
"input": "1 1 4",
"output": "1 "
},
{
"input": "1 999999999999999999 1000000000",
"output": "1 1000000000 "
},
{
"input": "1 1000000000000000000 999999990",
"output": "1 999999990 999999980000000100 "
},
{
"input": "1 1000000000000000000 999999984",
"output": "1 999999984 999999968000000256 "
},
{
"input": "1 1000000000000000000 324325",
"output": "1 324325 105186705625 34114678301828125 "
},
{
"input": "1 1000000000000000000 999999523",
"output": "1 999999523 999999046000227529 "
},
{
"input": "1 243 3",
"output": "1 3 9 27 81 243 "
},
{
"input": "62769392426654367 567152589733560993 688813",
"output": "326816522793383797 "
},
{
"input": "1 1000000000000000000 690852001",
"output": "1 690852001 477276487285704001 "
},
{
"input": "1 1000000000000000000 918745157",
"output": "1 918745157 844092663510954649 "
},
{
"input": "1 1000000000000000000 131299843",
"output": "1 131299843 17239648771824649 "
},
{
"input": "2861381721051425 2861381721051425 1234",
"output": "-1"
}
] | 1,657,763,265 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | def solve(a,b,c):
ans=[]
tmp=1
while tmp<=b:
if tmp>=a:
ans.append(tmp)
if tmp<=b//c+22:
tmp*=c
else:
break
if len(ans)==0:
return -1
fn=''
for i in range(len(ans)):
fn+=str(ans[i])
if i!=len(ans)-1:
fn+=" "
return fn
a,b,c=map(int,input().split())
print(solve(a,b,c))
| Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input Specification:
The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Output Specification:
Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Demo Input:
['1 10 2\n', '2 4 5\n']
Demo Output:
['1 2 4 8 ', '-1']
Note:
Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | ```python
def solve(a,b,c):
ans=[]
tmp=1
while tmp<=b:
if tmp>=a:
ans.append(tmp)
if tmp<=b//c+22:
tmp*=c
else:
break
if len(ans)==0:
return -1
fn=''
for i in range(len(ans)):
fn+=str(ans[i])
if i!=len(ans)-1:
fn+=" "
return fn
a,b,c=map(int,input().split())
print(solve(a,b,c))
``` | 3 |
|
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 1,381,003,193 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 218 | 7,065,600 | x=int(input())
y=[int(p) for p in input().split()]
temp=0
b=0
c=0
for ind,val in enumerate(y):
if(val==ind):
b+=1
elif(y[val]==ind):
c=2
elif(c==0):
c=1
print(b+c)
| Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Output Specification:
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
Demo Input:
['5\n0 1 3 4 2\n']
Demo Output:
['3\n']
Note:
none | ```python
x=int(input())
y=[int(p) for p in input().split()]
temp=0
b=0
c=0
for ind,val in enumerate(y):
if(val==ind):
b+=1
elif(y[val]==ind):
c=2
elif(c==0):
c=1
print(b+c)
``` | 3 |
|
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,584,635,789 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 170 | 819,200 | import string
n,k = map(int,input().split())
alpha = list(string.ascii_lowercase)[0:k:]
s = ''
cur_alpha = 0
for i in range(n):
s += alpha[cur_alpha]
cur_alpha = (cur_alpha + 1) % k
print(s) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | ```python
import string
n,k = map(int,input().split())
alpha = list(string.ascii_lowercase)[0:k:]
s = ''
cur_alpha = 0
for i in range(n):
s += alpha[cur_alpha]
cur_alpha = (cur_alpha + 1) % k
print(s)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1.
You would like to construct a sequence satisfying the properties:
- Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m* appears as an element of the input list. - The length of the sequence is maximized.
Construct any sequence satisfying the properties above. | The first line of input contains two integers *n* and *m* (0<=≤<=*n*<=<<=*m*<=≤<=200<=000) — the number of forbidden prefix products and the modulus.
If *n* is non-zero, the next line of input contains *n* distinct integers between 0 and *m*<=-<=1, the forbidden prefix products. If *n* is zero, this line doesn't exist. | On the first line, print the number *k*, denoting the length of your sequence.
On the second line, print *k* space separated integers, denoting your sequence. | [
"0 5\n",
"3 10\n2 9 1\n"
] | [
"5\n1 2 4 3 0\n",
"6\n3 9 2 9 8 0\n"
] | For the first case, the prefix products of this sequence modulo *m* are [1, 2, 3, 4, 0].
For the second case, the prefix products of this sequence modulo *m* are [3, 7, 4, 6, 8, 0]. | 0 | [
{
"input": "0 5",
"output": "5\n1 2 4 3 0"
},
{
"input": "3 10\n2 9 1",
"output": "6\n3 9 2 9 8 0"
},
{
"input": "0 1",
"output": "1\n0"
},
{
"input": "0 720",
"output": "397\n1 7 413 263 389 467 77 283 299 187 293 563 269 47 677 463 599 367 173 143 149 347 557 643 179 547 53 443 29 647 437 103 479 7 653 23 629 227 317 283 59 187 533 323 509 527 197 463 359 367 413 623 389 107 77 643 659 547 293 203 269 407 677 103 239 7 173 503 149 707 557 283 539 187 53 83 29 287 437 463 119 367 653 383 629 587 317 643 419 547 533 683 509 167 197 103 719 7 413 263 389 467 77 283 299 187 293 563 269 47 677 463 599 367 173 143 149 347 557 643 179 547 53 443 29 647 437 103 479 7 653 23 629 2..."
},
{
"input": "0 9997",
"output": "9985\n1 2 5000 6666 7499 4000 8332 8570 3750 5555 6999 5454 8332 9284 1334 6874 9410 2778 3158 3500 9522 7726 1305 4583 3600 8517 9641 3793 5666 646 8436 5151 9704 7713 6388 5675 3158 6749 1464 9760 466 8862 7110 653 7871 2292 9794 3400 9606 1510 4259 3091 4821 7718 1897 5762 7832 5737 5322 6507 8436 2576 6417 9851 3768 3857 9294 8193 7533 2838 2267 8288 1559 1393 3375 6172 5731 8914 9879 7881 5232 1265 9430 5168 7110 327 216 3936 8630 6145 1650 9896 5050 6699 5049 9900 3301 5904 5754 9344 2130 9356 1546 8..."
},
{
"input": "0 200000",
"output": "160625\n1 3 66669 114287 177779 18183 92309 164707 63159 104763 104349 125927 124139 167743 78789 145947 148719 195123 111629 12767 44899 54903 18869 154387 40679 95083 136509 38807 84059 143663 120549 174027 43039 108643 146989 108047 105619 178023 111829 28867 179799 19803 31069 164487 93579 181983 40709 182907 194959 92563 196749 192127 151939 59543 75189 140147 152519 70923 172029 14967 104699 194703 103269 44587 36479 178883 4909 97007 95859 51463 132949 80227 150839 120443 63389 142247 189419 173823 ..."
},
{
"input": "10 200000\n7853 79004 71155 23846 63333 31964 47634 15792 39758 55551",
"output": "160616\n1 3 66669 114287 177779 18183 92309 164707 63159 104763 104349 125927 124139 167743 78789 145947 148719 195123 111629 12767 44899 54903 18869 154387 40679 95083 136509 38807 84059 143663 120549 174027 43039 108643 146989 108047 105619 178023 111829 28867 179799 19803 31069 164487 93579 181983 40709 182907 194959 92563 196749 192127 151939 59543 75189 140147 152519 70923 172029 14967 104699 194703 103269 44587 36479 178883 4909 97007 95859 51463 132949 80227 150839 120443 63389 142247 189419 173823 ..."
},
{
"input": "3 19997\n4524 13719 9073",
"output": "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1..."
},
{
"input": "3 19997\n2024 4058 6143",
"output": "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1..."
},
{
"input": "3 19997\n6068 18563 12338",
"output": "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1..."
}
] | 1,692,655,848 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692655848.4074252")# 1692655848.4074426 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1.
You would like to construct a sequence satisfying the properties:
- Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m* appears as an element of the input list. - The length of the sequence is maximized.
Construct any sequence satisfying the properties above.
Input Specification:
The first line of input contains two integers *n* and *m* (0<=≤<=*n*<=<<=*m*<=≤<=200<=000) — the number of forbidden prefix products and the modulus.
If *n* is non-zero, the next line of input contains *n* distinct integers between 0 and *m*<=-<=1, the forbidden prefix products. If *n* is zero, this line doesn't exist.
Output Specification:
On the first line, print the number *k*, denoting the length of your sequence.
On the second line, print *k* space separated integers, denoting your sequence.
Demo Input:
['0 5\n', '3 10\n2 9 1\n']
Demo Output:
['5\n1 2 4 3 0\n', '6\n3 9 2 9 8 0\n']
Note:
For the first case, the prefix products of this sequence modulo *m* are [1, 2, 3, 4, 0].
For the second case, the prefix products of this sequence modulo *m* are [3, 7, 4, 6, 8, 0]. | ```python
print("_RANDOM_GUESS_1692655848.4074252")# 1692655848.4074426
``` | 0 |
|
221 | B | Little Elephant and Numbers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number. | A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109). | In a single line print an integer — the answer to the problem. | [
"1\n",
"10\n"
] | [
"1\n",
"2\n"
] | none | 1,000 | [
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "47",
"output": "1"
},
{
"input": "100",
"output": "5"
},
{
"input": "128",
"output": "6"
},
{
"input": "2",
"output": "1"
},
{
"input": "17",
"output": "2"
},
{
"input": "1000000",
"output": "41"
},
{
"input": "1000000000",
"output": "91"
},
{
"input": "4584725",
"output": "5"
},
{
"input": "999999999",
"output": "6"
},
{
"input": "9",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "20",
"output": "3"
},
{
"input": "24",
"output": "4"
},
{
"input": "48",
"output": "4"
},
{
"input": "2458450",
"output": "11"
},
{
"input": "97648850",
"output": "44"
},
{
"input": "96488450",
"output": "21"
},
{
"input": "879541",
"output": "7"
},
{
"input": "111111111",
"output": "5"
},
{
"input": "222222222",
"output": "6"
},
{
"input": "777777777",
"output": "9"
},
{
"input": "211768200",
"output": "244"
},
{
"input": "536870912",
"output": "29"
},
{
"input": "654885000",
"output": "698"
},
{
"input": "223092870",
"output": "479"
},
{
"input": "901800900",
"output": "639"
},
{
"input": "101871000",
"output": "460"
},
{
"input": "49",
"output": "1"
},
{
"input": "999999993",
"output": "5"
},
{
"input": "999999666",
"output": "8"
},
{
"input": "999999997",
"output": "6"
},
{
"input": "960690025",
"output": "8"
},
{
"input": "16",
"output": "2"
},
{
"input": "999000011",
"output": "2"
},
{
"input": "999999937",
"output": "1"
},
{
"input": "999999998",
"output": "6"
}
] | 1,622,829,598 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 1,228,800 | x=input()
n=int(x)
lst=[]
ans=[]
for i in range(1,n+1):
if(n%i==0):
lst.append(str(i))
for i in lst:
a_set = set(i)
b_set = set(x)
if (a_set & b_set):
ans.append(i)
print(len(ans))
| Title: Little Elephant and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number.
Input Specification:
A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
In a single line print an integer — the answer to the problem.
Demo Input:
['1\n', '10\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
x=input()
n=int(x)
lst=[]
ans=[]
for i in range(1,n+1):
if(n%i==0):
lst.append(str(i))
for i in lst:
a_set = set(i)
b_set = set(x)
if (a_set & b_set):
ans.append(i)
print(len(ans))
``` | 0 |
|
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,590,417,892 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 310 | 0 | def main():
N=int(input())
print(0,0,N)
if __name__=='__main__':
main() | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
def main():
N=int(input())
print(0,0,N)
if __name__=='__main__':
main()
``` | 3 |
|
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
{
"input": "10\nRLLRLRRRLL",
"output": "1 6\n2 7\n3 8\n9 4\n5 10"
},
{
"input": "12\nLRRRRRLRRRRL",
"output": "1 7\n2 8\n3 9\n4 10\n5 11\n12 6"
},
{
"input": "14\nRLLRLLLLRLLLRL",
"output": "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14"
},
{
"input": "16\nLLLRRRLRRLLRRLLL",
"output": "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8"
},
{
"input": "18\nRRRLLLLRRRLRLRLLRL",
"output": "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9"
},
{
"input": "20\nRLRLLRLRRLLRRRRRRLRL",
"output": "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20"
},
{
"input": "22\nRLLLRLLLRRLRRRLRLLLLLL",
"output": "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22"
},
{
"input": "24\nLRRRLRLLRLRRRRLLLLRRLRLR",
"output": "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24"
},
{
"input": "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR",
"output": "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26"
},
{
"input": "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL",
"output": "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14"
},
{
"input": "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL",
"output": "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30"
},
{
"input": "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR",
"output": "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32"
},
{
"input": "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR",
"output": "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34"
},
{
"input": "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL",
"output": "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18"
},
{
"input": "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL",
"output": "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38"
},
{
"input": "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL",
"output": "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40"
},
{
"input": "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR",
"output": "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42"
},
{
"input": "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR",
"output": "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44"
},
{
"input": "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL",
"output": "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46"
},
{
"input": "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL",
"output": "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50"
},
{
"input": "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52"
},
{
"input": "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54"
},
{
"input": "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56"
},
{
"input": "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL",
"output": "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58"
},
{
"input": "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL",
"output": "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60"
},
{
"input": "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR",
"output": "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62"
},
{
"input": "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL",
"output": "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64"
},
{
"input": "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR",
"output": "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66"
},
{
"input": "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL",
"output": "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34"
},
{
"input": "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70"
},
{
"input": "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72"
},
{
"input": "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74"
},
{
"input": "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76"
},
{
"input": "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78"
},
{
"input": "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL",
"output": "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80"
},
{
"input": "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR",
"output": "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82"
},
{
"input": "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR",
"output": "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84"
},
{
"input": "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR",
"output": "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86"
},
{
"input": "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR",
"output": "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88"
},
{
"input": "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90"
},
{
"input": "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92"
},
{
"input": "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94"
},
{
"input": "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96"
},
{
"input": "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98"
},
{
"input": "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100"
},
{
"input": "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL",
"output": "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100"
},
{
"input": "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50"
},
{
"input": "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR",
"output": "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100"
},
{
"input": "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR",
"output": "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR",
"output": "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100"
},
{
"input": "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50"
}
] | 1,621,755,177 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | 3 1
4 2
| Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.
Input Specification:
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Output Specification:
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.
Demo Input:
['6\nLLRLLL\n', '4\nRRLL\n']
Demo Output:
['1 4\n2 5\n6 3\n', '3 1\n4 2\n']
Note:
none | ```python
3 1
4 2
``` | -1 |
|
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 gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | 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 gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 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\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,480,936,256 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n=int(input())
s=[int(i) for i in input().split()]
s.sort()
k=0
for i in range(n):
k+=(n-i)*s[-(i+1)]
print(k+sum[s]-s[0])
| 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 the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
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.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
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 gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
n=int(input())
s=[int(i) for i in input().split()]
s.sort()
k=0
for i in range(n):
k+=(n-i)*s[-(i+1)]
print(k+sum[s]-s[0])
``` | -1 |
|
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 his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? | 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<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct. | 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 the contest. | 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\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 1,576,090,485 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 0 | n = int(input())
c = [map(int, input().split()[1:]) for _ in range(n)]
print('YES' if any([b > a >= 2400 for a, b in c]) else 'NO') | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
Input Specification:
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<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
Output Specification:
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
Demo Input:
['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n']
Demo Output:
['YES', 'NO']
Note:
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 the contest. | ```python
n = int(input())
c = [map(int, input().split()[1:]) for _ in range(n)]
print('YES' if any([b > a >= 2400 for a, b in c]) else 'NO')
``` | 3 |
|
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n0 1 1",
"output": "YES"
},
{
"input": "3\n0 1 0",
"output": "NO"
},
{
"input": "2\n0 1",
"output": "YES"
},
{
"input": "2\n1 0",
"output": "YES"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "10\n1 0 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5\n1 1 1 1 0",
"output": "YES"
},
{
"input": "4\n1 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 0 0",
"output": "NO"
},
{
"input": "10\n0 0 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "94\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "64\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "34\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "10\n1 1 0 1 1 1 0 1 1 1",
"output": "NO"
}
] | 1,520,047,240 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 62 | 5,632,000 | if __name__ == "__main__":
n, x = int(input()), [int(i) for i in input().split()]
if n == 1:
print('YES' if x[0] == 1 else 'NO')
else:
print('YES' if sum(x) == n-1 else 'NO')
| Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
Output Specification:
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Demo Input:
['3\n1 0 1\n', '3\n1 0 0\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
if __name__ == "__main__":
n, x = int(input()), [int(i) for i in input().split()]
if n == 1:
print('YES' if x[0] == 1 else 'NO')
else:
print('YES' if sum(x) == n-1 else 'NO')
``` | 3 |
|
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,671,874,459 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | n = int(input())
list1 = []
for i in range(0,n):
m = input()
if m not in list1:
print("NO")
list1.append(m)
else:
print("YES")
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | ```python
n = int(input())
list1 = []
for i in range(0,n):
m = input()
if m not in list1:
print("NO")
list1.append(m)
else:
print("YES")
``` | 3 |
|
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities. | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate. | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5 | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 100000 100000",
"output": "47052.10714286"
},
{
"input": "100 9 6\n109 711 40 95 935 48 228 253 308 726 816 534 252 8 966 363 162 508 84 83 807 506 748 178 45 30 106 108 764 698 825 198 336 353 158 790 64 262 403 334 577 571 742 541 946 602 279 621 910 776 421 886 29 133 114 394 762 965 339 263 750 530 49 80 124 31 322 292 27 590 960 278 111 932 849 491 561 744 469 511 106 271 156 160 836 363 149 473 457 543 976 809 490 29 85 626 265 88 995 946",
"output": "1849.66666667"
},
{
"input": "69 6 63\n53475 22876 79144 6335 33763 79104 65441 45527 65847 94406 74670 43529 75330 19403 67629 56187 57949 23071 64910 54409 55348 18056 855 24961 50565 6622 26467 33989 22660 79469 41246 13965 79706 14422 16075 93378 81313 48173 13470 97348 2346 27452 59427 29925 29847 73823 32021 10988 24609 98855 90919 45939 17203 8439 43007 40138 55693 30314 71734 33458 66850 4011 20089 20546 92090 50842 78859 62756 40177",
"output": "135712.88888889"
},
{
"input": "69 6 9\n2612 17461 69001 33130 10662 85485 88195 45974 16712 81365 67119 87797 15559 20197 74716 92979 97268 49466 68603 48351 99905 35606 54242 98603 68232 54398 82637 49647 38979 46171 54680 23334 15892 92186 69670 29711 67999 2220 32317 717 70667 68262 86760 55720 97158 61122 7251 138 21022 27197 12691 59331 13576 66999 38332 13574 83484 66646 17704 33065 98583 80259 64631 16745 69431 40747 82089 82788 32739",
"output": "183129.44444444"
}
] | 1,610,212,935 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n, n1, n2 = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
if n1>n2:
ans1 = 0
for i in range(n2):
ans1+=l[i]
ans2 = 0
for j in range(n2, n1+1):
ans2+=l[j]
ans = (ans1/n2)+(ans2/n1)
else:
ans1 = 0
for i in range(n1):
ans1+=l[i]
ans2 = 0
for j in range(n1, n2+1):
ans2+=l[j]
ans = (ans1/n1)+(ans2/n2)
print(ans)
| Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
Input Specification:
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate.
Output Specification:
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 1 1\n1 5\n', '4 2 1\n1 4 2 3\n']
Demo Output:
['6.00000000\n', '6.50000000\n']
Note:
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5 | ```python
n, n1, n2 = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
if n1>n2:
ans1 = 0
for i in range(n2):
ans1+=l[i]
ans2 = 0
for j in range(n2, n1+1):
ans2+=l[j]
ans = (ans1/n2)+(ans2/n1)
else:
ans1 = 0
for i in range(n1):
ans1+=l[i]
ans2 = 0
for j in range(n1, n2+1):
ans2+=l[j]
ans = (ans1/n1)+(ans2/n2)
print(ans)
``` | 0 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,630,499,462 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 124 | 20,172,800 | import math
print(math.factorial(min(map(int,input().split())))) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
import math
print(math.factorial(min(map(int,input().split()))))
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,669,003,009 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 0 | import sys
import math
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("./output.txt", "w")
string1 = input()
string2 = input()
if (string1 == string2[::-1]):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
import sys
import math
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("./output.txt", "w")
string1 = input()
string2 = input()
if (string1 == string2[::-1]):
print("YES")
else:
print("NO")
``` | 3.969 |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,416,410,352 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 0 | #TIME: 2014_11_19
#AUTHOR: Hermite_hy
#PROBLEM_ID: Codeforces_2A
#DESCRIPTION:
num = input()
player = {}
maxnum = -1
for i in range(int(num)):
name,score = input().split(" ")
if(name in player):
if(player[name] >= 0):
player[name] += int(score)
else:
player[name] = int(score)
for i in player:
if(maxnum < player[i]):
winner = i
maxnum = player[i]
print(winner)
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
#TIME: 2014_11_19
#AUTHOR: Hermite_hy
#PROBLEM_ID: Codeforces_2A
#DESCRIPTION:
num = input()
player = {}
maxnum = -1
for i in range(int(num)):
name,score = input().split(" ")
if(name in player):
if(player[name] >= 0):
player[name] += int(score)
else:
player[name] = int(score)
for i in player:
if(maxnum < player[i]):
winner = i
maxnum = player[i]
print(winner)
``` | -1 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,639,063,904 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n=int(input())
p=list()
for i in range(n):
p.append(int(input()))
p.sort()
q=1
for i in range(n-1):
if p[i]!=p[i+1]:
q+=1
else: continue
print(q)
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
n=int(input())
p=list()
for i in range(n):
p.append(int(input()))
p.sort()
q=1
for i in range(n-1):
if p[i]!=p[i+1]:
q+=1
else: continue
print(q)
``` | 0 |
|
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977",
"output": "23437499999999999/23437500000000000"
},
{
"input": "9 6 1",
"output": "1/9"
},
{
"input": "32 9 2",
"output": "3/32"
},
{
"input": "976 5 6",
"output": "41/244"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 714 345",
"output": "689/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 1173508 8918834",
"output": "1173507/329245015"
},
{
"input": "321076647734423976 7 7",
"output": "1/1"
},
{
"input": "455227494055672047 92 28",
"output": "19792499741550983/455227494055672047"
},
{
"input": "595779167455745259 6954 8697",
"output": "205511958419723/595779167455745259"
},
{
"input": "1000000000000000000 1000000000 2000000000",
"output": "1/2"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701",
"output": "33045955908448679/33045955908448702"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999",
"output": "2499999999999999/1000000000000000000"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999",
"output": "4999999549999999/2001500050002000000"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999",
"output": "29498980479974999/2451500050002000000"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "232 17 83",
"output": "2/29"
},
{
"input": "5496272 63 200",
"output": "13765/2748136"
},
{
"input": "180 174 53",
"output": "13/45"
},
{
"input": "1954 190 537",
"output": "189/1954"
},
{
"input": "146752429 510 514",
"output": "571199/146752429"
},
{
"input": "579312860 55 70",
"output": "10344881/144828215"
},
{
"input": "1 9 9",
"output": "1/1"
},
{
"input": "95 19 19",
"output": "1/1"
},
{
"input": "404 63 441",
"output": "31/202"
},
{
"input": "5566 4798 4798",
"output": "1/1"
},
{
"input": "118289676 570846883 570846883",
"output": "1/1"
},
{
"input": "763 358 358",
"output": "1/1"
},
{
"input": "85356138 7223 482120804",
"output": "3611/42678069"
},
{
"input": "674664088 435395270 5",
"output": "9/674664088"
},
{
"input": "762200126044291557 370330636048898430 6",
"output": "17/762200126044291557"
},
{
"input": "917148533938841535 47 344459175789842163",
"output": "28/183429706787768307"
},
{
"input": "360212127113008697 877228952036215545 5259",
"output": "5258/360212127113008697"
},
{
"input": "683705963104411677 89876390 116741460012229240",
"output": "539258339/683705963104411677"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339",
"output": "3959660298385016/573003994959686829"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955",
"output": "1/1"
},
{
"input": "19 1 19",
"output": "1/19"
},
{
"input": "576 18 32",
"output": "1/16"
},
{
"input": "9540 10 954",
"output": "1/477"
},
{
"input": "101997840 6 16999640",
"output": "1/8499820"
},
{
"input": "955944 1278 748",
"output": "1/639"
},
{
"input": "482120804 66748 7223",
"output": "1/66748"
},
{
"input": "370330636048898430 61721772674816405 6",
"output": "1/61721772674816405"
},
{
"input": "344459175789842163 7328918633826429 47",
"output": "1/7328918633826429"
},
{
"input": "877228952036215545 166805277055755 5259",
"output": "1/55601759018585"
},
{
"input": "116741460012229240 1298911316 89876390",
"output": "1/649455658"
},
{
"input": "275856334120822851 209 1319886766128339",
"output": "1/1319886766128339"
},
{
"input": "413850294331656955 1 413850294331656955",
"output": "1/413850294331656955"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 3931027 6443236",
"output": "357366/29931365"
},
{
"input": "321076647734423976 7 8",
"output": "1672274206950125/13378193655600999"
},
{
"input": "455227494055672047 71 60",
"output": "6411654845854559/455227494055672047"
},
{
"input": "595779167455745259 9741 9331",
"output": "61162012885196/595779167455745259"
},
{
"input": "6470 80 160",
"output": "327/647"
},
{
"input": "686325 828 1656",
"output": "114511/228775"
},
{
"input": "4535304 2129 4258",
"output": "755973/1511768"
},
{
"input": "40525189 6365 12730",
"output": "20265394/40525189"
},
{
"input": "675297075 25986 51972",
"output": "112553659/225099025"
},
{
"input": "5681598412 75376 226128",
"output": "1893897375/5681598412"
},
{
"input": "384118571739435733 619773000 1859319000",
"output": "128039524053435733/384118571739435733"
},
{
"input": "391554751752251913 625743359 1877230077",
"output": "130518250652782079/391554751752251913"
},
{
"input": "390728504279201198 625082797 1250165594",
"output": "195364252413988195/390728504279201198"
},
{
"input": "389902265396085075 624421544 1248843088",
"output": "64983710976697837/129967421798695025"
},
{
"input": "734812071040507372 857211800 2571635400",
"output": "61234339274051543/183703017760126843"
},
{
"input": "1 1 2",
"output": "0/1"
},
{
"input": "3 1 4",
"output": "0/1"
},
{
"input": "8 2 3",
"output": "3/8"
},
{
"input": "64 32 16",
"output": "1/2"
},
{
"input": "1 1 1000000000",
"output": "0/1"
},
{
"input": "1000000000 1 1",
"output": "1/1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1/1"
},
{
"input": "1000000000 2 4",
"output": "1/2"
},
{
"input": "1000000000 123 456",
"output": "6579023/1000000000"
},
{
"input": "1000000000 123123 654",
"output": "24851/1000000000"
},
{
"input": "123456 123 456",
"output": "215/30864"
},
{
"input": "123456 1234567 123",
"output": "61/61728"
},
{
"input": "314159265 271 8281",
"output": "37939/314159265"
},
{
"input": "11071994 4231 1324",
"output": "2647/11071994"
},
{
"input": "961748927 961748941 982451653",
"output": "1/1"
},
{
"input": "15485221 1259 90863",
"output": "1258/15485221"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963",
"output": "1249999999999999959/1250000000000000000"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887",
"output": "399999999999999969/400000000000000000"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737",
"output": "333333333333333236/333333333333333333"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991",
"output": "799999999999999968/799999999999999999"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029",
"output": "406156156156155948/406156156156156111"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931",
"output": "249999999999999963/250000000000000000"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229",
"output": "50505050505050462/50505050505050505"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391",
"output": "66473313998066456/66473313998066473"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573",
"output": "72842742705619241/72842742705619294"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213",
"output": "314159265358979166/314159265358979323"
},
{
"input": "10 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "5 100000000000000000 99999999999999999",
"output": "1/1"
},
{
"input": "5 1000000000000 1000000000001",
"output": "1/1"
},
{
"input": "5 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 10 11",
"output": "1/1"
},
{
"input": "10 123456789123456789 723456789123456781",
"output": "1/1"
},
{
"input": "12345678910 123456789101112131 123456789101112132",
"output": "1/1"
},
{
"input": "5 499999999999999999 499999999999999998",
"output": "1/1"
}
] | 1,446,314,444 | 5,444 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 46 | 0 | from sys import *
def gcd(a, b):
# print(a, b)
if (a == 0):
return b
elif (b == 0):
return a
elif (((a & 1) == 0) and ((b & 1) == 0)):
return 2*gcd(int(a/2), int(b/2))
elif ((a & 1) == 0):
return gcd(int(a/2), b)
elif ((b & 1) == 0):
return gcd(a, int(b/2))
else:
return gcd(max(a, b) - min(a, b), min(a, b));
(t, w, b) = map(int, (stdin.readline()).split())
y = gcd(b, w)
x = int(t/int(b*w/y))*min(b, w) + min(t%(int(b*w/y)) + 1, min(b, w)) - 1
#print(x, t)
a = gcd(x, t)
#print(a)
print(int(x/a), int(t/a), sep = '/') | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
Input Specification:
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Output Specification:
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*.
Demo Input:
['10 3 2\n', '7 1 2\n']
Demo Output:
['3/10\n', '3/7\n']
Note:
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | ```python
from sys import *
def gcd(a, b):
# print(a, b)
if (a == 0):
return b
elif (b == 0):
return a
elif (((a & 1) == 0) and ((b & 1) == 0)):
return 2*gcd(int(a/2), int(b/2))
elif ((a & 1) == 0):
return gcd(int(a/2), b)
elif ((b & 1) == 0):
return gcd(a, int(b/2))
else:
return gcd(max(a, b) - min(a, b), min(a, b));
(t, w, b) = map(int, (stdin.readline()).split())
y = gcd(b, w)
x = int(t/int(b*w/y))*min(b, w) + min(t%(int(b*w/y)) + 1, min(b, w)) - 1
#print(x, t)
a = gcd(x, t)
#print(a)
print(int(x/a), int(t/a), sep = '/')
``` | 0 |
|
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 1,586,881,383 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 140 | 512,000 | n, m, k = input().split()
m=int(m)
count=0
for j in range(10):
var=n+str(j)
if int(var)%m==0:
count=1
n=n+str(j)
break
if count==1:
print(str(n)+str(0)*(int(k)-1))
else:
print(-1)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
Input Specification:
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
Output Specification:
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Demo Input:
['5 4 5\n', '12 11 1\n', '260 150 10\n']
Demo Output:
['524848\n', '121\n', '-1\n']
Note:
none | ```python
n, m, k = input().split()
m=int(m)
count=0
for j in range(10):
var=n+str(j)
if int(var)%m==0:
count=1
n=n+str(j)
break
if count==1:
print(str(n)+str(0)*(int(k)-1))
else:
print(-1)
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | 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\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,689,998,652 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
xi,yi,zi = 0,0,0
for i in range(n):
x,y,z = map(int,input().split())
xi += x
yi += y
zi += z
if xi == 0 and yi == 0 and zi == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
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).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
xi,yi,zi = 0,0,0
for i in range(n):
x,y,z = map(int,input().split())
xi += x
yi += y
zi += z
if xi == 0 and yi == 0 and zi == 0:
print("YES")
else:
print("NO")
``` | 3.977 |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting. | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
{
"input": "10 3 4 5",
"output": "3"
},
{
"input": "100 23 15 50",
"output": "2"
},
{
"input": "3119 3515 1021 7",
"output": "11"
},
{
"input": "918 102 1327 1733",
"output": "9"
},
{
"input": "3164 42 430 1309",
"output": "15"
},
{
"input": "3043 317 1141 2438",
"output": "7"
},
{
"input": "26 1 772 2683",
"output": "26"
},
{
"input": "370 2 1 15",
"output": "370"
},
{
"input": "734 12 6 2",
"output": "367"
},
{
"input": "418 18 14 17",
"output": "29"
},
{
"input": "18 16 28 9",
"output": "2"
},
{
"input": "14 6 2 17",
"output": "7"
},
{
"input": "29 27 18 2",
"output": "2"
},
{
"input": "29 12 7 10",
"output": "3"
},
{
"input": "27 23 4 3",
"output": "9"
},
{
"input": "5 14 5 2",
"output": "1"
},
{
"input": "5 17 26 5",
"output": "1"
},
{
"input": "9 1 10 3",
"output": "9"
},
{
"input": "2 19 15 1",
"output": "2"
},
{
"input": "4 6 4 9",
"output": "1"
},
{
"input": "10 6 2 9",
"output": "5"
},
{
"input": "2 2 9 6",
"output": "1"
},
{
"input": "6 2 4 1",
"output": "6"
},
{
"input": "27 24 5 27",
"output": "1"
},
{
"input": "2683 83 26 2709",
"output": "101"
},
{
"input": "728 412 789 158",
"output": "3"
},
{
"input": "3964 4 2916 176",
"output": "991"
},
{
"input": "3399 2035 2 3334",
"output": "683"
},
{
"input": "3455 244 3301 3",
"output": "991"
},
{
"input": "595 2263 3625 1",
"output": "595"
},
{
"input": "4000 1 1 1",
"output": "4000"
},
{
"input": "3999 2 2 3999",
"output": "1"
},
{
"input": "25 6 8 11",
"output": "3"
},
{
"input": "4000 500 1000 2000",
"output": "8"
},
{
"input": "53 10 11 23",
"output": "5"
},
{
"input": "100 100 1 1",
"output": "100"
},
{
"input": "17 3 4 10",
"output": "5"
},
{
"input": "413 101 102 105",
"output": "4"
},
{
"input": "490 4 49 50",
"output": "111"
},
{
"input": "3999 2 3 3",
"output": "1999"
},
{
"input": "8 3 8 4",
"output": "2"
},
{
"input": "5 1 3 3",
"output": "5"
},
{
"input": "100 3 17 22",
"output": "27"
},
{
"input": "4000 2 3 4",
"output": "2000"
},
{
"input": "4000 3 3 5",
"output": "1332"
},
{
"input": "13 4 6 7",
"output": "2"
},
{
"input": "4000 5 2 2",
"output": "2000"
},
{
"input": "3999 2 2 3",
"output": "1999"
},
{
"input": "4000 33 7 3333",
"output": "564"
},
{
"input": "60 33 20 9",
"output": "4"
},
{
"input": "100 9 11 99",
"output": "10"
},
{
"input": "2009 6 8 9",
"output": "334"
}
] | 1,694,110,882 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n, a, b, c = map(int, input().split())
total = 0
lst = [a, b, c]
for i in range(len(lst)-1, -1, -1):
if n == 0:
print(total)
n -= lst[i]
total += 1
| Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
Input Specification:
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Output Specification:
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
Demo Input:
['5 5 3 2\n', '7 5 5 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | ```python
n, a, b, c = map(int, input().split())
total = 0
lst = [a, b, c]
for i in range(len(lst)-1, -1, -1):
if n == 0:
print(total)
n -= lst[i]
total += 1
``` | 0 |
|
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n1",
"output": "NO"
},
{
"input": "1 10 100\n100 10 1\n20",
"output": "NO"
},
{
"input": "1 1 1\n0 0 0\n1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1\n1",
"output": "YES"
},
{
"input": "5 5 5\n0 0 0\n2",
"output": "NO"
},
{
"input": "0 0 0\n10 10 10\n2",
"output": "NO"
},
{
"input": "21 61 39\n63 58 69\n44",
"output": "YES"
},
{
"input": "18 95 4\n7 1 75\n46",
"output": "YES"
},
{
"input": "64 27 81\n72 35 23\n48",
"output": "YES"
},
{
"input": "6 6 6\n11 11 11\n7",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n3",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n4",
"output": "YES"
},
{
"input": "99 99 99\n99 99 99\n89",
"output": "NO"
},
{
"input": "5 0 0\n15 0 0\n2",
"output": "NO"
},
{
"input": "10 10 10\n0 0 0\n1",
"output": "NO"
},
{
"input": "1 1 1\n1 1 1\n15",
"output": "YES"
},
{
"input": "2 3 5\n2 3 5\n2",
"output": "NO"
},
{
"input": "2 2 2\n3 3 5\n3",
"output": "NO"
},
{
"input": "1 2 2\n2 4 4\n1",
"output": "NO"
},
{
"input": "1 2 3\n1 5 5\n2",
"output": "NO"
}
] | 1,697,436,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # Read the counts of cups and medals for each prize level
cups = list(map(int, input().split()))
medals = list(map(int, input().split()))
n = int(input())
# Check if it's possible to arrange the rewards
def can_arrange_rewards(cups, medals, n):
if n < sum(cups) + 2 * sum(medals):
return "NO"
for i in range(3):
excess_cups = max(0, cups[i] - 5)
excess_medals = max(0, medals[i] - 10)
remaining_space = n - (cups[i] + medals[i])
total_excess = excess_cups + excess_medals
if total_excess > remaining_space:
return "NO"
return "YES"
result = can_arrange_rewards(cups, medals, n)
print(result)
| Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
Input Specification:
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
Output Specification:
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
Demo Input:
['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
# Read the counts of cups and medals for each prize level
cups = list(map(int, input().split()))
medals = list(map(int, input().split()))
n = int(input())
# Check if it's possible to arrange the rewards
def can_arrange_rewards(cups, medals, n):
if n < sum(cups) + 2 * sum(medals):
return "NO"
for i in range(3):
excess_cups = max(0, cups[i] - 5)
excess_medals = max(0, medals[i] - 10)
remaining_space = n - (cups[i] + medals[i])
total_excess = excess_cups + excess_medals
if total_excess > remaining_space:
return "NO"
return "YES"
result = can_arrange_rewards(cups, medals, n)
print(result)
``` | 0 |
|
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,565,843,221 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 10,342,400 | import math
n = int(input())
a = list(map(int , input().split()))
lcm = a[0]
for i in range(1,n):
lcm = (a[i] * lcm) // (math.gcd(a[i] , lcm))
# print(lcm)
# lcm = lcm // gcd
# print(lcm)
flag = "Yes"
for i in range(n):
if a[i] == lcm:
continue
bid = lcm // a[i]
while bid%2 == 0:
bid//=2
while bid%3 == 0:
bid//=3
if bid>1:
flag = "No"
break
print(flag) | Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
import math
n = int(input())
a = list(map(int , input().split()))
lcm = a[0]
for i in range(1,n):
lcm = (a[i] * lcm) // (math.gcd(a[i] , lcm))
# print(lcm)
# lcm = lcm // gcd
# print(lcm)
flag = "Yes"
for i in range(n):
if a[i] == lcm:
continue
bid = lcm // a[i]
while bid%2 == 0:
bid//=2
while bid%3 == 0:
bid//=3
if bid>1:
flag = "No"
break
print(flag)
``` | 0 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,696,931,175 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x=int(input())
n=(x//5)+1
print(str(n))
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
x=int(input())
n=(x//5)+1
print(str(n))
``` | 0 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,682,611,806 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 1,000 | 102,400 | t = int(input())
s = [int(i) for i in input().split()]
t1, t2, t3 = s.count(1), s.count(2), s.count(3)
print(min(t1, t2, t3))
if min(t1, t2, t3) != 0:
for i in range(min(t1, t2, t3)):
ans1 = [j for j, n in enumerate(s) if n == 1][i]
ans2 = [j for j, n in enumerate(s) if n == 2][i]
ans3 = [j for j, n in enumerate(s) if n == 3][i]
print(ans1+1, ans2+1, ans3+1) | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
t = int(input())
s = [int(i) for i in input().split()]
t1, t2, t3 = s.count(1), s.count(2), s.count(3)
print(min(t1, t2, t3))
if min(t1, t2, t3) != 0:
for i in range(min(t1, t2, t3)):
ans1 = [j for j, n in enumerate(s) if n == 1][i]
ans2 = [j for j, n in enumerate(s) if n == 2][i]
ans3 = [j for j, n in enumerate(s) if n == 3][i]
print(ans1+1, ans2+1, ans3+1)
``` | 0 |
|
550 | C | Divisibility by Eight | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"math"
] | null | null | You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it. | The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits. | Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any of them. | [
"3454\n",
"10\n",
"111111\n"
] | [
"YES\n344\n",
"YES\n0\n",
"NO\n"
] | none | 1,000 | [
{
"input": "3454",
"output": "YES\n344"
},
{
"input": "10",
"output": "YES\n0"
},
{
"input": "111111",
"output": "NO"
},
{
"input": "8996988892",
"output": "YES\n8"
},
{
"input": "5555555555",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188",
"output": "YES\n8"
},
{
"input": "8",
"output": "YES\n8"
},
{
"input": "14",
"output": "NO"
},
{
"input": "2363",
"output": "NO"
},
{
"input": "3554",
"output": "NO"
},
{
"input": "312",
"output": "YES\n32"
},
{
"input": "7674",
"output": "YES\n64"
},
{
"input": "126",
"output": "YES\n16"
},
{
"input": "344",
"output": "YES\n344"
},
{
"input": "976",
"output": "YES\n96"
},
{
"input": "3144",
"output": "YES\n344"
},
{
"input": "1492",
"output": "YES\n192"
},
{
"input": "1000",
"output": "YES\n0"
},
{
"input": "303",
"output": "YES\n0"
},
{
"input": "111111111111111111111171111111111111111111111111111112",
"output": "YES\n72"
},
{
"input": "3111111111111111111111411111111111111111111141111111441",
"output": "YES\n344"
},
{
"input": "7486897358699809313898215064443112428113331907121460549315254356705507612143346801724124391167293733",
"output": "YES\n8"
},
{
"input": "1787075866",
"output": "YES\n8"
},
{
"input": "836501278190105055089734832290981",
"output": "YES\n8"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "NO"
},
{
"input": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222",
"output": "NO"
},
{
"input": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333",
"output": "NO"
},
{
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "YES\n0"
},
{
"input": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"output": "NO"
},
{
"input": "66666666666666666666666666666666666666666666666666666666666666666666666666666",
"output": "NO"
},
{
"input": "88888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES\n8"
},
{
"input": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "NO"
},
{
"input": "353",
"output": "NO"
},
{
"input": "39",
"output": "NO"
},
{
"input": "3697519",
"output": "NO"
},
{
"input": "6673177113",
"output": "NO"
},
{
"input": "6666351371557713735",
"output": "NO"
},
{
"input": "17943911115335733153157373517",
"output": "NO"
},
{
"input": "619715515939999957957971971757533319177373",
"output": "NO"
},
{
"input": "4655797151375799393395377959959573533195153397997597195199777159133",
"output": "NO"
},
{
"input": "5531399953495399131957773999751571911139197159755793777773799119333593915333593153173775755771193715",
"output": "NO"
},
{
"input": "1319571733331774579193199551977735199771153997797535591739153377377111795579371959933533573517995559",
"output": "NO"
},
{
"input": "3313393139519343957311771319713797711159791515393917539133957799131393735795317131513557337319131993",
"output": "NO"
},
{
"input": "526",
"output": "YES\n56"
},
{
"input": "513",
"output": "NO"
},
{
"input": "674",
"output": "YES\n64"
},
{
"input": "8353",
"output": "YES\n8"
},
{
"input": "3957",
"output": "NO"
},
{
"input": "4426155776626276881222352363321488266188669874572115686737742545442766138617391954346963915982759371",
"output": "YES\n8"
},
{
"input": "9592419524227735697379444145348135927975358347769514686865768941989693174565893724972575152874281772",
"output": "YES\n8"
},
{
"input": "94552498866729239313265973246288189853135485783461",
"output": "YES\n8"
},
{
"input": "647934465937812",
"output": "YES\n8"
},
{
"input": "1327917795375366484539554526312125336",
"output": "YES\n8"
},
{
"input": "295971811535848297878828225646878276486982655866912496735794542",
"output": "YES\n8"
},
{
"input": "7217495392264549817889283233368819844137671271383133997418139697797385729777632527678136",
"output": "YES\n8"
},
{
"input": "11111111111111111111112111111111",
"output": "YES\n112"
},
{
"input": "262626262626262626262626262626262626",
"output": "NO"
},
{
"input": "1000000000000000000000000000000000000",
"output": "YES\n0"
},
{
"input": "9969929446",
"output": "YES\n96"
},
{
"input": "43523522125549722432232256557771715456345544922144",
"output": "YES\n32"
},
{
"input": "9344661521956564755454992376342544254667536539463277572111263273131199437332443253296774957",
"output": "YES\n96"
},
{
"input": "1946374341357914632311595531429723377642197432217137651552992479954116463332543456759911377223599715",
"output": "YES\n16"
},
{
"input": "461259",
"output": "NO"
},
{
"input": "461592",
"output": "YES\n152"
},
{
"input": "46159237",
"output": "YES\n152"
},
{
"input": "42367",
"output": "NO"
},
{
"input": "42376",
"output": "YES\n376"
},
{
"input": "42376159",
"output": "YES\n376"
},
{
"input": "444444444444444444444444444444666666666666666666666666666666222222222222222222222222222222",
"output": "NO"
},
{
"input": "0",
"output": "YES\n0"
},
{
"input": "33332",
"output": "YES\n32"
},
{
"input": "6499999999",
"output": "YES\n64"
}
] | 1,684,677,040 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # LUOGU_RID: 110981168
n = input().strip()
if int(n) % 8 == 0:
print(n)
exit()
for i in range(0, len(n)):
if int(n[i:i3]) % 8 == 0:
print(n[i:i+3])
exit()
for i in range(0, len(n)):
for j in range(i+1, len(n)):
if int(n[i] + n[j]) % 8 == 0:
print(n[i] + n])
exit()
print(-1)
| Title: Divisibility by Eight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it.
Input Specification:
The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
Output Specification:
Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any of them.
Demo Input:
['3454\n', '10\n', '111111\n']
Demo Output:
['YES\n344\n', 'YES\n0\n', 'NO\n']
Note:
none | ```python
# LUOGU_RID: 110981168
n = input().strip()
if int(n) % 8 == 0:
print(n)
exit()
for i in range(0, len(n)):
if int(n[i:i3]) % 8 == 0:
print(n[i:i+3])
exit()
for i in range(0, len(n)):
for j in range(i+1, len(n)):
if int(n[i] + n[j]) % 8 == 0:
print(n[i] + n])
exit()
print(-1)
``` | -1 |
|
87 | D | Beautiful Road | PROGRAMMING | 2,300 | [
"dfs and similar",
"dp",
"dsu",
"graphs",
"implementation",
"sortings",
"trees"
] | D. Beautiful Road | 1 | 256 | A long time ago in some country in Asia were civil wars.
Each of *n* cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.
Road making was difficult, so the country had few roads, exactly *n*<=-<=1. Also you could reach any city from any other city going on those roads.
Even during the war the Oriental people remain spiritually rich and appreciate the beauty of nature. And to keep the memory of this great crusade for the centuries to come, they planted one beautiful tree by the road on which the army spent most time. The Oriental people love nature, that's why if there were several such roads, then one tree was planted by each of them.
Recently, when the records of the war were found, it became clear that each city attacked each other one exactly once. There were exactly *n*(*n*<=-<=1) attacks in total. Everyone has been wondering what road after those wars became the most beautiful, that is, by which road they planted the largest number of beautiful trees. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105), which represents the number of cities. Next *n*<=-<=1 lines contain three integers each: the numbers of cities *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), connected by the *i*-th road and the number of days *d**i* the army spends to go on it (1<=≤<=*d**i*<=≤<=109). The lengths of several roads may coincide. | Print on the first line two integers — the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to *n*<=-<=1 in the order in which they are given in the input data.
Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator). | [
"2\n2 1 5\n",
"6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4\n"
] | [
"2 1\n1 \n",
"16 1\n2 \n"
] | none | 2,000 | [
{
"input": "2\n2 1 5",
"output": "2 1\n1 "
},
{
"input": "6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4",
"output": "16 1\n2 "
},
{
"input": "10\n10 6 43981\n4 2 6730\n1 2 35174\n5 3 61951\n8 7 43981\n7 1 6730\n5 8 6730\n9 3 52479\n6 4 18138",
"output": "32 1\n4 "
},
{
"input": "9\n6 4 72697\n9 6 72697\n1 6 38220\n2 6 38220\n6 7 72697\n6 5 72697\n8 6 72697\n3 6 38220",
"output": "16 5\n1 2 5 6 7 "
},
{
"input": "10\n9 2 18232\n3 4 45701\n3 9 13895\n8 9 18232\n7 6 56122\n3 5 45701\n7 1 56122\n8 10 18232\n2 7 91606",
"output": "42 1\n9 "
},
{
"input": "7\n1 2 7485\n6 7 50574\n3 1 50574\n3 4 50574\n5 6 58286\n6 1 58286",
"output": "24 1\n6 "
},
{
"input": "4\n2 3 1914\n4 1 31823\n4 2 26249",
"output": "6 1\n2 "
},
{
"input": "5\n3 2 72460\n3 4 69285\n3 5 69285\n1 3 11694",
"output": "8 1\n1 "
},
{
"input": "9\n5 9 29573\n7 3 72031\n8 5 72031\n6 7 72031\n9 7 27434\n3 2 27434\n4 7 76150\n1 9 27434",
"output": "24 1\n2 "
},
{
"input": "5\n5 4 58958\n2 1 37970\n2 5 37970\n1 3 37970",
"output": "8 2\n1 2 "
},
{
"input": "10\n6 5 30\n2 5 30\n7 8 81\n5 4 46\n9 10 30\n5 7 30\n10 2 46\n8 3 46\n1 10 46",
"output": "32 1\n3 "
},
{
"input": "10\n4 2 73\n10 8 73\n8 7 83\n9 5 83\n2 1 86\n4 9 88\n2 6 30\n8 4 30\n7 3 32",
"output": "32 1\n6 "
},
{
"input": "10\n9 4 75\n2 7 29\n1 8 19\n9 5 20\n4 1 19\n2 4 19\n10 3 29\n2 3 20\n6 4 29",
"output": "32 1\n1 "
},
{
"input": "10\n10 1 74\n8 1 43\n6 3 59\n2 9 58\n6 4 62\n6 7 74\n2 5 62\n1 6 74\n5 3 8",
"output": "42 1\n8 "
},
{
"input": "17\n6 16 69066\n2 5 77345\n7 17 49859\n11 15 77345\n14 2 96308\n3 5 49859\n10 13 16769\n4 17 58915\n15 1 99387\n1 3 77937\n6 8 53782\n13 14 21754\n9 4 49859\n12 8 96308\n11 9 96308\n12 7 96288",
"output": "140 1\n9 "
},
{
"input": "9\n1 6 802882924\n7 5 807576793\n9 4 343794537\n5 3 807576793\n2 7 394413002\n9 7 353519612\n1 7 784711994\n5 8 784711994",
"output": "36 1\n2 "
}
] | 1,675,405,990 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 47,923,200 | from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(s), get_root(t)
if not rs ^ rt:
return
if rank[s] == rank[t]:
rank[rs] += 1
if rank[s] >= rank[t]:
root[rt] = rs
size[rs] += size[rt]
else:
root[rs] = rt
size[rt] += size[rs]
return
def same(s, t):
return True if get_root(s) == get_root(t) else False
def get_size(s):
return size[get_root(s)]
def make_graph(n, m, x):
s = [0] * (n + 3)
for i in range(m):
u, v = x[2 * i], x[2 * i + 1]
s[u + 2] += 1
s[v + 2] += 1
for i in range(3, n + 3):
s[i] += s[i - 1]
G = [0] * (2 * m)
for i in range(2 * m):
j = x[i] + 1
G[s[j]] = x[i ^ 1]
s[j] += 1
return G, s
def bfs(u):
q, k = [u], 0
visit[u] = 1
while len(q) ^ k:
i = q[k]
for v in range(s0[i], s0[i + 1]):
j = G[v]
if not visit[j]:
q.append(j)
visit[j] = 1
parent[j] = i
k += 1
return q
n = int(input())
d = defaultdict(lambda : [])
for i in range(1, n):
a, b, c = map(int, input().split())
d[c].append((a, b, i))
root = [i for i in range(n + 1)]
rank = [1 for _ in range(n + 1)]
size = [1 for _ in range(n + 1)]
x = [0] * (n + 1)
color = [0] * (n + 1)
z = [0] * n
for c in sorted(d.keys()):
l = 0
s, y = [0], []
for a, b, _ in d[c]:
u, v = get_root(a), get_root(b)
if color[u] ^ c:
color[u], x[u] = c, l + 1
s.append(get_size(u))
l += 1
if color[v] ^ c:
color[v], x[v] = c, l + 1
s.append(get_size(v))
l += 1
e = dict()
for a, b, i in d[c]:
u, v = x[get_root(a)], x[get_root(b)]
e[(u, v)], e[(v, u)] = i, i
y.append(u)
y.append(v)
G, s0 = make_graph(n, len(y) // 2, y)
visit, parent = [0] * (l + 1), [-1] * (l + 1)
for i in range(1, l + 1):
if visit[i]:
continue
p = bfs(i)
cnt = 0
for j in p:
cnt += s[j]
for j in p[::-1][:-1]:
k = parent[j]
s[k] += s[j]
z[e[(j, k)]] = s[j] * (cnt - s[j])
for a, b, _ in d[c]:
unite(a, b)
m = max(z)
ans = []
for i in range(1, n):
if z[i] == m:
ans.append(i)
m *= 2
c = len(ans)
print(m, c)
sys.stdout.write(" ".join(map(str, ans))) | Title: Beautiful Road
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some country in Asia were civil wars.
Each of *n* cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.
Road making was difficult, so the country had few roads, exactly *n*<=-<=1. Also you could reach any city from any other city going on those roads.
Even during the war the Oriental people remain spiritually rich and appreciate the beauty of nature. And to keep the memory of this great crusade for the centuries to come, they planted one beautiful tree by the road on which the army spent most time. The Oriental people love nature, that's why if there were several such roads, then one tree was planted by each of them.
Recently, when the records of the war were found, it became clear that each city attacked each other one exactly once. There were exactly *n*(*n*<=-<=1) attacks in total. Everyone has been wondering what road after those wars became the most beautiful, that is, by which road they planted the largest number of beautiful trees.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105), which represents the number of cities. Next *n*<=-<=1 lines contain three integers each: the numbers of cities *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), connected by the *i*-th road and the number of days *d**i* the army spends to go on it (1<=≤<=*d**i*<=≤<=109). The lengths of several roads may coincide.
Output Specification:
Print on the first line two integers — the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to *n*<=-<=1 in the order in which they are given in the input data.
Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Demo Input:
['2\n2 1 5\n', '6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4\n']
Demo Output:
['2 1\n1 \n', '16 1\n2 \n']
Note:
none | ```python
from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(s), get_root(t)
if not rs ^ rt:
return
if rank[s] == rank[t]:
rank[rs] += 1
if rank[s] >= rank[t]:
root[rt] = rs
size[rs] += size[rt]
else:
root[rs] = rt
size[rt] += size[rs]
return
def same(s, t):
return True if get_root(s) == get_root(t) else False
def get_size(s):
return size[get_root(s)]
def make_graph(n, m, x):
s = [0] * (n + 3)
for i in range(m):
u, v = x[2 * i], x[2 * i + 1]
s[u + 2] += 1
s[v + 2] += 1
for i in range(3, n + 3):
s[i] += s[i - 1]
G = [0] * (2 * m)
for i in range(2 * m):
j = x[i] + 1
G[s[j]] = x[i ^ 1]
s[j] += 1
return G, s
def bfs(u):
q, k = [u], 0
visit[u] = 1
while len(q) ^ k:
i = q[k]
for v in range(s0[i], s0[i + 1]):
j = G[v]
if not visit[j]:
q.append(j)
visit[j] = 1
parent[j] = i
k += 1
return q
n = int(input())
d = defaultdict(lambda : [])
for i in range(1, n):
a, b, c = map(int, input().split())
d[c].append((a, b, i))
root = [i for i in range(n + 1)]
rank = [1 for _ in range(n + 1)]
size = [1 for _ in range(n + 1)]
x = [0] * (n + 1)
color = [0] * (n + 1)
z = [0] * n
for c in sorted(d.keys()):
l = 0
s, y = [0], []
for a, b, _ in d[c]:
u, v = get_root(a), get_root(b)
if color[u] ^ c:
color[u], x[u] = c, l + 1
s.append(get_size(u))
l += 1
if color[v] ^ c:
color[v], x[v] = c, l + 1
s.append(get_size(v))
l += 1
e = dict()
for a, b, i in d[c]:
u, v = x[get_root(a)], x[get_root(b)]
e[(u, v)], e[(v, u)] = i, i
y.append(u)
y.append(v)
G, s0 = make_graph(n, len(y) // 2, y)
visit, parent = [0] * (l + 1), [-1] * (l + 1)
for i in range(1, l + 1):
if visit[i]:
continue
p = bfs(i)
cnt = 0
for j in p:
cnt += s[j]
for j in p[::-1][:-1]:
k = parent[j]
s[k] += s[j]
z[e[(j, k)]] = s[j] * (cnt - s[j])
for a, b, _ in d[c]:
unite(a, b)
m = max(z)
ans = []
for i in range(1, n):
if z[i] == m:
ans.append(i)
m *= 2
c = len(ans)
print(m, c)
sys.stdout.write(" ".join(map(str, ans)))
``` | 0 |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
},
{
"input": "12 17\n10 19\n13 16",
"output": "-1"
},
{
"input": "11 11\n17 5\n12 10",
"output": "9 2\n8 3"
},
{
"input": "12 11\n11 12\n16 7",
"output": "-1"
},
{
"input": "5 9\n7 7\n8 6",
"output": "3 2\n4 5"
},
{
"input": "10 7\n4 13\n11 6",
"output": "-1"
},
{
"input": "18 10\n16 12\n12 16",
"output": "-1"
},
{
"input": "13 6\n10 9\n6 13",
"output": "-1"
},
{
"input": "14 16\n16 14\n18 12",
"output": "-1"
},
{
"input": "16 10\n16 10\n12 14",
"output": "-1"
},
{
"input": "11 9\n12 8\n11 9",
"output": "-1"
},
{
"input": "5 14\n10 9\n10 9",
"output": "-1"
},
{
"input": "2 4\n1 5\n3 3",
"output": "-1"
},
{
"input": "17 16\n14 19\n18 15",
"output": "-1"
},
{
"input": "12 12\n14 10\n16 8",
"output": "9 3\n5 7"
},
{
"input": "15 11\n16 10\n9 17",
"output": "7 8\n9 2"
},
{
"input": "8 10\n9 9\n13 5",
"output": "6 2\n3 7"
},
{
"input": "13 7\n10 10\n5 15",
"output": "4 9\n6 1"
},
{
"input": "14 11\n9 16\n16 9",
"output": "-1"
},
{
"input": "12 8\n14 6\n8 12",
"output": "-1"
},
{
"input": "10 6\n6 10\n4 12",
"output": "-1"
},
{
"input": "10 8\n10 8\n4 14",
"output": "-1"
},
{
"input": "14 13\n9 18\n14 13",
"output": "-1"
},
{
"input": "9 14\n8 15\n8 15",
"output": "-1"
},
{
"input": "3 8\n2 9\n6 5",
"output": "-1"
},
{
"input": "14 17\n18 13\n15 16",
"output": "-1"
},
{
"input": "16 14\n15 15\n17 13",
"output": "9 7\n6 8"
},
{
"input": "14 11\n16 9\n13 12",
"output": "9 5\n7 4"
},
{
"input": "13 10\n11 12\n7 16",
"output": "4 9\n7 3"
},
{
"input": "14 8\n11 11\n13 9",
"output": "8 6\n3 5"
},
{
"input": "12 11\n13 10\n10 13",
"output": "-1"
},
{
"input": "6 5\n2 9\n5 6",
"output": "-1"
},
{
"input": "7 8\n8 7\n12 3",
"output": "-1"
},
{
"input": "7 11\n7 11\n6 12",
"output": "-1"
},
{
"input": "8 5\n11 2\n8 5",
"output": "-1"
},
{
"input": "10 16\n14 12\n14 12",
"output": "-1"
},
{
"input": "7 9\n4 12\n5 11",
"output": "-1"
},
{
"input": "11 13\n19 5\n12 12",
"output": "-1"
},
{
"input": "8 12\n5 15\n11 9",
"output": "2 6\n3 9"
},
{
"input": "16 5\n13 8\n10 11",
"output": "9 7\n4 1"
},
{
"input": "3 14\n8 9\n10 7",
"output": "2 1\n6 8"
},
{
"input": "12 14\n11 15\n9 17",
"output": "3 9\n8 6"
},
{
"input": "13 7\n9 11\n14 6",
"output": "8 5\n1 6"
},
{
"input": "13 8\n15 6\n11 10",
"output": "9 4\n6 2"
},
{
"input": "9 6\n5 10\n3 12",
"output": "1 8\n4 2"
},
{
"input": "12 7\n5 14\n8 11",
"output": "3 9\n2 5"
},
{
"input": "9 12\n3 17\n10 10",
"output": "-1"
},
{
"input": "3 8\n4 6\n5 5",
"output": "-1"
}
] | 1,663,377,600 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 251,187,200 | '''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Help Vasilisa the Wise 2"
# Class: A
from itertools import permutations
import sys
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def Solve():
r1, r2 = list(map(int, input().split()))
c1, c2 = list(map(int, input().split()))
d1, d2 = list(map(int, input().split()))
list_ = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
e = True
while e:
x = list(permutations(list_))
for i in x:
a1, a2, a3, a4 = i[:4]
if c1 == a1 + a3 and c2 == a2 + a4 and r1 == a1 + a2 and r2 == a3 + a4 and d1 == a1 + a4 and d2 == a2 + a3:
print(a1, a2)
print(a3, a4)
e = False
break
# print(x)
if 10 in x[0] and e:
print(-1)
break
list_ = list(map(lambda x: x+1, list_))
if __name__ == "__main__":
Solve() | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input Specification:
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Output Specification:
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Demo Input:
['3 7\n4 6\n5 5\n', '11 10\n13 8\n5 16\n', '1 2\n3 4\n5 6\n', '10 10\n10 10\n10 10\n']
Demo Output:
['1 2\n3 4\n', '4 7\n9 1\n', '-1\n', '-1\n']
Note:
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | ```python
'''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Help Vasilisa the Wise 2"
# Class: A
from itertools import permutations
import sys
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def Solve():
r1, r2 = list(map(int, input().split()))
c1, c2 = list(map(int, input().split()))
d1, d2 = list(map(int, input().split()))
list_ = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
e = True
while e:
x = list(permutations(list_))
for i in x:
a1, a2, a3, a4 = i[:4]
if c1 == a1 + a3 and c2 == a2 + a4 and r1 == a1 + a2 and r2 == a3 + a4 and d1 == a1 + a4 and d2 == a2 + a3:
print(a1, a2)
print(a3, a4)
e = False
break
# print(x)
if 10 in x[0] and e:
print(-1)
break
list_ = list(map(lambda x: x+1, list_))
if __name__ == "__main__":
Solve()
``` | 0 |
|
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill. | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{
"input": "4\n4 5 4 4\n5\n5 3 4 2 4",
"output": "4"
},
{
"input": "1\n2\n1\n1",
"output": "1"
},
{
"input": "1\n3\n2\n3 2",
"output": "1"
},
{
"input": "1\n4\n3\n4 4 4",
"output": "1"
},
{
"input": "1\n2\n4\n3 1 4 2",
"output": "1"
},
{
"input": "1\n4\n5\n2 5 5 3 1",
"output": "1"
},
{
"input": "2\n2 2\n1\n2",
"output": "1"
},
{
"input": "2\n4 2\n2\n4 4",
"output": "1"
},
{
"input": "2\n4 1\n3\n2 3 2",
"output": "2"
},
{
"input": "2\n4 3\n4\n5 5 5 6",
"output": "1"
},
{
"input": "2\n5 7\n5\n4 6 7 2 5",
"output": "2"
},
{
"input": "3\n1 2 3\n1\n1",
"output": "1"
},
{
"input": "3\n5 4 5\n2\n2 1",
"output": "0"
},
{
"input": "3\n6 3 4\n3\n4 5 2",
"output": "3"
},
{
"input": "3\n7 7 7\n4\n2 7 2 4",
"output": "1"
},
{
"input": "3\n1 3 3\n5\n1 3 4 1 2",
"output": "3"
},
{
"input": "4\n1 2 1 3\n1\n4",
"output": "1"
},
{
"input": "4\n4 4 6 6\n2\n2 1",
"output": "0"
},
{
"input": "4\n3 1 1 1\n3\n1 6 7",
"output": "1"
},
{
"input": "4\n2 5 1 2\n4\n2 3 3 1",
"output": "3"
},
{
"input": "4\n9 1 7 1\n5\n9 9 9 8 4",
"output": "2"
},
{
"input": "5\n1 6 5 5 6\n1\n2",
"output": "1"
},
{
"input": "5\n5 2 4 5 6\n2\n7 4",
"output": "2"
},
{
"input": "5\n4 1 3 1 4\n3\n6 3 6",
"output": "1"
},
{
"input": "5\n5 2 3 1 4\n4\n1 3 1 7",
"output": "3"
},
{
"input": "5\n9 8 10 9 10\n5\n2 1 5 4 6",
"output": "0"
},
{
"input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6",
"output": "1"
},
{
"input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58",
"output": "0"
},
{
"input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96",
"output": "6"
},
{
"input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64",
"output": "9"
},
{
"input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1",
"output": "76"
},
{
"input": "4\n1 6 9 15\n2\n5 8",
"output": "2"
},
{
"input": "2\n2 4\n2\n3 1",
"output": "2"
},
{
"input": "3\n2 3 5\n3\n3 4 6",
"output": "3"
},
{
"input": "3\n1 3 4\n3\n2 1 5",
"output": "3"
},
{
"input": "2\n5 5\n4\n1 1 1 5",
"output": "1"
},
{
"input": "2\n3 2\n2\n3 4",
"output": "2"
},
{
"input": "2\n3 1\n2\n2 4",
"output": "2"
},
{
"input": "2\n2 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n10 12\n2\n11 9",
"output": "2"
},
{
"input": "3\n1 2 3\n3\n3 2 1",
"output": "3"
},
{
"input": "2\n1 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n4 5\n2\n5 3",
"output": "2"
},
{
"input": "2\n7 5\n2\n6 8",
"output": "2"
},
{
"input": "4\n4 3 2 1\n4\n1 2 3 4",
"output": "4"
},
{
"input": "2\n2 3\n2\n3 1",
"output": "2"
},
{
"input": "2\n2 4\n3\n3 1 8",
"output": "2"
},
{
"input": "3\n3 1 1\n3\n2 4 4",
"output": "2"
},
{
"input": "2\n5 3\n2\n4 6",
"output": "2"
},
{
"input": "4\n1 1 3 3\n4\n2 2 1 1",
"output": "4"
},
{
"input": "3\n3 2 1\n3\n2 4 3",
"output": "3"
},
{
"input": "5\n1 2 3 4 5\n5\n2 3 4 5 1",
"output": "5"
},
{
"input": "3\n3 2 1\n3\n1 2 3",
"output": "3"
},
{
"input": "2\n5 4\n2\n4 6",
"output": "2"
},
{
"input": "4\n3 3 5 5\n4\n4 4 2 2",
"output": "4"
},
{
"input": "3\n2 7 5\n3\n2 4 8",
"output": "3"
},
{
"input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5",
"output": "100"
},
{
"input": "1\n3\n2\n2 3",
"output": "1"
},
{
"input": "2\n5 6\n3\n1 5 100",
"output": "1"
},
{
"input": "2\n2 7\n2\n6 8",
"output": "1"
},
{
"input": "4\n4 10 15 17\n4\n3 12 16 16",
"output": "3"
},
{
"input": "2\n2 3\n2\n1 2",
"output": "2"
}
] | 1,690,868,921 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | n = int(input())
a = sorted(map(int,input().split()))
m = int(input())
b = sorted(map(int,input().split()))
c = 0
for i in range(len(a)):
for j in range(len(b)):
if abs(a[i]-b[j])<2:
b[j]=999
c += 1
break
print(c) | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill.
Output Specification:
Print a single number — the required maximum possible number of pairs.
Demo Input:
['4\n1 4 6 2\n5\n5 1 5 7 9\n', '4\n1 2 3 4\n4\n10 11 12 13\n', '5\n1 1 1 1 1\n3\n1 2 3\n']
Demo Output:
['3\n', '0\n', '2\n']
Note:
none | ```python
n = int(input())
a = sorted(map(int,input().split()))
m = int(input())
b = sorted(map(int,input().split()))
c = 0
for i in range(len(a)):
for j in range(len(b)):
if abs(a[i]-b[j])<2:
b[j]=999
c += 1
break
print(c)
``` | 3 |
|
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this. | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has. | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order. | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\n1 2 3 4 "
},
{
"input": "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89121 39568 28162",
"output": "8\n1 2 3 4 5 6 7 8 "
},
{
"input": "1 999999298\n85187",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 999999119\n34421",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n1",
"output": "44719\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "1 1000000000\n44720",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n44719",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n44721",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "3 1000000000\n123456789 234567891 345678912",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "2 5\n999999999 1000000000",
"output": "2\n1 2 "
},
{
"input": "2 1000000000\n1 1000000000",
"output": "44719\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "3 100000\n1000000000 100000000 1",
"output": "445\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 ..."
},
{
"input": "5 5\n100000000 200000000 300000000 400000000 1000000000",
"output": "2\n1 2 "
},
{
"input": "6 3\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "1 1000000000\n1000000000",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "5 1000000\n1000000000 100000000 10000000 99999999 123456789",
"output": "1413\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "2 10000000\n1234567 123456",
"output": "4471\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "1 1\n1000000000",
"output": "1\n1 "
},
{
"input": "1 1000000000\n9999999",
"output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "5 10000\n1000000000 888888888 777777777 666666666 959595959",
"output": "140\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 "
},
{
"input": "3 1\n1000000000 999999999 999999998",
"output": "1\n1 "
},
{
"input": "5 100000000\n100000000 999999999 1 2 3",
"output": "14138\n4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 15..."
},
{
"input": "3 55\n100000000 1000000000 999999999",
"output": "10\n1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "2 10\n5 10000009",
"output": "4\n1 2 3 4 "
},
{
"input": "3 10000000\n999999999 999999998 999999997",
"output": "4471\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "1 1100\n1000000000",
"output": "46\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 "
},
{
"input": "1 40\n1000000000",
"output": "8\n1 2 3 4 5 6 7 8 "
}
] | 1,528,456,122 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 102,400 | from collections import deque
def sum_fron_n_to_m(n, m):
sum = int(m + n) * int(m - n + 1) / 2
return int(sum)
tmp = input().rstrip("\n")
n, m = tmp.split(' ')
m = int(m)
tmp = input().rstrip("\n")
has = tmp.split(" ")
has = list(map(lambda x: int(x), has))
has.sort(reverse=True)
now = 0
spent = 0
ans = []
while (spent < m) and has:
i = int(has.pop())
if i - now < 2:
now = i
else:
potential = sum_fron_n_to_m(now+1, i-1)
if (spent + potential) <= m:
for x in range(now+1, i): ans.append(x)
spent += potential
now = i
else:
while(spent < m):
for x in range(now+1, i):
now = x
if spent + x < m:
ans.append(x)
spent+= x
else:
spent = m
break
if not has:
now += 1
while (spent + now) <= m:
ans.append(now)
spent += now
now += 1
print(len(ans))
print(' '.join(list(map(lambda x: str(x),ans))))
| Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
Input Specification:
The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has.
Output Specification:
In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order.
Demo Input:
['3 7\n1 3 4\n', '4 14\n4 6 12 8\n']
Demo Output:
['2\n2 5 \n', '4\n7 2 3 1\n']
Note:
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | ```python
from collections import deque
def sum_fron_n_to_m(n, m):
sum = int(m + n) * int(m - n + 1) / 2
return int(sum)
tmp = input().rstrip("\n")
n, m = tmp.split(' ')
m = int(m)
tmp = input().rstrip("\n")
has = tmp.split(" ")
has = list(map(lambda x: int(x), has))
has.sort(reverse=True)
now = 0
spent = 0
ans = []
while (spent < m) and has:
i = int(has.pop())
if i - now < 2:
now = i
else:
potential = sum_fron_n_to_m(now+1, i-1)
if (spent + potential) <= m:
for x in range(now+1, i): ans.append(x)
spent += potential
now = i
else:
while(spent < m):
for x in range(now+1, i):
now = x
if spent + x < m:
ans.append(x)
spent+= x
else:
spent = m
break
if not has:
now += 1
while (spent + now) <= m:
ans.append(now)
spent += now
now += 1
print(len(ans))
print(' '.join(list(map(lambda x: str(x),ans))))
``` | 0 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,608,626,376 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 409,600 | from collections import defaultdict
def sol(n,l):
d=defaultdict(int)
m=0
for i in l:
d[i]+=1
m=max(m,d[i])
return m
n=int(input())
l=list(map(int,input().split()))
print(sol(n,l))
| Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
from collections import defaultdict
def sol(n,l):
d=defaultdict(int)
m=0
for i in l:
d[i]+=1
m=max(m,d[i])
return m
n=int(input())
l=list(map(int,input().split()))
print(sol(n,l))
``` | 3 |
|
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,683,212,462 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, k = map(int, input().split())
sum = 240-k
i = 1
while(sum>5*i and i<=n):
sum = sum - 5*i
i = i + 1
print(i-1) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
n, k = map(int, input().split())
sum = 240-k
i = 1
while(sum>5*i and i<=n):
sum = sum - 5*i
i = i + 1
print(i-1)
``` | 0 |
|
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,691,766,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | import sys
nums = sys.stdin.readline().strip().split()
m = map(int, nums)
lst = list(m)
sortlst = sorted(lst)
mini = sortlst[0]
maxi = sortlst[2]
medi = sortlst[1]
place = (maxi - mini) / 2
point = mini + place
summ = point - mini
summ += (maxi - point)
if point < medi:
summ += (medi - point)
print(int(summ))
else:
summ += (point - medi)
print(int(summ)) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
import sys
nums = sys.stdin.readline().strip().split()
m = map(int, nums)
lst = list(m)
sortlst = sorted(lst)
mini = sortlst[0]
maxi = sortlst[2]
medi = sortlst[1]
place = (maxi - mini) / 2
point = mini + place
summ = point - mini
summ += (maxi - point)
if point < medi:
summ += (medi - point)
print(int(summ))
else:
summ += (point - medi)
print(int(summ))
``` | 0 |
|
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides. | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square. | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input": "5 1\n.\n*\n.\n.\n.",
"output": "*"
},
{
"input": "1 6\n*****.",
"output": "*****"
},
{
"input": "2 2\n..\n*.",
"output": "*"
},
{
"input": "8 2\n..\n..\n..\n..\n..\n*.\n..\n..",
"output": "*"
},
{
"input": "50 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*"
},
{
"input": "2 1\n*\n.",
"output": "*"
},
{
"input": "5 1\n*\n*\n*\n*\n*",
"output": "*\n*\n*\n*\n*"
},
{
"input": "2 2\n*.\n..",
"output": "*"
},
{
"input": "3 4\n...*\n*...\n..*.",
"output": "...*\n*...\n..*."
},
{
"input": "8 2\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "**\n**\n**\n**\n**\n**\n**\n**"
},
{
"input": "50 1\n.\n*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*\n.\n.\n.\n.\n.\n.",
"output": "*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*"
}
] | 1,598,444,219 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 204,800 | n, m =map(int, input().split())
a=[];p=[]
x=[];y=[]
for i in range(n):
s=input()
for j in range(m):
if s[j]=='*':
x+=[j];y+=[i]
p+=[s]
print(x)
print(y)
x0=min(x);x1=max(x)
y0=min(y);y1=max(y)
for i in range(y0,y1+1):
for j in range(x0, x1+1):
print(p[i][j],end="")
print("\n") | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input Specification:
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output Specification:
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Demo Input:
['6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n', '3 3\n***\n*.*\n***\n']
Demo Output:
['***\n*..\n***\n*..\n***\n', '***\n*.*\n***\n']
Note:
none | ```python
n, m =map(int, input().split())
a=[];p=[]
x=[];y=[]
for i in range(n):
s=input()
for j in range(m):
if s[j]=='*':
x+=[j];y+=[i]
p+=[s]
print(x)
print(y)
x0=min(x);x1=max(x)
y0=min(y);y1=max(y)
for i in range(y0,y1+1):
for j in range(x0, x1+1):
print(p[i][j],end="")
print("\n")
``` | 0 |
327 | C | Magic Five | PROGRAMMING | 1,700 | [
"combinatorics",
"math"
] | null | null | There is a long plate *s* containing *n* digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways he can obtain magic number, modulo 1000000007 (109<=+<=7). Two ways are different, if the set of deleted positions in *s* differs.
Look at the input part of the statement, *s* is given in a special form. | In the first line you're given a string *a* (1<=≤<=|*a*|<=≤<=105), containing digits only. In the second line you're given an integer *k* (1<=≤<=*k*<=≤<=109). The plate *s* is formed by concatenating *k* copies of *a* together. That is *n*<==<=|*a*|·*k*. | Print a single integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"1256\n1\n",
"13990\n2\n",
"555\n2\n"
] | [
"4\n",
"528\n",
"63\n"
] | In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of *a*. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 2<sup class="upper-index">6</sup> - 1 = 63 possible ways to delete digits. | 1,500 | [
{
"input": "1256\n1",
"output": "4"
},
{
"input": "13990\n2",
"output": "528"
},
{
"input": "555\n2",
"output": "63"
},
{
"input": "14\n178",
"output": "0"
},
{
"input": "27755776656210607832788619414635535178188775623838313967013958143619017005079991285469853503718562504927535176713879737569375166451462839457844835806559098448980069427607\n151",
"output": "319271478"
},
{
"input": "205831218776360805549796263726315728152440389522084825015113219980083245807721536032762703389\n161",
"output": "97770312"
},
{
"input": "58761716080256287618526160263668449282855983776878138369871377531384\n100",
"output": "48078375"
},
{
"input": "28626813825922172933379733204622160613220115755143268169598722697537715419\n184",
"output": "43220279"
},
{
"input": "0\n1000000000",
"output": "140625000"
},
{
"input": "079797897977\n1",
"output": "1"
}
] | 1,665,157,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | import sys
n = input()
ans = 0; r = 2**len(n); c = len(n)
d = int(sys.stdin.readline())
for x in range(c) :
if int(n[x])%5 == 0 : ans += ((1-(r**(d))) // (1-r) * 2**x) % 1000000007
print(ans ) | Title: Magic Five
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a long plate *s* containing *n* digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways he can obtain magic number, modulo 1000000007 (109<=+<=7). Two ways are different, if the set of deleted positions in *s* differs.
Look at the input part of the statement, *s* is given in a special form.
Input Specification:
In the first line you're given a string *a* (1<=≤<=|*a*|<=≤<=105), containing digits only. In the second line you're given an integer *k* (1<=≤<=*k*<=≤<=109). The plate *s* is formed by concatenating *k* copies of *a* together. That is *n*<==<=|*a*|·*k*.
Output Specification:
Print a single integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['1256\n1\n', '13990\n2\n', '555\n2\n']
Demo Output:
['4\n', '528\n', '63\n']
Note:
In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of *a*. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 2<sup class="upper-index">6</sup> - 1 = 63 possible ways to delete digits. | ```python
import sys
n = input()
ans = 0; r = 2**len(n); c = len(n)
d = int(sys.stdin.readline())
for x in range(c) :
if int(n[x])%5 == 0 : ans += ((1-(r**(d))) // (1-r) * 2**x) % 1000000007
print(ans )
``` | 0 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,690,451,186 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n = int(input())
teams = []
for i in range(n):
team = input()
teams.append(team)
for i in teams:
i = i.split(' ')
count = 0
for i in range(n):
for j in range(n):
if team[i][0] == team[j][1]:
count += 1
print(count) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
n = int(input())
teams = []
for i in range(n):
team = input()
teams.append(team)
for i in teams:
i = i.split(' ')
count = 0
for i in range(n):
for j in range(n):
if team[i][0] == team[j][1]:
count += 1
print(count)
``` | -1 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,633,410,903 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 6,758,400 | #aright this should be ez
L = int(input())
NumString = input()
NumList = [int(s) for s in NumString.split() if s.isdigit()]
EvenCount = 0
OddCount = 0
for i in range(L):
if NumList[i]%2 == 0 :
EvenCount += 1
if NumList[i]%2 == 1 :
OddCount += 1
print(abs(EvenCount - OddCount))
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
#aright this should be ez
L = int(input())
NumString = input()
NumList = [int(s) for s in NumString.split() if s.isdigit()]
EvenCount = 0
OddCount = 0
for i in range(L):
if NumList[i]%2 == 0 :
EvenCount += 1
if NumList[i]%2 == 1 :
OddCount += 1
print(abs(EvenCount - OddCount))
``` | 0 |
43 | B | Letter | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"abcdefg hijk\nk j i h g f e d c b a\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "NO"
},
{
"input": "abcdefg hijk\nk j i h g f e d c b a",
"output": "YES"
},
{
"input": "HpOKgo\neAtAVB",
"output": "NO"
},
{
"input": "GRZGc\nLPzD",
"output": "NO"
},
{
"input": "GtPXu\nd",
"output": "NO"
},
{
"input": "FVF\nr ",
"output": "NO"
},
{
"input": "HpOKgo\nogK",
"output": "YES"
},
{
"input": "GRZGc\nZG",
"output": "YES"
},
{
"input": "HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\nAHN XvoaNwV AVBKwKjr u U K wKE D K Jy KiHsR h d W Js IHyMPK Br iSqe E fDA g H",
"output": "YES"
},
{
"input": "GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj bCDgKF jJxa RddtLFAi VGLHH SecObzG q hPF ",
"output": "YES"
},
{
"input": "GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp",
"output": "YES"
},
{
"input": "FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\nUzrU K an GFGR Wc zt iBa P c T K v p V In b B c",
"output": "YES"
},
{
"input": "lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\nAoxe jWZ u yImg o AZ FNI w lpj tNhT g y ZYcb rc J w Dlv",
"output": "YES"
},
{
"input": "kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc",
"output": "YES"
},
{
"input": "kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\nBsH bWHJD n Ca T xq PRCv tatn Wjy sm I q s WCjFqdWe t W XUs Do eb Pfh ii hTbF O Fll",
"output": "YES"
},
{
"input": "OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK",
"output": "YES"
},
{
"input": "NwcGaIeSkOva\naIa",
"output": "YES"
},
{
"input": "gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui",
"output": "YES"
},
{
"input": "ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy",
"output": "NO"
},
{
"input": "hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW",
"output": "NO"
},
{
"input": "yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw",
"output": "NO"
},
{
"input": "jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL",
"output": "NO"
},
{
"input": "zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl",
"output": "NO"
},
{
"input": "kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh",
"output": "NO"
},
{
"input": "AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ",
"output": "NO"
},
{
"input": "lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl",
"output": "NO"
},
{
"input": "BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk",
"output": "NO"
},
{
"input": "KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk",
"output": "NO"
}
] | 1,571,647,452 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | s=input()
a=input()
for i in range(len(a)):
if a[i]!=' ':
if a.count(a[i])<=s.count(a[i]):
flag=1
else:
flag=0
print('NO')
break
if flag==1:
print('YES') | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input Specification:
The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output Specification:
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Demo Input:
['Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n', 'Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'abcdefg hijk\nk j i h g f e d c b a\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
s=input()
a=input()
for i in range(len(a)):
if a[i]!=' ':
if a.count(a[i])<=s.count(a[i]):
flag=1
else:
flag=0
print('NO')
break
if flag==1:
print('YES')
``` | 3.938 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,686,389,942 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
p = [int(x) for x in input().split()]
print(sum(p)/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
n = int(input())
p = [int(x) for x in input().split()]
print(sum(p)/n)
``` | 3 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1"
}
] | 1,682,262,599 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 280 | 0 | n=int(input())
a=list(map(int,input().split(' ')))
ret=[-1]*n
for i in range(n):
ret[a[i]-1]=i+1
print(' '.join(map(str,ret)))
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n=int(input())
a=list(map(int,input().split(' ')))
ret=[-1]*n
for i in range(n):
ret[a[i]-1]=i+1
print(' '.join(map(str,ret)))
``` | 3 |
|
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof". | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "YES\nwronganswer"
},
{
"input": "3\na\nb\nab",
"output": "NO"
},
{
"input": "2\nababaab\nabaab",
"output": "YES\nabaab\nababaab"
},
{
"input": "2\nq\nqq",
"output": "YES\nq\nqq"
},
{
"input": "5\nabab\nbab\nba\nab\na",
"output": "NO"
},
{
"input": "3\nb\nc\nd",
"output": "NO"
},
{
"input": "3\naba\nbab\nababa",
"output": "NO"
},
{
"input": "4\na\nba\nabacabac\nb",
"output": "NO"
},
{
"input": "4\nab\nba\nabab\na",
"output": "NO"
},
{
"input": "3\naaa\naab\naaab",
"output": "NO"
},
{
"input": "2\nac\nabac",
"output": "YES\nac\nabac"
},
{
"input": "2\na\nb",
"output": "NO"
},
{
"input": "3\nbaa\nbaaaaaaaab\naaaaaa",
"output": "NO"
},
{
"input": "3\naaab\naab\naaaab",
"output": "YES\naab\naaab\naaaab"
},
{
"input": "2\naaba\naba",
"output": "YES\naba\naaba"
},
{
"input": "10\na\nb\nc\nd\nab\nbc\ncd\nabc\nbcd\nabcd",
"output": "NO"
},
{
"input": "5\na\nab\nae\nabcd\nabcde",
"output": "NO"
},
{
"input": "3\nv\nab\nvab",
"output": "NO"
},
{
"input": "4\na\nb\nc\nabc",
"output": "NO"
},
{
"input": "2\nab\naab",
"output": "YES\nab\naab"
},
{
"input": "3\nabc\na\nc",
"output": "NO"
},
{
"input": "2\nabaab\nababaab",
"output": "YES\nabaab\nababaab"
},
{
"input": "3\ny\nxx\nxxy",
"output": "NO"
},
{
"input": "4\naaaa\naaaa\naaaa\nab",
"output": "NO"
},
{
"input": "3\nbad\naba\nabad",
"output": "NO"
},
{
"input": "3\nabcabc\nab\nbc",
"output": "NO"
},
{
"input": "2\naaaab\naaaaab",
"output": "YES\naaaab\naaaaab"
},
{
"input": "5\nab\naba\naba\naba\nabd",
"output": "NO"
},
{
"input": "4\nded\nd\ne\nd",
"output": "NO"
},
{
"input": "5\nekgetterherforme\ner\nter\nher\ntter",
"output": "NO"
},
{
"input": "3\naa\nbba\ncbba",
"output": "NO"
},
{
"input": "3\nab\naa\naab",
"output": "NO"
},
{
"input": "6\naaaa\naaaa\naaaa\naaaaab\nab\nab",
"output": "NO"
},
{
"input": "3\na\nbcd\nabcd",
"output": "NO"
},
{
"input": "3\naa\nab\naab",
"output": "NO"
},
{
"input": "3\nabcde\nab\ncde",
"output": "NO"
},
{
"input": "4\nanoop\np\nan\noop",
"output": "NO"
},
{
"input": "3\nab\ncd\nabcd",
"output": "NO"
},
{
"input": "3\nafaba\nafab\nfaba",
"output": "NO"
},
{
"input": "3\nababc\nabababc\nab",
"output": "YES\nab\nababc\nabababc"
},
{
"input": "3\na\nba\nbbab",
"output": "YES\na\nba\nbbab"
},
{
"input": "2\naabaa\naba",
"output": "YES\naba\naabaa"
},
{
"input": "3\nbc\nbca\na",
"output": "NO"
},
{
"input": "2\naba\nabba",
"output": "NO"
},
{
"input": "7\na\nb\nc\nab\nac\nac\nac",
"output": "NO"
},
{
"input": "2\naa\nmmmmmmmammmmmmmm",
"output": "NO"
}
] | 1,632,584,373 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 92 | 20,172,800 | N = int(input())
A = []
for x in range(N):
A.append(input())
A = sorted(A,key=len)
for i in range(len(A)-1):
A0 = []
for j in range(len(A[i+1])+1):
for k in range(j):
A0.append(A[i+1][k:j])
if A[i] not in A0:
print("NO")
break
else:
print("YES")
for l in A:
print(l)
break | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
Input Specification:
The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal.
Output Specification:
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order.
Demo Input:
['5\na\naba\nabacaba\nba\naba\n', '5\na\nabacaba\nba\naba\nabab\n', '3\nqwerty\nqwerty\nqwerty\n']
Demo Output:
['YES\na\nba\naba\naba\nabacaba\n', 'NO\n', 'YES\nqwerty\nqwerty\nqwerty\n']
Note:
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | ```python
N = int(input())
A = []
for x in range(N):
A.append(input())
A = sorted(A,key=len)
for i in range(len(A)-1):
A0 = []
for j in range(len(A[i+1])+1):
for k in range(j):
A0.append(A[i+1][k:j])
if A[i] not in A0:
print("NO")
break
else:
print("YES")
for l in A:
print(l)
break
``` | 0 |
|
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "0\n0\n3\n3\n3\n0\n3"
},
{
"input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969",
"output": "1\n1\n0\n1\n1\n1\n0\n1\n1"
},
{
"input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192",
"output": "4\n4\n4\n4"
},
{
"input": "1\n1\n1\n1000000000",
"output": "1"
},
{
"input": "1\n1\n1\n100005",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100005",
"output": "3"
},
{
"input": "2\n1 2\n3\n100004\n100005\n100006",
"output": "2\n2\n2"
},
{
"input": "3\n1 1 1\n1\n1",
"output": "3"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100000",
"output": "3"
},
{
"input": "5\n1 1 1 1 10\n2\n1\n10",
"output": "4\n5"
},
{
"input": "5\n3 10 8 6 11\n1\n10000000",
"output": "5"
}
] | 1,688,465,623 | 2,147,483,647 | Python 3 | OK | TESTS | 103 | 327 | 15,257,600 | from bisect import bisect_right
def count_shops(n, prices, q, coins):
prices.sort() # Sort the prices in ascending order
result = []
for c in coins:
count = bisect_right(prices, c) # Find the index to the right of c
result.append(count)
return result
# Read the input
n = int(input())
prices = list(map(int, input().split()))
q = int(input())
coins = [int(input()) for _ in range(q)]
# Calculate and print the number of shops for each day
result = count_shops(n, prices, q, coins)
for count in result:
print(count)
| Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Output Specification:
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
Demo Input:
['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n']
Demo Output:
['0\n4\n1\n5\n']
Note:
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | ```python
from bisect import bisect_right
def count_shops(n, prices, q, coins):
prices.sort() # Sort the prices in ascending order
result = []
for c in coins:
count = bisect_right(prices, c) # Find the index to the right of c
result.append(count)
return result
# Read the input
n = int(input())
prices = list(map(int, input().split()))
q = int(input())
coins = [int(input()) for _ in range(q)]
# Calculate and print the number of shops for each day
result = count_shops(n, prices, q, coins)
for count in result:
print(count)
``` | 3 |
|
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"output": "12"
},
{
"input": "25\ntcqpchnqskqjacruoaqilgebu",
"output": "7"
},
{
"input": "13\naebaecedabbee",
"output": "8"
},
{
"input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "10\nbababbdaee",
"output": "6"
},
{
"input": "11\ndbadcdbdbca",
"output": "7"
},
{
"input": "12\nacceaabddaaa",
"output": "7"
},
{
"input": "13\nabddfbfaeecfa",
"output": "7"
},
{
"input": "14\neeceecacdbcbbb",
"output": "9"
},
{
"input": "15\ndcbceaaggabaheb",
"output": "8"
},
{
"input": "16\nhgiegfbadgcicbhd",
"output": "7"
},
{
"input": "17\nabhfibbdddfghgfdi",
"output": "10"
},
{
"input": "26\nbbbbbabbaababaaabaaababbaa",
"output": "24"
},
{
"input": "26\nahnxdnbfbcrirerssyzydihuee",
"output": "11"
},
{
"input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc",
"output": "8"
},
{
"input": "26\nrvxmulriorilidecqwmfaemifj",
"output": "10"
},
{
"input": "26\naowpmreooavnmamogdoopuisge",
"output": "12"
},
{
"input": "26\ninimevtuefhvuefirdehmmfudh",
"output": "15"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25"
},
{
"input": "27\nqdcfjtblgglnilgassirrjekcjt",
"output": "-1"
},
{
"input": "27\nabcdefghijklmnopqrstuvwxyza",
"output": "-1"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "0"
},
{
"input": "5\nzzzzz",
"output": "4"
},
{
"input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa",
"output": "-1"
},
{
"input": "1\nq",
"output": "0"
},
{
"input": "27\nqwertyuioplkjhgfdsazxcvbnmm",
"output": "-1"
},
{
"input": "9\nxxxyyyzzz",
"output": "6"
},
{
"input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk",
"output": "-1"
},
{
"input": "27\nqwertyuiopasdfghjklzxcvbnmm",
"output": "-1"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxya",
"output": "1"
},
{
"input": "27\nabcdefghijklmnopqrstuvwxyzz",
"output": "-1"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25"
},
{
"input": "26\nqwertyuioplkjhgfdsazxcvbnm",
"output": "0"
},
{
"input": "10\nzzzzzzzzzz",
"output": "9"
},
{
"input": "1\na",
"output": "0"
},
{
"input": "30\nabcdefghtyabcdefghtyabcdefghty",
"output": "-1"
}
] | 1,599,989,732 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 171 | 819,200 | from collections import defaultdict
d=defaultdict(int)
n=int(input())
c=input()
if n>26:
print(-1)
else:
for char in c:
d[char]+=1
tot=0
for i in d.values():
tot+=(i-1)
print(tot)
| Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters.
Output Specification:
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
Demo Input:
['2\naa\n', '4\nkoko\n', '5\nmurat\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | ```python
from collections import defaultdict
d=defaultdict(int)
n=int(input())
c=input()
if n>26:
print(-1)
else:
for char in c:
d[char]+=1
tot=0
for i in d.values():
tot+=(i-1)
print(tot)
``` | 3 |
|
789 | B | Masha and geometric depression | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=><=1 the respective term satisfies the condition *b**i*<==<=*b**i*<=-<=1·*q*, where *q* is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both *b*1 and *q* can equal 0. Also, Dvastan gave Masha *m* "bad" integers *a*1,<=*a*2,<=...,<=*a**m*, and an integer *l*.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |*b**i*|<=≤<=*l* is satisfied (|*x*| means absolute value of *x*). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. | The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m* (-109<=≤<=*a**i*<=≤<=109) — numbers that will never be written on the board. | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | [
"3 2 30 4\n6 14 25 48\n",
"123 1 2143435 4\n123 11 -5453 141245\n",
"123 1 2143435 4\n54343 -13 6 124\n"
] | [
"3",
"0",
"inf"
] | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123. | 1,000 | [
{
"input": "3 2 30 4\n6 14 25 48",
"output": "3"
},
{
"input": "123 1 2143435 4\n123 11 -5453 141245",
"output": "0"
},
{
"input": "123 1 2143435 4\n54343 -13 6 124",
"output": "inf"
},
{
"input": "3 2 25 2\n379195692 -69874783",
"output": "4"
},
{
"input": "3 2 30 3\n-691070108 -934106649 -220744807",
"output": "4"
},
{
"input": "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250",
"output": "3"
},
{
"input": "-1000000000 -1000000000 1 1\n232512888",
"output": "0"
},
{
"input": "11 0 228 5\n-1 0 1 5 -11245",
"output": "1"
},
{
"input": "11 0 228 5\n-1 -17 1 5 -11245",
"output": "inf"
},
{
"input": "0 0 2143435 5\n-1 -153 1 5 -11245",
"output": "inf"
},
{
"input": "123 0 2143435 4\n5433 0 123 -645",
"output": "0"
},
{
"input": "123 -1 2143435 5\n-123 0 12 5 -11245",
"output": "inf"
},
{
"input": "123 0 21 4\n543453 -123 6 1424",
"output": "0"
},
{
"input": "3 2 115 16\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956",
"output": "1"
},
{
"input": "-3 0 92055 36\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317",
"output": "inf"
},
{
"input": "0 -3 2143435 5\n-1 0 1 5 -11245",
"output": "0"
},
{
"input": "123 -1 2143435 5\n-123 0 123 -5453 141245",
"output": "0"
},
{
"input": "123 0 2143435 4\n5433 0 -123 -645",
"output": "1"
},
{
"input": "11 0 2 5\n-1 0 1 5 -11245",
"output": "0"
},
{
"input": "2 2 4 1\n2",
"output": "1"
},
{
"input": "1 -2 1000000000 1\n0",
"output": "30"
},
{
"input": "0 8 10 1\n5",
"output": "inf"
},
{
"input": "-1000 0 10 1\n5",
"output": "0"
},
{
"input": "0 2 2143435 4\n54343 -13 6 124",
"output": "inf"
},
{
"input": "0 8 5 1\n9",
"output": "inf"
},
{
"input": "-10 1 5 1\n100",
"output": "0"
},
{
"input": "123 -1 2143435 4\n54343 -13 6 123",
"output": "inf"
},
{
"input": "-5 -1 10 1\n-5",
"output": "inf"
},
{
"input": "2 0 1 1\n2",
"output": "0"
},
{
"input": "0 5 8 1\n10",
"output": "inf"
},
{
"input": "0 5 100 2\n34 56",
"output": "inf"
},
{
"input": "15 -1 15 4\n15 -15 1 2",
"output": "0"
},
{
"input": "10 -1 2 1\n1",
"output": "0"
},
{
"input": "2 0 2 1\n2",
"output": "inf"
},
{
"input": "4 0 4 1\n0",
"output": "1"
},
{
"input": "10 10 10 1\n123",
"output": "1"
},
{
"input": "2 2 4 1\n3",
"output": "2"
},
{
"input": "0 1 1 1\n0",
"output": "0"
},
{
"input": "3 2 30 1\n3",
"output": "3"
},
{
"input": "1000000000 100000 1000000000 4\n5433 13 6 0",
"output": "1"
},
{
"input": "-2 0 1 1\n1",
"output": "0"
},
{
"input": "2 -1 10 1\n2",
"output": "inf"
},
{
"input": "1 -1 2 1\n1",
"output": "inf"
},
{
"input": "0 10 10 1\n2",
"output": "inf"
},
{
"input": "0 35 2 1\n3",
"output": "inf"
},
{
"input": "3 1 3 1\n5",
"output": "inf"
},
{
"input": "3 2 3 4\n6 14 25 48",
"output": "1"
},
{
"input": "0 69 12 1\n1",
"output": "inf"
},
{
"input": "100 0 100000 1\n100",
"output": "inf"
},
{
"input": "0 4 1000 3\n5 6 7",
"output": "inf"
},
{
"input": "0 2 100 1\n5",
"output": "inf"
},
{
"input": "3 2 24 4\n6 14 25 48",
"output": "3"
},
{
"input": "0 4 1 1\n2",
"output": "inf"
},
{
"input": "1 5 10000 1\n125",
"output": "5"
},
{
"input": "2 -1 1 1\n1",
"output": "0"
},
{
"input": "0 3 100 1\n5",
"output": "inf"
},
{
"input": "0 3 3 1\n1",
"output": "inf"
},
{
"input": "0 2 5 1\n1",
"output": "inf"
},
{
"input": "5 -1 100 1\n5",
"output": "inf"
},
{
"input": "-20 0 10 1\n0",
"output": "0"
},
{
"input": "3 0 1 1\n3",
"output": "0"
},
{
"input": "2 -1 3 1\n2",
"output": "inf"
},
{
"input": "1 1 1000000000 1\n100",
"output": "inf"
},
{
"input": "5 -1 3 1\n0",
"output": "0"
},
{
"input": "0 5 10 1\n2",
"output": "inf"
},
{
"input": "123 0 125 1\n123",
"output": "inf"
},
{
"input": "2 -1 100 1\n2",
"output": "inf"
},
{
"input": "5 2 100 1\n5",
"output": "4"
},
{
"input": "-5 0 1 1\n1",
"output": "0"
},
{
"input": "-3 0 1 1\n-3",
"output": "0"
},
{
"input": "2 -2 10 1\n1",
"output": "3"
},
{
"input": "0 2 30 4\n6 14 25 48",
"output": "inf"
},
{
"input": "1 -1 1 1\n1",
"output": "inf"
},
{
"input": "2 -1 6 1\n2",
"output": "inf"
},
{
"input": "-3 1 100 1\n-3",
"output": "0"
},
{
"input": "1 0 2 1\n1",
"output": "inf"
},
{
"input": "1000000000 999999998 1000000000 1\n0",
"output": "1"
},
{
"input": "1 0 2143435 4\n1 -123 -5453 141245",
"output": "inf"
},
{
"input": "-1000 0 100 1\n-1000",
"output": "0"
},
{
"input": "100 10 2 1\n100",
"output": "0"
},
{
"input": "-3 1 100 1\n3",
"output": "inf"
},
{
"input": "123 -1 10000 1\n123",
"output": "inf"
},
{
"input": "1 -1 2143435 4\n1 -123 -5453 141245",
"output": "inf"
},
{
"input": "5 1 5 5\n1 2 3 4 0",
"output": "inf"
},
{
"input": "-100 -1 1 1\n1",
"output": "0"
},
{
"input": "10 -1 3 2\n10 8",
"output": "0"
},
{
"input": "-10 0 5 1\n0",
"output": "0"
},
{
"input": "3 0 3 1\n0",
"output": "1"
},
{
"input": "2 0 2 1\n-1",
"output": "inf"
},
{
"input": "5 0 20 1\n5",
"output": "inf"
},
{
"input": "-4 1 1 1\n0",
"output": "0"
},
{
"input": "11 0 1111 1\n11",
"output": "inf"
},
{
"input": "2 0 3 1\n2",
"output": "inf"
},
{
"input": "-1 -1 2143435 4\n-1 -123 -5453 141245",
"output": "inf"
},
{
"input": "-100 0 50 1\n0",
"output": "0"
},
{
"input": "5 1 2 1\n2",
"output": "0"
},
{
"input": "3 0 3 1\n4",
"output": "inf"
},
{
"input": "0 23 3 1\n3",
"output": "inf"
},
{
"input": "-1000 0 100 1\n2",
"output": "0"
},
{
"input": "1 -1 10 1\n1",
"output": "inf"
}
] | 1,490,853,468 | 1,668 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 5,529,600 | import math
b, q, l, m = list(map(int,input().split(" ")))
a = set(map(int,input().split(" ")))
if q == 1:
if b in a:
ans = 0
else:
ans = "inf"
elif q == -1:
if b in a and -b in a:
ans = 0
else:
ans = "inf"
else:
# Finite progression
# b_n = b_1*q^(n-1): |b_n| <= l -> |b_1*q^(n-1)| <= l
# (log(l)-log(|b_1|))/ log(q) + 1 >= n
max_num = int((math.log(l) - math.log(abs(b))) / math.log(q) + 1)
# a/b == 0 mod (q)
bad_count = sum(map(lambda x: x <= l and (math.log(x/b)/math.log(q)) % 1 == 0, a))
# print(bad_count)
ans = max_num - bad_count
print(ans) | Title: Masha and geometric depression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=><=1 the respective term satisfies the condition *b**i*<==<=*b**i*<=-<=1·*q*, where *q* is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both *b*1 and *q* can equal 0. Also, Dvastan gave Masha *m* "bad" integers *a*1,<=*a*2,<=...,<=*a**m*, and an integer *l*.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |*b**i*|<=≤<=*l* is satisfied (|*x*| means absolute value of *x*). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input Specification:
The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m* (-109<=≤<=*a**i*<=≤<=109) — numbers that will never be written on the board.
Output Specification:
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Demo Input:
['3 2 30 4\n6 14 25 48\n', '123 1 2143435 4\n123 11 -5453 141245\n', '123 1 2143435 4\n54343 -13 6 124\n']
Demo Output:
['3', '0', 'inf']
Note:
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123. | ```python
import math
b, q, l, m = list(map(int,input().split(" ")))
a = set(map(int,input().split(" ")))
if q == 1:
if b in a:
ans = 0
else:
ans = "inf"
elif q == -1:
if b in a and -b in a:
ans = 0
else:
ans = "inf"
else:
# Finite progression
# b_n = b_1*q^(n-1): |b_n| <= l -> |b_1*q^(n-1)| <= l
# (log(l)-log(|b_1|))/ log(q) + 1 >= n
max_num = int((math.log(l) - math.log(abs(b))) / math.log(q) + 1)
# a/b == 0 mod (q)
bad_count = sum(map(lambda x: x <= l and (math.log(x/b)/math.log(q)) % 1 == 0, a))
# print(bad_count)
ans = max_num - bad_count
print(ans)
``` | -1 |
|
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,697,563,465 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 0 | s='QAQ'
s1=input()
dp=[[0 for i in range(len(s)+1)] for j in range(len(s1)+1)]
for i in range(len(s1)+1):
dp[i][0]=1
for i in range(1,len(s1)+1):
for j in range(1,len(s)+1):
dp[i][j]=dp[i-1][j]
if s1[i-1]==s[j-1]:
dp[i][j]=(dp[i][j]+dp[i-1][j-1])
print(dp[len(s1)][len(s)])
| Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
s='QAQ'
s1=input()
dp=[[0 for i in range(len(s)+1)] for j in range(len(s1)+1)]
for i in range(len(s1)+1):
dp[i][0]=1
for i in range(1,len(s1)+1):
for j in range(1,len(s)+1):
dp[i][j]=dp[i-1][j]
if s1[i-1]==s[j-1]:
dp[i][j]=(dp[i][j]+dp[i-1][j-1])
print(dp[len(s1)][len(s)])
``` | 3 |
|
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*). | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
{
"input": "70 38 66",
"output": "9"
},
{
"input": "54 4 38",
"output": "17"
},
{
"input": "3 1 69",
"output": "2"
},
{
"input": "11 9 60",
"output": "0"
},
{
"input": "71 49 65",
"output": "0"
},
{
"input": "78 55 96",
"output": "20"
},
{
"input": "2765 768 9020",
"output": "248635"
},
{
"input": "3478 1728 9727",
"output": "336578"
},
{
"input": "9678 6173 5658",
"output": "541409"
},
{
"input": "1138 570 6666",
"output": "75290"
},
{
"input": "7754 204 9038",
"output": "700603"
},
{
"input": "8403 7401 4769",
"output": "393339"
},
{
"input": "4909 2111 8860",
"output": "432827"
},
{
"input": "6571 6449 8965",
"output": "582642"
},
{
"input": "9178 2255 7996",
"output": "731618"
},
{
"input": "6151 6148 3746",
"output": "224269"
},
{
"input": "8890 5449 8734",
"output": "771004"
},
{
"input": "7879 2590 2818",
"output": "219441"
},
{
"input": "8484 6400 547",
"output": "40008"
},
{
"input": "7835 6710 1639",
"output": "121706"
},
{
"input": "2379 1436 9663",
"output": "228447"
},
{
"input": "6487 5670 8",
"output": "0"
},
{
"input": "4470 2543 6",
"output": "0"
},
{
"input": "7261 5328 10",
"output": "0"
},
{
"input": "3871 3795 7",
"output": "0"
},
{
"input": "9620 6557 6",
"output": "0"
},
{
"input": "4890 1112 5",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 1 10000",
"output": "99"
},
{
"input": "10000 1 1",
"output": "99"
},
{
"input": "10000 1 10000",
"output": "999999"
},
{
"input": "10000 10000 1",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "990000"
},
{
"input": "67 1 3",
"output": "2"
},
{
"input": "7878 4534 9159",
"output": "717013"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "3271 5 50",
"output": "1631"
}
] | 1,621,315,585 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | import math
n, x, y= [int(x) for x in input().split(" ")]
c=0
p= (x/n) * 100
if p>=y:
print(0)
else:
c= math.ceil((n*y)/100)
print(abs(c-x)) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | ```python
import math
n, x, y= [int(x) for x in input().split(" ")]
c=0
p= (x/n) * 100
if p>=y:
print(0)
else:
c= math.ceil((n*y)/100)
print(abs(c-x))
``` | 3 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,469,157,731 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import java.util.*;
public class LaunchOfCollider {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = Integer.parseInt(in.nextLine());
boolean found = false;
int ans = Integer.MAX_VALUE;
String directions = in.nextLine();
StringTokenizer s = new StringTokenizer(in.nextLine());
ArrayList<Integer> coordinates = new ArrayList<Integer>();
for(int i = 0; i < N; i++){
coordinates.add(Integer.parseInt(s.nextToken()));
if(i >= 1){
if(directions.substring(i-1,i+1).equals("RL")){
found = true;
if((coordinates.get(i).intValue() - coordinates.get(i-1).intValue())/2 < ans){
ans = (coordinates.get(i).intValue() - coordinates.get(i-1).intValue())/2;
}
}
}
}
if(!found){System.out.println("-1");}
else{System.out.println(ans);}
}
} | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
import java.util.*;
public class LaunchOfCollider {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = Integer.parseInt(in.nextLine());
boolean found = false;
int ans = Integer.MAX_VALUE;
String directions = in.nextLine();
StringTokenizer s = new StringTokenizer(in.nextLine());
ArrayList<Integer> coordinates = new ArrayList<Integer>();
for(int i = 0; i < N; i++){
coordinates.add(Integer.parseInt(s.nextToken()));
if(i >= 1){
if(directions.substring(i-1,i+1).equals("RL")){
found = true;
if((coordinates.get(i).intValue() - coordinates.get(i-1).intValue())/2 < ans){
ans = (coordinates.get(i).intValue() - coordinates.get(i-1).intValue())/2;
}
}
}
}
if(!found){System.out.println("-1");}
else{System.out.println(ans);}
}
}
``` | -1 |
|
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment. | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 100000",
"output": "Yes"
},
{
"input": "1 99989",
"output": "No"
},
{
"input": "512 2",
"output": "Yes"
},
{
"input": "100 24",
"output": "No"
},
{
"input": "1 100000",
"output": "No"
},
{
"input": "100000 1",
"output": "Yes"
},
{
"input": "3 99929",
"output": "No"
},
{
"input": "99961 99971",
"output": "No"
},
{
"input": "1 65536",
"output": "Yes"
},
{
"input": "4 65536",
"output": "Yes"
},
{
"input": "3 65536",
"output": "Yes"
},
{
"input": "32768 65536",
"output": "Yes"
},
{
"input": "65535 65536",
"output": "Yes"
},
{
"input": "1 65535",
"output": "No"
},
{
"input": "98812 100000",
"output": "No"
},
{
"input": "10 5",
"output": "Yes"
},
{
"input": "6 8",
"output": "Yes"
}
] | 1,661,614,901 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 31 | 0 | (a, m) = [int(i) for i in str(input()).split(" ")]
if m % 2 != 0 and a < m:
print("No")
else:
print("Yes")
| Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment.
Input Specification:
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Output Specification:
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Demo Input:
['1 5\n', '3 6\n']
Demo Output:
['No\n', 'Yes\n']
Note:
none | ```python
(a, m) = [int(i) for i in str(input()).split(" ")]
if m % 2 != 0 and a < m:
print("No")
else:
print("Yes")
``` | 0 |
|
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4 4 4 2"
},
{
"input": "1\n2000",
"output": "1"
},
{
"input": "2\n2000 2000",
"output": "1 1"
},
{
"input": "3\n500 501 502",
"output": "3 2 1"
},
{
"input": "10\n105 106 1 1 1 11 1000 999 1000 999",
"output": "6 5 8 8 8 7 1 3 1 3"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 5 4 3 2 1"
},
{
"input": "7\n6 5 4 3 2 1 1",
"output": "1 2 3 4 5 6 6"
},
{
"input": "8\n153 100 87 14 10 8 6 5",
"output": "1 2 3 4 5 6 7 8"
},
{
"input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10",
"output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63"
},
{
"input": "5\n1 2000 1 1 2000",
"output": "3 1 3 3 1"
}
] | 1,434,128,360 | 860 | Python 3 | OK | TESTS | 36 | 62 | 512,000 | n = int(input())
a = list(map(int, input().split()))
a = sorted([(a[i], i) for i in range(n)], reverse = True)
place = 1
ans = [(a[0][1], 1)]
for i in range(1, n):
if a[i][0] != a[i - 1][0]:
place = i + 1
ans.append((a[i][1], place))
ans.sort()
ans = [ans[i][1] for i in range(n)]
print(*ans) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
Output Specification:
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
Demo Input:
['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n']
Demo Output:
['3 1 1\n', '1\n', '4 1 4 3 1\n']
Note:
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | ```python
n = int(input())
a = list(map(int, input().split()))
a = sorted([(a[i], i) for i in range(n)], reverse = True)
place = 1
ans = [(a[0][1], 1)]
for i in range(1, n):
if a[i][0] != a[i - 1][0]:
place = i + 1
ans.append((a[i][1], place))
ans.sort()
ans = [ans[i][1] for i in range(n)]
print(*ans)
``` | 3 |
|
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other words he can learn a chapter of a particular subject in *x* hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the *n* subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type. | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 hours.
Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3",
"output": "196"
},
{
"input": "1 1\n9273",
"output": "9273"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 2\n1",
"output": "2"
},
{
"input": "1 2\n2",
"output": "4"
},
{
"input": "2 1\n1 2",
"output": "3"
}
] | 1,532,011,394 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 233 | 7,372,800 | n, x = map(int, input().split())
cs = list(map(int, input().split()))
cs.sort()
sol = 0
for c in cs:
sol += c * x
if x > 1:
x -= 1
print(sol)
| Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other words he can learn a chapter of a particular subject in *x* hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the *n* subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
Input Specification:
The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105).
Output Specification:
Output a single integer representing the answer to the problem.
Demo Input:
['2 3\n4 1\n', '4 2\n5 1 2 1\n', '3 3\n1 1 1\n']
Demo Output:
['11\n', '10\n', '6\n']
Note:
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 hours.
Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. | ```python
n, x = map(int, input().split())
cs = list(map(int, input().split()))
cs.sort()
sol = 0
for c in cs:
sol += c * x
if x > 1:
x -= 1
print(sol)
``` | 3 |
|
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$. | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,666,058,842 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 20,480,000 | def lit_len(a_list):
y=0
if len(a_list)!=1:
for j in range(int(len(a_list)/2)):
y+=a_list[2*j+1]-a_list[2*j]
return y
n,M=[int(a) for a in input().split()]
a_list=[0]+[int(b) for b in input().split()]+[M]
x_set={lit_len(a_list)}
for k in range(1,M):
if k not in a_list:
x_set.add(lit_len(sorted(a_list+[k])))
print(max(x_set)) | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | ```python
def lit_len(a_list):
y=0
if len(a_list)!=1:
for j in range(int(len(a_list)/2)):
y+=a_list[2*j+1]-a_list[2*j]
return y
n,M=[int(a) for a in input().split()]
a_list=[0]+[int(b) for b in input().split()]+[M]
x_set={lit_len(a_list)}
for k in range(1,M):
if k not in a_list:
x_set.add(lit_len(sorted(a_list+[k])))
print(max(x_set))
``` | 0 |
|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,686,385,956 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
a.sort()
result = ' '.join(map(str, a))
print(result)
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
result = ' '.join(map(str, a))
print(result)
``` | 3 |
|
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))",
"output": "28 1"
},
{
"input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))",
"output": "68 1"
},
{
"input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((",
"output": "80 1"
},
{
"input": "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))((",
"output": "92 1"
}
] | 1,535,001,817 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,496 | 26,931,200 | s = [-1]
l = 0
rep = 0
for i, c in enumerate(input()):
if c == '(':
s.append(i)
else:
if len(s) > 1:
s.pop()
temp = i - s[-1]
if temp > l:
l = temp
rep = 1
elif temp == l:
rep += 1
else:
s[0] = i
if l:
print (l, rep)
else :
print (0, 1)
| Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
Input Specification:
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Output Specification:
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
Demo Input:
[')((())))(()())\n', '))(\n']
Demo Output:
['6 2\n', '0 1\n']
Note:
none | ```python
s = [-1]
l = 0
rep = 0
for i, c in enumerate(input()):
if c == '(':
s.append(i)
else:
if len(s) > 1:
s.pop()
temp = i - s[-1]
if temp > l:
l = temp
rep = 1
elif temp == l:
rep += 1
else:
s[0] = i
if l:
print (l, rep)
else :
print (0, 1)
``` | 3.575837 |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
},
{
"input": "2\n8 2",
"output": "1 1"
},
{
"input": "3\n6 8 4",
"output": "1 2"
},
{
"input": "4\n4 3 2 8",
"output": "3 1"
},
{
"input": "5\n1 9 8 2 7",
"output": "2 3"
},
{
"input": "6\n1 4 7 3 2 1",
"output": "3 3"
},
{
"input": "11\n7 9 1 8 7 1 7 1 4 8 1",
"output": "4 7"
},
{
"input": "12\n4 2 7 1 9 5 6 2 7 8 5 7",
"output": "7 5"
},
{
"input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "7 6"
}
] | 1,677,317,999 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 |
n= int(input())
nums = list(map(int, input().split()))
preSum = []
postSum = [0] * n
sum_ = 0
for num in nums:
sum_ += num
preSum.append(sum_)
sum_ = 0
for indx in range(n-1,-1,-1):
sum_ += nums[indx]
postSum[indx] = sum_
left = 0
right = n - 1
print(preSum)
print(postSum)
while right >= left:
if preSum[left] > postSum[right]:
right -= 1
else:
left += 1
print(right + 1, n - left) | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Output Specification:
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
Demo Input:
['5\n2 9 8 2 7\n']
Demo Output:
['2 3\n']
Note:
none | ```python
n= int(input())
nums = list(map(int, input().split()))
preSum = []
postSum = [0] * n
sum_ = 0
for num in nums:
sum_ += num
preSum.append(sum_)
sum_ = 0
for indx in range(n-1,-1,-1):
sum_ += nums[indx]
postSum[indx] = sum_
left = 0
right = n - 1
print(preSum)
print(postSum)
while right >= left:
if preSum[left] > postSum[right]:
right -= 1
else:
left += 1
print(right + 1, n - left)
``` | 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* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. | 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 integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. | 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 81 2 67 52\n2\n2 40\n6 51",
"output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52"
},
{
"input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1",
"output": "0\n0"
},
{
"input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5",
"output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21"
},
{
"input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0",
"output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95"
},
{
"input": "1\n100\n1\n1 100",
"output": "0"
},
{
"input": "1\n100\n1\n1 1",
"output": "0"
},
{
"input": "1\n50\n1\n1 25",
"output": "0"
},
{
"input": "2\n50 0\n1\n1 1",
"output": "0\n49"
},
{
"input": "1\n10\n0",
"output": "10"
}
] | 1,546,616,352 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
t = [int(j) for j in input().split()]
m = int(input())
i = 0
while (i < m):
d = [int(j) for j in input().split()]
if (d[0] < n):
t[d[0]] += t[d[0] - 1] - d[1]
if (d[0] > 1):
t[d[0] - 2] += d[1] - 1
t[d[0] - 1] = 0
i += 1
i = 0
while (i < n):
print(t[i])
i += 1 | 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 other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
Input Specification:
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 integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
Output Specification:
On the *i*-th line of the output print the number of birds on the *i*-th wire.
Demo Input:
['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']
Demo Output:
['0\n12\n5\n0\n16\n', '3\n0\n3\n']
Note:
none | ```python
n = int(input())
t = [int(j) for j in input().split()]
m = int(input())
i = 0
while (i < m):
d = [int(j) for j in input().split()]
if (d[0] < n):
t[d[0]] += t[d[0] - 1] - d[1]
if (d[0] > 1):
t[d[0] - 2] += d[1] - 1
t[d[0] - 1] = 0
i += 1
i = 0
while (i < n):
print(t[i])
i += 1
``` | -1 |
|
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,690,400,151 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = int(input())
if n == 1:
print(-1)
elif n%2:
l = [i for i in range(1,n+1)][::-1]
mid = n//2
l[-1],l[mid]=l[mid],l[-1]
print(l)
else:
print([i for i in range(1,n+1)][::-1]) | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
n = int(input())
if n == 1:
print(-1)
elif n%2:
l = [i for i in range(1,n+1)][::-1]
mid = n//2
l[-1],l[mid]=l[mid],l[-1]
print(l)
else:
print([i for i in range(1,n+1)][::-1])
``` | 0 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,675,776,208 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | s=input()
s1="WUB"
res=""
i=3
wubCount=0
start=True
while(i<len(s)):
if s[i:i+3]==s1 and wubCount==0 and start==False:
res+=" "
i+=3
wubCount+=1
elif s[i:i+3]==s1 and wubCount==0 and start==True:
i+=3
elif s[i:i+3]==s1 and wubCount>0:
i+=3
wubCount+=1
else:
res+=s[i]
i+=1
wubCount=0
start=False
print(res)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
s=input()
s1="WUB"
res=""
i=3
wubCount=0
start=True
while(i<len(s)):
if s[i:i+3]==s1 and wubCount==0 and start==False:
res+=" "
i+=3
wubCount+=1
elif s[i:i+3]==s1 and wubCount==0 and start==True:
i+=3
elif s[i:i+3]==s1 and wubCount>0:
i+=3
wubCount+=1
else:
res+=s[i]
i+=1
wubCount=0
start=False
print(res)
``` | 0 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,695,121,695 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 109 | 0 | n=int(input())
s=input()
t='qwertyuiopasdfghjklzxcvbnm'
l=''
l=s.lower()
z=0;
m=''
m=set(l);
for i in m:
if i in t:
z+=1;
if z==len(t):
print('YES');
else:
print('NO');
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n=int(input())
s=input()
t='qwertyuiopasdfghjklzxcvbnm'
l=''
l=s.lower()
z=0;
m=''
m=set(l);
for i in m:
if i in t:
z+=1;
if z==len(t):
print('YES');
else:
print('NO');
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation.
Let's define the deviation of a permutation *p* as .
Find a cyclic shift of permutation *p* with minimum possible deviation. If there are multiple solutions, print any of them.
Let's denote id *k* (0<=≤<=*k*<=<<=*n*) of a cyclic shift of permutation *p* as the number of right shifts needed to reach this shift, for example:
- *k*<==<=0: shift *p*1,<=*p*2,<=... *p**n*, - *k*<==<=1: shift *p**n*,<=*p*1,<=... *p**n*<=-<=1, - ..., - *k*<==<=*n*<=-<=1: shift *p*2,<=*p*3,<=... *p**n*,<=*p*1. | First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation.
The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct. | Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them. | [
"3\n1 2 3\n",
"3\n2 3 1\n",
"3\n3 2 1\n"
] | [
"0 0\n",
"0 1\n",
"2 1\n"
] | In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift.
In the third sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts. | 0 | [
{
"input": "3\n1 2 3",
"output": "0 0"
},
{
"input": "3\n2 3 1",
"output": "0 1"
},
{
"input": "3\n3 2 1",
"output": "2 1"
},
{
"input": "2\n1 2",
"output": "0 0"
},
{
"input": "2\n2 1",
"output": "0 1"
},
{
"input": "10\n10 1 9 2 8 3 7 4 6 5",
"output": "24 7"
},
{
"input": "108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40 22 79 103 25 101 35 51 15 98 67 5 34 69 54 27 45 88 56 16 46 60 74 108 21 41 73 39 107 59 3 8 28 49 7 38",
"output": "3428 30"
},
{
"input": "4\n1 2 3 4",
"output": "0 0"
},
{
"input": "4\n1 2 4 3",
"output": "2 0"
},
{
"input": "4\n1 3 2 4",
"output": "2 0"
},
{
"input": "4\n1 3 4 2",
"output": "2 1"
},
{
"input": "4\n1 4 2 3",
"output": "4 0"
},
{
"input": "4\n1 4 3 2",
"output": "4 0"
},
{
"input": "4\n2 1 3 4",
"output": "2 0"
},
{
"input": "4\n2 1 4 3",
"output": "4 0"
},
{
"input": "4\n2 3 1 4",
"output": "4 0"
},
{
"input": "4\n2 3 4 1",
"output": "0 1"
},
{
"input": "4\n2 4 1 3",
"output": "2 2"
},
{
"input": "4\n2 4 3 1",
"output": "2 1"
},
{
"input": "4\n3 1 2 4",
"output": "2 3"
},
{
"input": "4\n3 1 4 2",
"output": "4 1"
},
{
"input": "4\n3 2 1 4",
"output": "4 0"
},
{
"input": "4\n3 2 4 1",
"output": "2 1"
},
{
"input": "4\n3 4 1 2",
"output": "0 2"
},
{
"input": "4\n3 4 2 1",
"output": "2 2"
},
{
"input": "4\n4 1 2 3",
"output": "0 3"
},
{
"input": "4\n4 1 3 2",
"output": "2 3"
},
{
"input": "4\n4 2 1 3",
"output": "2 3"
},
{
"input": "4\n4 2 3 1",
"output": "4 1"
},
{
"input": "4\n4 3 1 2",
"output": "2 2"
},
{
"input": "4\n4 3 2 1",
"output": "4 1"
},
{
"input": "10\n1 2 3 4 6 5 7 9 10 8",
"output": "6 0"
},
{
"input": "10\n1 2 10 9 7 4 8 3 6 5",
"output": "26 5"
},
{
"input": "10\n1 3 10 9 4 7 5 8 6 2",
"output": "22 1"
},
{
"input": "10\n1 4 10 8 9 2 3 6 7 5",
"output": "20 5"
},
{
"input": "10\n1 5 10 8 4 3 9 2 7 6",
"output": "26 6"
},
{
"input": "10\n1 6 10 7 9 5 3 8 4 2",
"output": "24 4"
},
{
"input": "10\n1 7 10 6 5 2 3 8 9 4",
"output": "26 6"
},
{
"input": "10\n1 8 10 6 2 4 9 3 7 5",
"output": "24 6"
},
{
"input": "10\n1 9 10 5 6 7 3 8 4 2",
"output": "26 1"
},
{
"input": "10\n1 10 9 5 3 2 4 7 8 6",
"output": "20 7"
},
{
"input": "10\n2 1 10 5 8 4 9 3 7 6",
"output": "28 0"
},
{
"input": "10\n2 3 10 5 4 8 6 9 7 1",
"output": "14 1"
},
{
"input": "10\n2 4 10 3 9 1 5 7 8 6",
"output": "28 0"
},
{
"input": "10\n2 5 10 3 6 4 9 1 8 7",
"output": "28 0"
},
{
"input": "10\n2 6 10 1 9 7 4 8 5 3",
"output": "28 1"
},
{
"input": "10\n2 7 10 1 6 3 4 8 9 5",
"output": "20 7"
}
] | 1,498,735,945 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 64,819,200 | def main():
n = int(input())
data = input().split()
#print(str(n) + " " + str(data))
data = list(map(lambda x: int(x), data))
res = 0
ires = 0
neg = 0
when = [0] * n
for i in range(n):
data[i] = i + 1 - data[i]
res += abs(data[i])
if data[i] <= 0:
neg += 1
a = -data[i]
if a < 0:
a = a + n
when[a] += 1
#print(when)
ares = res
#print(str(res) + " " + str(ires) + " " + str(neg))
for i in range(n):
neg -= when[i]
ares -= neg
ares += (n - neg)
x = data[n - i - 1] + i + 1
ares -= x
ares += n - x
#print(str(res) + " " + str(ires) + " " + str(ares) + " " + str(i) + " " + str(neg))
neg += 1
if ares < res:
res = ares
ires = i + 1
print(str(res) + " " + str(ires))
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation.
Let's define the deviation of a permutation *p* as .
Find a cyclic shift of permutation *p* with minimum possible deviation. If there are multiple solutions, print any of them.
Let's denote id *k* (0<=≤<=*k*<=<<=*n*) of a cyclic shift of permutation *p* as the number of right shifts needed to reach this shift, for example:
- *k*<==<=0: shift *p*1,<=*p*2,<=... *p**n*, - *k*<==<=1: shift *p**n*,<=*p*1,<=... *p**n*<=-<=1, - ..., - *k*<==<=*n*<=-<=1: shift *p*2,<=*p*3,<=... *p**n*,<=*p*1.
Input Specification:
First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation.
The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct.
Output Specification:
Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them.
Demo Input:
['3\n1 2 3\n', '3\n2 3 1\n', '3\n3 2 1\n']
Demo Output:
['0 0\n', '0 1\n', '2 1\n']
Note:
In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift.
In the third sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts. | ```python
def main():
n = int(input())
data = input().split()
#print(str(n) + " " + str(data))
data = list(map(lambda x: int(x), data))
res = 0
ires = 0
neg = 0
when = [0] * n
for i in range(n):
data[i] = i + 1 - data[i]
res += abs(data[i])
if data[i] <= 0:
neg += 1
a = -data[i]
if a < 0:
a = a + n
when[a] += 1
#print(when)
ares = res
#print(str(res) + " " + str(ires) + " " + str(neg))
for i in range(n):
neg -= when[i]
ares -= neg
ares += (n - neg)
x = data[n - i - 1] + i + 1
ares -= x
ares += n - x
#print(str(res) + " " + str(ires) + " " + str(ares) + " " + str(i) + " " + str(neg))
neg += 1
if ares < res:
res = ares
ires = i + 1
print(str(res) + " " + str(ires))
main()
``` | 0 |
|
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",
"output": "Yes"
},
{
"input": "365289629 223844571",
"output": "No"
},
{
"input": "247579518 361164458",
"output": "No"
},
{
"input": "424836699 793451637",
"output": "No"
},
{
"input": "602093880 930771525",
"output": "No"
},
{
"input": "779351061 773124120",
"output": "Yes"
},
{
"input": "661640950 836815080",
"output": "No"
},
{
"input": "543930839 974134967",
"output": "No"
},
{
"input": "16155311 406422145",
"output": "No"
},
{
"input": "81601559 445618240",
"output": "No"
},
{
"input": "963891449 582938127",
"output": "No"
},
{
"input": "141148629 351661795",
"output": "No"
},
{
"input": "318405810 783948974",
"output": "No"
},
{
"input": "495662991 921268861",
"output": "No"
},
{
"input": "1 0",
"output": "No"
},
{
"input": "0 1",
"output": "Yes"
},
{
"input": "0 0",
"output": "No"
},
{
"input": "453462237 167520068",
"output": "Yes"
},
{
"input": "630719418 9872663",
"output": "Yes"
},
{
"input": "807976599 442159843",
"output": "No"
},
{
"input": "690266488 579479730",
"output": "No"
},
{
"input": "771581370 589752968",
"output": "No"
},
{
"input": "948838551 727072855",
"output": "No"
},
{
"input": "831128440 790763814",
"output": "No"
},
{
"input": "303352912 928083702",
"output": "No"
},
{
"input": "185642801 65403588",
"output": "Yes"
},
{
"input": "67932690 202723476",
"output": "No"
},
{
"input": "540157163 340043363",
"output": "No"
},
{
"input": "422447052 772330542",
"output": "No"
},
{
"input": "599704233 541054210",
"output": "Yes"
},
{
"input": "481994122 678374097",
"output": "No"
},
{
"input": "48564714 743566477",
"output": "No"
},
{
"input": "225821895 880886365",
"output": "No"
},
{
"input": "403079076 313173543",
"output": "Yes"
},
{
"input": "1000000000 1000000000",
"output": "No"
},
{
"input": "1 1",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "No"
},
{
"input": "2 2",
"output": "No"
},
{
"input": "2 0",
"output": "No"
},
{
"input": "0 2",
"output": "No"
},
{
"input": "1000000000 1",
"output": "No"
},
{
"input": "777777 0",
"output": "No"
},
{
"input": "10 1",
"output": "No"
},
{
"input": "7 0",
"output": "No"
},
{
"input": "3 0",
"output": "No"
},
{
"input": "3 2",
"output": "Yes"
}
] | 1,571,480,618 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | x,y=map(int, input().split())
if x>=2 and x%2==0 and y>=x-1 and x%2!=0:
print("yes")
elif x>=3 and x%2!=0 and y>=x-1 and y%2==0:
print("yes")
elif x==1 and y==0:
print("yes")
else:
print("no")
| Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
Input Specification:
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Output Specification:
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['6 3\n', '4 2\n', '1000 1001\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | ```python
x,y=map(int, input().split())
if x>=2 and x%2==0 and y>=x-1 and x%2!=0:
print("yes")
elif x>=3 and x%2!=0 and y>=x-1 and y%2==0:
print("yes")
elif x==1 and y==0:
print("yes")
else:
print("no")
``` | 0 |
|
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,683,056,494 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | f=0
x=int(input())
for k in range(x):
d=int(input())
f=f+d
j=float(f/x)
print(j) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
f=0
x=int(input())
for k in range(x):
d=int(input())
f=f+d
j=float(f/x)
print(j)
``` | -1 |
|
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,531,915,455 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | gcd = lambda a, b: gcd(b, a % b) if b else a
n = int(input())
for a, b in zip(range((n - 1) // 2, 0, -1), range((n + 2) // 2, n)):
if gcd(a, b) == 1:
print(a, b)
break | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
gcd = lambda a, b: gcd(b, a % b) if b else a
n = int(input())
for a, b in zip(range((n - 1) // 2, 0, -1), range((n + 2) // 2, n)):
if gcd(a, b) == 1:
print(a, b)
break
``` | 3 |
|
593 | A | 2Char | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length. | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input. | Print a single integer — the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | 250 | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output": "0"
},
{
"input": "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg",
"output": "36"
},
{
"input": "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab",
"output": "36"
},
{
"input": "1\nabc",
"output": "0"
},
{
"input": "2\nabc\nbca",
"output": "0"
},
{
"input": "3\nab\nba\nzzz",
"output": "4"
},
{
"input": "3\nab\nba\nzzzzz",
"output": "5"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "37"
},
{
"input": "26\nq\nw\ne\nr\nt\ny\nu\ni\no\np\na\ns\nd\nf\ng\nh\nj\nk\nl\nz\nx\nc\nv\nb\nn\nm",
"output": "2"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaaf",
"output": "28"
},
{
"input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba",
"output": "0"
},
{
"input": "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml",
"output": "0"
},
{
"input": "5\nzloyfreid\ngraciocode\nschooldiary\nkazakov\nevgesha",
"output": "0"
},
{
"input": "4\nurkop\nvisualac\ngnutl\nwtf",
"output": "0"
},
{
"input": "3\naa\nb\nccc",
"output": "5"
},
{
"input": "3\na\nbd\ncaaaaaaa",
"output": "9"
},
{
"input": "4\naa\nax\nay\nxxxx",
"output": "8"
},
{
"input": "5\nc\nbb\ne\ndd\nf",
"output": "4"
},
{
"input": "2\naaaaa\naaaaa",
"output": "10"
}
] | 1,681,413,533 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | from itertools import combinations
import sys
n = int(input())
words = [input().strip() for _ in range(n)]
valid_words = [word for word in words if len(set(word)) <= 2]
max_length = 0
for selection in combinations(valid_words, len(valid_words) - 1):
selection_length = sum(len(word) for word in selection)
if selection_length > max_length:
max_length = selection_length
print(max_length)
| Title: 2Char
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
Input Specification:
The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Output Specification:
Print a single integer — the maximum possible total length of words in Andrew's article.
Demo Input:
['4\nabb\ncacc\naaa\nbbb\n', '5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n']
Demo Output:
['9', '6']
Note:
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | ```python
from itertools import combinations
import sys
n = int(input())
words = [input().strip() for _ in range(n)]
valid_words = [word for word in words if len(set(word)) <= 2]
max_length = 0
for selection in combinations(valid_words, len(valid_words) - 1):
selection_length = sum(len(word) for word in selection)
if selection_length > max_length:
max_length = selection_length
print(max_length)
``` | 0 |
|
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 1,695,142,973 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=input()
n=set([*a])
if len(n)%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!') | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
Input Specification:
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
Output Specification:
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Demo Input:
['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n']
Demo Output:
['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n']
Note:
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | ```python
n=input()
n=set([*a])
if len(n)%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | -1 |
|
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5",
"output": "0"
},
{
"input": "555 777 1 1000000",
"output": "257"
},
{
"input": "1000 1000 1 32323",
"output": "32"
},
{
"input": "45 125 93451125 100000000",
"output": "5821"
},
{
"input": "101 171 1 1000000000",
"output": "57900"
},
{
"input": "165 255 69696 1000000000",
"output": "356482"
},
{
"input": "555 777 666013 1000000000",
"output": "257229"
},
{
"input": "23 46 123321 900000000",
"output": "19562537"
},
{
"input": "321 123 15 1000000",
"output": "75"
},
{
"input": "819 1000 9532 152901000",
"output": "186"
},
{
"input": "819 1000 10000 1000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 1000003",
"output": "500001"
},
{
"input": "1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "10 15 69 195610342",
"output": "6520342"
},
{
"input": "2 1 1 1000000000",
"output": "500000000"
},
{
"input": "1000 1000 1 20",
"output": "0"
},
{
"input": "1 1 1 2000000000",
"output": "2000000000"
},
{
"input": "1 2 1 2000000000",
"output": "1000000000"
},
{
"input": "2 1 1 2000000000",
"output": "1000000000"
},
{
"input": "2 3 1 1000000000",
"output": "166666666"
},
{
"input": "2 3 1 2000000000",
"output": "333333333"
},
{
"input": "3 7 1 1000000000",
"output": "47619047"
},
{
"input": "1 1 1000000000 2000000000",
"output": "1000000001"
},
{
"input": "2 2 1 2000000000",
"output": "1000000000"
},
{
"input": "1 1 2 2000000000",
"output": "1999999999"
},
{
"input": "3 2 1 2000000000",
"output": "333333333"
},
{
"input": "1 1 2000000000 2000000000",
"output": "1"
},
{
"input": "2 3 7 7",
"output": "0"
},
{
"input": "3 3 3 7",
"output": "2"
}
] | 1,585,574,689 | 949 | Python 3 | OK | TESTS | 35 | 218 | 307,200 | x,y,a,b = map(int,input().strip().split())
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
j = lcm(x,y)
n1 = a//j + 1
if (n1-1)*j < a:
n1 += 1
n2 = b//j + 1
if (n2-1)*j > b:
n2 -= 1
print(int(n2 - n1 + 1)) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
Input Specification:
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output Specification:
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
Demo Input:
['2 3 6 18\n']
Demo Output:
['3']
Note:
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | ```python
x,y,a,b = map(int,input().strip().split())
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
j = lcm(x,y)
n1 = a//j + 1
if (n1-1)*j < a:
n1 += 1
n2 = b//j + 1
if (n2-1)*j > b:
n2 -= 1
print(int(n2 - n1 + 1))
``` | 3 |
|
865 | D | Buy Low Sell High | PROGRAMMING | 2,400 | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the *N* days you would like to again own zero shares, but want to have as much money as possible. | Input begins with an integer *N* (2<=≤<=*N*<=≤<=3·105), the number of days.
Following this is a line with exactly *N* integers *p*1,<=*p*2,<=...,<=*p**N* (1<=≤<=*p**i*<=≤<=106). The price of one share of stock on the *i*-th day is given by *p**i*. | Print the maximum amount of money you can end up with at the end of *N* days. | [
"9\n10 5 4 7 9 12 6 2 10\n",
"20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n"
] | [
"20\n",
"41\n"
] | In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20. | 2,000 | [
{
"input": "9\n10 5 4 7 9 12 6 2 10",
"output": "20"
},
{
"input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4",
"output": "41"
},
{
"input": "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19",
"output": "147"
},
{
"input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 24 179 243 92 115 56 83 26 3 456 622 325 366 360 299 153 140 552 216 117 61 307 278 189 496 562 38 527 566 503 303 16 36 286 632 196 395 452 194 77 321 615 356 250 381 174 139 123",
"output": "13765"
},
{
"input": "20\n499559 302871 194704 903169 447219 409938 42087 753609 589270 719332 855199 609182 315644 980473 966759 851389 900793 905536 258772 453222",
"output": "4620235"
},
{
"input": "47\n403136 169462 358897 935260 150614 688938 111490 148144 462915 753991 551831 303917 772190 188564 854800 7094 491120 997932 271873 236736 797113 427200 681780 911765 217707 339475 313125 56785 749677 313468 902148 993064 747609 387815 768631 41886 68862 707668 32853 653517 941150 858711 562604 867235 840369 337814 129019",
"output": "12525965"
},
{
"input": "2\n4 77",
"output": "73"
}
] | 1,697,771,604 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 467 | 26,931,200 | import heapq
n = int(input())
prices = [int(i) for i in input().split()]
#print(prices)
sells = [-prices[-1]]
bought = set()
profit = 0
for i in range(len(prices) - 2,-1,-1):
sell = -sells[0]
buy = prices[i]
if buy < sell:
heapq.heappop(sells)
profit += sell - buy
bought.add(buy)
if sell in bought:
heapq.heappush(sells,-sell)
bought.remove(sell)
heapq.heappush(sells,-buy)
print(profit)
#print(sells) | Title: Buy Low Sell High
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the *N* days you would like to again own zero shares, but want to have as much money as possible.
Input Specification:
Input begins with an integer *N* (2<=≤<=*N*<=≤<=3·105), the number of days.
Following this is a line with exactly *N* integers *p*1,<=*p*2,<=...,<=*p**N* (1<=≤<=*p**i*<=≤<=106). The price of one share of stock on the *i*-th day is given by *p**i*.
Output Specification:
Print the maximum amount of money you can end up with at the end of *N* days.
Demo Input:
['9\n10 5 4 7 9 12 6 2 10\n', '20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n']
Demo Output:
['20\n', '41\n']
Note:
In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20. | ```python
import heapq
n = int(input())
prices = [int(i) for i in input().split()]
#print(prices)
sells = [-prices[-1]]
bought = set()
profit = 0
for i in range(len(prices) - 2,-1,-1):
sell = -sells[0]
buy = prices[i]
if buy < sell:
heapq.heappop(sells)
profit += sell - buy
bought.add(buy)
if sell in bought:
heapq.heappush(sells,-sell)
bought.remove(sell)
heapq.heappush(sells,-buy)
print(profit)
#print(sells)
``` | 0 |
|
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,699,898,893 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 61 | 0 | n, h = map(int, input().split())
print(sum(2 if i > h else 1 for i in list(map(int, input().split()))))
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | ```python
n, h = map(int, input().split())
print(sum(2 if i > h else 1 for i in list(map(int, input().split()))))
``` | 3 |
Subsets and Splits